Merge pull request #390 from TylerHorth/master

Add arguments_are_optional variable
This commit is contained in:
Shougo 2017-06-24 15:37:34 +09:00 committed by GitHub
commit 867149c566
3 changed files with 27 additions and 6 deletions

View File

@ -22,6 +22,8 @@ call neosnippet#util#set_default(
call neosnippet#util#set_default(
\ 'g:neosnippet#enable_completed_snippet', 0,
\ 'g:neosnippet#enable_complete_done')
call neosnippet#util#set_default(
\ 'g:neosnippet#enable_optional_arguments', 1)
call neosnippet#util#set_default(
\ 'g:neosnippet#enable_auto_clear_markers', 1)
call neosnippet#util#set_default(

View File

@ -339,9 +339,7 @@ function! neosnippet#parser#_get_completed_snippet(completed_item, cur_text, nex
for arg in split(substitute(
\ neosnippet#parser#_get_in_paren('<', '>', abbr),
\ '<\zs.\{-}\ze>', '', 'g'), '[^[]\zs\s*,\s*')
let args .= printf('${%d:#:%s%s}',
\ cnt, ((args != '') ? ', ' : ''),
\ escape(arg, '{}'))
let args .= neosnippet#parser#_conceal_argument(arg, cnt, args)
let cnt += 1
endfor
let snippet .= args
@ -364,9 +362,7 @@ function! neosnippet#parser#_get_completed_snippet(completed_item, cur_text, nex
continue
endif
let args .= printf('${%d:#:%s%s}',
\ cnt, ((args != '') ? ', ' : ''),
\ escape(arg, '{}'))
let args .= neosnippet#parser#_conceal_argument(arg, cnt, args)
let cnt += 1
endfor
let snippet .= args
@ -408,4 +404,16 @@ function! neosnippet#parser#_get_in_paren(key, pair, str) abort "{{{
return ''
endfunction"}}}
function! neosnippet#parser#_conceal_argument(arg, cnt, args) abort "{{{
let outside = ''
let inside = ''
if (a:args != '')
if g:neosnippet#enable_optional_arguments
let inside = ', '
else
let outside = ', '
endif
endif
return printf('%s${%d:#:%s%s}', outside, a:cnt, inside, escape(a:arg, '{}'))
endfunction"}}}
" vim: foldmethod=marker

View File

@ -216,6 +216,17 @@ g:neosnippet#enable_completed_snippet
prototype.
The default value is 0.
*g:neosnippet#enable_optional_arguments*
g:neosnippet#enable_optional_arguments
If this variable is not 0, neosnippet will conceal commas in
expanded arguments from completed snippets.
Useful for languages where arguments are optional by default.
Note: For use with |g:neosnippet#enable_completed_snippet| = 1
The default value is 1.
*g:neosnippet#enable_auto_clear_markers*
g:neosnippet#enable_auto_clear_markers