Skip to content

Commit 7a429a5

Browse files
committed
indent/eruby.vim and syntax/ruby.vim
1 parent 227751f commit 7a429a5

3 files changed

Lines changed: 44 additions & 30 deletions

File tree

ChangeLog

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
2007-02-22 Tim Pope <vim@tpope.info>
2+
3+
* indent/eruby.vim: Fixed an edge case.
4+
* syntax/ruby.vim: Simpler method and class declaration highlighting.
5+
Changed some contains=ALLBUT,... to contains=TOP. Altered some
6+
highlight links: rubyConstant is now Type; rubySymbol is now Constant.
7+
New groups like rubyLoop and rubyCondition.
8+
19
2007-02-22 Doug Kearns <dougkearns@gmail.com>
210

311
* syntax/ruby.vim: highlight short format interpolated variables

indent/eruby.vim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ function! GetErubyIndent(lnum)
3131
call cursor(a:lnum,1)
3232
let inruby = searchpair('<%','','%>')
3333
call cursor(a:lnum,vcol)
34-
if inruby
34+
if inruby && getline(a:lnum) !~ '^<%'
3535
let ind = GetRubyIndent()
3636
else
3737
let ind = HtmlIndentGet(a:lnum)

syntax/ruby.vim

Lines changed: 35 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ endif
4343
syn match rubyEscape "\\\\\|\\[abefnrstv]\|\\\o\{1,3}\|\\x\x\{1,2}" contained display
4444
syn match rubyEscape "\%(\\M-\\C-\|\\C-\\M-\|\\M-\\c\|\\c\\M-\|\\c\|\\C-\|\\M-\)\%(\\\o\{1,3}\|\\x\x\{1,2}\|\\\=\S\)" contained display
4545
syn region rubyInterpolated matchgroup=rubyInterpolation start="#{" end="}" contains=TOP contained
46+
"syn match rubyInterpolation "#\%(\$\|@@\=\)\w\+" contained contains=rubyInstanceVariable,rubyClassVariable,rubyGlobalVariable display
4647
syn match rubyInterpolation "#\ze\%(\$\|@@\=\)\w\+" contained display nextgroup=rubyClassVariable,rubyInstanceVariable,rubyGlobalVariable
4748
syn match rubyNoInterpolation "\\#{[^}]*}" contained
4849
syn match rubyNoInterpolation "\\#\%(\$\|@@\=\)\w\+" contained display
@@ -70,7 +71,7 @@ syn match rubyFloat "\<\%(0\|[1-9]\d*\%(_\d\+\)*\)\%(\.\d\+\%(_\d\+\)*\)\=\%([eE
7071
syn match rubyLocalVariableOrMethod "\<[_[:lower:]][_[:alnum:]]*[?!=]\=" contains=NONE display transparent
7172
syn match rubyBlockArgument "&[_[:lower:]][_[:alnum:]]" contains=NONE display transparent
7273

73-
syn match rubyConstant "\%(\%(\.\@<!\.\)\@<!\<\|::\)\_s*\zs\u\w*\>\%(\s*(\)\@!"
74+
syn match rubyConstant "\%(\%([.@$]\@<!\.\)\@<!\<\|::\)\_s*\zs\u\w*\>\%(\s*(\)\@!"
7475
syn match rubyClassVariable "@@\h\w*" display
7576
syn match rubyInstanceVariable "@\h\w*" display
7677
syn match rubyGlobalVariable "$\%(\h\w*\|-.\)"
@@ -148,50 +149,54 @@ if exists('main_syntax') && main_syntax == 'eruby'
148149
let b:ruby_no_expensive = 1
149150
end
150151

