Matchit confuses :function and function()

11 views
Skip to first unread message

Tony Mechelynck

unread,
Jul 26, 2020, 9:26:31 AM7/26/20
to Bram Moolenaar, Christian Brabandt, vim_dev
Not sure how easy this will be to fix; I just noticed it. Also not
sure of whether the problem is in matchit.vim, in
$VIMRUNTIME/ftplugin/vim.vim, or in both.

Software in use:
Vim or gvim, Big version, 8.2.1296
$VIMRUNTIME/pack/dist/opt/matchit/plugin/matchit.vim version 1.17
dated 2019 Oct 24
$VIMRUNTIME/pack/dist/opt/matchit/autoload/matchit.vim (Last change
Mar 01, 2020)
$VIMRUNTIME/ftplugin/vim.vim (Last change 2020 Jul 06)

The bug is exhibited, for example, when viewing the CSApprox.vim
plugin version 4.00 dated 14 Sep 2012; this is the latest version at
vim.org: https://www.vim.org/scripts/script.php?script_id=2390
On my installation: ~/.vim/plugin/CSApprox.vim line 437

With matchit enabled, when viewing a Vim script where the function()
function is used within the range of a function definition (between
:function and :endfunction), hiting % on that :endfunction statement
goes to the function() invocation and vice-versa; hitting % on that
:function command does nothing.

The problem is of course due to the fact that b:match_words (for the
"vim" filetype) recognises "function" but does not skip "function(".

I'm attaching a proposed patch. Please check it, I haven't written
complex regular expressions in a long time.

Best regards,
Tony.
vim_matchwords.diff

Bram Moolenaar

unread,
Jul 26, 2020, 10:43:04 AM7/26/20
to vim...@googlegroups.com, Tony Mechelynck, Bram Moolenaar, Christian Brabandt
Thanks for pointing out. I think a simpler way is to add [^(], that is:
match anything but a paren. A quick test shows that this works.


--
How many light bulbs does it take to change a person?

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

Tony Mechelynck

unread,
Jul 26, 2020, 11:58:47 AM7/26/20
to Bram Moolenaar, vim_dev, Christian Brabandt
According to the help it requires one character, while )\@! matches
with zero length. The construct

function
\ foobar(...)

would be matched by the one but not by the other, but maybe it is a
marginal case that can be ignored? Also, the given regexp ends (after
the \%( \) group) with \> ; I thought that in

function foobar(x,y)

the space after "function" (or the first space, if several) would not
be seen as _followed_ by an end-of-word? (That space is, IIUC, what
[^(] matches)

Best regards,
Tony.

Tony Mechelynck

unread,
Jul 26, 2020, 12:40:08 PM7/26/20
to Bram Moolenaar, vim_dev, Christian Brabandt
Hadn't seen that the [^(] was added after the \>. That's clever.

The next line starts with a space followed by a tab. My patch took
care of that but I should have mentioned it more explicitly.

Line-continuation betwen "function" and the function name makes % not
work — the marginal case I already mentioned.

Thanks!
Best regards,
Tony.
Reply all
Reply to author
Forward
0 new messages