aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormattn <mattn.jp@gmail.com>2012-06-11 21:52:47 +0900
committermattn <mattn.jp@gmail.com>2012-06-11 21:52:47 +0900
commit6c46469120f08065627cb33a58281e9dc0969574 (patch)
treee32111b5a0cb6aeed9371eea159da7345625661f
parenta243c5b22d450ef6f4f3a13079e139bbd8e0489a (diff)
downloadvim-sonictemplate-6c46469120f08065627cb33a58281e9dc0969574.tar.gz
vim-sonictemplate-6c46469120f08065627cb33a58281e9dc0969574.tar.bz2
vim-sonictemplate-6c46469120f08065627cb33a58281e9dc0969574.zip
cleanup.
-rw-r--r--autoload/sonictemplate.vim45
1 files changed, 14 insertions, 31 deletions
diff --git a/autoload/sonictemplate.vim b/autoload/sonictemplate.vim
index 5699a6f..e15446f 100644
--- a/autoload/sonictemplate.vim
+++ b/autoload/sonictemplate.vim
@@ -51,21 +51,19 @@ function! sonictemplate#get_filetype()
endif
return ft
endfunction
-
-function! sonictemplate#complete(lead, cmdline, curpos) abort
- let ft = &ft
- let tmp = []
- let fts = [&ft, sonictemplate#get_filetype()]
+
+function! s:get_candidate(fts)
+ let prefix = search('[^ \t]', 'wn') ? 'snip-' : 'base-'
for tmpldir in s:tmpldir
- for ft in fts
- let tmp += map(split(globpath(join([tmpldir, ft], '/'), (search('[^ \t]', 'wn') ? 'snip-' : 'base-') . a:lead . '*.*'), "\n"), 'fnamemodify(v:val, ":t:r")[5:]')
+ for ft in a:fts
+ let tmp += map(split(globpath(join([tmpldir, ft], '/'), prefix . a:lead . '*.*'), "\n"), 'fnamemodify(v:val, ":t:r")[5:]')
if len(tmp) > 0
break
endif
endfor
endfor
for tmpldir in s:tmpldir
- let tmp += map(split(globpath(join([tmpldir, '_'], '/'), (search('[^ \t]', 'wn') ? 'snip-' : 'base-') . a:lead . '*.*'), "\n"), 'fnamemodify(v:val, ":t:r")[5:]')
+ let tmp += map(split(globpath(join([tmpldir, '_'], '/'), prefix . a:lead . '*.*'), "\n"), 'fnamemodify(v:val, ":t:r")[5:]')
endfor
let candidate = []
for c in tmp
@@ -75,32 +73,15 @@ function! sonictemplate#complete(lead, cmdline, curpos) abort
endfor
return candidate
endfunction
+
+function! sonictemplate#complete(lead, cmdline, curpos) abort
+ return s:get_candidate([&ft, sonictemplate#get_filetype()])
+endfunction
function! sonictemplate#complete_intelligent(lead, cmdline, curpos) abort
- let ft = &ft
- let tmp = []
- let fts = [tolower(sonictemplate#get_filetype()), &ft]
- for tmpldir in s:tmpldir
- for ft in fts
- let tmp += map(split(globpath(join([tmpldir, ft], '/'), (search('[^ \t]', 'wn') ? 'snip-' : 'base-') . a:lead . '*.*'), "\n"), 'fnamemodify(v:val, ":t:r")[5:]')
- if len(tmp) > 0
- break
- endif
- endfor
- endfor
- for tmpldir in s:tmpldir
- let tmp += map(split(globpath(join([tmpldir, '_'], '/'), (search('[^ \t]', 'wn') ? 'snip-' : 'base-') . a:lead . '*.*'), "\n"), 'fnamemodify(v:val, ":t:r")[5:]')
- endfor
- let candidate = []
- for c in tmp
- if index(candidate, c) == -1
- call add(candidate, c)
- endif
- endfor
- return candidate
+ return s:get_candidate([sonictemplate#get_filetype(), &ft])
endfunction
-
function! sonictemplate#apply(name, mode, ...) abort
let name = matchstr(a:name, '\S\+')
let buffer_is_not_empty = search('[^ \t]', 'wn')
@@ -113,7 +94,9 @@ function! sonictemplate#apply(name, mode, ...) abort
let prefix = search('[^ \t]', 'wn') ? 'snip-' : 'base-'
for tmpldir in s:tmpldir
for ft in fts
- let fs += split(globpath(join([tmpldir, ft], '/'), prefix . name . '.*'), "\n")
+ if len(ft) > 0
+ let fs += split(globpath(join([tmpldir, ft], '/'), prefix . name . '.*'), "\n")
+ endif
endfor
endfor
if len(fs) == 0