aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormattn <mattn.jp@gmail.com>2012-04-13 10:20:22 +0900
committermattn <mattn.jp@gmail.com>2012-04-13 10:20:22 +0900
commit41bc85e984230758d4f50f630771fe1f039edc52 (patch)
treef57eeb4a8b666e9a66bbd014b77d4978f9dd9c80
parent630373d3f5de5c9196000762fb9541a6d27071ed (diff)
downloadvim-sonictemplate-41bc85e984230758d4f50f630771fe1f039edc52.tar.gz
vim-sonictemplate-41bc85e984230758d4f50f630771fe1f039edc52.tar.bz2
vim-sonictemplate-41bc85e984230758d4f50f630771fe1f039edc52.zip
improve template dir. related #4
-rw-r--r--autoload/sonictemplate.vim36
-rw-r--r--doc/sonictemplate-vim.txt20
2 files changed, 37 insertions, 19 deletions
diff --git a/autoload/sonictemplate.vim b/autoload/sonictemplate.vim
index 9ac3be5..033524a 100644
--- a/autoload/sonictemplate.vim
+++ b/autoload/sonictemplate.vim
@@ -6,10 +6,13 @@
let s:save_cpo = &cpo
set cpo&vim
+let s:tmpldir = [expand('<sfile>:p:h:h') . '/template/']
if exists('g:sonictemplate_vim_template_dir')
- let s:tmpldir = fnamemodify(expand(g:sonictemplate_vim_template_dir), ':p')
-else
- let s:tmpldir = expand('<sfile>:p:h:h') . '/template/'
+ if type(g:sonictemplate_vim_template_dir) == 3
+ let s:tmpldir += map(g:sonictemplate_vim_template_dir, 'fnamemodify(expand(v:val), ":p")')
+ else
+ call add(s:tmpldir, fnamemodify(expand(g:sonictemplate_vim_template_dir), ":p"))
+ endif
endif
function! sonictemplate#select(mode) abort
@@ -22,11 +25,16 @@ endfunction
function! sonictemplate#complete(lead, cmdline, curpos) abort
let ft = &ft
- let candidate = map(split(globpath(join([s:tmpldir, ft], '/'), (search('[^ \t]', 'wn') ? 'snip-' : 'base-') . a:lead . '*.*'), "\n"), 'fnamemodify(v:val, ":t:r")[5:]')
+ let candidate = []
+ 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:]')
+ endfor
if len(candidate) == 0
let ft = tolower(synIDattr(synID(line("."), col("."), 1), "name"))
if len(ft) > 0
- let candidate = map(split(globpath(join([s:tmpldir, ft], '/'), (search('[^ \t]', 'wn') ? 'snip-' : 'base-') . a:lead . '*.*'), "\n"), 'fnamemodify(v:val, ":t:r")[5:]')
+ 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:]')
+ endfor
endif
endif
return candidate
@@ -35,14 +43,18 @@ endfunction
function! sonictemplate#apply(name, mode) abort
let name = matchstr(a:name, '\S\+')
let buffer_is_not_empty = search('[^ \t]', 'wn')
- let ft = &ft
- let fs = split(globpath(join([s:tmpldir, ft], '/'), (search('[^ \t]', 'wn') ? 'snip-' : 'base-') . name . '.*'), "\n")
- if len(fs) == 0
- let ft = tolower(synIDattr(synID(line("."), col("."), 1), "name"))
- if len(ft) > 0
- let fs = split(globpath(join([s:tmpldir, ft], '/'), (search('[^ \t]', 'wn') ? 'snip-' : 'base-') . name . '.*'), "\n")
+ let fs = []
+ for tmpldir in s:tmpldir
+ let ft = &ft
+ let fsl = split(globpath(join([tmpldir, ft], '/'), (search('[^ \t]', 'wn') ? 'snip-' : 'base-') . name . '.*'), "\n")
+ if len(fsl) == 0
+ let ft = tolower(synIDattr(synID(line("."), col("."), 1), "name"))
+ if len(ft) > 0
+ let fsl = split(globpath(join([tmpldir, ft], '/'), (search('[^ \t]', 'wn') ? 'snip-' : 'base-') . name . '.*'), "\n")
+ endif
endif
- endif
+ let fs += fsl
+ endfor
if len(fs) == 0
echomsg 'Template '.name.' is not exists.'
return
diff --git a/doc/sonictemplate-vim.txt b/doc/sonictemplate-vim.txt
index 4295981..0a21163 100644
--- a/doc/sonictemplate-vim.txt
+++ b/doc/sonictemplate-vim.txt
@@ -13,11 +13,11 @@ License: BSD style license
==============================================================================
CONTENTS *sonictemplate-vim-contents*
-Introduction |sonictemplate-introduction|
-Install |sonictemplate-install|
-Tutorial |sonictemplate-tutorial|
-Customize |sonictemplate-customize|
-Write Your Template |sonictemplate-writetemplate|
+Introduction |sonictemplate-vim-introduction|
+Install |sonictemplate-vim-install|
+Tutorial |sonictemplate-vim-tutorial|
+Customize |sonictemplate-vim-customize|
+Write Your Template |sonictemplate-vim-writetemplate|
==============================================================================
INTRODUCTION *sonictemplate-vim-introduction*
@@ -107,10 +107,16 @@ For example, you are writing C++ file.
==============================================================================
CUSTOMIZE *sonictemplate-vim-customize*
-You can modify template directory for your-self templates.
->
+You can modify template directory for your-self templates: >
let g:template_vim_template_dir = '/path/to/your/template/directory'
<
+ or >
+
+ let g:template_vim_template_dir = [
+ \ '$HOME/.vim/template',
+ \ '/path/to/another/template/directory'
+ \]
+<
==============================================================================
WRITE YOUR TEMPLATE *sonictemplate-vim-writetemplate*