Fix #252 improve optional placeholder behavior

This commit is contained in:
Shougo Matsushita 2014-10-14 20:49:56 +09:00
parent 58a8296b2a
commit 4734238921
4 changed files with 8 additions and 3 deletions

View File

@ -188,7 +188,7 @@ function! s:trigger(function) "{{{
" Get selected text. " Get selected text.
let neosnippet = neosnippet#variables#current_neosnippet() let neosnippet = neosnippet#variables#current_neosnippet()
let neosnippet.trigger = 1 let neosnippet.trigger = 1
if mode() ==# 's' && neosnippet.selected_text =~ '^#:' if mode() ==# 's' && neosnippet.optional_tabstop
let expr .= "\<C-o>\"_d" let expr .= "\<C-o>\"_d"
endif endif

View File

@ -33,6 +33,7 @@ function! neosnippet#variables#current_neosnippet() "{{{
\ 'selected_text' : '', \ 'selected_text' : '',
\ 'target' : '', \ 'target' : '',
\ 'trigger' : 0, \ 'trigger' : 0,
\ 'optional_tabstop' : 0,
\} \}
endif endif

View File

@ -289,11 +289,15 @@ function! s:expand_placeholder(start, end, holder_cnt, line, ...) "{{{
let default = substitute( let default = substitute(
\ matchstr(current_line, default_pattern), \ matchstr(current_line, default_pattern),
\ '\\\ze[^\\]', '', 'g') \ '\\\ze[^\\]', '', 'g')
let neosnippet.optional_tabstop = (default =~ '^#:')
if !is_select && default =~ '^#:' if !is_select && default =~ '^#:'
" Delete comments. " Delete comments.
let default = '' let default = ''
endif endif
" Remove optional marker
let default = substitute(default, '^#:', '', '')
let is_target = (default =~ '^TARGET\>' && neosnippet.target != '') let is_target = (default =~ '^TARGET\>' && neosnippet.target != '')
let default = substitute(default, '^TARGET:\?', neosnippet.target, '') let default = substitute(default, '^TARGET:\?', neosnippet.target, '')

View File

@ -453,7 +453,7 @@ available providing different functionality.
The structure of a placeholder can be: The structure of a placeholder can be:
- ${number:placeholder text} - ${number:default placeholder text}
The placeholder starts with a dollar sign "$". The number of a The placeholder starts with a dollar sign "$". The number of a
placeholder and the placeholder text are separated by a colon ":". placeholder and the placeholder text are separated by a colon ":".
@ -472,7 +472,7 @@ The structure of a placeholder can be:
endif endif
< <
- ${number:#:placeholder text} - ${number:#:optional placeholder text}
In this kind of placeholder the number is followed by the hash In this kind of placeholder the number is followed by the hash
character "#". If you jump over this placeholder and do not insert character "#". If you jump over this placeholder and do not insert