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,17 +52,10 @@ 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 .= '('
endif
for arg in split(substitute(neosnippet#handlers#_get_in_paren(abbr), for arg in split(substitute(neosnippet#handlers#_get_in_paren(abbr),
\ '(\zs.\{-}\ze)', '', 'g'), '[^[]\zs\s*,\s*') \ '(\zs.\{-}\ze)', '', 'g'), '[^[]\zs\s*,\s*')
if arg ==# 'self' && &filetype ==# 'python' if arg ==# 'self' && &filetype ==# 'python'
@ -68,15 +69,13 @@ function! neosnippet#handlers#_complete_done() "{{{
let snippet .= printf('${%d:#:%s}', cnt, escape(arg, '{}')) let snippet .= printf('${%d:#:%s}', cnt, escape(arg, '{}'))
let cnt += 1 let cnt += 1
endfor endfor
endif
if s:is_auto_pairs() if !s:is_auto_pairs()
" Remove auto pair from the snippet if key != '(' && snippet =~ key.'$'
let snippet = substitute(snippet, ')$', '', '') let snippet .= '${'. cnt .'}'.pair
else elseif snippet !~ pair.'$'
if snippet =~ '($' let snippet .= pair
let snippet .= '${'. cnt .'})'
elseif snippet !~ ')$'
let snippet .= ')'
endif endif
let snippet .= '${0}' let snippet .= '${0}'