PATCH: improve b:match_words pattern

Doug Kearns dougkearns at gmail.com
Sat Sep 10 03:13:08 EDT 2005


On Thu, Sep 08, 2005 at 01:06:31AM +1000, Doug Kearns wrote:
> This improves the b:match_words pattern. Among other things, it now
> handles the if/unless/while/until/rescue modifiers.
> 
> It could be refined but the patterns largely match those in the syntax
> file which is useful for updating purposes and does no harm.

Except searchpairs() doesn't work the way I thought it did so multiline
patterns are difficult to implement and probably not worth the effort
right now. This means something like:

if true
  x.
  end
end

won't work. Strangely enough I can only find one example of this at the
moment but in the past I've come across a significant number and
received a bug report against the syntax file.

The pattern below does not attempt to handle loops with the optional do
properly yet. So you can currently only jump between the 'do and 'end'
in this example. If anyone has more experience with matchit and has a
solution please let me know. Loops without the 'do' should work as
expected.

for ... do
  ...
end

Most of the problems in these config files seem to stem from this
optional do...

Regards,
Doug


Index: ftplugin/ruby.vim
===================================================================
RCS file: /var/cvs/vim-ruby/vim-ruby/ftplugin/ruby.vim,v
retrieving revision 1.9
diff -u -r1.9 ruby.vim
--- ftplugin/ruby.vim	8 Sep 2005 08:22:40 -0000	1.9
+++ ftplugin/ruby.vim	9 Sep 2005 12:09:22 -0000
@@ -28,11 +28,23 @@
 " Matchit support
 if exists("loaded_matchit") && !exists("b:match_words")
   let b:match_ignorecase = 0
-  let b:match_words =
-     \ '\%(\%(\%(^\|[;=]\)\s*\)\@<=\%(class\|module\|while\|begin\|until' .
-     \ '\|for\|if\|unless\|def\|case\)\|\<do\)\>:' .
-     \ '\<\%(else\|elsif\|ensure\|rescue\|when\)\>:' .
-     \ '\%(^\|[^.]\)\@<=\<end\>'
+
+ " TODO: improve optional do loops
+ let b:match_words =
+    \ '\%(' .
+    \     '\%(\%(\.\|\:\:\)\s*\)\@<!\<\%(class\|module\|begin\|def\|case\|for\|do\)\>' .
+    \   '\|' .
+    \     '\%(\%(^\|\.\.\.\=\|[\,;=([<>~\*/%!&^|+-]\)\s*\)\@<=\%(if\|unless\|until\|while\)\>' .
+    \ '\)' .
+    \ ':' .
+    \ '\%(' .
+    \     '\%(\%(\.\|\:\:\)\s*\)\@<!\<\%(else\|elsif\|ensure\|when\)\>' .
+    \   '\|' .
+    \     '\%(\%(^\|;\)\s*\)\@<=\<rescue\>' .
+    \ '\)' .
+    \ ':' .
+    \ '\%(\%(\.\|\:\:\)\s*\)\@<!\<end\>'
+
   let b:match_skip =
      \ "synIDattr(synID(line('.'),col('.'),0),'name') =~ '" .
      \ "\\<ruby\\%(String\\|StringDelimiter\\|ASCIICode\\|Interpolation\\|" .


More information about the vim-ruby-devel mailing list