Fix paren parser
This commit is contained in:
parent
d4a154ff6d
commit
1617094a8c
@ -60,7 +60,9 @@ function! neosnippet#handlers#_complete_done() "{{{
|
|||||||
if snippet !~ '()\?$'
|
if snippet !~ '()\?$'
|
||||||
let snippet .= '('
|
let snippet .= '('
|
||||||
endif
|
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
|
if cnt != 1
|
||||||
let snippet .= ', '
|
let snippet .= ', '
|
||||||
endif
|
endif
|
||||||
@ -100,6 +102,30 @@ function! neosnippet#handlers#_cursor_moved() "{{{
|
|||||||
endif
|
endif
|
||||||
endfunction"}}}
|
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
|
let &cpo = s:save_cpo
|
||||||
unlet s:save_cpo
|
unlet s:save_cpo
|
||||||
|
|
||||||
|
12
test/functions.vim
Normal file
12
test/functions.vim
Normal file
@ -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
|
||||||
|
|
Loading…
Reference in New Issue
Block a user