diff --git a/autoload/neosnippet.vim b/autoload/neosnippet.vim index 890abf7..68769df 100644 --- a/autoload/neosnippet.vim +++ b/autoload/neosnippet.vim @@ -676,20 +676,21 @@ function! neosnippet#expand_target()"{{{ return endif + call neosnippet#expand_target_trigger(trigger) +endfunction"}}} +function! neosnippet#expand_target_trigger(trigger)"{{{ + let neosnippet = neosnippet#get_current_neosnippet() let neosnippet.target = substitute( \ neosnippet#get_selected_text(visualmode(), 1), '\n$', '', '') - let base_indent = matchstr(neosnippet.target, '^\s*') - " Delete base_indent. - let neosnippet.target = substitute(neosnippet.target, - \'^' . base_indent, '', 'g') + let line = getpos("'<")[1] + let col = getpos("'<")[2] - call neosnippet#substitute_selected_text(visualmode(), - \ base_indent) + call neosnippet#delete_selected_text(visualmode()) - let col = (col('.') < len(base_indent)+1) ? - \ len(base_indent)+1 : col('.') - call neosnippet#expand(neosnippet#util#get_cur_text(), col, trigger) + call cursor(line, col) + + call neosnippet#expand(neosnippet#util#get_cur_text(), col, a:trigger) endfunction"}}} function! s:indent_snippet(begin, end)"{{{ if a:begin > a:end @@ -1176,7 +1177,7 @@ function! neosnippet#get_selected_text(type, ...)"{{{ elseif a:type == 'line' silent exe "normal! '[V']y" elseif a:type == 'block' - silent exe "normal! `[\`]y" + silent exe "normal! `[\`]y" else silent exe "normal! `[v`]y" endif @@ -1198,10 +1199,10 @@ function! neosnippet#delete_selected_text(type, ...)"{{{ " Invoked from Visual mode, use '< and '> marks. if a:0 silent exe "normal! `<" . a:type . "`>d" - elseif a:type == 'line' - silent exe "normal! '[V']d" - elseif a:type == 'block' - silent exe "normal! `[\`]d" + elseif a:type ==# 'V' + silent exe "normal! `[V`]s" + elseif a:type ==# "\" + silent exe "normal! `[\`]d" else silent exe "normal! `[v`]d" endif @@ -1219,7 +1220,15 @@ function! neosnippet#substitute_selected_text(type, text)"{{{ try " Invoked from Visual mode, use '< and '> marks. - silent exe "normal! `<" . a:type . "`>s" . a:text + if a:0 + silent exe "normal! `<" . a:type . "`>s" . a:text + elseif a:type ==# 'V' + silent exe "normal! '[V']hs" . a:text + elseif a:type ==# "\" + silent exe "normal! `[\`]s" . a:text + else + silent exe "normal! `[v`]s" . a:text + endif finally let &selection = sel_save let @@ = reg_save diff --git a/autoload/unite/sources/snippet.vim b/autoload/unite/sources/snippet.vim index a202e3f..3d1e6b1 100644 --- a/autoload/unite/sources/snippet.vim +++ b/autoload/unite/sources/snippet.vim @@ -1,7 +1,7 @@ "============================================================================= " FILE: snippet.vim " AUTHOR: Shougo Matsushita -" Last Modified: 02 Nov 2012. +" Last Modified: 13 Dec 2012. " License: MIT license {{{ " Permission is hereby granted, free of charge, to any person obtaining " a copy of this software and associated documentation files (the @@ -64,7 +64,8 @@ function! s:source.gather_candidates(args, context) "{{{ let list = [] for keyword in a:context.source__snippets let dict = { - \ 'word' : printf('%-50s %s', keyword.word, keyword.menu), + \ 'word' : keyword.word, + \ 'abbr' : printf('%-50s %s', keyword.word, keyword.menu), \ 'kind': 'snippet', \ 'action__complete_word' : keyword.word, \ 'action__complete_pos' : keyword_pos, @@ -167,8 +168,7 @@ function! unite#sources#snippet#start_complete() "{{{ endif return unite#start_complete(['snippet'], - \ { 'input': neosnippet#util#get_cur_text(), - \ 'buffer_name' : 'snippet' }) + \ { 'input': neosnippet#util#get_cur_text(), 'buffer_name' : '' }) endfunction "}}} function! s:get_keyword_pos(cur_text)"{{{ diff --git a/autoload/unite/sources/snippet_target.vim b/autoload/unite/sources/snippet_target.vim index ac5ec89..6ddbd2d 100644 --- a/autoload/unite/sources/snippet_target.vim +++ b/autoload/unite/sources/snippet_target.vim @@ -1,7 +1,7 @@ "============================================================================= " FILE: snippet_target.vim " AUTHOR: Shougo Matsushita -" Last Modified: 06 Nov 2012. +" Last Modified: 13 Dec 2012. " License: MIT license {{{ " Permission is hereby granted, free of charge, to any person obtaining " a copy of this software and associated documentation files (the @@ -82,24 +82,7 @@ function! s:source.action_table.select.func(candidate)"{{{ return endif - let neosnippet = neosnippet#get_current_neosnippet() - - let neosnippet.target = substitute( - \ neosnippet#get_selected_text(visualmode(), 1), '\n$', '', '') - let base_indent = matchstr(neosnippet.target, '^\s*') - - " Delete base_indent. - let neosnippet.target = substitute(neosnippet.target, - \'^' . base_indent, '', 'g') - - call neosnippet#substitute_selected_text(visualmode(), - \ base_indent) - - call cursor(0, getpos("'<")[2]) - - let col = col('.') < len(base_indent)+1 ? len(base_indent)+1 : col('.') - call neosnippet#expand(neosnippet#util#get_cur_text(), - \ col, a:candidate.source__trigger) + call neosnippet#expand_target_trigger(a:candidate.source__trigger) endfunction"}}} "}}} diff --git a/doc/neosnippet.txt b/doc/neosnippet.txt index 69c7580..6dd3cdf 100755 --- a/doc/neosnippet.txt +++ b/doc/neosnippet.txt @@ -713,6 +713,7 @@ CHANGELOG *neosnippet-changelog* 2012-12-13 - Skip neocomplcache completion when expand or jump snippets. +- Fixed expand target behavior. 2012-11-09 - Improved syntax error.