From e2edb97bb2c44b36d745c6500b720a2553416570 Mon Sep 17 00:00:00 2001 From: mattn Date: Thu, 27 Oct 2011 18:21:28 +0900 Subject: support {{__input__:xxx}} to input(). --- plugin/template.vim | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) 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() +command! -nargs=1 -complete=customlist,TemplateComplete Template call s:Template() let s:tmpldir = expand(':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 -- cgit v1.2.3-54-g00ecf