mirror of
https://github.com/vim/vim.git
synced 2025-09-28 04:24:06 -04:00
updated for version 7.3.625
Problem: "gn" does not handle zero-width matches correctly. Solution: Handle zero-width patterns specially. (Christian Brabandt)
This commit is contained in:
38
src/search.c
38
src/search.c
@@ -4546,6 +4546,9 @@ current_search(count, forward)
|
|||||||
int visual_active = FALSE;
|
int visual_active = FALSE;
|
||||||
int flags = 0;
|
int flags = 0;
|
||||||
pos_T save_VIsual;
|
pos_T save_VIsual;
|
||||||
|
regmmatch_T regmatch;
|
||||||
|
int nmatched = 0;
|
||||||
|
int zerowidth = FALSE;
|
||||||
|
|
||||||
|
|
||||||
/* wrapping should not occur */
|
/* wrapping should not occur */
|
||||||
@@ -4580,6 +4583,24 @@ current_search(count, forward)
|
|||||||
else
|
else
|
||||||
orig_pos = pos = start_pos = curwin->w_cursor;
|
orig_pos = pos = start_pos = curwin->w_cursor;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Check for zero-width pattern.
|
||||||
|
*/
|
||||||
|
if (search_regcomp(spats[last_idx].pat, RE_SEARCH, RE_SEARCH,
|
||||||
|
((SEARCH_HIS + SEARCH_KEEP)), ®match) == FAIL)
|
||||||
|
return FAIL;
|
||||||
|
|
||||||
|
/* Zero-width pattern should match somewhere, then we can check if start
|
||||||
|
* and end are in the same position. */
|
||||||
|
nmatched = vim_regexec_multi(®match, curwin, curbuf,
|
||||||
|
curwin->w_cursor.lnum, (colnr_T)0, NULL);
|
||||||
|
if (called_emsg)
|
||||||
|
return FAIL;
|
||||||
|
if (nmatched && regmatch.startpos[0].lnum == regmatch.endpos[0].lnum
|
||||||
|
&& regmatch.endpos[0].col == regmatch.startpos[0].col)
|
||||||
|
zerowidth = TRUE;
|
||||||
|
vim_free(regmatch.regprog);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The trick is to first search backwards and then search forward again,
|
* The trick is to first search backwards and then search forward again,
|
||||||
* so that a match at the current cursor position will be correctly
|
* so that a match at the current cursor position will be correctly
|
||||||
@@ -4587,17 +4608,18 @@ current_search(count, forward)
|
|||||||
*/
|
*/
|
||||||
for (i = 0; i < 2; i++)
|
for (i = 0; i < 2; i++)
|
||||||
{
|
{
|
||||||
if (i && count == 1)
|
|
||||||
flags = SEARCH_START;
|
|
||||||
|
|
||||||
if (forward)
|
if (forward)
|
||||||
dir = i;
|
dir = i;
|
||||||
else
|
else
|
||||||
dir = !i;
|
dir = !i;
|
||||||
|
|
||||||
|
flags = 0;
|
||||||
|
if (!dir && !zerowidth)
|
||||||
|
flags = SEARCH_END;
|
||||||
|
|
||||||
result = searchit(curwin, curbuf, &pos, (dir ? FORWARD : BACKWARD),
|
result = searchit(curwin, curbuf, &pos, (dir ? FORWARD : BACKWARD),
|
||||||
spats[last_idx].pat, (long) (i ? count : 1),
|
spats[last_idx].pat, (long) (i ? count : 1),
|
||||||
SEARCH_KEEP | flags | (dir ? 0 : SEARCH_END),
|
SEARCH_KEEP | flags, RE_SEARCH, 0, NULL);
|
||||||
RE_SEARCH, 0, NULL);
|
|
||||||
|
|
||||||
/* First search may fail, but then start searching from the
|
/* First search may fail, but then start searching from the
|
||||||
* beginning of the file (cursor might be on the search match)
|
* beginning of the file (cursor might be on the search match)
|
||||||
@@ -4629,9 +4651,11 @@ current_search(count, forward)
|
|||||||
}
|
}
|
||||||
|
|
||||||
start_pos = pos;
|
start_pos = pos;
|
||||||
flags = (forward ? SEARCH_END : 0);
|
flags = forward ? SEARCH_END : 0;
|
||||||
|
|
||||||
/* move to match */
|
/* move to match, except for zero-width matches, in which case, we are
|
||||||
|
* already on the next match */
|
||||||
|
if (!zerowidth)
|
||||||
result = searchit(curwin, curbuf, &pos, (forward ? FORWARD : BACKWARD),
|
result = searchit(curwin, curbuf, &pos, (forward ? FORWARD : BACKWARD),
|
||||||
spats[last_idx].pat, 0L, flags | SEARCH_KEEP, RE_SEARCH, 0, NULL);
|
spats[last_idx].pat, 0L, flags | SEARCH_KEEP, RE_SEARCH, 0, NULL);
|
||||||
|
|
||||||
|
@@ -714,6 +714,8 @@ static char *(features[]) =
|
|||||||
|
|
||||||
static int included_patches[] =
|
static int included_patches[] =
|
||||||
{ /* Add new patch number below this line */
|
{ /* Add new patch number below this line */
|
||||||
|
/**/
|
||||||
|
625,
|
||||||
/**/
|
/**/
|
||||||
624,
|
624,
|
||||||
/**/
|
/**/
|
||||||
|
Reference in New Issue
Block a user