- 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
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! `[\<C-V>`]y"
silent exe "normal! `[\<C-v>`]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! `[\<C-V>`]d"
elseif a:type ==# 'V'
silent exe "normal! `[V`]s"
elseif a:type ==# "\<C-v>"
silent exe "normal! `[\<C-v>`]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 ==# "\<C-v>"
silent exe "normal! `[\<C-v>`]s" . a:text
else
silent exe "normal! `[v`]s" . a:text
endif
finally
let &selection = sel_save
let @@ = reg_save

View File

@ -1,7 +1,7 @@
"=============================================================================
" FILE: snippet.vim
" AUTHOR: Shougo Matsushita <Shougo.Matsu@gmail.com>
" 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)"{{{

View File

@ -1,7 +1,7 @@
"=============================================================================
" FILE: snippet_target.vim
" AUTHOR: Shougo Matsushita <Shougo.Matsu@gmail.com>
" 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"}}}
"}}}

View File

@ -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.