Add jst/est template support
This commit is contained in:
parent
d96dc724d4
commit
700eeff069
1
build.sh
1
build.sh
@ -52,6 +52,7 @@ syntax 'vim-scripts/python.vim--Vasiliev' &
|
|||||||
syntax 'vim-scripts/octave.vim--' &
|
syntax 'vim-scripts/octave.vim--' &
|
||||||
syntax 'uggedal/go-vim' &
|
syntax 'uggedal/go-vim' &
|
||||||
syntax 'spf13/PIV' &
|
syntax 'spf13/PIV' &
|
||||||
|
syntax 'briancollins/vim-jst' &
|
||||||
|
|
||||||
wait
|
wait
|
||||||
|
|
||||||
|
3
ftdetect/jst.vim
Normal file
3
ftdetect/jst.vim
Normal file
@ -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
|
75
indent/jst.vim
Normal file
75
indent/jst.vim
Normal file
@ -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:
|
||||||
|
|
73
syntax/jst.vim
Normal file
73
syntax/jst.vim
Normal file
@ -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:
|
Loading…
Reference in New Issue
Block a user