Improve complete done behavior

This commit is contained in:
Shougo Matsushita 2015-12-15 22:04:36 +09:00
parent 33aa676c8f
commit 4c1650096f

View File

@ -27,11 +27,19 @@ let s:save_cpo = &cpo
set cpo&vim set cpo&vim
function! neosnippet#handlers#_complete_done() "{{{ function! neosnippet#handlers#_complete_done() "{{{
if empty(v:completed_item) || !g:neosnippet#enable_complete_done if empty(v:completed_item)
\ || !g:neosnippet#enable_complete_done
\ || v:completed_item.word !~ '($' \ || v:completed_item.word !~ '($'
return return
endif endif
let pairs = { '(' : ')', '{' : '}', '"' : '"' }
if index(keys(pairs), v:completed_item.word[-1:]) < 0
return
endif
let key = v:completed_item.word[-1:]
let pair = pairs[key]
let item = v:completed_item let item = v:completed_item
let abbr = (item.abbr != '') ? item.abbr : item.word let abbr = (item.abbr != '') ? item.abbr : item.word
@ -44,39 +52,30 @@ function! neosnippet#handlers#_complete_done() "{{{
let abbr = split(item.info, '\n')[0] let abbr = split(item.info, '\n')[0]
endif endif
if abbr !~ '('
return
endif
" Make snippet arguments " Make snippet arguments
let cnt = 1 let cnt = 1
let snippet = '' let snippet = ''
if item.word !~ '()\?$' if key == '('
let snippet .= '(' for arg in split(substitute(neosnippet#handlers#_get_in_paren(abbr),
\ '(\zs.\{-}\ze)', '', 'g'), '[^[]\zs\s*,\s*')
if arg ==# 'self' && &filetype ==# 'python'
" Ignore self argument
continue
endif
if cnt != 1
let snippet .= ', '
endif
let snippet .= printf('${%d:#:%s}', cnt, escape(arg, '{}'))
let cnt += 1
endfor
endif endif
for arg in split(substitute(neosnippet#handlers#_get_in_paren(abbr), if !s:is_auto_pairs()
\ '(\zs.\{-}\ze)', '', 'g'), '[^[]\zs\s*,\s*') if key != '(' && snippet =~ key.'$'
if arg ==# 'self' && &filetype ==# 'python' let snippet .= '${'. cnt .'}'.pair
" Ignore self argument elseif snippet !~ pair.'$'
continue let snippet .= pair
endif
if cnt != 1
let snippet .= ', '
endif
let snippet .= printf('${%d:#:%s}', cnt, escape(arg, '{}'))
let cnt += 1
endfor
if s:is_auto_pairs()
" Remove auto pair from the snippet
let snippet = substitute(snippet, ')$', '', '')
else
if snippet =~ '($'
let snippet .= '${'. cnt .'})'
elseif snippet !~ ')$'
let snippet .= ')'
endif endif
let snippet .= '${0}' let snippet .= '${0}'