diff --git a/autoload/neosnippet/handlers.vim b/autoload/neosnippet/handlers.vim index 5e37bd0..0b442a2 100644 --- a/autoload/neosnippet/handlers.vim +++ b/autoload/neosnippet/handlers.vim @@ -60,7 +60,9 @@ function! neosnippet#handlers#_complete_done() "{{{ if snippet !~ '()\?$' let snippet .= '(' endif - for arg in split(matchstr(abbr, '(\zs.\{-}\ze)'), '[^[]\zs\s*,\s*') + + for arg in split(substitute(neosnippet#handlers#_get_in_paren(abbr), + \ '(\zs.\{-}\ze)', '', 'g'), '[^[]\zs\s*,\s*') if cnt != 1 let snippet .= ', ' endif @@ -100,6 +102,30 @@ function! neosnippet#handlers#_cursor_moved() "{{{ endif endfunction"}}} +function! neosnippet#handlers#_get_in_paren(str) abort "{{{ + let s = '' + let level = 0 + for c in split(a:str, '\zs') + if c == '(' + let level += 1 + + if level == 1 + continue + endif + elseif c == ')' + if level == 1 + return s + else + let level -= 1 + endif + endif + + let s .= c + endfor + + return s +endfunction"}}} + let &cpo = s:save_cpo unlet s:save_cpo diff --git a/test/functions.vim b/test/functions.vim new file mode 100644 index 0000000..f493c4b --- /dev/null +++ b/test/functions.vim @@ -0,0 +1,12 @@ +let s:suite = themis#suite('toml') +let s:assert = themis#helper('assert') + +function! s:suite.get_in_paren() + call s:assert.equals(neosnippet#handlers#_get_in_paren('(foobar)'), + \ 'foobar') + call s:assert.equals(neosnippet#handlers#_get_in_paren('(foobar, baz)'), + \ 'foobar, baz') + call s:assert.equals(neosnippet#handlers#_get_in_paren('(foobar, (baz))'), + \ 'foobar, (baz)') +endfunction +