152+
syn match rubyMethodDeclaration "[_[:alnum:]@$][^[:space:];#(]*" contained contains=rubyFunction,rubyConstant,rubyBoolean,rubyPseudoVariable,rubyInstanceVariable,rubyClassVariable,rubyGlobalVariable
153+
syn match rubyClassDeclaration "[_[:alnum:]@$][^[:space:];#(]*" contained contains=rubyConstant
154+
syn match rubyModuleDeclaration "[_[:alnum:]@$][^[:space:];#(]*" contained contains=rubyConstant
155+
syn match rubyFunction "\<[_[:lower:]][_[:alnum:]]*[?!=]\=.\@!" contained
151156
" Expensive Mode - colorize *end* according to opening statement
152157
if !exists("b:ruby_no_expensive") && !exists("ruby_no_expensive")
153-
syn region rubyFunction matchgroup=rubyDefine start="\<def\>\s*" end="\%(\s*\%(\s\|(\|;\|$\|#\)\)\@=" oneline contains=rubyPseudoVariable
154-
syn region rubyClass matchgroup=rubyType start="\<class\>\s*" end="\%(\s*\%(\s\|<\|;\|$\|#\)\)\@=" oneline
155-
syn match rubyType "\<class\ze\s*<<"
156-
syn region rubyModule matchgroup=rubyType start="\<module\>\s*" end="\%(\s*\%(\s\|;\|$\|#\)\)\@=" oneline
157-
158-
syn region rubyBlock start="\<def\>" matchgroup=rubyDefine end="\<end\>" contains=ALLBUT,@rubyExtendedStringSpecial,rubyTodo nextgroup=rubyFunction fold
159-
syn region rubyBlock start="\<class\>" matchgroup=rubyType end="\<end\>" contains=ALLBUT,@rubyExtendedStringSpecial,rubyTodo nextgroup=rubyClass fold
160-
syn region rubyBlock start="\<module\>" matchgroup=rubyType end="\<end\>" contains=ALLBUT,@rubyExtendedStringSpecial,rubyTodo nextgroup=rubyModule fold
158+
syn match rubyDefine "\<def\>" nextgroup=rubyMethodDeclaration skipwhite skipnl
159+
syn match rubyClass "\<class\>" nextgroup=rubyClassDeclaration skipwhite skipnl
160+
syn match rubyModule "\<module\>" nextgroup=rubyModuleDeclaration skipwhite skipnl
161+
syn region rubyBlock start="\<def\>" matchgroup=rubyDefine end="\<end\>" contains=TOP fold
162+
syn region rubyBlock start="\<class\>" matchgroup=rubyClass end="\<end\>" contains=TOP fold
163+
syn region rubyBlock start="\<module\>" matchgroup=rubyModule end="\<end\>" contains=TOP fold
161164

162165
" modifiers
163-
syn match rubyControl "\<\%(if\|unless\|while\|until\)\>" display
166+
syn match rubyConditional "\<\%(if\|unless\)\>" display
167+
syn match rubyLoop "\<\%(while\|until\)\>" display
164168

165169
" *do* requiring *end*
166-
syn region rubyDoBlock matchgroup=rubyControl start="\<do\>" end="\<end\>" contains=ALLBUT,@rubyExtendedStringSpecial,rubyTodo fold
170+
syn region rubyDoBlock matchgroup=rubyControl start="\<do\>" end="\<end\>" contains=TOP fold
167171

168172
" *{* requiring *}*
169-
syn region rubyCurlyBlock start="{" end="}" contains=ALLBUT,@rubyExtendedStringSpecial,rubyTodo fold
173+
syn region rubyCurlyBlock start="{" end="}" contains=TOP fold
170174

171175
" statements without *do*
172-
syn region rubyNoDoBlock matchgroup=rubyControl start="\<\%(case\|begin\)\>" start="\%(^\|\.\.\.\=\|[,;=([<>~\*/%&^|+-]\|\%(\<[_[:lower:]][_[:alnum:]]*\)\@<![!=?]\)\s*\zs\%(if\|unless\)\>" end="\<end\>" contains=ALLBUT,@rubyExtendedStringSpecial,rubyTodo fold
176+
syn region rubyNoDoBlock matchgroup=rubyControl start="\<begin\>" end="\<end\>" contains=TOP fold
177+
syn region rubyNoDoBlock matchgroup=rubyConditional start="\<case\>" start="\%(^\|\.\.\.\=\|[,;=([<>~\*/%&^|+-]\|\%(\<[_[:lower:]][_[:alnum:]]*\)\@<![!=?]\)\s*\zs\%(if\|unless\)\>" end="\<end\>" contains=TOP fold
178+
syn keyword rubyConditional else elsif then when
173179

174180
" statement with optional *do*
175-
syn region rubyOptDoLine matchgroup=rubyControl start="\<for\>" start="\%(\%(^\|\.\.\.\=\|[?:,;=([<>~\*/%&^|+-]\|\%(\<[_[:lower:]][_[:alnum:]]*\)\@<![!=?]\)\s*\)\@<=\<\%(until\|while\)\>" end="\%(\<do\>\|:\)" end="\ze\%(;\|$\)" oneline contains=ALLBUT,@rubyExtendedStringSpecial,rubyTodo
176-
syn region rubyOptDoBlock start="\<for\>" start="\%(\%(^\|\.\.\.\=\|[:,;([<>~\*/%&^|+-]\|\%(\<[_[:lower:]][_[:alnum:]]*\)\@<![!=?]\)\s*\)\@<=\<\%(until\|while\)\>" matchgroup=rubyControl end="\<end\>" contains=ALLBUT,@rubyExtendedStringSpecial,rubyTodo nextgroup=rubyOptDoLine fold
181+
syn region rubyOptDoLine matchgroup=rubyLoop start="\<for\>" start="\%(\%(^\|\.\.\.\=\|[?:,;=([<>~\*/%&^|+-]\|\%(\<[_[:lower:]][_[:alnum:]]*\)\@<![!=?]\)\s*\)\@<=\<\%(until\|while\)\>" end="\%(\<do\>\|:\)" end="\ze\%(;\|$\)" oneline contains=TOP
182+
syn region rubyOptDoBlock start="\<for\>" start="\%(\%(^\|\.\.\.\=\|[:,;([<>~\*/%&^|+-]\|\%(\<[_[:lower:]][_[:alnum:]]*\)\@<![!=?]\)\s*\)\@<=\<\%(until\|while\)\>" matchgroup=rubyLoop end="\<end\>" contains=TOP nextgroup=rubyOptDoLine fold
177183

