To: vim_dev@googlegroups.com Subject: Patch 8.2.0295 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.2.0295 Problem: Highlighting for :s wrong when using different separator. Solution: Use separat argument for search direction and separator. (Rob Pilling, closes #5665) Files: src/ex_docmd.c, src/ex_getln.c, src/gui.c, src/normal.c, src/proto/search.pro, src/quickfix.c, src/search.c, src/spell.c, src/tag.c, src/testdir/dumps/Test_incsearch_substitute_15.dump, src/testdir/test_search.vim *** ../vim-8.2.0294/src/ex_docmd.c 2020-02-18 21:32:55.850340488 +0100 --- src/ex_docmd.c 2020-02-21 21:18:43.930882073 +0100 *************** *** 3671,3677 **** curwin->w_cursor.col = 0; searchcmdlen = 0; flags = silent ? 0 : SEARCH_HIS | SEARCH_MSG; ! if (!do_search(NULL, c, cmd, 1L, flags, NULL)) { curwin->w_cursor = pos; cmd = NULL; --- 3671,3677 ---- curwin->w_cursor.col = 0; searchcmdlen = 0; flags = silent ? 0 : SEARCH_HIS | SEARCH_MSG; ! if (!do_search(NULL, c, c, cmd, 1L, flags, NULL)) { curwin->w_cursor = pos; cmd = NULL; *** ../vim-8.2.0294/src/ex_getln.c 2019-12-14 16:18:11.578458401 +0100 --- src/ex_getln.c 2020-02-21 21:18:43.930882073 +0100 *************** *** 184,190 **** * May change the last search pattern. */ static int ! do_incsearch_highlighting(int firstc, incsearch_state_T *is_state, int *skiplen, int *patlen) { char_u *cmd; --- 184,190 ---- * May change the last search pattern. */ static int ! do_incsearch_highlighting(int firstc, int *search_delim, incsearch_state_T *is_state, int *skiplen, int *patlen) { char_u *cmd; *************** *** 210,216 **** --- 210,219 ---- search_last_line = MAXLNUM; if (firstc == '/' || firstc == '?') + { + *search_delim = firstc; return TRUE; + } if (firstc != ':') return FALSE; *************** *** 273,278 **** --- 276,282 ---- p = skipwhite(p); delim = (delim_optional && vim_isIDc(*p)) ? ' ' : *p++; + *search_delim = delim; end = skip_regexp(p, delim, p_magic, NULL); use_last_pat = end == p && *end == delim; *************** *** 385,396 **** int next_char; int use_last_pat; int did_do_incsearch = is_state->did_incsearch; // Parsing range may already set the last search pattern. // NOTE: must call restore_last_search_pattern() before returning! save_last_search_pattern(); ! if (!do_incsearch_highlighting(firstc, is_state, &skiplen, &patlen)) { restore_last_search_pattern(); finish_incsearch_highlighting(FALSE, is_state, TRUE); --- 389,401 ---- int next_char; int use_last_pat; int did_do_incsearch = is_state->did_incsearch; + int search_delim; // Parsing range may already set the last search pattern. // NOTE: must call restore_last_search_pattern() before returning! save_last_search_pattern(); ! if (!do_incsearch_highlighting(firstc, &search_delim, is_state, &skiplen, &patlen)) { restore_last_search_pattern(); finish_incsearch_highlighting(FALSE, is_state, TRUE); *************** *** 457,463 **** vim_memset(&sia, 0, sizeof(sia)); sia.sa_tm = &tm; #endif ! found = do_search(NULL, firstc == ':' ? '/' : firstc, ccline.cmdbuff + skiplen, count, search_flags, #ifdef FEAT_RELTIME &sia --- 462,468 ---- vim_memset(&sia, 0, sizeof(sia)); sia.sa_tm = &tm; #endif ! found = do_search(NULL, firstc == ':' ? '/' : firstc, search_delim, ccline.cmdbuff + skiplen, count, search_flags, #ifdef FEAT_RELTIME &sia *************** *** 565,576 **** int search_flags = SEARCH_NOOF; int i; int save; // Parsing range may already set the last search pattern. // NOTE: must call restore_last_search_pattern() before returning! save_last_search_pattern(); ! if (!do_incsearch_highlighting(firstc, is_state, &skiplen, &patlen)) { restore_last_search_pattern(); return OK; --- 570,582 ---- int search_flags = SEARCH_NOOF; int i; int save; + int search_delim; // Parsing range may already set the last search pattern. // NOTE: must call restore_last_search_pattern() before returning! save_last_search_pattern(); ! if (!do_incsearch_highlighting(firstc, &search_delim, is_state, &skiplen, &patlen)) { restore_last_search_pattern(); return OK; *************** *** 581,587 **** return FAIL; } ! if (firstc == ccline.cmdbuff[skiplen]) { pat = last_search_pattern(); skiplen = 0; --- 587,593 ---- return FAIL; } ! if (search_delim == ccline.cmdbuff[skiplen]) { pat = last_search_pattern(); skiplen = 0; *************** *** 668,680 **** static int may_add_char_to_search(int firstc, int *c, incsearch_state_T *is_state) { ! int skiplen, patlen; // Parsing range may already set the last search pattern. // NOTE: must call restore_last_search_pattern() before returning! save_last_search_pattern(); ! if (!do_incsearch_highlighting(firstc, is_state, &skiplen, &patlen)) { restore_last_search_pattern(); return FAIL; --- 674,686 ---- static int may_add_char_to_search(int firstc, int *c, incsearch_state_T *is_state) { ! int skiplen, patlen, search_delim; // Parsing range may already set the last search pattern. // NOTE: must call restore_last_search_pattern() before returning! save_last_search_pattern(); ! if (!do_incsearch_highlighting(firstc, &search_delim, is_state, &skiplen, &patlen)) { restore_last_search_pattern(); return FAIL; *************** *** 693,699 **** // the character to lowercase. if (p_ic && p_scs && !pat_has_uppercase(ccline.cmdbuff + skiplen)) *c = MB_TOLOWER(*c); ! if (*c == firstc || vim_strchr((char_u *)( p_magic ? "\\~^$.*[" : "\\^$"), *c) != NULL) { // put a backslash before special characters --- 699,705 ---- // the character to lowercase. if (p_ic && p_scs && !pat_has_uppercase(ccline.cmdbuff + skiplen)) *c = MB_TOLOWER(*c); ! if (*c == search_delim || vim_strchr((char_u *)( p_magic ? "\\~^$.*[" : "\\^$"), *c) != NULL) { // put a backslash before special characters *** ../vim-8.2.0294/src/gui.c 2020-01-26 21:59:25.624718145 +0100 --- src/gui.c 2020-02-21 21:18:43.930882073 +0100 *************** *** 5374,5380 **** i = msg_scroll; if (down) { ! (void)do_search(NULL, '/', ga.ga_data, 1L, searchflags, NULL); } else { --- 5374,5380 ---- i = msg_scroll; if (down) { ! (void)do_search(NULL, '/', '/', ga.ga_data, 1L, searchflags, NULL); } else { *************** *** 5382,5388 **** // direction p = vim_strsave_escaped(ga.ga_data, (char_u *)"?"); if (p != NULL) ! (void)do_search(NULL, '?', p, 1L, searchflags, NULL); vim_free(p); } --- 5382,5388 ---- // direction p = vim_strsave_escaped(ga.ga_data, (char_u *)"?"); if (p != NULL) ! (void)do_search(NULL, '?', '?', p, 1L, searchflags, NULL); vim_free(p); } *** ../vim-8.2.0294/src/normal.c 2020-01-26 21:59:25.628718127 +0100 --- src/normal.c 2020-02-21 21:18:43.930882073 +0100 *************** *** 4304,4310 **** curwin->w_set_curswant = TRUE; vim_memset(&sia, 0, sizeof(sia)); ! i = do_search(cap->oap, dir, pat, cap->count1, opt | SEARCH_OPT | SEARCH_ECHO | SEARCH_MSG, &sia); if (wrapped != NULL) *wrapped = sia.sa_wrapped; --- 4304,4310 ---- curwin->w_set_curswant = TRUE; vim_memset(&sia, 0, sizeof(sia)); ! i = do_search(cap->oap, dir, dir, pat, cap->count1, opt | SEARCH_OPT | SEARCH_ECHO | SEARCH_MSG, &sia); if (wrapped != NULL) *wrapped = sia.sa_wrapped; *** ../vim-8.2.0294/src/proto/search.pro 2020-02-12 22:15:14.856205206 +0100 --- src/proto/search.pro 2020-02-21 21:18:43.934882059 +0100 *************** *** 24,30 **** void last_pat_prog(regmmatch_T *regmatch); int searchit(win_T *win, buf_T *buf, pos_T *pos, pos_T *end_pos, int dir, char_u *pat, long count, int options, int pat_use, searchit_arg_T *extra_arg); void set_search_direction(int cdir); ! int do_search(oparg_T *oap, int dirc, char_u *pat, long count, int options, searchit_arg_T *sia); int search_for_exact_line(buf_T *buf, pos_T *pos, int dir, char_u *pat); int searchc(cmdarg_T *cap, int t_cmd); pos_T *findmatch(oparg_T *oap, int initc); --- 24,30 ---- void last_pat_prog(regmmatch_T *regmatch); int searchit(win_T *win, buf_T *buf, pos_T *pos, pos_T *end_pos, int dir, char_u *pat, long count, int options, int pat_use, searchit_arg_T *extra_arg); void set_search_direction(int cdir); ! int do_search(oparg_T *oap, int dirc, int search_delim, char_u *pat, long count, int options, searchit_arg_T *sia); int search_for_exact_line(buf_T *buf, pos_T *pos, int dir, char_u *pat); int searchc(cmdarg_T *cap, int t_cmd); pos_T *findmatch(oparg_T *oap, int initc); *** ../vim-8.2.0294/src/quickfix.c 2020-02-15 23:06:40.826770264 +0100 --- src/quickfix.c 2020-02-21 21:18:43.934882059 +0100 *************** *** 3197,3203 **** // Move the cursor to the first line in the buffer save_cursor = curwin->w_cursor; curwin->w_cursor.lnum = 0; ! if (!do_search(NULL, '/', qf_pattern, (long)1, SEARCH_KEEP, NULL)) curwin->w_cursor = save_cursor; } } --- 3197,3203 ---- // Move the cursor to the first line in the buffer save_cursor = curwin->w_cursor; curwin->w_cursor.lnum = 0; ! if (!do_search(NULL, '/', '/', qf_pattern, (long)1, SEARCH_KEEP, NULL)) curwin->w_cursor = save_cursor; } } *** ../vim-8.2.0294/src/search.c 2020-02-12 22:15:14.856205206 +0100 --- src/search.c 2020-02-21 21:18:43.934882059 +0100 *************** *** 1187,1192 **** --- 1187,1193 ---- do_search( oparg_T *oap, // can be NULL int dirc, // '/' or '?' + int search_delim, // the delimiter for the search, e.g. '%' in s%regex%replacement% char_u *pat, long count, int options, *************** *** 1285,1291 **** searchstr = pat; dircp = NULL; // use previous pattern ! if (pat == NULL || *pat == NUL || *pat == dirc) { if (spats[RE_SEARCH].pat == NULL) // no previous pattern { --- 1286,1292 ---- searchstr = pat; dircp = NULL; // use previous pattern ! if (pat == NULL || *pat == NUL || *pat == search_delim) { if (spats[RE_SEARCH].pat == NULL) // no previous pattern { *************** *** 1311,1317 **** * If there is a matching '/' or '?', toss it. */ ps = strcopy; ! p = skip_regexp(pat, dirc, (int)p_magic, &strcopy); if (strcopy != ps) { // made a copy of "pat" to change "\?" to "?" --- 1312,1318 ---- * If there is a matching '/' or '?', toss it. */ ps = strcopy; ! p = skip_regexp(pat, search_delim, (int)p_magic, &strcopy); if (strcopy != ps) { // made a copy of "pat" to change "\?" to "?" *************** *** 1319,1325 **** pat = strcopy; searchstr = strcopy; } ! if (*p == dirc) { dircp = p; // remember where we put the NUL *p++ = NUL; --- 1320,1326 ---- pat = strcopy; searchstr = strcopy; } ! if (*p == search_delim) { dircp = p; // remember where we put the NUL *p++ = NUL; *************** *** 1525,1531 **** RE_LAST, sia); if (dircp != NULL) ! *dircp = dirc; // restore second '/' or '?' for normal_cmd() if (!shortmess(SHM_SEARCH) && ((dirc == '/' && LT_POS(pos, curwin->w_cursor)) --- 1526,1532 ---- RE_LAST, sia); if (dircp != NULL) ! *dircp = search_delim; // restore second '/' or '?' for normal_cmd() if (!shortmess(SHM_SEARCH) && ((dirc == '/' && LT_POS(pos, curwin->w_cursor)) *************** *** 1606,1611 **** --- 1607,1613 ---- break; dirc = *++pat; + search_delim = dirc; if (dirc != '?' && dirc != '/') { retval = 0; *** ../vim-8.2.0294/src/spell.c 2020-01-26 21:59:25.632718110 +0100 --- src/spell.c 2020-02-21 21:18:43.934882059 +0100 *************** *** 2861,2867 **** curwin->w_cursor.lnum = 0; while (!got_int) { ! if (do_search(NULL, '/', frompat, 1L, SEARCH_KEEP, NULL) == 0 || u_save_cursor() == FAIL) break; --- 2861,2867 ---- curwin->w_cursor.lnum = 0; while (!got_int) { ! if (do_search(NULL, '/', '/', frompat, 1L, SEARCH_KEEP, NULL) == 0 || u_save_cursor() == FAIL) break; *** ../vim-8.2.0294/src/tag.c 2020-01-30 14:55:29.010670407 +0100 --- src/tag.c 2020-02-21 21:18:43.934882059 +0100 *************** *** 3543,3549 **** else // start search before first line curwin->w_cursor.lnum = 0; ! if (do_search(NULL, pbuf[0], pbuf + 1, (long)1, search_options, NULL)) retval = OK; else --- 3543,3549 ---- else // start search before first line curwin->w_cursor.lnum = 0; ! if (do_search(NULL, pbuf[0], pbuf[0], pbuf + 1, (long)1, search_options, NULL)) retval = OK; else *************** *** 3555,3561 **** * try again, ignore case now */ p_ic = TRUE; ! if (!do_search(NULL, pbuf[0], pbuf + 1, (long)1, search_options, NULL)) { /* --- 3555,3561 ---- * try again, ignore case now */ p_ic = TRUE; ! if (!do_search(NULL, pbuf[0], pbuf[0], pbuf + 1, (long)1, search_options, NULL)) { /* *************** *** 3566,3578 **** cc = *tagp.tagname_end; *tagp.tagname_end = NUL; sprintf((char *)pbuf, "^%s\\s\\*(", tagp.tagname); ! if (!do_search(NULL, '/', pbuf, (long)1, search_options, NULL)) { // Guess again: "^char * \ @7 *** ../vim-8.2.0294/src/testdir/test_search.vim 2020-02-18 21:54:36.982093690 +0100 --- src/testdir/test_search.vim 2020-02-21 21:18:43.934882059 +0100 *************** *** 1084,1089 **** --- 1084,1113 ---- call delete('Xis_subst_script') endfunc + func Test_incsearch_highlighting() + if !exists('+incsearch') + return + endif + if !CanRunVimInTerminal() + throw 'Skipped: cannot make screendumps' + endif + + call writefile([ + \ 'set incsearch hlsearch', + \ 'call setline(1, "hello/there")', + \ ], 'Xis_subst_hl_script') + let buf = RunVimInTerminal('-S Xis_subst_hl_script', {'rows': 4, 'cols': 20}) + " Give Vim a chance to redraw to get rid of the spaces in line 2 caused by + " the 'ambiwidth' check. + sleep 300m + + " Using a different search delimiter should still highlight matches + " that contain a '/'. + call term_sendkeys(buf, ":%s;ello/the") + call VerifyScreenDump(buf, 'Test_incsearch_substitute_15', {}) + call term_sendkeys(buf, "") + endfunc + func Test_incsearch_with_change() if !has('timers') || !exists('+incsearch') || !CanRunVimInTerminal() throw 'Skipped: cannot make screendumps and/or timers feature and/or incsearch option missing' *** ../vim-8.2.0294/src/version.c 2020-02-21 18:41:49.249885543 +0100 --- src/version.c 2020-02-21 21:30:11.172073034 +0100 *************** *** 740,741 **** --- 740,743 ---- { /* Add new patch number below this line */ + /**/ + 295, /**/ -- I AM THANKFUL... ...for the piles of laundry and ironing because it means I have plenty of clothes to wear. /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\ \\\ an exciting new programming language -- http://www.Zimbu.org /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///