|
1 | 1 | " Vim syntax file |
2 | | -" Language: eRuby |
3 | | -" Maintainer: Doug Kearns <dougkearns@gmail.com> |
| 2 | +" Language: ERB |
| 3 | +" Maintainer: Tim Pope <vim@tpope.info> |
4 | 4 | " Info: $Id$ |
5 | 5 | " URL: http://vim-ruby.rubyforge.org |
6 | 6 | " Anon CVS: See above site |
7 | 7 | " Release Coordinator: Doug Kearns <dougkearns@gmail.com> |
8 | 8 |
|
9 | 9 | if exists("b:current_syntax") |
10 | | - finish |
| 10 | + finish |
11 | 11 | endif |
12 | 12 |
|
13 | 13 | if !exists("main_syntax") |
14 | 14 | let main_syntax = 'eruby' |
15 | 15 | endif |
16 | 16 |
|
| 17 | +if !exists("b:eruby_subtype") |
| 18 | + let s:lines = getline(1)."\n".getline(2)."\n".getline(3)."\n".getline(4)."\n".getline(5)."\n".getline("$") |
| 19 | + let b:eruby_subtype = matchstr(s:lines,'eruby_subtype=\zs\w\+') |
| 20 | + " Check extension if main_syntax wasn't set. main_syntax can be set if this |
| 21 | + " file is included from yet another syntax file. |
| 22 | + if main_syntax == 'eruby' && b:eruby_subtype == '' |
| 23 | + let b:eruby_subtype = matchstr(substitute(expand("%:t"),'\c\.erb$','',''),'\.\zs\w\+$') |
| 24 | + endif |
| 25 | + if b:eruby_subtype == 'rhtml' |
| 26 | + let b:eruby_subtype = 'html' |
| 27 | + elseif b:eruby_subtype == 'yml' |
| 28 | + let b:eruby_subtype = 'yaml' |
| 29 | + elseif b:eruby_subtype == 'txt' |
| 30 | + " Conventional; not a real file type |
| 31 | + let b:eruby_subtype = 'text' |
| 32 | + elseif b:eruby_subtype == '' && main_syntax == 'eruby' |
| 33 | + let b:eruby_subtype == 'html' |
| 34 | + endif |
| 35 | +endif |
| 36 | + |
17 | 37 | if version < 600 |
18 | | - so <sfile>:p:h/html.vim |
19 | 38 | syn include @rubyTop <sfile>:p:h/ruby.vim |
20 | 39 | else |
21 | | - runtime! syntax/html.vim |
22 | | - unlet b:current_syntax |
| 40 | + if b:eruby_subtype != '' |
| 41 | + exe "runtime! syntax/".b:eruby_subtype.".vim" |
| 42 | + unlet! b:current_syntax |
| 43 | + endif |
23 | 44 | syn include @rubyTop syntax/ruby.vim |
24 | 45 | endif |
25 | 46 |
|
26 | 47 | syn cluster erubyRegions contains=erubyOneLiner,erubyBlock,erubyExpression,erubyComment |
27 | 48 |
|
28 | | -syn region erubyOneLiner matchgroup=erubyDelimiter start="^%%\@!" end="$" contains=@rubyTop containedin=ALLBUT,@erubyRegions keepend oneline |
29 | | -syn region erubyBlock matchgroup=erubyDelimiter start="<%%\@!-\=" end="-\=%>" contains=@rubyTop containedin=ALLBUT,@erubyRegions |
30 | | -syn region erubyExpression matchgroup=erubyDelimiter start="<%=" end="-\=%>" contains=@rubyTop containedin=ALLBUT,@erubyRegions |
31 | | -syn region erubyComment matchgroup=erubyDelimiter start="<%#" end="-\=%>" contains=rubyTodo,@Spell containedin=ALLBUT,@erubyRegions keepend |
| 49 | +syn region erubyOneLiner matchgroup=erubyDelimiter start="^%%\@!" end="$" contains=@rubyTop containedin=ALLBUT,@erbRegions keepend oneline |
| 50 | +syn region erubyBlock matchgroup=erubyDelimiter start="<%%\@!-\=" end="-\=%>" contains=@rubyTop containedin=ALLBUT,@erbRegions |
| 51 | +syn region erubyExpression matchgroup=erubyDelimiter start="<%=" end="-\=%>" contains=@rubyTop containedin=ALLBUT,@erbRegions |
| 52 | +syn region erubyComment matchgroup=erubyDelimiter start="<%#" end="-\=%>" contains=rubyTodo,@Spell containedin=ALLBUT,@erbRegions keepend |
32 | 53 |
|
33 | | -hi def link erubyDelimiter Delimiter |
34 | | -hi def link erubyComment Comment |
| 54 | +" Define the default highlighting. |
| 55 | +" For version 5.7 and earlier: only when not done already |
| 56 | +" For version 5.8 and later: only when an item doesn't have highlighting yet |
| 57 | +if version >= 508 || !exists("did_eruby_syntax_inits") |
| 58 | + if version < 508 |
| 59 | + let did_ruby_syntax_inits = 1 |
| 60 | + command -nargs=+ HiLink hi link <args> |
| 61 | + else |
| 62 | + command -nargs=+ HiLink hi def link <args> |
| 63 | + endif |
35 | 64 |
|
36 | | -let b:current_syntax = "eruby" |
| 65 | + HiLink erubyDelimiter Delimiter |
| 66 | + HiLink erubyComment Comment |
| 67 | + |
| 68 | + delcommand HiLink |
| 69 | +endif |
| 70 | +let b:current_syntax = 'eruby' |
37 | 71 |
|
38 | 72 | if main_syntax == 'eruby' |
39 | 73 | unlet main_syntax |
|
0 commit comments