PATCH: prevent the optional 'do' in loop constructs from matching a do/end code block

Doug Kearns djkea2 at mugca.its.monash.edu.au
Tue Sep 2 20:33:42 EDT 2003


This prevents the optional 'do' in loop constructs from matching the
start of a do/end code block, it also adds support for matching the new
optional ':'.

Code like,

    def join_nowait(*threads)
            threads.flatten!
            @threads.concat threads
            for th in threads do
                    Thread.start(th) do |t|
                            t.join
                            @wait_queue.push t
                    end
            end
    end

should now be highlighted and fold properly.

BTW, does anyone know why the optional ':' was introduced?

Regards,
Doug

Index: syntax/ruby.vim
===================================================================
RCS file: /var/cvs/vim-ruby/vim-ruby/syntax/ruby.vim,v
retrieving revision 1.13
diff -u -r1.13 ruby.vim
--- syntax/ruby.vim	28 Aug 2003 14:36:01 -0000	1.13
+++ syntax/ruby.vim	2 Sep 2003 09:40:16 -0000
@@ -184,11 +184,11 @@
   syn region rubyBlock start="^\s*def\s\+"rs=s		   matchgroup=rubyDefine end="\<end\>" contains=ALLBUT,rubyExprSubst,rubyTodo nextgroup=rubyFunction fold
   syn region rubyBlock start="^\s*\(class\|module\)\>"rs=s matchgroup=rubyDefine end="\<end\>" contains=ALLBUT,rubyExprSubst,rubyTodo nextgroup=rubyClassOrModule fold
 
-  " modifiers + redundant *do*
-  syn match  rubyControl "\<\(if\|unless\|while\|until\|do\)\>"
+  " modifiers
+  syn match  rubyControl "\<\(if\|unless\|while\|until\)\>"
 
   " *do* requiring *end*
-  syn region rubyDoBlock matchgroup=rubyControl start="\<do\>" end="\<end\>" contains=ALLBUT,rubyExprSubst,rubyTodo fold
+  syn region rubyDoBlock matchgroup=rubyControl start="\(\<\(for\|until\|while\)\s.*\s\)\@<!do\>" end="\<end\>" contains=ALLBUT,rubyExprSubst,rubyTodo fold
 
   " *{* requiring *}*
   syn region rubyCurlyBlock start="{" end="}" contains=ALLBUT,rubyExprSubst,rubyTodo fold
@@ -198,6 +198,9 @@
 
   " statement with optional *do*
   syn region rubyOptDoBlock matchgroup=rubyControl start="\<for\>" start="^\s*\(while\|until\)\>" start=";\s*\(while\|until\)\>"hs=s+1 end="\<end\>" contains=ALLBUT,rubyExprSubst,rubyTodo fold
+  
+  " optional *do*
+  syn match  rubyControl "\(\<\(for\|until\|while\)\s.*\s\)\@<=\(do\|:\)\>"
 
   if !exists("ruby_minlines")
     let ruby_minlines = 50


More information about the vim-ruby-devel mailing list