diff options
author | mattn <mattn.jp@gmail.com> | 2011-10-27 18:21:28 +0900 |
---|---|---|
committer | mattn <mattn.jp@gmail.com> | 2011-10-27 18:21:28 +0900 |
commit | e2edb97bb2c44b36d745c6500b720a2553416570 (patch) | |
tree | f12cf4f9eb564ec181cba51eacd7a7e3597d6319 | |
parent | 8bf5c41b132f14abaebf5d842df45c1ef04af864 (diff) | |
download | vim-sonictemplate-e2edb97bb2c44b36d745c6500b720a2553416570.tar.gz vim-sonictemplate-e2edb97bb2c44b36d745c6500b720a2553416570.tar.bz2 vim-sonictemplate-e2edb97bb2c44b36d745c6500b720a2553416570.zip |
support {{__input__:xxx}} to input().
-rw-r--r-- | plugin/template.vim | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/plugin/template.vim b/plugin/template.vim index de6c001..20a4b41 100644 --- a/plugin/template.vim +++ b/plugin/template.vim @@ -18,7 +18,7 @@ " script.perl " -command! -buffer -nargs=1 -complete=customlist,TemplateComplete Template call s:Template(<f-args>) +command! -nargs=1 -complete=customlist,TemplateComplete Template call s:Template(<f-args>) let s:tmpldir = expand('<sfile>:p:h:h') . '/template/' @@ -39,6 +39,23 @@ function! s:Template(name) let c = join(readfile(f, "b"), "\n") let c = substitute(c, '{{_name_}}', expand('%:t:r:'), 'g') let c = substitute(c, '{{_expr_:\(.\{-}\)}}', '\=eval(submatch(1))', 'g') + let c = substitute(c, '{{_expr_:\(.\{-}\)}}', '\=eval(submatch(1))', 'g') + let tmp = c + let mx = '{{_input_:\(.\{-}\)}}' + let vars = {} + while 1 + let match = matchstr(tmp, mx) + if len(match) == 0 + break + endif + let token = substitute(match, mx, '\1', 'ig') + let vars[token] = 1 + let tmp = tmp[stridx(tmp, match) + len(match):] + endwhile + for key in keys(vars) + let val = input(key . ":") + let c = substitute(c, '\V{{_input_:'.key.'}}', '\=val', 'g') + endfor silent! %d _ silent! put = c silent! normal! ggdd |