Hi Andy!
On Mi, 25 Jul 2012, Andy Wokula wrote:
> Am 25.07.2012 15:06, schrieb Bram Moolenaar:
> >Patch 7.3.610
> >Problem: Cannot operate on the text that a search pattern matches.
> >Solution: Add the "gn" and "gN" commands. (Christian Brabandt)
> >Files: runtime/doc/index.txt, runtime/doc/visual.txt, src/normal.c,
> > src/proto/search.pro, src/search.c, src/testdir/test53.in,
> > src/testdir/test53.ok
>
> * zero-width patterns
> /$
> dgn
> joins lines (intended?)
>
> /^
> dgn
> deletes the current line, up to and including the first char of the
> next line
>
> /\zs
> dgn
> deletes 3 characters
Attached patch, should catch correctly zero-width patterns.
regards,
Christian
--
--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
diff --git a/src/search.c b/src/search.c
--- a/src/search.c
+++ b/src/search.c
@@ -3418,6 +3418,9 @@
int visual_active = FALSE;
int flags = 0;
pos_T save_VIsual;
+ regmmatch_T regmatch;
+ int nmatched = 0;
+ int zerowidth = FALSE;
/* wrapping should not occur */
@@ -3452,6 +3455,25 @@
else
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 everywhere... */
+ 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 == 0
+ && regmatch.endpos[0].lnum == 0
+ && 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,
* so that a match at the current cursor position will be correctly
@@ -3459,17 +3481,22 @@
*/
for (i = 0; i < 2; i++)
{
- if (i && count == 1)
- flags = SEARCH_START;
+ /* if (i && count == 1))
+ flags = SEARCH_START; */
if (forward)
dir = i;
else
dir = !i;
+
+ flags = 0;
+
+ if (!dir && !zerowidth)
+ flags = SEARCH_END;
+
result = searchit(curwin, curbuf, &pos, (dir ? FORWARD : BACKWARD),
spats[last_idx].pat, (long) (i ? count : 1),
- SEARCH_KEEP | flags | (dir ? 0 : SEARCH_END),
- RE_SEARCH, 0, NULL);
+ SEARCH_KEEP | flags, RE_SEARCH, 0, NULL);
/* First search may fail, but then start searching from the
* beginning of the file (cursor might be on the search match)
@@ -3500,10 +3527,14 @@
}
start_pos = pos;
- flags = (forward ? SEARCH_END : 0);
-
- /* move to match */
- result = searchit(curwin, curbuf, &pos, (forward ? FORWARD : BACKWARD),
+ flags = 0;
+
+ if (forward)
+ flags |= SEARCH_END;
+
+ if (!zerowidth)
+ /* move to match, except for zero-width matches, in which case, we are already on the next match */
+ result = searchit(curwin, curbuf, &pos, (forward ? FORWARD : BACKWARD),
spats[last_idx].pat, 0L, flags | SEARCH_KEEP, RE_SEARCH, 0, NULL);
if (!VIsual_active)