Hi JohnBeckett!
On Mo, 14 Dez 2015, JohnBeckett wrote:
> Christian Brabandt wrote:
> > ...
> > A fix is attached, but it is ugly.
>
> Thanks! I applied the patch and did some tests trying to break
> it, but it works well.
I think, the attached patch is slightly better (more consistent and does
not mix 2 different search functions).
> I don't understand the code, but I can see that:
>
> flag + SEARCH_KEEP + SEARCH_END
>
> works because of the possible values in flag, and '+' is how it
> was done earlier in "SEARCH_KEEP + flag", but why not replace
> each '+' with '|'?
I believe I did this, because this seemed to be the style used for the
searchit() function elsewhere, so I kept this style for consistency.
Best,
Christian
--
In der Weltpolitik spritzt mancher, der sich als Feuerwehrmann
ausgibt, mit Benzin.
-- Bertrand A. W. Russell
--
--
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
---
You received this message because you are subscribed to the Google Groups
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.
diff --git a/src/search.c b/src/search.c
--- a/src/search.c
+++ b/src/search.c
@@ -4753,7 +4753,7 @@ current_search(count, forward)
}
/*
- * Check if the pattern is one character or zero-width.
+ * Check if the pattern is one character long or zero-width.
* If move is TRUE, check from the beginning of the buffer, else from the
* current cursor position.
* Returns TRUE, FALSE or -1 for failure.
@@ -4770,6 +4770,9 @@ is_one_char(pattern, move)
int save_called_emsg = called_emsg;
int flag = 0;
+ if (pattern == NULL)
+ pattern = spats[last_idx].pat;
+
if (search_regcomp(pattern, RE_SEARCH, RE_SEARCH,
SEARCH_KEEP, ®match) == FAIL)
return -1;
@@ -4784,22 +4787,30 @@ is_one_char(pattern, move)
flag = SEARCH_START;
}
- if (searchit(curwin, curbuf, &pos, FORWARD, spats[last_idx].pat, 1,
+ if (searchit(curwin, curbuf, &pos, FORWARD, pattern, 1,
SEARCH_KEEP + flag, RE_SEARCH, 0, NULL) != FAIL)
{
/* Zero-width pattern should match somewhere, then we can check if
* start and end are in the same position. */
called_emsg = FALSE;
- nmatched = vim_regexec_multi(®match, curwin, curbuf,
- pos.lnum, (colnr_T)0, NULL);
+ do
+ {
+ regmatch.startpos[0].col++;
+ nmatched = vim_regexec_multi(®match, curwin, curbuf,
+ pos.lnum, regmatch.startpos[0].col, NULL);
+ if (!nmatched)
+ break;
+ } while (regmatch.startpos[0].col < pos.col);
if (!called_emsg)
+ {
result = (nmatched != 0
&& regmatch.startpos[0].lnum == regmatch.endpos[0].lnum
&& regmatch.startpos[0].col == regmatch.endpos[0].col);
-
- if (!result && inc(&pos) >= 0 && pos.col == regmatch.endpos[0].col)
- result = TRUE;
+ /* one char width */
+ if (!result && inc(&pos) >= 0 && pos.col == regmatch.endpos[0].col)
+ result = TRUE;
+ }
}
called_emsg |= save_called_emsg;
diff --git a/src/testdir/test53.in b/src/testdir/test53.in
--- a/src/testdir/test53.in
+++ b/src/testdir/test53.in
@@ -53,6 +53,7 @@ dit
:put =match('abc', '\zs', 2, 1) " 2
:put =match('abc', '\zs', 3, 1) " 3
:put =match('abc', '\zs', 4, 1) " -1
+:" Tests for gn
/^foobar
gncsearchmatch/one\_s*two\_s
:1
@@ -82,6 +83,9 @@ ggdgn.
gggUgn.
gg/a:0\@!\zs\d\+
nygnop
+/^abc x
+0/x
+cgn'x'..
:/^start:/,/^end:/wq! test.out
ENDTEST
@@ -131,4 +135,5 @@ Depp
--4
Depp
--5
+abc x def x ghi x jkl
end:
diff --git a/src/testdir/test53.ok b/src/testdir/test53.ok
--- a/src/testdir/test53.ok
+++ b/src/testdir/test53.ok
@@ -68,4 +68,5 @@ DEPP
--4
DEPP
--5
+abc 'x' def 'x' ghi 'x' jkl
end: