To: vim_dev@googlegroups.com Subject: Patch 8.2.4724 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.2.4724 Problem: Current instance of last search pattern not easily spotted. Solution: Add CurSearch highlighting. (closes #10133) Files: runtime/doc/options.txt, runtime/doc/syntax.txt, src/highlight.c, src/match.c, src/normal.c, src/optiondefs.h, src/structs.h, src/vim.h, src/normal.c, src/testdir/test_search.vim, src/testdir/dumps/Test_hlsearch_cursearch_multiple_line.dump, src/testdir/dumps/Test_hlsearch_cursearch_single_line_1.dump, src/testdir/dumps/Test_hlsearch_cursearch_single_line_2.dump, src/testdir/dumps/Test_hlsearch_cursearch_single_line_3.dump *** ../vim-8.2.4723/runtime/doc/options.txt 2022-04-07 12:39:03.983973910 +0100 --- runtime/doc/options.txt 2022-04-09 20:24:08.859204648 +0100 *************** *** 4143,4148 **** --- 4165,4171 ---- |hl-ErrorMsg| e error messages h (obsolete, ignored) |hl-IncSearch| i 'incsearch' highlighting + |hl-CurSearch| y current instance of last search pattern |hl-Search| l last search pattern highlighting (see 'hlsearch') |hl-MoreMsg| m |more-prompt| |hl-ModeMsg| M Mode (e.g., "-- INSERT --") *** ../vim-8.2.4723/runtime/doc/syntax.txt 2021-11-27 17:21:54.085161469 +0000 --- runtime/doc/syntax.txt 2022-04-09 20:24:08.859204648 +0100 *************** *** 5242,5247 **** --- 5318,5325 ---- *hl-Search* Search Last search pattern highlighting (see 'hlsearch'). Also used for similar items that need to stand out. + *hl-CurSearch* + CurSearch Current match for the last search pattern (see 'hlsearch'). *hl-SpecialKey* SpecialKey Meta and special keys listed with ":map", also for text used to show unprintable characters in the text, 'listchars'. *** ../vim-8.2.4723/src/highlight.c 2022-04-04 15:16:50.738014123 +0100 --- src/highlight.c 2022-04-09 20:24:08.859204648 +0100 *************** *** 157,162 **** --- 157,163 ---- "default link QuickFixLine Search", "default link CursorLineSign SignColumn", "default link CursorLineFold FoldColumn", + "default link CurSearch Search", CENT("Normal cterm=NONE", "Normal gui=NONE"), NULL }; *** ../vim-8.2.4723/src/match.c 2022-04-04 15:16:50.738014123 +0100 --- src/match.c 2022-04-09 20:24:08.859204648 +0100 *************** *** 652,657 **** --- 652,658 ---- shl = &cur->hl; shl->startcol = MAXCOL; shl->endcol = MAXCOL; + shl->lines = 0; shl->attr_cur = 0; shl->is_addpos = FALSE; if (cur != NULL) *************** *** 674,679 **** --- 675,684 ---- shl->endcol = shl->rm.endpos[0].col; else shl->endcol = MAXCOL; + if (shl->rm.endpos[0].lnum != shl->rm.startpos[0].lnum) + shl->lines = shl->rm.endpos[0].lnum - shl->rm.startpos[0].lnum; + else + shl->lines = 1; // Highlight one character for an empty match. if (shl->startcol == shl->endcol) { *************** *** 768,773 **** --- 773,789 ---- else *has_match_conc = 0; # endif + // Highlight the match were the cursor is using the CurSearch + // group. + if (shl == search_hl + && wp->w_cursor.lnum >= shl->lnum + && wp->w_cursor.lnum < shl->lnum + shl->lines + && wp->w_cursor.col >= shl->startcol + && wp->w_cursor.col < shl->endcol) + { + shl->attr_cur = HL_ATTR(HLF_LC); + } + } else if (col == shl->endcol) { *** ../vim-8.2.4723/src/normal.c 2022-04-09 18:17:30.056746549 +0100 --- src/normal.c 2022-04-09 20:47:57.826468977 +0100 *************** *** 4153,4158 **** --- 4153,4159 ---- ? 0 : SEARCH_MARK, NULL); } + /* * Handle "N" and "n" commands. * cap->arg is SEARCH_REV for "N", 0 for "n". *************** *** 4173,4178 **** --- 4174,4185 ---- (void)normal_search(cap, 0, NULL, SEARCH_MARK | cap->arg, NULL); cap->count1 -= 1; } + + #ifdef FEAT_SEARCH_EXTRA + // Redraw the window to refresh the highlighted matches. + if (i > 0 && p_hls && !no_hlsearch) + redraw_later(SOME_VALID); + #endif } /* *************** *** 4190,4195 **** --- 4197,4203 ---- { int i; searchit_arg_T sia; + pos_T prev_cursor = curwin->w_cursor; cap->oap->motion_type = MCHAR; cap->oap->inclusive = FALSE; *************** *** 4213,4218 **** --- 4221,4231 ---- foldOpenCursor(); #endif } + #ifdef FEAT_SEARCH_EXTRA + // Redraw the window to refresh the highlighted matches. + if (!EQUAL_POS(curwin->w_cursor, prev_cursor) && p_hls && !no_hlsearch) + redraw_later(SOME_VALID); + #endif // "/$" will put the cursor after the end of the line, may need to // correct that here *** ../vim-8.2.4723/src/optiondefs.h 2022-04-07 12:39:03.987973874 +0100 --- src/optiondefs.h 2022-04-09 20:24:08.859204648 +0100 *************** *** 299,305 **** # define ISP_LATIN1 (char_u *)"@,161-255" #endif ! # define HIGHLIGHT_INIT "8:SpecialKey,~:EndOfBuffer,@:NonText,d:Directory,e:ErrorMsg,i:IncSearch,l:Search,m:MoreMsg,M:ModeMsg,n:LineNr,a:LineNrAbove,b:LineNrBelow,N:CursorLineNr,G:CursorLineSign,O:CursorLineFold,r:Question,s:StatusLine,S:StatusLineNC,c:VertSplit,t:Title,v:Visual,V:VisualNOS,w:WarningMsg,W:WildMenu,f:Folded,F:FoldColumn,A:DiffAdd,C:DiffChange,D:DiffDelete,T:DiffText,>:SignColumn,-:Conceal,B:SpellBad,P:SpellCap,R:SpellRare,L:SpellLocal,+:Pmenu,=:PmenuSel,x:PmenuSbar,X:PmenuThumb,*:TabLine,#:TabLineSel,_:TabLineFill,!:CursorColumn,.:CursorLine,o:ColorColumn,q:QuickFixLine,z:StatusLineTerm,Z:StatusLineTermNC" // Default python version for pyx* commands #if defined(FEAT_PYTHON) && defined(FEAT_PYTHON3) --- 299,305 ---- # define ISP_LATIN1 (char_u *)"@,161-255" #endif ! # define HIGHLIGHT_INIT "8:SpecialKey,~:EndOfBuffer,@:NonText,d:Directory,e:ErrorMsg,i:IncSearch,l:Search,y:CurSearch,m:MoreMsg,M:ModeMsg,n:LineNr,a:LineNrAbove,b:LineNrBelow,N:CursorLineNr,G:CursorLineSign,O:CursorLineFold,r:Question,s:StatusLine,S:StatusLineNC,c:VertSplit,t:Title,v:Visual,V:VisualNOS,w:WarningMsg,W:WildMenu,f:Folded,F:FoldColumn,A:DiffAdd,C:DiffChange,D:DiffDelete,T:DiffText,>:SignColumn,-:Conceal,B:SpellBad,P:SpellCap,R:SpellRare,L:SpellLocal,+:Pmenu,=:PmenuSel,x:PmenuSbar,X:PmenuThumb,*:TabLine,#:TabLineSel,_:TabLineFill,!:CursorColumn,.:CursorLine,o:ColorColumn,q:QuickFixLine,z:StatusLineTerm,Z:StatusLineTermNC" // Default python version for pyx* commands #if defined(FEAT_PYTHON) && defined(FEAT_PYTHON3) *** ../vim-8.2.4723/src/structs.h 2022-04-08 15:17:53.071952540 +0100 --- src/structs.h 2022-04-09 20:24:08.863204639 +0100 *************** *** 3329,3334 **** --- 3329,3335 ---- // found match (may continue in next line) buf_T *buf; // the buffer to search for a match linenr_T lnum; // the line to search for a match + linenr_T lines; // number of lines starting from lnum int attr; // attributes to be used for a match int attr_cur; // attributes currently active in win_line() linenr_T first_lnum; // first lnum to search for multi-line pat *** ../vim-8.2.4723/src/vim.h 2022-04-08 15:17:53.071952540 +0100 --- src/vim.h 2022-04-09 20:24:08.863204639 +0100 *************** *** 1410,1415 **** --- 1410,1416 ---- , HLF_H // obsolete, ignored , HLF_I // incremental search , HLF_L // last search string + , HLF_LC // last search string under cursor , HLF_M // "--More--" message , HLF_CM // Mode (e.g., "-- INSERT --") , HLF_N // line number for ":number" and ":#" commands *************** *** 1457,1463 **** // The HL_FLAGS must be in the same order as the HLF_ enums! // When changing this also adjust the default for 'highlight'. ! #define HL_FLAGS {'8', '~', '@', 'd', 'e', 'h', 'i', 'l', 'm', 'M', \ 'n', 'a', 'b', 'N', 'G', 'O', 'r', 's', 'S', 'c', 't', 'v', 'V', \ 'w', 'W', 'f', 'F', 'A', 'C', 'D', 'T', '-', '>', \ 'B', 'P', 'R', 'L', \ --- 1458,1464 ---- // The HL_FLAGS must be in the same order as the HLF_ enums! // When changing this also adjust the default for 'highlight'. ! #define HL_FLAGS {'8', '~', '@', 'd', 'e', 'h', 'i', 'l', 'y', 'm', 'M', \ 'n', 'a', 'b', 'N', 'G', 'O', 'r', 's', 'S', 'c', 't', 'v', 'V', \ 'w', 'W', 'f', 'F', 'A', 'C', 'D', 'T', '-', '>', \ 'B', 'P', 'R', 'L', \ *** ../vim-8.2.4723/src/normal.c 2022-04-09 18:17:30.056746549 +0100 --- src/normal.c 2022-04-09 20:47:57.826468977 +0100 *************** *** 4153,4158 **** --- 4153,4159 ---- ? 0 : SEARCH_MARK, NULL); } + /* * Handle "N" and "n" commands. * cap->arg is SEARCH_REV for "N", 0 for "n". *************** *** 4173,4178 **** --- 4174,4185 ---- (void)normal_search(cap, 0, NULL, SEARCH_MARK | cap->arg, NULL); cap->count1 -= 1; } + + #ifdef FEAT_SEARCH_EXTRA + // Redraw the window to refresh the highlighted matches. + if (i > 0 && p_hls && !no_hlsearch) + redraw_later(SOME_VALID); + #endif } /* *************** *** 4190,4195 **** --- 4197,4203 ---- { int i; searchit_arg_T sia; + pos_T prev_cursor = curwin->w_cursor; cap->oap->motion_type = MCHAR; cap->oap->inclusive = FALSE; *************** *** 4213,4218 **** --- 4221,4231 ---- foldOpenCursor(); #endif } + #ifdef FEAT_SEARCH_EXTRA + // Redraw the window to refresh the highlighted matches. + if (!EQUAL_POS(curwin->w_cursor, prev_cursor) && p_hls && !no_hlsearch) + redraw_later(SOME_VALID); + #endif // "/$" will put the cursor after the end of the line, may need to // correct that here *** ../vim-8.2.4723/src/testdir/test_search.vim 2022-01-02 16:16:30.523363109 +0000 --- src/testdir/test_search.vim 2022-04-09 20:54:41.786417621 +0100 *************** *** 1038,1043 **** --- 1038,1071 ---- bwipe! endfunc + func Test_hlsearch_cursearch() + CheckScreendump + + let lines =<< trim END + set hlsearch scrolloff=0 + call setline(1, ['one', 'foo', 'bar', 'baz', 'foo', 'bar']) + hi Search ctermbg=yellow + hi CurSearch ctermbg=blue + END + call writefile(lines, 'Xhlsearch_cursearch') + let buf = RunVimInTerminal('-S Xhlsearch_cursearch', {'rows': 9, 'cols': 60}) + + call term_sendkeys(buf, "gg/foo\") + call VerifyScreenDump(buf, 'Test_hlsearch_cursearch_single_line_1', {}) + + call term_sendkeys(buf, "n") + call VerifyScreenDump(buf, 'Test_hlsearch_cursearch_single_line_2', {}) + + call term_sendkeys(buf, "?\") + call VerifyScreenDump(buf, 'Test_hlsearch_cursearch_single_line_3', {}) + + call term_sendkeys(buf, "gg/foo\\nbar\") + call VerifyScreenDump(buf, 'Test_hlsearch_cursearch_multiple_line', {}) + + call StopVimInTerminal(buf) + call delete('Xhlsearch_cursearch') + endfunc + " Similar to Test_incsearch_substitute() but with a screendump halfway. func Test_incsearch_substitute_dump() CheckOption incsearch *** ../vim-8.2.4723/src/testdir/dumps/Test_hlsearch_cursearch_multiple_line.dump 2022-04-09 20:59:22.786332386 +0100 --- src/testdir/dumps/Test_hlsearch_cursearch_multiple_line.dump 2022-04-09 20:57:03.766378022 +0100 *************** *** 0 **** --- 1,9 ---- + |o+0&#ffffff0|n|e| @56 + >f+0࿈ff13|o@1| | +0&#ffffff0@55 + |b+0࿈ff13|a|r| +0&#ffffff0@56 + |b|a|z| @56 + |f+0&#ffff4012|o@1| | +0&#ffffff0@55 + |b+0&#ffff4012|a|r| +0&#ffffff0@56 + |~+0#4040ff13&| @58 + |~| @58 + |/+0#0000000&|f|o@1|\|n|b|a|r| @32|2|,|1| @10|A|l@1| *** ../vim-8.2.4723/src/testdir/dumps/Test_hlsearch_cursearch_single_line_1.dump 2022-04-09 20:59:22.790332384 +0100 --- src/testdir/dumps/Test_hlsearch_cursearch_single_line_1.dump 2022-04-09 20:54:47.962416075 +0100 *************** *** 0 **** --- 1,9 ---- + |o+0&#ffffff0|n|e| @56 + >f+0࿈ff13|o@1| +0&#ffffff0@56 + |b|a|r| @56 + |b|a|z| @56 + |f+0&#ffff4012|o@1| +0&#ffffff0@56 + |b|a|r| @56 + |~+0#4040ff13&| @58 + |~| @58 + |/+0#0000000&|f|o@1| @37|2|,|1| @10|A|l@1| *** ../vim-8.2.4723/src/testdir/dumps/Test_hlsearch_cursearch_single_line_2.dump 2022-04-09 20:59:22.794332382 +0100 --- src/testdir/dumps/Test_hlsearch_cursearch_single_line_2.dump 2022-04-09 20:54:49.026415804 +0100 *************** *** 0 **** --- 1,9 ---- + |o+0&#ffffff0|n|e| @56 + |f+0&#ffff4012|o@1| +0&#ffffff0@56 + |b|a|r| @56 + |b|a|z| @56 + >f+0࿈ff13|o@1| +0&#ffffff0@56 + |b|a|r| @56 + |~+0#4040ff13&| @58 + |~| @58 + |/+0#0000000&|f|o@1| @37|5|,|1| @10|A|l@1| *** ../vim-8.2.4723/src/testdir/dumps/Test_hlsearch_cursearch_single_line_3.dump 2022-04-09 20:59:22.798332379 +0100 --- src/testdir/dumps/Test_hlsearch_cursearch_single_line_3.dump 2022-04-09 20:54:50.090415534 +0100 *************** *** 0 **** --- 1,9 ---- + |o+0&#ffffff0|n|e| @56 + >f+0࿈ff13|o@1| +0&#ffffff0@56 + |b|a|r| @56 + |b|a|z| @56 + |f+0&#ffff4012|o@1| +0&#ffffff0@56 + |b|a|r| @56 + |~+0#4040ff13&| @58 + |~| @58 + |?+0#0000000&|f|o@1| @37|2|,|1| @10|A|l@1| *** ../vim-8.2.4723/src/version.c 2022-04-09 18:17:30.060746546 +0100 --- src/version.c 2022-04-09 20:26:12.351967927 +0100 *************** *** 748,749 **** --- 748,751 ---- { /* Add new patch number below this line */ + /**/ + 4724, /**/ -- Kiss me twice. I'm schizophrenic. /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// \\\ \\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///