From 3a642d622a13cebe9e91520f18515d48d14eb5a8 Mon Sep 17 00:00:00 2001 From: mattn Date: Thu, 9 May 2013 16:34:21 +0900 Subject: Regexp filter --- autoload/sonictemplate.vim | 3 ++- autoload/sonictemplate/lang/html.vim | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 autoload/sonictemplate/lang/html.vim 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 -- cgit v1.2.3-54-g00ecf