summaryrefslogtreecommitdiff
path: root/runtime/syntax/eruby.vim
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2007-05-10 18:25:20 +0000
committerBram Moolenaar <Bram@vim.org>2007-05-10 18:25:20 +0000
commitccc18222dd2b40397536703923842f026a6141f0 (patch)
tree5ebf27663225d11e70f382e51236b9f3f9890ed4 /runtime/syntax/eruby.vim
parent2c7a763832663d5878ff37a58c81fbe95527084a (diff)
downloadvim-ccc18222dd2b40397536703923842f026a6141f0.zip
updated for version 7.1b
Diffstat (limited to 'runtime/syntax/eruby.vim')
-rw-r--r--runtime/syntax/eruby.vim62
1 files changed, 44 insertions, 18 deletions
diff --git a/runtime/syntax/eruby.vim b/runtime/syntax/eruby.vim
index 3aedc6cfd..f85e0093d 100644
--- a/runtime/syntax/eruby.vim
+++ b/runtime/syntax/eruby.vim
@@ -1,16 +1,12 @@
" Vim syntax file
" Language: eRuby
-" Maintainer: Doug Kearns <dougkearns@gmail.com>
+" Maintainer: Tim Pope <vimNOSPAM@tpope.info>
" Info: $Id$
" URL: http://vim-ruby.rubyforge.org
" Anon CVS: See above site
" Release Coordinator: Doug Kearns <dougkearns@gmail.com>
-" For version 5.x: Clear all syntax items
-" For version 6.x: Quit when a syntax file was already loaded
-if version < 600
- syntax clear
-elseif exists("b:current_syntax")
+if exists("b:current_syntax")
finish
endif
@@ -18,21 +14,51 @@ if !exists("main_syntax")
let main_syntax = 'eruby'
endif
-if version < 600
- so <sfile>:p:h/html.vim
- syn include @rubyTop <sfile>:p:h/ruby.vim
-else
- runtime! syntax/html.vim
- unlet b:current_syntax
- syn include @rubyTop syntax/ruby.vim
+if !exists("g:eruby_default_subtype")
+ let g:eruby_default_subtype = "html"
endif
+if !exists("b:eruby_subtype") && main_syntax == 'eruby'
+ let s:lines = getline(1)."\n".getline(2)."\n".getline(3)."\n".getline(4)."\n".getline(5)."\n".getline("$")
+ let b:eruby_subtype = matchstr(s:lines,'eruby_subtype=\zs\w\+')
+ if b:eruby_subtype == ''
+ let b:eruby_subtype = matchstr(substitute(expand("%:t"),'\c\%(\.erb\)\+$','',''),'\.\zs\w\+$')
+ endif
+ if b:eruby_subtype == 'rhtml'
+ let b:eruby_subtype = 'html'
+ elseif b:eruby_subtype == 'rb'
+ let b:eruby_subtype = 'ruby'
+ elseif b:eruby_subtype == 'yml'
+ let b:eruby_subtype = 'yaml'
+ elseif b:eruby_subtype == 'js'
+ let b:eruby_subtype = 'javascript'
+ elseif b:eruby_subtype == 'txt'
+ " Conventional; not a real file type
+ let b:eruby_subtype = 'text'
+ elseif b:eruby_subtype == ''
+ let b:eruby_subtype = g:eruby_default_subtype
+ endif
+endif
+
+if !exists("b:eruby_nest_level")
+ let b:eruby_nest_level = strlen(substitute(substitute(substitute(expand("%:t"),'@','','g'),'\c\.\%(erb\|rhtml\)\>','@','g'),'[^@]','','g'))
+endif
+if !b:eruby_nest_level
+ let b:eruby_nest_level = 1
+endif
+
+if exists("b:eruby_subtype") && b:eruby_subtype != ''
+ exe "runtime! syntax/".b:eruby_subtype.".vim"
+ unlet! b:current_syntax
+endif
+syn include @rubyTop syntax/ruby.vim
+
syn cluster erubyRegions contains=erubyOneLiner,erubyBlock,erubyExpression,erubyComment
-syn region erubyOneLiner matchgroup=erubyDelimiter start="^%%\@!" end="$" contains=@rubyTop containedin=ALLBUT,@erubyRegions keepend oneline
-syn region erubyBlock matchgroup=erubyDelimiter start="<%%\@!-\=" end="-\=%>" contains=@rubyTop containedin=ALLBUT,@erubyRegions
-syn region erubyExpression matchgroup=erubyDelimiter start="<%=" end="-\=%>" contains=@rubyTop containedin=ALLBUT,@erubyRegions
-syn region erubyComment matchgroup=erubyDelimiter start="<%#" end="-\=%>" contains=rubyTodo,@Spell containedin=ALLBUT,@erubyRegions keepend
+exe 'syn region erubyOneLiner matchgroup=erubyDelimiter start="^%\{1,'.b:eruby_nest_level.'\}%\@!" end="$" contains=@rubyTop containedin=ALLBUT,@erbRegions keepend oneline'
+exe 'syn region erubyBlock matchgroup=erubyDelimiter start="<%\{1,'.b:eruby_nest_level.'\}%\@!-\=" end="-\=%>" contains=@rubyTop containedin=ALLBUT,@erbRegions'
+exe 'syn region erubyExpression matchgroup=erubyDelimiter start="<%\{1,'.b:eruby_nest_level.'\}=" end="-\=%>" contains=@rubyTop containedin=ALLBUT,@erbRegions'
+exe 'syn region erubyComment matchgroup=erubyDelimiter start="<%\{1,'.b:eruby_nest_level.'\}#" end="-\=%>" contains=rubyTodo,@Spell containedin=ALLBUT,@erbRegions keepend'
" Define the default highlighting.
" For version 5.7 and earlier: only when not done already
@@ -50,7 +76,7 @@ if version >= 508 || !exists("did_eruby_syntax_inits")
delcommand HiLink
endif
-let b:current_syntax = "eruby"
+let b:current_syntax = 'eruby'
if main_syntax == 'eruby'
unlet main_syntax