From 38a24ec1dbf71dc1d38680081ff5d0474d0cf232 Mon Sep 17 00:00:00 2001 From: Shougo Matsushita Date: Wed, 25 Dec 2013 21:56:56 +0900 Subject: [PATCH] Fix #199 add :NeoSnippetClearMarkers command --- autoload/neosnippet/commands.vim | 45 +++++++++++++++++++++++++++++- autoload/neosnippet/view.vim | 47 ++++++-------------------------- doc/neosnippet.txt | 12 ++++++-- plugin/neosnippet.vim | 5 +++- 4 files changed, 67 insertions(+), 42 deletions(-) diff --git a/autoload/neosnippet/commands.vim b/autoload/neosnippet/commands.vim index 8a18c78..c113e02 100644 --- a/autoload/neosnippet/commands.vim +++ b/autoload/neosnippet/commands.vim @@ -1,7 +1,7 @@ "============================================================================= " FILE: commands.vim " AUTHOR: Shougo Matsushita -" Last Modified: 21 Nov 2013. +" Last Modified: 25 Dec 2013. " License: MIT license {{{ " Permission is hereby granted, free of charge, to any person obtaining " a copy of this software and associated documentation files (the @@ -123,6 +123,49 @@ function! neosnippet#commands#_source(filename) "{{{ call neosnippet#parser#_parse(neosnippet.snippets, a:filename) endfunction"}}} +function! neosnippet#commands#_clear_markers() "{{{ + let expand_stack = neosnippet#variables#expand_stack() + + " Get patterns and count. + if empty(expand_stack) + \ || neosnippet#variables#current_neosnippet().trigger + return + endif + + let expand_info = expand_stack[-1] + + " Search patterns. + let [begin, end] = neosnippet#view#_get_snippet_range( + \ expand_info.begin_line, + \ expand_info.begin_patterns, + \ expand_info.end_line, + \ expand_info.end_patterns) + + let pos = getpos('.') + + " Found snippet. + let found = 0 + try + while neosnippet#view#_search_snippet_range( + \ begin, end, expand_info.holder_cnt, 0) + " Next count. + let expand_info.holder_cnt += 1 + let found = 1 + endwhile + + " Search placeholder 0. + if neosnippet#view#_search_snippet_range(begin, end, 0) + let found = 1 + endif + finally + if found + stopinsert + endif + + call setpos('.', pos) + endtry +endfunction"}}} + " Complete helpers. function! neosnippet#commands#_edit_complete(arglead, cmdline, cursorpos) "{{{ return filter(s:edit_options + diff --git a/autoload/neosnippet/view.vim b/autoload/neosnippet/view.vim index 33130c5..1e0d0f9 100644 --- a/autoload/neosnippet/view.vim +++ b/autoload/neosnippet/view.vim @@ -1,7 +1,7 @@ "============================================================================= " FILE: view.vim " AUTHOR: Shougo Matsushita -" Last Modified: 22 Nov 2013. +" Last Modified: 25 Dec 2013. " License: MIT license {{{ " Permission is hereby granted, free of charge, to any person obtaining " a copy of this software and associated documentation files (the @@ -142,19 +142,20 @@ function! neosnippet#view#_jump(cur_text, col) "{{{ let expand_info = expand_stack[-1] " Search patterns. - let [begin, end] = s:get_snippet_range( + let [begin, end] = neosnippet#view#_get_snippet_range( \ expand_info.begin_line, \ expand_info.begin_patterns, \ expand_info.end_line, \ expand_info.end_patterns) - if s:search_snippet_range(begin, end, expand_info.holder_cnt) + if neosnippet#view#_search_snippet_range( + \ begin, end, expand_info.holder_cnt) " Next count. let expand_info.holder_cnt += 1 return 1 endif " Search placeholder 0. - if s:search_snippet_range(begin, end, 0) + if neosnippet#view#_search_snippet_range(begin, end, 0) return 1 endif @@ -174,41 +175,11 @@ function! neosnippet#view#_on_insert_leave() "{{{ return endif - let expand_info = expand_stack[-1] - - if expand_info.begin_line != expand_info.end_line + if expand_stack[-1].begin_line != expand_stack[-1].end_line return endif - " Search patterns. - let [begin, end] = s:get_snippet_range( - \ expand_info.begin_line, - \ expand_info.begin_patterns, - \ expand_info.end_line, - \ expand_info.end_patterns) - - let pos = getpos('.') - - " Found snippet. - let found = 0 - try - while s:search_snippet_range(begin, end, expand_info.holder_cnt, 0) - " Next count. - let expand_info.holder_cnt += 1 - let found = 1 - endwhile - - " Search placeholder 0. - if s:search_snippet_range(begin, end, 0) - let found = 1 - endif - finally - if found - stopinsert - endif - - call setpos('.', pos) - endtry + call neosnippet#commands#_clear_markers() endfunction"}}} function! s:indent_snippet(begin, end) "{{{ @@ -253,7 +224,7 @@ function! s:indent_snippet(begin, end) "{{{ endtry endfunction"}}} -function! s:get_snippet_range(begin_line, begin_patterns, end_line, end_patterns) "{{{ +function! neosnippet#view#_get_snippet_range(begin_line, begin_patterns, end_line, end_patterns) "{{{ let pos = getpos('.') call cursor(a:begin_line, 0) @@ -287,7 +258,7 @@ function! s:get_snippet_range(begin_line, begin_patterns, end_line, end_patterns call setpos('.', pos) return [begin, end] endfunction"}}} -function! s:search_snippet_range(start, end, cnt, ...) "{{{ +function! neosnippet#view#_search_snippet_range(start, end, cnt, ...) "{{{ let is_select = get(a:000, 0, 1) call s:substitute_placeholder_marker(a:start, a:end, a:cnt) diff --git a/doc/neosnippet.txt b/doc/neosnippet.txt index c714441..b52c54b 100755 --- a/doc/neosnippet.txt +++ b/doc/neosnippet.txt @@ -71,7 +71,6 @@ COMMANDS *neosnippet-commands* *:NeoSnippetMakeCache* :NeoSnippetMakeCache [filetype] - Creates a cache for the snippets of the given [filetype]. It automatically chooses the current buffer's file type unless you specify another one by [filetype]. @@ -120,10 +119,15 @@ COMMANDS *neosnippet-commands* *:NeoSnippetSource* :NeoSnippetSource [filename] - Load the snippets of a [filetype]. Note: The loaded snippets are enabled in current buffer only. + *:NeoSnippetClearMarkers* +:NeoSnippetClearMarkers + Clear current markers. + Note: If you delete markers, you cannot jump to next + placeholder. + ------------------------------------------------------------------------------ VARIABLES *neosnippet-variables* @@ -725,5 +729,9 @@ Q: I want to add snippets dynamically. A: You can use |:NeoSnippetSource| for it. +Q: I want to delete markers in multiline snippet. + +A: You can use |:NeoSnippetClearMarkers| command. + ============================================================================== vim:tw=78:ts=8:ft=help:norl:noet:fen:noet: diff --git a/plugin/neosnippet.vim b/plugin/neosnippet.vim index 7475cb3..e6e19c5 100644 --- a/plugin/neosnippet.vim +++ b/plugin/neosnippet.vim @@ -1,7 +1,7 @@ "============================================================================= " FILE: neosnippet.vim " AUTHOR: Shougo Matsushita -" Last Modified: 21 Nov 2013. +" Last Modified: 25 Dec 2013. " License: MIT license {{{ " Permission is hereby granted, free of charge, to any person obtaining " a copy of this software and associated documentation files (the @@ -85,6 +85,9 @@ command! -nargs=? -complete=customlist,neosnippet#commands#_filetype_complete command! -nargs=1 -complete=file \ NeoSnippetSource \ call neosnippet#commands#_source() + +command! NeoSnippetClearMarkers + \ call neosnippet#commands#_clear_markers() "}}} let g:loaded_neosnippet = 1