diff options
author | Adam Stankiewicz <sheerun@sher.pl> | 2013-09-12 16:34:47 +0200 |
---|---|---|
committer | Adam Stankiewicz <sheerun@sher.pl> | 2013-09-12 16:34:47 +0200 |
commit | 700eeff06989525276be7ff5e05fc59beaf7e9bf (patch) | |
tree | 4e07d1139af9fb075c350b1d0bff3344eb229ae3 | |
parent | d96dc724d442bbc9788815ab3da09d9fff0555a9 (diff) | |
download | vim-polyglot-700eeff06989525276be7ff5e05fc59beaf7e9bf.tar.gz vim-polyglot-700eeff06989525276be7ff5e05fc59beaf7e9bf.zip |
Add jst/est template support
-rwxr-xr-x | build.sh | 1 | ||||
-rw-r--r-- | ftdetect/jst.vim | 3 | ||||
-rw-r--r-- | indent/jst.vim | 75 | ||||
-rw-r--r-- | syntax/jst.vim | 73 |
4 files changed, 152 insertions, 0 deletions
@@ -52,6 +52,7 @@ syntax 'vim-scripts/python.vim--Vasiliev' & syntax 'vim-scripts/octave.vim--' & syntax 'uggedal/go-vim' & syntax 'spf13/PIV' & +syntax 'briancollins/vim-jst' & wait diff --git a/ftdetect/jst.vim b/ftdetect/jst.vim new file mode 100644 index 00000000..2ec59364 --- /dev/null +++ b/ftdetect/jst.vim @@ -0,0 +1,3 @@ +au BufNewFile,BufRead *.ejs set filetype=jst +au BufNewFile,BufRead *.jst set filetype=jst +au BufNewFile,BufRead *.hamljs set filetype=jst diff --git a/indent/jst.vim b/indent/jst.vim new file mode 100644 index 00000000..c9162741 --- /dev/null +++ b/indent/jst.vim @@ -0,0 +1,75 @@ +if exists("b:did_indent") + finish +endif + +runtime! indent/javascript.vim +unlet! b:did_indent +setlocal indentexpr= + +if exists("b:jst_subtype") + exe "runtime! indent/".b:jst_subtype.".vim" +else + runtime! indent/html.vim +endif +unlet! b:did_indent + +if &l:indentexpr == '' + if &l:cindent + let &l:indentexpr = 'cindent(v:lnum)' + else + let &l:indentexpr = 'indent(prevnonblank(v:lnum-1))' + endif +endif +let b:jst_subtype_indentexpr = &l:indentexpr + +let b:did_indent = 1 + +setlocal indentexpr=GetJstIndent() +setlocal indentkeys=o,O,*<Return>,<>>,{,},0),0],o,O,!^F,=end,=else,=elsif,=rescue,=ensure,=when + +" Only define the function once. +if exists("*GetJstIndent") + finish +endif + +function! GetJstIndent(...) + if a:0 && a:1 == '.' + let v:lnum = line('.') + elseif a:0 && a:1 =~ '^\d' + let v:lnum = a:1 + endif + let vcol = col('.') + call cursor(v:lnum,1) + let injavascript = searchpair('<%','','%>','W') + call cursor(v:lnum,vcol) + if injavascript && getline(v:lnum) !~ '^<%\|^\s*[-=]\=%>' + let ind = GetJavascriptIndent() + else + exe "let ind = ".b:jst_subtype_indentexpr + endif + let lnum = prevnonblank(v:lnum-1) + let line = getline(lnum) + let cline = getline(v:lnum) + if cline =~# '^\s*<%[-=]\=\s*\%(}.\{-\}\)\s*\%([-=]\=%>\|$\)' + let ind = ind - &sw + endif + if line =~# '\S\s*<%[-=]\=\s*\%(}\).\{-\}\s*\%([-=]\=%>\|$\)' + let ind = ind - &sw + endif + if line =~# '\%({\|\<do\)\%(\s*|[^|]*|\)\=\s*[-=]\=%>' + let ind = ind + &sw + endif + if line =~# '^\s*<%[=#-]\=\s*$' && cline !~# '^\s*end\>' + let ind = ind + &sw + endif + if line !~# '^\s*<%' && line =~# '%>\s*$' + let ind = ind - &sw + endif + if cline =~# '^\s*[-=]\=%>\s*$' + let ind = ind - &sw + endif + return ind +endfunction + +" vim:set sw=2 sts=2 ts=8 noet: + diff --git a/syntax/jst.vim b/syntax/jst.vim new file mode 100644 index 00000000..25abe238 --- /dev/null +++ b/syntax/jst.vim @@ -0,0 +1,73 @@ +if exists("b:current_syntax") + finish +endif + +if !exists("main_syntax") + let main_syntax = 'jst' +endif + +if !exists("g:jst_default_subtype") + let g:jst_default_subtype = "html" +endif + +if &filetype =~ '^jst\.' + let b:jst_subtype = matchstr(&filetype,'^jst\.\zs\w\+') +elseif !exists("b:jst_subtype") && main_syntax == 'jst' + let s:lines = getline(1)."\n".getline(2)."\n".getline(3)."\n".getline(4)."\n".getline(5)."\n".getline("$") + let b:jst_subtype = matchstr(s:lines,'jst_subtype=\zs\w\+') + if b:jst_subtype == '' + let b:jst_subtype = matchstr(substitute(expand("%:t"),'\c\%(\.jst\)\+$','',''),'\.\zs\w\+$') + endif + if b:jst_subtype == 'rhtml' + let b:jst_subtype = 'html' + elseif b:jst_subtype == 'hamljs' + let b:jst_subtype = 'haml' + elseif b:jst_subtype == 'ejs' + let b:jst_subtype = 'html' + elseif b:jst_subtype == 'rb' + let b:jst_subtype = 'ruby' + elseif b:jst_subtype == 'yml' + let b:jst_subtype = 'yaml' + elseif b:jst_subtype == 'js' + let b:jst_subtype = 'javascript' + elseif b:jst_subtype == 'txt' + " Conventional; not a real file type + let b:jst_subtype = 'text' + elseif b:jst_subtype == '' + let b:jst_subtype = g:jst_default_subtype + endif +endif + +if !exists("b:jst_nest_level") + let b:jst_nest_level = strlen(substitute(substitute(substitute(expand("%:t"),'@','','g'),'\c\.\%(erb\|rhtml\)\>','@','g'),'[^@]','','g')) +endif +if !b:jst_nest_level + let b:jst_nest_level = 1 +endif + +if exists("b:jst_subtype") && b:jst_subtype != '' + exe "runtime! syntax/".b:jst_subtype.".vim" + unlet! b:current_syntax +endif + +syn include @jsTop syntax/javascript.vim + +syn cluster jstRegions contains=jstOneLiner,jstBlock,jstExpression,jstComment + +exe 'syn region jstOneLiner matchgroup=jstDelimiter start="^%\{1,'.b:jst_nest_level.'\}%\@!" end="$" contains=@jsTop containedin=ALLBUT,@jstRegions keepend oneline' +exe 'syn region jstBlock matchgroup=jstDelimiter start="<%\{1,'.b:jst_nest_level.'\}%\@!-\=" end="[=-]\=%\@<!%\{1,'.b:jst_nest_level.'\}>" contains=@jsTop containedin=ALLBUT,@jstRegions keepend' +exe 'syn region jstExpression matchgroup=jstDelimiter start="<%\{1,'.b:jst_nest_level.'\}=\{1,4}" end="[=-]\=%\@<!%\{1,'.b:jst_nest_level.'\}>" contains=@jsTop containedin=ALLBUT,@jstRegions keepend' +exe 'syn region jstComment matchgroup=jstDelimiter start="<%\{1,'.b:jst_nest_level.'\}#" end="%\@<!%\{1,'.b:jst_nest_level.'\}>" contains=jsTodo,@Spell containedin=ALLBUT,@jstRegions keepend' + +" Define the default highlighting. + +hi def link jstDelimiter PreProc +hi def link jstComment Comment + +let b:current_syntax = 'jst' + +if main_syntax == 'jst' + unlet main_syntax +endif + +" vim: nowrap sw=2 sts=2 ts=8: |