Skip to content

Commit 5eb3fb0

Browse files
committed
syntax/ruby.vim changes
1 parent dbbaf09 commit 5eb3fb0

2 files changed

Lines changed: 21 additions & 10 deletions

File tree

ChangeLog

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
2007-02-23 Tim Pope <vim@tpope.info>
2+
3+
* syntax/ruby.vim: Fixed method highlighting when not at the end of
4+
the line. Highlight aliases. Account for \ before #{} interpolation.
5+
16
2007-02-23 Doug Kearns <dougkearns@gmail.com>
27

38
* syntax/ruby.vim: make sure multi-line backslash escaped

syntax/ruby.vim

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ endif
4242
" Expression Substitution and Backslash Notation
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
45-
syn region rubyInterpolated matchgroup=rubyInterpolation start="#{" end="}" contains=TOP contained
45+
syn region rubyInterpolated matchgroup=rubyInterpolation start="\\\@<!#{" end="}" contains=TOP contained
4646
"syn match rubyInterpolation "#\%(\$\|@@\=\)\w\+" contained contains=rubyInstanceVariable,rubyClassVariable,rubyGlobalVariable display
4747
syn match rubyInterpolation "#\ze\%(\$\|@@\=\)\w\+" contained display nextgroup=rubyClassVariable,rubyInstanceVariable,rubyGlobalVariable
4848
syn region rubyNoInterpolation start="\\#{" end="}" contained
@@ -149,12 +149,17 @@ if exists('main_syntax') && main_syntax == 'eruby'
149149
let b:ruby_no_expensive = 1
150150
end
151151

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
152+
syn match rubyAliasDeclaration "[^[:space:];#.()]\+" contained nextgroup=rubyAliasDeclaration2 skipwhite
153+
syn match rubyAliasDeclaration2 "[^[:space:];#.()]\+" contained
154+
syn match rubyMethodDeclaration "[^[:space:];#(]\+" contained contains=rubyConstant,rubyBoolean,rubyPseudoVariable,rubyInstanceVariable,rubyClassVariable,rubyGlobalVariable
155+
syn match rubyClassDeclaration "[^[:space:];#(]\+" contained contains=rubyConstant
156+
syn match rubyModuleDeclaration "[^[:space:];#(]\+" contained contains=rubyConstant
157+
syn match rubyFunction "\<[_[:lower:]][_[:alnum:]]*[?!=]\=\.\@!" contained containedin=rubyMethodDeclaration
158+
syn match rubyFunction "\%(\s\|^\)\@<=[_[:lower:]][_[:alnum:]]*[?!=]\=\%(\s\|$\)\@=" contained containedin=rubyAliasDeclaration,rubyAliasDeclaration2
159+
syn match rubyFunction "\%([[:space:].]\|^\)\@<=\%(\[\]=\=\|\*\*\|[+-]@\=\|[*/%|^~]\|<<\|>>\|[<>]=\=\|<=>\|===\|=\~\)\%([[:space:];#(]\|$\)\@=" contained containedin=rubyAliasDeclaration,rubyAliasDeclaration2,rubyMethodDeclaration
156160
" Expensive Mode - colorize *end* according to opening statement
157161
if !exists("b:ruby_no_expensive") && !exists("ruby_no_expensive")
162+
syn match rubyDefine "\<alias\>" nextgroup=rubyAliasDeclaration skipwhite skipnl
158163
syn match rubyDefine "\<def\>" nextgroup=rubyMethodDeclaration skipwhite skipnl
159164
syn match rubyClass "\<class\>" nextgroup=rubyClassDeclaration skipwhite skipnl
160165
syn match rubyModule "\<module\>" nextgroup=rubyModuleDeclaration skipwhite skipnl
@@ -164,7 +169,7 @@ if !exists("b:ruby_no_expensive") && !exists("ruby_no_expensive")
164169

165170
" modifiers
166171
syn match rubyConditional "\<\%(if\|unless\)\>" display
167-
syn match rubyLoop "\<\%(while\|until\)\>" display
172+
syn match rubyRepeat "\<\%(while\|until\)\>" display
168173

169174
" *do* requiring *end*
170175
syn region rubyDoBlock matchgroup=rubyControl start="\<do\>" end="\<end\>" contains=TOP fold
@@ -178,8 +183,8 @@ if !exists("b:ruby_no_expensive") && !exists("ruby_no_expensive")
178183
syn keyword rubyConditional else elsif then when
179184

180185
" statement with optional *do*
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
186+
syn region rubyOptDoLine matchgroup=rubyRepeat start="\<for\>" start="\%(\%(^\|\.\.\.\=\|[?:,;=([<>~\*/%&^|+-]\|\%(\<[_[:lower:]][_[:alnum:]]*\)\@<![!=?]\)\s*\)\@<=\<\%(until\|while\)\>" end="\%(\<do\>\|:\)" end="\ze\%(;\|$\)" oneline contains=TOP
187+
syn region rubyOptDoBlock start="\<for\>" start="\%(\%(^\|\.\.\.\=\|[:,;([<>~\*/%&^|+-]\|\%(\<[_[:lower:]][_[:alnum:]]*\)\@<![!=?]\)\s*\)\@<=\<\%(until\|while\)\>" matchgroup=rubyRepeat end="\<end\>" contains=TOP nextgroup=rubyOptDoLine fold
183188

184189
if !exists("ruby_minlines")
185190
let ruby_minlines = 50
@@ -191,14 +196,15 @@ else
191196
syn match rubyControl "\<class\>" nextgroup=rubyClassDeclaration skipwhite skipnl
192197
syn match rubyControl "\<module\>" nextgroup=rubyModuleDeclaration skipwhite skipnl
193198
syn keyword rubyControl case begin do for if unless while until else elsif then when end
199+
syn keyword rubyKeyword alias
194200
endif
195201

196202
" Keywords
197203
" Note: the following keywords have already been defined:
198204
" begin case class def do end for if module unless until while
199205
syn keyword rubyControl and break ensure in next not or redo rescue retry return
200206
syn match rubyOperator "\<defined?" display
201-
syn keyword rubyKeyword alias super undef yield
207+
syn keyword rubyKeyword super undef yield
202208
syn keyword rubyBoolean true false
203209
syn keyword rubyPseudoVariable nil self __FILE__ __LINE__
204210
syn keyword rubyBeginEnd BEGIN END
@@ -257,7 +263,7 @@ if version >= 508 || !exists("did_ruby_syntax_inits")
257263
HiLink rubyDefine Define
258264
HiLink rubyFunction Function
259265
HiLink rubyConditional Conditional
260-
HiLink rubyLoop Repeat
266+
HiLink rubyRepeat Repeat
261267
HiLink rubyControl Statement
262268
HiLink rubyInclude Include
263269
HiLink rubyInteger Number

0 commit comments

Comments
 (0)