diff options
author | mityu <mityu.mob@gmail.com> | 2019-03-07 22:19:44 +0900 |
---|---|---|
committer | mityu <mityu.mob@gmail.com> | 2019-03-10 11:20:55 +0900 |
commit | c9d83ccee0be778fcb52315b907431af0ea1057e (patch) | |
tree | 51ca07f28d1c14aa400d4d1182ad24e1e05306e8 /autoload | |
parent | ffd98639c3a2444d84585397e42a985371a90358 (diff) | |
download | vim-sonictemplate-c9d83ccee0be778fcb52315b907431af0ea1057e.tar.gz vim-sonictemplate-c9d83ccee0be778fcb52315b907431af0ea1057e.tar.bz2 vim-sonictemplate-c9d83ccee0be778fcb52315b907431af0ea1057e.zip |
Fix command-line completion returns templates of VimScript on command-line window.
- Add s:get_raw_filetype() to check whether being command-line window.
- Replace '&ft' with s:get_raw_filetype() automatically.
Diffstat (limited to 'autoload')
-rw-r--r-- | autoload/sonictemplate.vim | 30 |
1 files changed, 17 insertions, 13 deletions
diff --git a/autoload/sonictemplate.vim b/autoload/sonictemplate.vim index 2c68664..a98f3e2 100644 --- a/autoload/sonictemplate.vim +++ b/autoload/sonictemplate.vim @@ -1,7 +1,7 @@ "============================================================================= " sonictemplate.vim " Author: Yasuhiro Matsumoto <mattn.jp@gmail.com> -" Last Change: 25-Feb-2019. +" Last Change: 07-Mar-2019. let s:save_cpo = &cpo set cpo&vim @@ -90,7 +90,7 @@ function! s:get_candidate(fts, lead) for tmpldir in s:tmpldir let tmp += map(split(globpath(join([tmpldir, ft], '/'), 'file-' . expand('%:t:r') . '*.*'), "\n"), 'fnamemodify(v:val, ":t:r")[5:]') endfor - if &ft == '' + if s:get_raw_filetype() == '' for tmpldir in s:tmpldir let tmp += sort(map(split(globpath(join([tmpldir, '_'], '/'), 'file-' . expand('%:t:r') . '*.*'), "\n"), 'fnamemodify(v:val, ":t:r")[5:]')) endfor @@ -129,11 +129,11 @@ function! s:get_candidate(fts, lead) endfunction function! sonictemplate#complete(lead, cmdline, curpos) abort - return s:get_candidate([&ft, s:get_filetype(), sonictemplate#get_filetype()], a:lead) + return s:get_candidate([s:get_raw_filetype(), s:get_filetype(), sonictemplate#get_filetype()], a:lead) endfunction function! sonictemplate#complete_intelligent(lead, cmdline, curpos) abort - return s:get_candidate([sonictemplate#get_filetype(), &ft, s:get_filetype()], a:lead) + return s:get_candidate([sonictemplate#get_filetype(), s:get_raw_filetype(), s:get_filetype()], a:lead) endfunction function! s:setopt(k, v) @@ -153,7 +153,11 @@ endfunction let s:vars = {} function! s:get_filetype() - return matchstr(&ft, '^\([^.]\)\+') + return matchstr(s:get_raw_filetype(), '^\([^.]\)\+') +endfunction + +function! s:get_raw_filetype() + return getcmdwintype() ==# '' ? &ft : getbufvar('#', '&ft') endfunction function! sonictemplate#getvar(name) @@ -176,9 +180,9 @@ function! sonictemplate#apply(name, mode, ...) abort let ft = s:getopt('filetype') if ft == '' if get(a:000, 0, 0) - let fts = [sonictemplate#get_filetype(), &ft, s:get_filetype(), '_'] + let fts = [sonictemplate#get_filetype(), s:get_raw_filetype(), s:get_filetype(), '_'] else - let fts = [&ft, s:get_filetype(), sonictemplate#get_filetype(), '_'] + let fts = [s:get_raw_filetype(), s:get_filetype(), sonictemplate#get_filetype(), '_'] endif else let fts = [ft] @@ -237,8 +241,8 @@ function! sonictemplate#apply(name, mode, ...) abort if exists('V') unlet V endif - if has_key(gvars, &ft) && type(gvars[&ft]) == 4 && has_key(gvars[&ft], var) - let V = gvars[&ft][var] + if has_key(gvars, s:get_raw_filetype()) && type(gvars[s:get_raw_filetype()]) == 4 && has_key(gvars[s:get_raw_filetype()], var) + let V = gvars[s:get_raw_filetype()][var] if type(V) == 1 | let val = V | else | let val = string(V) | endif elseif has_key(gvars, '_') && type(gvars['_']) == 4 && has_key(gvars['_'], var) let V = gvars['_'][var] @@ -332,16 +336,16 @@ let s:pat = {} function! sonictemplate#postfix() call sonictemplate#load_postfix() - if !has_key(s:pat, &ft) + if !has_key(s:pat, s:get_raw_filetype()) return '' endif let line = getline('.')[:col('.')] - for k in keys(s:pat[&ft]) + for k in keys(s:pat[s:get_raw_filetype()]) 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") + let c = join(s:pat[s:get_raw_filetype()][k], "\n") for i in range(1, 9) let c = substitute(c, '{{$' . i . '}}', ml[i], 'g') endfor @@ -383,7 +387,7 @@ function! sonictemplate#postfix() endfunction function! sonictemplate#load_postfix() - let ft = &ft + let ft = s:get_raw_filetype() if has_key(s:pat, ft) return endif |