From 47342389214ed9f7cf3e0b38cf9991e88b222ace Mon Sep 17 00:00:00 2001 From: Shougo Matsushita Date: Tue, 14 Oct 2014 20:49:56 +0900 Subject: [PATCH] Fix #252 improve optional placeholder behavior --- autoload/neosnippet/mappings.vim | 2 +- autoload/neosnippet/variables.vim | 1 + autoload/neosnippet/view.vim | 4 ++++ doc/neosnippet.txt | 4 ++-- 4 files changed, 8 insertions(+), 3 deletions(-) diff --git a/autoload/neosnippet/mappings.vim b/autoload/neosnippet/mappings.vim index db22d3a..5a3f38b 100644 --- a/autoload/neosnippet/mappings.vim +++ b/autoload/neosnippet/mappings.vim @@ -188,7 +188,7 @@ function! s:trigger(function) "{{{ " Get selected text. let neosnippet = neosnippet#variables#current_neosnippet() let neosnippet.trigger = 1 - if mode() ==# 's' && neosnippet.selected_text =~ '^#:' + if mode() ==# 's' && neosnippet.optional_tabstop let expr .= "\\"_d" endif diff --git a/autoload/neosnippet/variables.vim b/autoload/neosnippet/variables.vim index f7cc1c3..7080892 100644 --- a/autoload/neosnippet/variables.vim +++ b/autoload/neosnippet/variables.vim @@ -33,6 +33,7 @@ function! neosnippet#variables#current_neosnippet() "{{{ \ 'selected_text' : '', \ 'target' : '', \ 'trigger' : 0, + \ 'optional_tabstop' : 0, \} endif diff --git a/autoload/neosnippet/view.vim b/autoload/neosnippet/view.vim index 6a2eb68..c6f9588 100644 --- a/autoload/neosnippet/view.vim +++ b/autoload/neosnippet/view.vim @@ -289,11 +289,15 @@ function! s:expand_placeholder(start, end, holder_cnt, line, ...) "{{{ let default = substitute( \ matchstr(current_line, default_pattern), \ '\\\ze[^\\]', '', 'g') + let neosnippet.optional_tabstop = (default =~ '^#:') if !is_select && default =~ '^#:' " Delete comments. let default = '' endif + " Remove optional marker + let default = substitute(default, '^#:', '', '') + let is_target = (default =~ '^TARGET\>' && neosnippet.target != '') let default = substitute(default, '^TARGET:\?', neosnippet.target, '') diff --git a/doc/neosnippet.txt b/doc/neosnippet.txt index 3b6f9fa..082d374 100755 --- a/doc/neosnippet.txt +++ b/doc/neosnippet.txt @@ -453,7 +453,7 @@ available providing different functionality. 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 placeholder and the placeholder text are separated by a colon ":". @@ -472,7 +472,7 @@ The structure of a placeholder can be: endif < -- ${number:#:placeholder text} +- ${number:#:optional placeholder text} In this kind of placeholder the number is followed by the hash character "#". If you jump over this placeholder and do not insert