[patch] fix wrong behaviour of gn command

52 views
Skip to first unread message

Christian Brabandt

unread,
May 22, 2018, 2:24:30 AM5/22/18
to vim...@vim.org
Bram,
this patch fixes a problem with the gn command. This behaviour has been
noticed on https://vi.stackexchange.com/q/16276/71

It might happen, that the area being matched by the gn command is
actually not correct, because of the last search wrapping around and
matching at a previous match. Therefore, make sure to reset wrapscan
later and also check the return value of the last searchit() function.
If the last searchit() fails, try again from the position of the last
match before failing.

Patch contains a test, that currently fails.

Best,
Christian
--
Denn das Gemeine ist's eigentlich, was den Herren Natur heißt!
Aus sich schöpfen mag wohl heißen, mit dem eben fertig werden, was
uns bequem wird!
-- Goethe, Maximen und Reflektionen, Nr. 1143
0001-gn-might-select-the-wrong-match.patch

Bram Moolenaar

unread,
May 22, 2018, 11:51:34 AM5/22/18
to vim...@googlegroups.com, Christian Brabandt, vim...@vim.org

Christian wrote:

> this patch fixes a problem with the gn command. This behaviour has been
> noticed on https://vi.stackexchange.com/q/16276/71
>
> It might happen, that the area being matched by the gn command is
> actually not correct, because of the last search wrapping around and
> matching at a previous match. Therefore, make sure to reset wrapscan
> later and also check the return value of the last searchit() function.
> If the last searchit() fails, try again from the position of the last
> match before failing.
>
> Patch contains a test, that currently fails.

Thanks. I think the comment for "first_match" was wrong, I'll correct
that.


--
"Beware of bugs in the above code; I have only proved
it correct, not tried it." -- Donald Knuth

/// Bram Moolenaar -- Br...@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 ///
Reply all
Reply to author
Forward
0 new messages