Skip to content

Commit ea30586

Browse files
committed
Early support for eruby subtypes
1 parent f5f62e0 commit ea30586

4 files changed

Lines changed: 54 additions & 15 deletions

File tree

ChangeLog

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
2007-04-16 Tim Pope <vim@tpope.info>
2+
3+
* ftdetect/ruby.vim: detect *.erb as eruby
4+
* syntax/eruby.vim: determine subtype by inspecting filename
5+
16
2007-04-03 Doug Kearns <dougkearns@gmail.com>
27

38
* syntax/ruby.vim: allow text to appear after, and on the same line,

ftdetect/ruby.vim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ au BufNewFile,BufRead [rR]akefile* set filetype=ruby
88
au BufNewFile,BufRead [rR]antfile,*.rant set filetype=ruby
99

1010
" eRuby
11-
au BufNewFile,BufRead *.rhtml set filetype=eruby
11+
au BufNewFile,BufRead *.erb,*.rhtml set filetype=eruby

ftplugin/ruby.vim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ function! RubyBalloonexpr()
148148
return ''
149149
endif
150150
silent! let res = substitute(system("ri -f simple -T \"".str.'"'),'\n$','','')
151-
if res =~ '^Nothing known about' || res =~ '^Bad argument:'
151+
if res =~ '^Nothing known about' || res =~ '^Bad argument:' || res =~ '^More than one method'
152152
return ''
153153
endif
154154
return res

syntax/eruby.vim

Lines changed: 47 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,73 @@
11
" Vim syntax file
2-
" Language: eRuby
3-
" Maintainer: Doug Kearns <dougkearns@gmail.com>
2+
" Language: ERB
3+
" Maintainer: Tim Pope <vim@tpope.info>
44
" Info: $Id$
55
" URL: http://vim-ruby.rubyforge.org
66
" Anon CVS: See above site
77
" Release Coordinator: Doug Kearns <dougkearns@gmail.com>
88

99
if exists("b:current_syntax")
10-
finish
10+
finish
1111
endif
1212

1313
if !exists("main_syntax")
1414
let main_syntax = 'eruby'
1515
endif
1616

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+
1737
if version < 600
18-
so <sfile>:p:h/html.vim
1938
syn include @rubyTop <sfile>:p:h/ruby.vim
2039
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
2344
syn include @rubyTop syntax/ruby.vim
2445
endif
2546

2647
syn cluster erubyRegions contains=erubyOneLiner,erubyBlock,erubyExpression,erubyComment
2748

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
3253

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
3564

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'
3771

3872
if main_syntax == 'eruby'
3973
unlet main_syntax

0 commit comments

Comments
 (0)