diff options
author | mattn <mattn.jp@gmail.com> | 2012-04-15 23:05:26 +0900 |
---|---|---|
committer | mattn <mattn.jp@gmail.com> | 2012-04-15 23:05:26 +0900 |
commit | 2328c985fcfeb67ae20c8d937b04e0f3254608c8 (patch) | |
tree | 1a4c90f4d1ac4ac29ac52c3696871a60ef4fed89 | |
parent | 1f40c1ff7b2d85da0f54832b925a60149aa7f6d2 (diff) | |
download | vim-sonictemplate-2328c985fcfeb67ae20c8d937b04e0f3254608c8.tar.gz vim-sonictemplate-2328c985fcfeb67ae20c8d937b04e0f3254608c8.tar.bz2 vim-sonictemplate-2328c985fcfeb67ae20c8d937b04e0f3254608c8.zip |
user can override default template.
-rw-r--r-- | autoload/sonictemplate.vim | 16 | ||||
-rw-r--r-- | doc/sonictemplate-vim.txt | 14 |
2 files changed, 25 insertions, 5 deletions
diff --git a/autoload/sonictemplate.vim b/autoload/sonictemplate.vim index 04bfd22..fef7d6f 100644 --- a/autoload/sonictemplate.vim +++ b/autoload/sonictemplate.vim @@ -1,7 +1,7 @@ "============================================================================= " sonictemplate.vim " Author: Yasuhiro Matsumoto <mattn.jp@gmail.com> -" Last Change: 13-Apr-2012. +" Last Change: 15-Apr-2012. let s:save_cpo = &cpo set cpo&vim @@ -26,18 +26,24 @@ endfunction function! sonictemplate#complete(lead, cmdline, curpos) abort let ft = &ft - let candidate = [] + let tmp = [] for tmpldir in s:tmpldir - let candidate += map(split(globpath(join([tmpldir, ft], '/'), (search('[^ \t]', 'wn') ? 'snip-' : 'base-') . a:lead . '*.*'), "\n"), 'fnamemodify(v:val, ":t:r")[5:]') + let tmp += map(split(globpath(join([tmpldir, ft], '/'), (search('[^ \t]', 'wn') ? 'snip-' : 'base-') . a:lead . '*.*'), "\n"), 'fnamemodify(v:val, ":t:r")[5:]') endfor - if len(candidate) == 0 + if len(tmp) == 0 let ft = tolower(synIDattr(synID(line("."), col("."), 1), "name")) if len(ft) > 0 for tmpldir in s:tmpldir - let candidate += map(split(globpath(join([tmpldir, ft], '/'), (search('[^ \t]', 'wn') ? 'snip-' : 'base-') . a:lead . '*.*'), "\n"), 'fnamemodify(v:val, ":t:r")[5:]') + let tmp += map(split(globpath(join([tmpldir, ft], '/'), (search('[^ \t]', 'wn') ? 'snip-' : 'base-') . a:lead . '*.*'), "\n"), 'fnamemodify(v:val, ":t:r")[5:]') endfor endif endif + let candidate = [] + for c in tmp + if index(candidate, c) == -1 + call add(candidate, c) + endif + endfor return candidate endfunction diff --git a/doc/sonictemplate-vim.txt b/doc/sonictemplate-vim.txt index 73ada2e..3efe061 100644 --- a/doc/sonictemplate-vim.txt +++ b/doc/sonictemplate-vim.txt @@ -117,6 +117,20 @@ You can modify template directory for your-self templates: > \ '/path/to/another/template/directory' \] < +You can override default template to make same structures. For example, a +default C language template 'main' is like following. +> + #include <stdio.h> + + int + main(int argc, char* argv[]) { + {{_cursor_}} + return 0; + } + +This template is stored in 'sonictemplate-vim/template/c/base-main.c'. +If you store base-main.c in another template directory that is specified +|g:sonictemplate_vim_template_dir|, it will be overrided with your's one. ============================================================================== WRITE YOUR TEMPLATE *sonictemplate-vim-writetemplate* |