From 6f2f181cb3822276a28dd3c8742aacfdd58daef0 Mon Sep 17 00:00:00 2001 From: Shougo Matsushita Date: Sun, 28 Oct 2012 18:58:55 +0900 Subject: [PATCH] - Improved expand behavior. --- autoload/neosnippet.vim | 59 ++++++++++++++------------- autoload/neosnippet/snippets/vim.snip | 10 +++++ doc/neosnippet.txt | 1 + 3 files changed, 42 insertions(+), 28 deletions(-) diff --git a/autoload/neosnippet.vim b/autoload/neosnippet.vim index 0c13b50..b3cb2d3 100644 --- a/autoload/neosnippet.vim +++ b/autoload/neosnippet.vim @@ -575,39 +575,42 @@ function! neosnippet#expand(cur_text, col, trigger_name)"{{{ let &l:foldmethod = 'manual' endif - call setline('.', snippet_lines[0]) - if len(snippet_lines) > 1 - call append('.', snippet_lines[1:]) - endif + try + call setline('.', snippet_lines[0]) + if len(snippet_lines) > 1 + call append('.', snippet_lines[1:]) + endif - call s:indent_snippet(begin_line, end_line) + call s:indent_snippet(begin_line, end_line) - let begin_patterns = (begin_line > 1) ? - \ [getline(begin_line - 1)] : [] - let end_patterns = (end_line < line('$')) ? - \ [getline(end_line + 1)] : [] - call add(s:snippets_expand_stack, { - \ 'begin_line' : begin_line, - \ 'begin_patterns' : begin_patterns, - \ 'end_line' : end_line, - \ 'end_patterns' : end_patterns, - \ 'holder_cnt' : 1, - \ }) + let begin_patterns = (begin_line > 1) ? + \ [getline(begin_line - 1)] : [] + let end_patterns = (end_line < line('$')) ? + \ [getline(end_line + 1)] : [] + call add(s:snippets_expand_stack, { + \ 'begin_line' : begin_line, + \ 'begin_patterns' : begin_patterns, + \ 'end_line' : end_line, + \ 'end_patterns' : end_patterns, + \ 'holder_cnt' : 1, + \ }) - if next_col < col('$') - startinsert - else - startinsert! - endif + if next_col < col('$') + startinsert + else + startinsert! + endif - if snip_word =~ s:get_placeholder_marker_pattern() - call s:snippets_jump(a:cur_text, a:col) - endif + if snip_word =~ s:get_placeholder_marker_pattern() + call s:snippets_jump(a:cur_text, a:col) + endif + finally + if has('folding') + let &l:foldmethod = foldmethod + silent! execute begin_line . ',' . end_line . 'foldopen!' + endif + endtry - if has('folding') - let &l:foldmethod = foldmethod - silent! execute begin_line . ',' . end_line . 'foldopen!' - endif let &l:iminsert = 0 let &l:imsearch = 0 endfunction"}}} diff --git a/autoload/neosnippet/snippets/vim.snip b/autoload/neosnippet/snippets/vim.snip index b76a0c0..79d33ff 100644 --- a/autoload/neosnippet/snippets/vim.snip +++ b/autoload/neosnippet/snippets/vim.snip @@ -50,6 +50,16 @@ options head ${3} endtry +snippet tryfinally +abbr try ... finally ... endtry +alias tryf +options head + try + ${1} + finally + ${2} + endtry + snippet catch options head catch ${1:/${2:pattern: empty, E484, Vim(cmdname):{errmsg\\}\}/} diff --git a/doc/neosnippet.txt b/doc/neosnippet.txt index c4ff305..d0d9ced 100644 --- a/doc/neosnippet.txt +++ b/doc/neosnippet.txt @@ -456,6 +456,7 @@ CHANGELOG *neosnippet-changelog* 2012-10-28 - Improved snipMate compatibility. +- Improved expand behavior. 2012-10-27 - Fixed for :SnippetEdit.