aboutsummaryrefslogtreecommitdiff
path: root/autoload/sonictemplate.vim
diff options
context:
space:
mode:
authormattn <mattn.jp@gmail.com>2013-05-08 21:31:14 +0900
committermattn <mattn.jp@gmail.com>2013-05-08 21:31:14 +0900
commit100bc1c4db1e80720787aab7ce48fcbad5dc481c (patch)
tree6c2f2e12ecb9518953a3f9d8ba01d48cacc4223f /autoload/sonictemplate.vim
parent4f0daba2cbb22736eeefdf2ec48bfa5471c24429 (diff)
downloadvim-sonictemplate-100bc1c4db1e80720787aab7ce48fcbad5dc481c.tar.gz
vim-sonictemplate-100bc1c4db1e80720787aab7ce48fcbad5dc481c.tar.bz2
vim-sonictemplate-100bc1c4db1e80720787aab7ce48fcbad5dc481c.zip
_var_ use _define_-ed var or _input_-ed var
Diffstat (limited to 'autoload/sonictemplate.vim')
-rw-r--r--autoload/sonictemplate.vim21
1 files changed, 19 insertions, 2 deletions
diff --git a/autoload/sonictemplate.vim b/autoload/sonictemplate.vim
index 7326186..01c3407 100644
--- a/autoload/sonictemplate.vim
+++ b/autoload/sonictemplate.vim
@@ -1,7 +1,7 @@
"=============================================================================
" sonictemplate.vim
" Author: Yasuhiro Matsumoto <mattn.jp@gmail.com>
-" Last Change: 28-Nov-2012.
+" Last Change: 08-May-2013.
let s:save_cpo = &cpo
set cpo&vim
@@ -73,6 +73,12 @@ function! s:get_candidate(fts, lead)
endif
endfor
let filter = s:getopt('filter')
+ if filter == ''
+ try
+ let filter = sonictemplate#lang#{&ft}#guess()
+ catch
+ endtry
+ endif
if filter != ''
let [lhs, rhs] = [[], []]
for c in candidate
@@ -153,8 +159,19 @@ function! sonictemplate#apply(name, mode, ...) abort
endwhile
for var in vars
let val = input(var . ":")
- let c = substitute(c, '\V{{_input_:'.var.'}}', '\=val', 'g')
+ let c = substitute(c, '\V{{\(_input_\|_var_\):'.var.'}}', '\=val', 'g')
endfor
+ let mx = '{{_define_:\([^:]\+\):\(.\{-}\)}}\s*'
+ while 1
+ let match = matchstr(c, mx)
+ if len(match) == 0
+ break
+ endif
+ let var = substitute(match, mx, '\1', 'ig')
+ let val = eval(substitute(match, mx, '\2', 'ig'))
+ let c = substitute(c, mx, '', 'g')
+ let c = substitute(c, '\V{{_var_:'.var.'}}', '\=val', 'g')
+ endwhile
sandbox let c = substitute(c, '{{_if_:\(.\{-}\);\(.\{-}\)\(;\(.\{-}\)\)\{-}}}', '\=eval(submatch(1))?submatch(2):submatch(4)', 'g')
sandbox let c = substitute(c, '{{_expr_:\(.\{-}\)}}', '\=eval(submatch(1))', 'g')
if len(c) == 0