178184
if !exists("ruby_minlines")
179185
let ruby_minlines = 50
180186
endif
181187
exec "syn sync minlines=" . ruby_minlines
182188

183189
else
184-
syn region rubyFunction matchgroup=rubyControl start="\<def\>\s*" end="\ze\%(\s\|(\|;\|$\)" oneline contains=rubyPseudoVariable
185-
syn region rubyClass matchgroup=rubyControl start="\<class\>\s*" end="\ze\%(\s\|<\|;\|$\)" oneline
186-
syn match rubyControl "\<class\ze\s*<<"
187-
syn region rubyModule matchgroup=rubyControl start="\<module\>\s*" end="\ze\%(\s\|;\|$\)" oneline
188-
syn keyword rubyControl case begin do for if unless while until end
190+
syn match rubyControl "\<def\>" nextgroup=rubyMethodDeclaration skipwhite skipnl
191+
syn match rubyControl "\<class\>" nextgroup=rubyClassDeclaration skipwhite skipnl
192+
syn match rubyControl "\<module\>" nextgroup=rubyModuleDeclaration skipwhite skipnl
193+
syn keyword rubyControl case begin do for if unless while until else elsif then when end
189194
endif
190195

191196
" Keywords
192197
" Note: the following keywords have already been defined:
193198
" begin case class def do end for if module unless until while
194-
syn keyword rubyControl and break else elsif ensure in next not or redo rescue retry return then when
199+
syn keyword rubyControl and break ensure in next not or redo rescue retry return
195200
syn match rubyOperator "\<defined?" display
196201
syn keyword rubyKeyword alias super undef yield
197202
syn keyword rubyBoolean true false
@@ -247,32 +252,33 @@ if version >= 508 || !exists("did_ruby_syntax_inits")
247252
command -nargs=+ HiLink hi def link <args>
248253
endif
249254

250-
HiLink rubyType rubyDefine
255+
HiLink rubyClass rubyDefine
256+
HiLink rubyModule rubyDefine
251257
HiLink rubyDefine Define
252258
HiLink rubyFunction Function
259+
HiLink rubyConditional Conditional
260+
HiLink rubyLoop Loop
253261
HiLink rubyControl Statement
254262
HiLink rubyInclude Include
255263
HiLink rubyInteger Number
256-
HiLink rubyASCIICode rubyInteger
264+
HiLink rubyASCIICode Character
257265
HiLink rubyFloat Float
258-
HiLink rubyBoolean rubyPseudoVariable
266+
HiLink rubyBoolean Boolean
259267
HiLink rubyException Exception
260-
HiLink rubyClass Type
261-
HiLink rubyModule Type
262268
if !exists("ruby_no_identifiers")
263269
HiLink rubyIdentifier Identifier
264270
else
265271
HiLink rubyIdentifier NONE
266272
endif
267273
HiLink rubyClassVariable rubyIdentifier
268-
HiLink rubyConstant rubyIdentifier
274+
HiLink rubyConstant Type
269275
HiLink rubyGlobalVariable rubyIdentifier
270276
HiLink rubyBlockParameter rubyIdentifier
271277
HiLink rubyInstanceVariable rubyIdentifier
272278
HiLink rubyPredefinedIdentifier rubyIdentifier
273279
HiLink rubyPredefinedConstant rubyPredefinedIdentifier
274280
HiLink rubyPredefinedVariable rubyPredefinedIdentifier
275-
HiLink rubySymbol rubyIdentifier
281+
HiLink rubySymbol Constant
276282
HiLink rubyKeyword Keyword
277283
HiLink rubyOperator Operator
278284
HiLink rubyPseudoOperator rubyOperator
@@ -304,4 +310,4 @@ endif
304310

305311
let b:current_syntax = "ruby"
306312

307-
" vim: nowrap sw=2 sts=2 ts=8 ff=unix:
313+
" vim: nowrap sw=2 sts=2 ts=8 noet ff=unix:

0 commit comments

Comments
 (0)