diff options
author | mattn <mattn.jp@gmail.com> | 2012-11-28 21:53:22 +0900 |
---|---|---|
committer | mattn <mattn.jp@gmail.com> | 2012-11-28 21:53:22 +0900 |
commit | e0fcf5a243a8ca47e2276e02a05254b4aa003b2b (patch) | |
tree | f96709ca62da39c825613596a7dae8a255cbdef8 /autoload | |
parent | e97be0835bc225d673fe2a71d186943b09f7a29c (diff) | |
download | vim-sonictemplate-e0fcf5a243a8ca47e2276e02a05254b4aa003b2b.tar.gz vim-sonictemplate-e0fcf5a243a8ca47e2276e02a05254b4aa003b2b.tar.bz2 vim-sonictemplate-e0fcf5a243a8ca47e2276e02a05254b4aa003b2b.zip |
add template filter.
Diffstat (limited to 'autoload')
-rw-r--r-- | autoload/sonictemplate.vim | 37 |
1 files changed, 35 insertions, 2 deletions
diff --git a/autoload/sonictemplate.vim b/autoload/sonictemplate.vim index 13c1651..7326186 100644 --- a/autoload/sonictemplate.vim +++ b/autoload/sonictemplate.vim @@ -1,7 +1,7 @@ "============================================================================= " sonictemplate.vim " Author: Yasuhiro Matsumoto <mattn.jp@gmail.com> -" Last Change: 27-Jun-2012. +" Last Change: 28-Nov-2012. let s:save_cpo = &cpo set cpo&vim @@ -72,6 +72,18 @@ function! s:get_candidate(fts, lead) call add(candidate, c) endif endfor + let filter = s:getopt('filter') + if filter != '' + let [lhs, rhs] = [[], []] + for c in candidate + if stridx(c, filter) == 0 + call add(lhs, c) + else + call add(rhs, c) + endif + endfor + let candidate = lhs + rhs + endif return candidate endfunction @@ -83,6 +95,20 @@ function! sonictemplate#complete_intelligent(lead, cmdline, curpos) abort return s:get_candidate([sonictemplate#get_filetype(), &ft], a:lead) endfunction +function! s:setopt(k, v) + if !exists('b:sonictemplate') + let b:sonictemplate = {} + endif + let b:sonictemplate[a:k] = a:v +endfunction + +function! s:getopt(k) + if !exists('b:sonictemplate') || !has_key(b:sonictemplate, a:k) + return '' + endif + return b:sonictemplate[a:k] +endfunction + function! sonictemplate#apply(name, mode, ...) abort let name = matchstr(a:name, '\S\+') let buffer_is_not_empty = search('[^ \t]', 'wn') @@ -134,8 +160,15 @@ function! sonictemplate#apply(name, mode, ...) abort if len(c) == 0 return endif + let mx = '{{_filter_:\(\w\+\)}}\s*' + let bf = matchstr(c, mx) + if len(bf) > 0 + call s:setopt('filter', substitute(bf, mx, '\1', '')) + let c = substitute(c, mx, '', 'g') + endif + if !buffer_is_not_empty - let c = substitute(c, '{{_inline_}}', '', 'g') + let c = substitute(c, '{{_inline_}}\s*', '', 'g') if &expandtab || &tabstop != &shiftwidth let c = substitute(c, "\t", repeat(' ', &shiftwidth), 'g') endif |