- Fixed expand target behavior.

This commit is contained in:
Shougo Matsushita 2012-12-13 16:52:58 +09:00
parent d01cd7247f
commit 0fa62bcea1
4 changed files with 31 additions and 38 deletions

View File

@ -676,20 +676,21 @@ function! neosnippet#expand_target()"{{{
return return
endif endif
call neosnippet#expand_target_trigger(trigger)
endfunction"}}}
function! neosnippet#expand_target_trigger(trigger)"{{{
let neosnippet = neosnippet#get_current_neosnippet()
let neosnippet.target = substitute( let neosnippet.target = substitute(
\ neosnippet#get_selected_text(visualmode(), 1), '\n$', '', '') \ neosnippet#get_selected_text(visualmode(), 1), '\n$', '', '')
let base_indent = matchstr(neosnippet.target, '^\s*')
" Delete base_indent. let line = getpos("'<")[1]
let neosnippet.target = substitute(neosnippet.target, let col = getpos("'<")[2]
\'^' . base_indent, '', 'g')
call neosnippet#substitute_selected_text(visualmode(), call neosnippet#delete_selected_text(visualmode())
\ base_indent)
let col = (col('.') < len(base_indent)+1) ? call cursor(line, col)
\ len(base_indent)+1 : col('.')
call neosnippet#expand(neosnippet#util#get_cur_text(), col, trigger) call neosnippet#expand(neosnippet#util#get_cur_text(), col, a:trigger)
endfunction"}}} endfunction"}}}
function! s:indent_snippet(begin, end)"{{{ function! s:indent_snippet(begin, end)"{{{
if a:begin > a:end if a:begin > a:end
@ -1176,7 +1177,7 @@ function! neosnippet#get_selected_text(type, ...)"{{{
elseif a:type == 'line' elseif a:type == 'line'
silent exe "normal! '[V']y" silent exe "normal! '[V']y"
elseif a:type == 'block' elseif a:type == 'block'
silent exe "normal! `[\<C-V>`]y" silent exe "normal! `[\<C-v>`]y"
else else
silent exe "normal! `[v`]y" silent exe "normal! `[v`]y"
endif endif
@ -1198,10 +1199,10 @@ function! neosnippet#delete_selected_text(type, ...)"{{{
" Invoked from Visual mode, use '< and '> marks. " Invoked from Visual mode, use '< and '> marks.
if a:0 if a:0
silent exe "normal! `<" . a:type . "`>d" silent exe "normal! `<" . a:type . "`>d"
elseif a:type == 'line' elseif a:type ==# 'V'
silent exe "normal! '[V']d" silent exe "normal! `[V`]s"
elseif a:type == 'block' elseif a:type ==# "\<C-v>"
silent exe "normal! `[\<C-V>`]d" silent exe "normal! `[\<C-v>`]d"
else else
silent exe "normal! `[v`]d" silent exe "normal! `[v`]d"
endif endif
@ -1219,7 +1220,15 @@ function! neosnippet#substitute_selected_text(type, text)"{{{
try try
" Invoked from Visual mode, use '< and '> marks. " Invoked from Visual mode, use '< and '> marks.
if a:0
silent exe "normal! `<" . a:type . "`>s" . a:text silent exe "normal! `<" . a:type . "`>s" . a:text
elseif a:type ==# 'V'
silent exe "normal! '[V']hs" . a:text
elseif a:type ==# "\<C-v>"
silent exe "normal! `[\<C-v>`]s" . a:text
else
silent exe "normal! `[v`]s" . a:text
endif
finally finally
let &selection = sel_save let &selection = sel_save
let @@ = reg_save let @@ = reg_save

View File

@ -1,7 +1,7 @@
"============================================================================= "=============================================================================
" FILE: snippet.vim " FILE: snippet.vim
" AUTHOR: Shougo Matsushita <Shougo.Matsu@gmail.com> " AUTHOR: Shougo Matsushita <Shougo.Matsu@gmail.com>
" Last Modified: 02 Nov 2012. " Last Modified: 13 Dec 2012.
" License: MIT license {{{ " License: MIT license {{{
" Permission is hereby granted, free of charge, to any person obtaining " Permission is hereby granted, free of charge, to any person obtaining
" a copy of this software and associated documentation files (the " a copy of this software and associated documentation files (the
@ -64,7 +64,8 @@ function! s:source.gather_candidates(args, context) "{{{
let list = [] let list = []
for keyword in a:context.source__snippets for keyword in a:context.source__snippets
let dict = { let dict = {
\ 'word' : printf('%-50s %s', keyword.word, keyword.menu), \ 'word' : keyword.word,
\ 'abbr' : printf('%-50s %s', keyword.word, keyword.menu),
\ 'kind': 'snippet', \ 'kind': 'snippet',
\ 'action__complete_word' : keyword.word, \ 'action__complete_word' : keyword.word,
\ 'action__complete_pos' : keyword_pos, \ 'action__complete_pos' : keyword_pos,
@ -167,8 +168,7 @@ function! unite#sources#snippet#start_complete() "{{{
endif endif
return unite#start_complete(['snippet'], return unite#start_complete(['snippet'],
\ { 'input': neosnippet#util#get_cur_text(), \ { 'input': neosnippet#util#get_cur_text(), 'buffer_name' : '' })
\ 'buffer_name' : 'snippet' })
endfunction "}}} endfunction "}}}
function! s:get_keyword_pos(cur_text)"{{{ function! s:get_keyword_pos(cur_text)"{{{

View File

@ -1,7 +1,7 @@
"============================================================================= "=============================================================================
" FILE: snippet_target.vim " FILE: snippet_target.vim
" AUTHOR: Shougo Matsushita <Shougo.Matsu@gmail.com> " AUTHOR: Shougo Matsushita <Shougo.Matsu@gmail.com>
" Last Modified: 06 Nov 2012. " Last Modified: 13 Dec 2012.
" License: MIT license {{{ " License: MIT license {{{
" Permission is hereby granted, free of charge, to any person obtaining " Permission is hereby granted, free of charge, to any person obtaining
" a copy of this software and associated documentation files (the " a copy of this software and associated documentation files (the
@ -82,24 +82,7 @@ function! s:source.action_table.select.func(candidate)"{{{
return return
endif endif
let neosnippet = neosnippet#get_current_neosnippet() call neosnippet#expand_target_trigger(a:candidate.source__trigger)
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)
endfunction"}}} endfunction"}}}
"}}} "}}}

View File

@ -713,6 +713,7 @@ CHANGELOG *neosnippet-changelog*
2012-12-13 2012-12-13
- Skip neocomplcache completion when expand or jump snippets. - Skip neocomplcache completion when expand or jump snippets.
- Fixed expand target behavior.
2012-11-09 2012-11-09
- Improved syntax error. - Improved syntax error.