bug: matchparen.vim changing cursor position on brace

71 views
Skip to first unread message

Martin Kunev

unread,
Feb 9, 2016, 7:39:21 AM2/9/16
to vim_dev
I'm using vim 7.4.1229 on Gentoo.

In input mode, navigating near braces changes cursor position unexpectedly.

I enter the following code in a new file:

if (a)
{
}

In input mode, navigating up from column 2 on the last line moves the cursor to column 1 on the previous line (before the curly brace).

Commenting the lines related to getcurpos() in matchparen.vim fixes the problem.

Christian Brabandt

unread,
Feb 9, 2016, 11:58:34 AM2/9/16
to vim_dev
Hi Martin!
Can you check, if this patch fixes it?

diff --git a/src/eval.c b/src/eval.c
--- a/src/eval.c
+++ b/src/eval.c
@@ -12449,8 +12449,11 @@ getpos_both(
#endif
(varnumber_T)0);
if (getcurpos)
+ {
+ update_curswant();
list_append_number(l, curwin->w_curswant == MAXCOL ?
(varnumber_T)MAXCOL : (varnumber_T)curwin->w_curswant + 1);
+ }
}
else
rettv->vval.v_number = FALSE;



Best,
Christian
--
Stilblüten aus Polizeiberichten und Gerichtsverhandlungen:
Wie man hört, ist die Genannte ausgezogen. Sie war eine gewisse Zeit
in Bad H. wo sie als eine Leiche galt.

Martin Kunev

unread,
Feb 9, 2016, 12:32:45 PM2/9/16
to vim_dev
Hi Christian

Yes, this fixed the bug.

Bram Moolenaar

unread,
Feb 9, 2016, 3:25:21 PM2/9/16
to Martin Kunev, vim_dev
I see the problem. It looks like it's not caused by matchparen, but
getcurpos() returns the wrong curswant when doing "a" on the "}".
If you get there in another way it usually works OK.

OK, found the problem, will send out a patch.

--
hundred-and-one symptoms of being an internet addict:
200. You really believe in the concept of a "paperless" office.

/// 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 ///

Bram Moolenaar

unread,
Feb 9, 2016, 4:53:17 PM2/9/16
to Christian Brabandt, vim_dev
Only noticed this after sending out my fix. We could do both of them.

I was trying to write a test for the fix, but autocommands are not
triggered when there is typeahead. We probably need some kind of
special support for tests to pretend there is no typeahead. Perhaps
inserting some special character, e.g. "\<Wait>". Would work a bit like
<Nop> but make char_avail() return false.

--
hundred-and-one symptoms of being an internet addict:
202. You're amazed to find out Spam is a food.

Christian Brabandt

unread,
Feb 10, 2016, 2:42:04 PM2/10/16
to vim_dev
Hi Bram!

On Di, 09 Feb 2016, Bram Moolenaar wrote:

> Only noticed this after sending out my fix. We could do both of them.
>
> I was trying to write a test for the fix, but autocommands are not
> triggered when there is typeahead. We probably need some kind of
> special support for tests to pretend there is no typeahead. Perhaps
> inserting some special character, e.g. "\<Wait>". Would work a bit like
> <Nop> but make char_avail() return false.


I rather not mess with getchar.c as long as I am not sure, how to
correctly test this. I trust you more in this regards.

Best,
Christian
--
Wie man sein Kind nicht nennen sollte:
Otto Versand

Bram Moolenaar

unread,
Feb 10, 2016, 4:23:37 PM2/10/16
to Christian Brabandt, vim_dev

Christian Brabandt wrote:

> On Di, 09 Feb 2016, Bram Moolenaar wrote:
>
> > Only noticed this after sending out my fix. We could do both of them.
> >
> > I was trying to write a test for the fix, but autocommands are not
> > triggered when there is typeahead. We probably need some kind of
> > special support for tests to pretend there is no typeahead. Perhaps
> > inserting some special character, e.g. "\<Wait>". Would work a bit like
> > <Nop> but make char_avail() return false.
>
> I rather not mess with getchar.c as long as I am not sure, how to
> correctly test this. I trust you more in this regards.

Looking at vgetorpeek() it's going to be tricky. It returns one byte at
a time and a special key takes three bytes. Checking for a specific
special key would require advancing, but some special keys are handled
in vgetc().

It's simpler to make char_avail() return false.

call disable_char_avail_for_testing(1)
exe "normal ..."
call disable_char_avail_for_testing(0)

Ugly but straightforward.

Oh, I found that your solution to call update_curswant() in getcurpos()
makes Test_move_cursor() fail. Still seems like your change was good,
perhaps the test is wrong? Yes, it's checking the old version of
curswant.

--
'Psychologist' -- Someone who looks at everyone else when
an attractive woman enters the room.
Reply all
Reply to author
Forward
0 new messages