summaryrefslogtreecommitdiffstats
path: root/syntax/jst.vim
blob: 907b303164fc56381af37fd648ea382dc7047526 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
if !has_key(g:polyglot_is_disabled, 'jst')
  finish
endif

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 == 'ect'
    let b:jst_subtype = 'html'
  elseif b:jst_subtype == 'djs'
    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

set commentstring=<!--%s-->

if exists("loaded_matchit")
  let b:match_ignorecase = 1
  let b:match_words = '<:>,' .
  \ '<\@<=[ou]l\>[^>]*\%(>\|$\):<\@<=li\>:<\@<=/[ou]l>,' .
  \ '<\@<=dl\>[^>]*\%(>\|$\):<\@<=d[td]\>:<\@<=/dl>,' .
  \ '<\@<=\([^/][^ \t>]*\)[^>]*\%(>\|$\):<\@<=/\1>'
endif

" vim: nowrap sw=2 sts=2 ts=8: