diff options
author | mattn <mattn.jp@gmail.com> | 2013-05-09 16:34:21 +0900 |
---|---|---|
committer | mattn <mattn.jp@gmail.com> | 2013-05-09 16:34:21 +0900 |
commit | 3a642d622a13cebe9e91520f18515d48d14eb5a8 (patch) | |
tree | 9e1b92838ba5dd91e885b5c58fa7282b06cf4e18 | |
parent | 6c13caa6bcff4b2b8f2b1d56c01440afc6f09193 (diff) | |
download | vim-sonictemplate-3a642d622a13cebe9e91520f18515d48d14eb5a8.tar.gz vim-sonictemplate-3a642d622a13cebe9e91520f18515d48d14eb5a8.tar.bz2 vim-sonictemplate-3a642d622a13cebe9e91520f18515d48d14eb5a8.zip |
Regexp filter
-rw-r--r-- | autoload/sonictemplate.vim | 3 | ||||
-rw-r--r-- | autoload/sonictemplate/lang/html.vim | 36 |
2 files changed, 38 insertions, 1 deletions
diff --git a/autoload/sonictemplate.vim b/autoload/sonictemplate.vim index b110197..1728de8 100644 --- a/autoload/sonictemplate.vim +++ b/autoload/sonictemplate.vim @@ -98,7 +98,8 @@ function! s:get_candidate(fts, lead) if filter != '' let [lhs, rhs] = [[], []] for c in candidate - if stridx(c, filter) == 0 + let ms = matchstr(c, filter) + if ms != '' && matchstr(c, ms) == 0 call add(lhs, c) else call add(rhs, c) diff --git a/autoload/sonictemplate/lang/html.vim b/autoload/sonictemplate/lang/html.vim new file mode 100644 index 0000000..d804f54 --- /dev/null +++ b/autoload/sonictemplate/lang/html.vim @@ -0,0 +1,36 @@ +function! sonictemplate#lang#html#guess() + let [m1, m2] = ['<\([^ >]\+\)[^>]*>', '</[^>]\+>\zs'] + let area = [searchpairpos(m1, '\%#', m2, 'bnW'), searchpos(m2, 'nW')] + if area[0][0] == 0 || area[1][0] == 0 + return [] + endif + let lines = getline(area[0][0], area[1][0]) + if area[0][0] == area[1][0] + let lines[0] = lines[0][area[0][1]-1:area[1][1]-1] + else + let lines[0] = lines[0][area[0][1]-1:] + let lines[-1] = lines[-1][:area[1][1]-1] + endif + let content = join(lines, "\n") + let tag = matchstr(content, '^<\zs[^> ]\+\ze.*') + let inner = substitute(matchstr(content, '^<[^>]\+>\zs.*\ze</[^>]\+>$'), '[ \t\r\n]', '', 'g') + let g:hoge = inner + if tag == 'script' + return { + \ 'filetype': 'javascript', + \ 'prefix': len(inner) > 0 ? 'snip' : 'base', + \} + endif + if tag == 'style' + return { + \ 'filetype': 'css', + \ 'prefix': len(inner) > 0 ? 'snip' : 'base', + \} + endif + if tag == 'head' + return { + \ 'filter': 'link\|meta' + \} + endif + return [] +endfunction |