comparison src/search.c @ 19475:5512aa74cb62 v8.2.0295

patch 8.2.0295: highlighting for :s wrong when using different separator Commit: https://github.com/vim/vim/commit/c036e87bd7001238ab7cc5d9e30e59bbf989a5fd Author: Bram Moolenaar <Bram@vim.org> Date: Fri Feb 21 21:30:52 2020 +0100 patch 8.2.0295: highlighting for :s wrong when using different separator Problem: Highlighting for :s wrong when using different separator. Solution: Use separat argument for search direction and separator. (Rob Pilling, closes #5665)
author Bram Moolenaar <Bram@vim.org>
date Fri, 21 Feb 2020 21:45:04 +0100
parents 6c944fee0d7e
children 5feb426d2ea1
comparison
equal deleted inserted replaced
19474:3e0b71dd3dc5 19475:5512aa74cb62
1185 */ 1185 */
1186 int 1186 int
1187 do_search( 1187 do_search(
1188 oparg_T *oap, // can be NULL 1188 oparg_T *oap, // can be NULL
1189 int dirc, // '/' or '?' 1189 int dirc, // '/' or '?'
1190 int search_delim, // the delimiter for the search, e.g. '%' in s%regex%replacement%
1190 char_u *pat, 1191 char_u *pat,
1191 long count, 1192 long count,
1192 int options, 1193 int options,
1193 searchit_arg_T *sia) // optional arguments or NULL 1194 searchit_arg_T *sia) // optional arguments or NULL
1194 { 1195 {
1283 int show_top_bot_msg = FALSE; 1284 int show_top_bot_msg = FALSE;
1284 1285
1285 searchstr = pat; 1286 searchstr = pat;
1286 dircp = NULL; 1287 dircp = NULL;
1287 // use previous pattern 1288 // use previous pattern
1288 if (pat == NULL || *pat == NUL || *pat == dirc) 1289 if (pat == NULL || *pat == NUL || *pat == search_delim)
1289 { 1290 {
1290 if (spats[RE_SEARCH].pat == NULL) // no previous pattern 1291 if (spats[RE_SEARCH].pat == NULL) // no previous pattern
1291 { 1292 {
1292 searchstr = spats[RE_SUBST].pat; 1293 searchstr = spats[RE_SUBST].pat;
1293 if (searchstr == NULL) 1294 if (searchstr == NULL)
1309 /* 1310 /*
1310 * Find end of regular expression. 1311 * Find end of regular expression.
1311 * If there is a matching '/' or '?', toss it. 1312 * If there is a matching '/' or '?', toss it.
1312 */ 1313 */
1313 ps = strcopy; 1314 ps = strcopy;
1314 p = skip_regexp(pat, dirc, (int)p_magic, &strcopy); 1315 p = skip_regexp(pat, search_delim, (int)p_magic, &strcopy);
1315 if (strcopy != ps) 1316 if (strcopy != ps)
1316 { 1317 {
1317 // made a copy of "pat" to change "\?" to "?" 1318 // made a copy of "pat" to change "\?" to "?"
1318 searchcmdlen += (int)(STRLEN(pat) - STRLEN(strcopy)); 1319 searchcmdlen += (int)(STRLEN(pat) - STRLEN(strcopy));
1319 pat = strcopy; 1320 pat = strcopy;
1320 searchstr = strcopy; 1321 searchstr = strcopy;
1321 } 1322 }
1322 if (*p == dirc) 1323 if (*p == search_delim)
1323 { 1324 {
1324 dircp = p; // remember where we put the NUL 1325 dircp = p; // remember where we put the NUL
1325 *p++ = NUL; 1326 *p++ = NUL;
1326 } 1327 }
1327 spats[0].off.line = FALSE; 1328 spats[0].off.line = FALSE;
1523 + SEARCH_MSG + SEARCH_START 1524 + SEARCH_MSG + SEARCH_START
1524 + ((pat != NULL && *pat == ';') ? 0 : SEARCH_NOOF))), 1525 + ((pat != NULL && *pat == ';') ? 0 : SEARCH_NOOF))),
1525 RE_LAST, sia); 1526 RE_LAST, sia);
1526 1527
1527 if (dircp != NULL) 1528 if (dircp != NULL)
1528 *dircp = dirc; // restore second '/' or '?' for normal_cmd() 1529 *dircp = search_delim; // restore second '/' or '?' for normal_cmd()
1529 1530
1530 if (!shortmess(SHM_SEARCH) 1531 if (!shortmess(SHM_SEARCH)
1531 && ((dirc == '/' && LT_POS(pos, curwin->w_cursor)) 1532 && ((dirc == '/' && LT_POS(pos, curwin->w_cursor))
1532 || (dirc == '?' && LT_POS(curwin->w_cursor, pos)))) 1533 || (dirc == '?' && LT_POS(curwin->w_cursor, pos))))
1533 show_top_bot_msg = TRUE; 1534 show_top_bot_msg = TRUE;
1604 */ 1605 */
1605 if (!(options & SEARCH_OPT) || pat == NULL || *pat != ';') 1606 if (!(options & SEARCH_OPT) || pat == NULL || *pat != ';')
1606 break; 1607 break;
1607 1608
1608 dirc = *++pat; 1609 dirc = *++pat;
1610 search_delim = dirc;
1609 if (dirc != '?' && dirc != '/') 1611 if (dirc != '?' && dirc != '/')
1610 { 1612 {
1611 retval = 0; 1613 retval = 0;
1612 emsg(_("E386: Expected '?' or '/' after ';'")); 1614 emsg(_("E386: Expected '?' or '/' after ';'"));
1613 goto end_do_search; 1615 goto end_do_search;