PATCH: improve b:match_words pattern

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

PATCH: improve b:match_words pattern

Doug Kearns
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.

Regards,
Doug


Index: ftplugin/ruby.vim
===================================================================
RCS file: /var/cvs/vim-ruby/vim-ruby/ftplugin/ruby.vim,v
retrieving revision 1.8
diff -u -r1.8 ruby.vim
--- ftplugin/ruby.vim 2 Sep 2005 14:45:32 -0000 1.8
+++ ftplugin/ruby.vim 7 Sep 2005 14:50:53 -0000
@@ -28,11 +28,24 @@
 " Matchit support
 if exists("loaded_matchit") && !exists("b:match_words")
   let b:match_ignorecase = 0
+  " TODO: improve optional do loops
   let b:match_words =
-     \ '\%(\%(\%(^\|[;=]\)\s*\)\@<=\%(class\|module\|while\|begin\|until' .
-     \ '\|for\|if\|unless\|def\|case\)\|\<do\)\>:' .
-     \ '\<\%(else\|elsif\|ensure\|rescue\|when\)\>:' .
-     \ '\%(^\|[^.]\)\@<=\<end\>'
+     \ '\%(' .
+     \     '\%(\%(\%(\.\@<!\.\)\|\:\:\)\_s*\)\@<!\<\%(class\|module\|begin\|def\|case\|for\|do\)\>' .
+     \   '\|' .
+     \     '\%(\%(^\|\.\.\.\=\|[;=([<>~\*/%!&^|+-]\)\s*\)\@<=\%(if\|unless\)\>' .
+     \   '\|' .
+     \     '\%(\%(^\|;\)\s*\)\@<=\%(until\|while\)\>' .
+     \ '\)' .
+     \ ':' .
+     \ '\%(' .
+     \     '\%(\%(\%(\.\@<!\.\)\|\:\:\)\_s*\)\@<!\<\%(else\|elsif\|ensure\|when\)\>' .
+     \   '\|' .
+     \     '\%(\%(^\|;\)\s*\)\@<=\<rescue\>' .
+     \ '\)' .
+     \ ':' .
+     \ '\%(\%(\%(\.\@<!\.\)\|\:\:\)\_s*\)\@<!\<end\>' .
+     \ ',=begin:=end'
   let b:match_skip =
      \ "synIDattr(synID(line('.'),col('.'),0),'name') =~ '" .
      \ "\<ruby\%(String\|StringDelimiter\|ASCIICode\|Interpolation\|" .
_______________________________________________
vim-ruby-devel mailing list
[hidden email]
http://rubyforge.org/mailman/listinfo/vim-ruby-devel
Reply | Threaded
Open this post in threaded view
|

Re: PATCH: improve b:match_words pattern

Doug Kearns
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\\|" .
_______________________________________________
vim-ruby-devel mailing list
[hidden email]
http://rubyforge.org/mailman/listinfo/vim-ruby-devel