PATCH: one line module, class and method definitions

Doug Kearns djkea2 at mugca.its.monash.edu.au
Tue Sep 9 16:12:29 EDT 2003


This improves highlighting of one line module, class and method
definitions.

I've also fixed a minor bug in which some peculiarly formatted class
definitions were highlighted as the start of a heredoc.

Regards,
Doug

Index: syntax/ruby.vim
===================================================================
RCS file: /var/cvs/vim-ruby/vim-ruby/syntax/ruby.vim,v
retrieving revision 1.16
diff -u -r1.16 ruby.vim
--- syntax/ruby.vim	8 Sep 2003 15:39:09 -0000	1.16
+++ syntax/ruby.vim	9 Sep 2003 05:01:03 -0000
@@ -165,24 +165,26 @@
   syn region rubyString matchgroup=rubyStringDelimit start=+<<\(EOF\|'EOF'\|"EOF"\|`EOF`\)+hs=s+2		   end=+^EOF$+	    contains=rubyExprSubst fold
   syn region rubyString matchgroup=rubyStringDelimit start=+<<\(EOS\|'EOS'\|"EOS"\|`EOS`\)+hs=s+2		   end=+^EOS$+	    contains=rubyExprSubst fold
 else
-  syn region rubyString matchgroup=rubyStringDelimit start=+\(class\s*\|\(\.\|::\)\_s*\)\@<!<<\z(\h\w*\)\ze\s*$+hs=s+2 end=+^\z1$+ contains=rubyExprSubst fold
-  syn region rubyString matchgroup=rubyStringDelimit start=+\(class\s*\|\(\.\|::\)\_s*\)\@<!<<"\z(.*\)"\ze\s*$+hs=s+2  end=+^\z1$+ contains=rubyExprSubst fold
-  syn region rubyString matchgroup=rubyStringDelimit start=+\(class\s*\|\(\.\|::\)\_s*\)\@<!<<'\z(.*\)'\ze\s*$+hs=s+2  end=+^\z1$+			       fold
-  syn region rubyString matchgroup=rubyStringDelimit start=+\(class\s*\|\(\.\|::\)\_s*\)\@<!<<`\z(.*\)`\ze\s*$+hs=s+2  end=+^\z1$+ contains=rubyExprSubst fold
-
-  syn region rubyString matchgroup=rubyStringDelimit start=+\(class\s*\|\(\.\|::\)\_s*\)\@<!<<-\z(\h\w*\)\ze\s*$+hs=s+3 end=+^\s*\zs\z1$+ contains=rubyExprSubst fold
-  syn region rubyString matchgroup=rubyStringDelimit start=+\(class\s*\|\(\.\|::\)\_s*\)\@<!<<-"\z(.*\)"\ze\s*$+hs=s+3  end=+^\s*\zs\z1$+ contains=rubyExprSubst fold
-  syn region rubyString matchgroup=rubyStringDelimit start=+\(class\s*\|\(\.\|::\)\_s*\)\@<!<<-'\z(.*\)'\ze\s*$+hs=s+3  end=+^\s*\zs\z1$+			      fold
-  syn region rubyString matchgroup=rubyStringDelimit start=+\(class\s*\|\(\.\|::\)\_s*\)\@<!<<-`\z(.*\)`\ze\s*$+hs=s+3  end=+^\s*\zs\z1$+ contains=rubyExprSubst fold
+  syn region rubyString matchgroup=rubyStringDelimit start=+\(\(class\s*\|\(\.\|::\)\)\_s*\)\@<!<<\z(\h\w*\)\ze\s*$+hs=s+2 end=+^\z1$+ contains=rubyExprSubst fold
+  syn region rubyString matchgroup=rubyStringDelimit start=+\(\(class\s*\|\(\.\|::\)\)\_s*\)\@<!<<"\z(.*\)"\ze\s*$+hs=s+2  end=+^\z1$+ contains=rubyExprSubst fold
+  syn region rubyString matchgroup=rubyStringDelimit start=+\(\(class\s*\|\(\.\|::\)\)\_s*\)\@<!<<'\z(.*\)'\ze\s*$+hs=s+2  end=+^\z1$+			      fold
+  syn region rubyString matchgroup=rubyStringDelimit start=+\(\(class\s*\|\(\.\|::\)\)\_s*\)\@<!<<`\z(.*\)`\ze\s*$+hs=s+2  end=+^\z1$+ contains=rubyExprSubst fold
+
+  syn region rubyString matchgroup=rubyStringDelimit start=+\(\(class\s*\|\(\.\|::\)\)\_s*\)\@<!<<-\z(\h\w*\)\ze\s*$+hs=s+3 end=+^\s*\zs\z1$+ contains=rubyExprSubst fold
+  syn region rubyString matchgroup=rubyStringDelimit start=+\(\(class\s*\|\(\.\|::\)\)\_s*\)\@<!<<-"\z(.*\)"\ze\s*$+hs=s+3  end=+^\s*\zs\z1$+ contains=rubyExprSubst fold
+  syn region rubyString matchgroup=rubyStringDelimit start=+\(\(class\s*\|\(\.\|::\)\)\_s*\)\@<!<<-'\z(.*\)'\ze\s*$+hs=s+3  end=+^\s*\zs\z1$+			     fold
+  syn region rubyString matchgroup=rubyStringDelimit start=+\(\(class\s*\|\(\.\|::\)\)\_s*\)\@<!<<-`\z(.*\)`\ze\s*$+hs=s+3  end=+^\s*\zs\z1$+ contains=rubyExprSubst fold
 endif
 
 " Expensive Mode - colorize *end* according to opening statement
 if !exists("ruby_no_expensive")
