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