Skip to content

Commit 19c19a5

Browse files
committed
Add highlighting support for magic comments
A feature no one asked for and, probably, no one wants.
1 parent cc7a38a commit 19c19a5

1 file changed

Lines changed: 9 additions & 4 deletions

File tree

syntax/ruby.vim

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

6262
" }}}
6363

64-
syn cluster rubyNotTop contains=@rubyExtendedStringSpecial,@rubyRegexpSpecial,@rubyDeclaration,rubyConditional,rubyExceptional,rubyMethodExceptional,rubyTodo,rubyModuleName,rubyClassName,rubySymbolDelimiter
64+
syn cluster rubyNotTop contains=@rubyExtendedStringSpecial,@rubyRegexpSpecial,@rubyDeclaration,rubyConditional,rubyExceptional,rubyMethodExceptional,rubyTodo,rubyModuleName,rubyClassName,rubySymbolDelimiter,rubyEncoding
6565

6666
" Whitespace Errors {{{1
6767
if exists("ruby_space_errors")
@@ -361,9 +361,12 @@ if !exists("ruby_no_special_methods")
361361
endif
362362

363363
" Comments and Documentation {{{1
364-
syn match rubySharpBang "\%^#!.*" display
365-
syn keyword rubyTodo FIXME NOTE TODO OPTIMIZE HACK REVIEW XXX todo contained
366-
syn match rubyComment "#.*" contains=rubySharpBang,rubySpaceError,rubyTodo,@Spell
364+
syn match rubySharpBang "\%^#!.*" display
365+
syn keyword rubyTodo FIXME NOTE TODO OPTIMIZE HACK REVIEW XXX todo contained
366+
syn match rubyEncoding "[[:alnum:]-]\+" contained display
367+
syn match rubyMagicComment "\c\%<3l#\s*\zs\%(coding\|encoding\):" contained nextgroup=rubyEncoding skipwhite
368+
syn match rubyMagicComment "\c\%<10l#\s*\zs\%(frozen_string_literal\|warn_indent\|warn_past_scope\):" contained nextgroup=rubyBoolean skipwhite
369+
syn match rubyComment "#.*" contains=rubySharpBang,rubySpaceError,rubyTodo,rubyMagicComment,@Spell
367370
if !exists("ruby_no_comment_fold") && s:foldable('#')
368371
syn region rubyMultilineComment start="^\s*#.*\n\%(^\s*#\)\@=" end="^\s*#.*\n\%(^\s*#\)\@!" contains=rubyComment transparent fold keepend
369372
syn region rubyDocumentation start="^=begin\ze\%(\s.*\)\=$" end="^=end\%(\s.*\)\=$" contains=rubySpaceError,rubyTodo,@Spell fold
@@ -431,6 +434,8 @@ hi def link rubyPseudoVariable Constant
431434
hi def link rubyCapitalizedMethod rubyLocalVariableOrMethod
432435

433436
hi def link rubyComment Comment
437+
hi def link rubyEncoding Constant
438+
hi def link rubyMagicComment SpecialComment
434439
hi def link rubyData Comment
435440
hi def link rubyDataDirective Delimiter
436441
hi def link rubyDocumentation Comment

0 commit comments

Comments
 (0)