-  syn region rubyFunction      matchgroup=rubyDefine start="^\s*def\s" matchgroup=NONE end="\ze\(\s\|(\|;\|$\)" skip="\.\|\(::\)" oneline fold
-  syn region rubyClassOrModule matchgroup=rubyDefine start="^\s*\(class\|module\)\s"   end="<\|$\|;\|\>"he=e-1 oneline fold
-
-  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
+  syn region rubyFunction matchgroup=rubyDefine start="\<def\s\+"    end="\ze\(\s\|(\|;\|$\)" oneline
+  syn region rubyClass    matchgroup=rubyDefine start="\<class\s\+"  end="\ze\(\s\|<\|;\|$\)" oneline
+  syn region rubyModule   matchgroup=rubyDefine start="\<module\s\+" end="\ze\(\s\|;\|$\)"    oneline
+
+  syn region rubyBlock start="\<def\>"    matchgroup=rubyDefine end="\(^\|;\)\s*\zs\<end\>" contains=ALLBUT,rubyExprSubst,rubyTodo nextgroup=rubyFunction fold
+  syn region rubyBlock start="\<class\>"  matchgroup=rubyDefine end="\(^\|;\)\s*\zs\<end\>" contains=ALLBUT,rubyExprSubst,rubyTodo nextgroup=rubyClass    fold
+  syn region rubyBlock start="\<module\>" matchgroup=rubyDefine end="\(^\|;\)\s*\zs\<end\>" contains=ALLBUT,rubyExprSubst,rubyTodo nextgroup=rubyModule   fold
 
   " modifiers
   syn match  rubyControl "\<\(if\|unless\|while\|until\)\>"
@@ -208,8 +210,9 @@
   exec "syn sync minlines=" . ruby_minlines
 
 else
-  syn region  rubyFunction      matchgroup=rubyControl start="^\s*def\s" matchgroup=NONE end="\ze\(\s\|(\|;\|$\)" skip="\.\|\(::\)" oneline fold
-  syn region  rubyClassOrModule matchgroup=rubyControl start="^\s*\(class\|module\)\s"   end="<\|$\|;\|\>"he=e-1 oneline fold
+  syn region  rubyFunction matchgroup=rubyDefine start="\<def\s\+"    end="\ze\(\s\|(\|;\|$\)" oneline
+  syn region  rubyClass    matchgroup=rubyDefine start="\<class\s\+"  end="\ze\(\s\|<\|;\|$\)" oneline
+  syn region  rubyModule   matchgroup=rubyDefine start="\<module\s\+" end="\ze\(\s\|;\|$\)"    oneline
   syn keyword rubyControl case begin do for if unless while until end
 endif
 
@@ -277,7 +280,8 @@
   HiLink rubyNumber			Number
   HiLink rubyBoolean			Boolean
   HiLink rubyException			Exception
-  HiLink rubyClassOrModule		Type
+  HiLink rubyClass			Type
+  HiLink rubyModule			Type
   HiLink rubyIdentifier			Identifier
   HiLink rubyClassVariable		rubyIdentifier
   HiLink rubyConstant			rubyIdentifier


More information about the vim-ruby-devel mailing list