Skip to content

Commit 1ba3c95

Browse files
committed
Highlight exception handlers in module, class and do blocks
Exception handling in do blocks was introduced in 2.6.
1 parent db00e97 commit 1ba3c95

1 file changed

Lines changed: 9 additions & 8 deletions

File tree

syntax/ruby.vim

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ com! -nargs=* SynFold call s:run_syntax_fold(<q-args>)
6666

6767
" }}}
6868

69-
syn cluster rubyNotTop contains=@rubyCommentNotTop,@rubyStringNotTop,@rubyRegexpSpecial,@rubyDeclaration,rubyConditional,rubyExceptional,rubyMethodExceptional,rubyModuleName,rubyClassName,rubySymbolDelimiter
69+
syn cluster rubyNotTop contains=@rubyCommentNotTop,@rubyStringNotTop,@rubyRegexpSpecial,@rubyDeclaration,@rubyExceptionHandler,rubyConditional,rubyModuleName,rubyClassName,rubySymbolDelimiter
7070

7171
" Whitespace Errors {{{1
7272
if exists("ruby_space_errors")
@@ -306,8 +306,8 @@ if !exists("b:ruby_no_expensive") && !exists("ruby_no_expensive")
306306
syn match rubyModule "\<module\>" nextgroup=rubyModuleDeclaration skipwhite skipnl
307307

308308
SynFold 'def' syn region rubyMethodBlock start="\<def\>" matchgroup=rubyDefine end="\%(\<def\_s\+\)\@<!\<end\>" contains=ALLBUT,@rubyNotTop
309-
SynFold 'class' syn region rubyBlock start="\<class\>" matchgroup=rubyClass end="\<end\>" contains=ALLBUT,@rubyNotTop
310-
SynFold 'module' syn region rubyBlock start="\<module\>" matchgroup=rubyModule end="\<end\>" contains=ALLBUT,@rubyNotTop
309+
SynFold 'class' syn region rubyClassBlock start="\<class\>" matchgroup=rubyClass end="\<end\>" contains=ALLBUT,@rubyNotTop
310+
SynFold 'module' syn region rubyModuleBlock start="\<module\>" matchgroup=rubyModule end="\<end\>" contains=ALLBUT,@rubyNotTop
311311

312312
" modifiers
313313
syn match rubyLineContinuation "\\$" nextgroup=rubyConditionalModifier,rubyRepeatModifier,rubyRescueModifier skipwhite skipnl
@@ -332,8 +332,9 @@ if !exists("b:ruby_no_expensive") && !exists("ruby_no_expensive")
332332
syn match rubyConditional "\<\%(then\|else\|when\)\>[?!]\@!" contained containedin=rubyCaseExpression
333333
syn match rubyConditional "\<\%(then\|else\|elsif\)\>[?!]\@!" contained containedin=rubyConditionalExpression
334334

335-
syn match rubyExceptional "\<\%(\%(\%(;\|^\)\s*\)\@<=rescue\|else\|ensure\)\>[?!]\@!" contained containedin=rubyBlockExpression
336-
syn match rubyMethodExceptional "\<\%(\%(\%(;\|^\)\s*\)\@<=rescue\|else\|ensure\)\>[?!]\@!" contained containedin=rubyMethodBlock
335+
syn match rubyExceptionHandler "\<\%(\%(\%(;\|^\)\s*\)\@<=rescue\|else\|ensure\)\>[?!]\@!" contained containedin=rubyBlockExpression,rubyDoBlock
336+
syn match rubyExceptionHandler1 "\<\%(\%(\%(;\|^\)\s*\)\@<=rescue\|else\|ensure\)\>[?!]\@!" contained containedin=rubyModuleBlock,rubyClassBlock,rubyMethodBlock
337+
syn cluster rubyExceptionHandler contains=rubyExceptionHandler,rubyExceptionHandler1
337338

338339
" statements with optional 'do'
339340
syn region rubyOptionalDoLine matchgroup=rubyRepeat start="\<for\>[?!]\@!" start="\%(\%(^\|\.\.\.\=\|[{:,;([<>~\*/%&^|+-]\|\%(\<[_[:lower:]][_[:alnum:]]*\)\@<![!=?]\)\s*\)\@<=\<\%(until\|while\)\>" matchgroup=rubyOptionalDo end="\%(\<do\>\)" end="\ze\%(;\|$\)" oneline contains=ALLBUT,@rubyNotTop
@@ -405,7 +406,7 @@ SynFold '__END__' syn region rubyData matchgroup=rubyDataDirective start="^__END
405406
" Default Highlighting {{{1
406407
hi def link rubyClass rubyDefine
407408
hi def link rubyModule rubyDefine
408-
hi def link rubyMethodExceptional rubyDefine
409+
hi def link rubyExceptionHandler1 rubyDefine
409410
hi def link rubyDefine Define
410411
hi def link rubyAccess rubyMacro
411412
hi def link rubyAttribute rubyMacro
@@ -414,8 +415,8 @@ hi def link rubyMethodName rubyFunction
414415
hi def link rubyFunction Function
415416
hi def link rubyConditional Conditional
416417
hi def link rubyConditionalModifier rubyConditional
417-
hi def link rubyExceptional rubyConditional
418-
hi def link rubyRescueModifier rubyExceptional
418+
hi def link rubyExceptionHandler rubyConditional
419+
hi def link rubyRescueModifier rubyExceptionHandler
419420
hi def link rubyRepeat Repeat
420421
hi def link rubyRepeatModifier rubyRepeat
421422
hi def link rubyOptionalDo rubyRepeat

0 commit comments

Comments
 (0)