From e416d25436b9cd9d24907be4ef893b56bb98251d Mon Sep 17 00:00:00 2001 From: Tyler Horth Date: Fri, 16 Jun 2017 22:50:37 -0400 Subject: [PATCH 1/3] Add arguments_are_optional completion setting --- autoload/neosnippet.vim | 2 ++ autoload/neosnippet/parser.vim | 20 ++++++++++++++------ 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/autoload/neosnippet.vim b/autoload/neosnippet.vim index e6c46b2..64ca45f 100644 --- a/autoload/neosnippet.vim +++ b/autoload/neosnippet.vim @@ -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#arguments_are_optional', 1) call neosnippet#util#set_default( \ 'g:neosnippet#enable_auto_clear_markers', 1) call neosnippet#util#set_default( diff --git a/autoload/neosnippet/parser.vim b/autoload/neosnippet/parser.vim index e8577d4..b635247 100644 --- a/autoload/neosnippet/parser.vim +++ b/autoload/neosnippet/parser.vim @@ -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 @@ -362,9 +360,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 @@ -406,4 +402,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#arguments_are_optional + let inside = ', ' + else + let outside = ', ' + endif + endif + return printf('%s${%d:#:%s%s}', outside, a:cnt, inside, escape(a:arg, '{}')) +endfunction"}}} " vim: foldmethod=marker From ce2007bb15e84b5139fb445d64e2fac01ed67e19 Mon Sep 17 00:00:00 2001 From: Tyler Horth Date: Fri, 16 Jun 2017 23:13:20 -0400 Subject: [PATCH 2/3] Update docs --- doc/neosnippet.txt | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/doc/neosnippet.txt b/doc/neosnippet.txt index 582d76c..dbd390e 100755 --- a/doc/neosnippet.txt +++ b/doc/neosnippet.txt @@ -216,6 +216,15 @@ g:neosnippet#enable_completed_snippet prototype. The default value is 0. + + *g:neosnippet#arguments_are_optional* +g:neosnippet#arguments_are_optional + If this variable is not 0, neosnippet expanded function + arguments will conceal commas. + + Useful for languages where arguments are optional by default. + + The default value is 1. *g:neosnippet#enable_auto_clear_markers* g:neosnippet#enable_auto_clear_markers From 4e55330cc3cd7d8ed7d10f0d6cff3b78075cf84b Mon Sep 17 00:00:00 2001 From: Tyler Horth Date: Mon, 19 Jun 2017 21:04:58 -0400 Subject: [PATCH 3/3] Change variable name and improve docs --- autoload/neosnippet.vim | 2 +- autoload/neosnippet/parser.vim | 2 +- doc/neosnippet.txt | 10 ++++++---- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/autoload/neosnippet.vim b/autoload/neosnippet.vim index 64ca45f..202b774 100644 --- a/autoload/neosnippet.vim +++ b/autoload/neosnippet.vim @@ -23,7 +23,7 @@ call neosnippet#util#set_default( \ 'g:neosnippet#enable_completed_snippet', 0, \ 'g:neosnippet#enable_complete_done') call neosnippet#util#set_default( - \ 'g:neosnippet#arguments_are_optional', 1) + \ 'g:neosnippet#enable_optional_arguments', 1) call neosnippet#util#set_default( \ 'g:neosnippet#enable_auto_clear_markers', 1) call neosnippet#util#set_default( diff --git a/autoload/neosnippet/parser.vim b/autoload/neosnippet/parser.vim index b635247..aa92b42 100644 --- a/autoload/neosnippet/parser.vim +++ b/autoload/neosnippet/parser.vim @@ -406,7 +406,7 @@ function! neosnippet#parser#_conceal_argument(arg, cnt, args) abort "{{{ let outside = '' let inside = '' if (a:args != '') - if g:neosnippet#arguments_are_optional + if g:neosnippet#enable_optional_arguments let inside = ', ' else let outside = ', ' diff --git a/doc/neosnippet.txt b/doc/neosnippet.txt index dbd390e..354162a 100755 --- a/doc/neosnippet.txt +++ b/doc/neosnippet.txt @@ -217,13 +217,15 @@ g:neosnippet#enable_completed_snippet The default value is 0. - *g:neosnippet#arguments_are_optional* -g:neosnippet#arguments_are_optional - If this variable is not 0, neosnippet expanded function - arguments will conceal commas. + *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*