aboutsummaryrefslogtreecommitdiff
path: root/autoload
diff options
context:
space:
mode:
authorYasuhiro Matsumoto <mattn.jp@gmail.com>2016-07-01 19:02:41 +0900
committerYasuhiro Matsumoto <mattn.jp@gmail.com>2016-07-01 19:02:41 +0900
commitec26576455628e716467b657c170c7ba4c3375d1 (patch)
tree20b72a3b61a5197f27a286b9d7d0d3019b8c80de /autoload
parent0c661f5f888ea180d7aaeca13a9ef44bf22165d2 (diff)
downloadvim-sonictemplate-ec26576455628e716467b657c170c7ba4c3375d1.tar.gz
vim-sonictemplate-ec26576455628e716467b657c170c7ba4c3375d1.tar.bz2
vim-sonictemplate-ec26576455628e716467b657c170c7ba4c3375d1.zip
pattern input
Diffstat (limited to 'autoload')
-rw-r--r--autoload/sonictemplate.vim68
1 files changed, 67 insertions, 1 deletions
diff --git a/autoload/sonictemplate.vim b/autoload/sonictemplate.vim
index dc4f33a..2db9d77 100644
--- a/autoload/sonictemplate.vim
+++ b/autoload/sonictemplate.vim
@@ -117,7 +117,7 @@ function! s:get_candidate(fts, lead)
endif
return candidate
endfunction
-
+
function! sonictemplate#complete(lead, cmdline, curpos) abort
return s:get_candidate([&ft, s:get_filetype(), sonictemplate#get_filetype()], a:lead)
endfunction
@@ -315,6 +315,72 @@ function! sonictemplate#apply(name, mode, ...) abort
endif
endfunction
+let s:pat = {}
+
+function! sonictemplate#pattern()
+ if !has_key(s:pat, &ft)
+ return ''
+ endif
+ let line = getline('.')[:col('.')]
+ for k in keys(s:pat[&ft])
+ let m = matchstr(line, k)
+ if len(m) > 0
+ let ml = matchlist(line, k)
+ let line = line[:-len(m)-1]
+ let c = join(s:pat[&ft][k], "\n")
+ for i in range(1, 9)
+ let c = substitute(c, '{{$' . i . '}}', ml[i], 'g')
+ endfor
+ if line !~ '^\s*$'
+ let indent = matchstr(line, '^\(\s*\)')
+ let lhs = col('.') > 1 ? line[:col('.')-2] : ''
+ let rhs = line[len(lhs):]
+ let lhs = lhs[len(indent):]
+ let c = lhs . c . rhs
+ endif
+ let c = join(split(c, "\n"), "")
+ call setline('.', line)
+ silent! exe "normal! a\<c-r>=c\<cr>"
+ if stridx(c, '{{_cursor_}}') != -1
+ silent! call search('{{_cursor_}}\zs', 'w')
+ silent! foldopen
+ silent! call feedkeys(repeat("\<bs>", 12))
+ endif
+ break
+ endif
+ endfor
+ return ''
+endfunction
+
+function! sonictemplate#load_pattern()
+ let ft = &ft
+ let tmp = []
+ for tmpldir in s:tmpldir
+ let tmp += split(globpath(join([tmpldir, ft], '/'), 'pattern.tpl'), "\n")
+ endfor
+ if len(tmp) == 0
+ return
+ endif
+ let s:pat[ft] = {}
+ for f in tmp
+ let k = ''
+ let l = []
+ for line in add(readfile(f), '__END__')
+ if line == ''
+ continue
+ elseif line !~ '^\t'
+ if k != ''
+ let s:pat[ft][k] = l
+ endif
+ let k = line
+ let l = []
+ else
+ call add(l, line[1:])
+ endif
+ endfor
+ endfor
+endfunction
+
let &cpo = s:save_cpo
unlet s:save_cpo