- Improved targetted placeholder.

This commit is contained in:
Shougo Matsushita 2012-10-30 08:03:53 +09:00
parent 617a858341
commit dc4ad41100

View File

@ -463,7 +463,7 @@ function! s:snippets_expand(cur_text, col)"{{{
call neosnippet#expand( call neosnippet#expand(
\ a:cur_text, a:col, cur_word) \ a:cur_text, a:col, cur_word)
endfunction"}}} endfunction"}}}
function! s:snippets_jump(cur_text, col)"{{{ function! neosnippet#jump(cur_text, col)"{{{
" Get patterns and count. " Get patterns and count.
if empty(s:snippets_expand_stack) if empty(s:snippets_expand_stack)
return s:search_outof_range(a:col) return s:search_outof_range(a:col)
@ -501,7 +501,7 @@ function! s:snippets_expand_or_jump(cur_text, col)"{{{
call neosnippet#expand( call neosnippet#expand(
\ a:cur_text, a:col, cur_word) \ a:cur_text, a:col, cur_word)
else else
call s:snippets_jump(a:cur_text, a:col) call neosnippet#jump(a:cur_text, a:col)
endif endif
endfunction"}}} endfunction"}}}
function! s:snippets_jump_or_expand(cur_text, col)"{{{ function! s:snippets_jump_or_expand(cur_text, col)"{{{
@ -510,7 +510,7 @@ function! s:snippets_jump_or_expand(cur_text, col)"{{{
if search(s:get_placeholder_marker_pattern(). '\|' if search(s:get_placeholder_marker_pattern(). '\|'
\ .s:get_sync_placeholder_marker_pattern(), 'nw') > 0 \ .s:get_sync_placeholder_marker_pattern(), 'nw') > 0
" Found snippet placeholder. " Found snippet placeholder.
call s:snippets_jump(a:cur_text, a:col) call neosnippet#jump(a:cur_text, a:col)
else else
call neosnippet#expand( call neosnippet#expand(
\ a:cur_text, a:col, cur_word) \ a:cur_text, a:col, cur_word)
@ -601,7 +601,7 @@ function! neosnippet#expand(cur_text, col, trigger_name)"{{{
endif endif
if snip_word =~ s:get_placeholder_marker_pattern() if snip_word =~ s:get_placeholder_marker_pattern()
call s:snippets_jump(a:cur_text, a:col) call neosnippet#jump(a:cur_text, a:col)
endif endif
finally finally
if has('folding') if has('folding')
@ -615,9 +615,11 @@ function! neosnippet#expand(cur_text, col, trigger_name)"{{{
endfunction"}}} endfunction"}}}
function! neosnippet#expand_target()"{{{ function! neosnippet#expand_target()"{{{
let trigger = input('Please input snippet trigger: ', let trigger = input('Please input snippet trigger: ',
\ '', 'customlist,neosnippet#snippet_complete') \ '', 'customlist,neosnippet#complete_target_snippets')
let neosnippet = neosnippet#get_current_neosnippet() let neosnippet = neosnippet#get_current_neosnippet()
if !has_key(neosnippet#get_snippets(), trigger) if !has_key(neosnippet#get_snippets(), trigger) ||
\ neosnippet#get_snippets()[trigger].snip !~#
\ s:get_placeholder_target_marker_pattern()
let neosnippet.target = '' let neosnippet.target = ''
return return
endif endif
@ -863,6 +865,8 @@ function! s:expand_target_placeholder(line, col)"{{{
endtry endtry
let neosnippet.target = '' let neosnippet.target = ''
call neosnippet#jump(neosnippet#util#get_cur_text(), col('.'))
endfunction"}}} endfunction"}}}
function! s:search_sync_placeholder(start, end, number)"{{{ function! s:search_sync_placeholder(start, end, number)"{{{
if a:end == 0 if a:end == 0
@ -1006,11 +1010,15 @@ function! neosnippet#filetype_complete(arglead, cmdline, cursorpos)"{{{
return sort(keys(ret)) return sort(keys(ret))
endfunction"}}} endfunction"}}}
function! neosnippet#snippet_complete(arglead, cmdline, cursorpos)"{{{ function! neosnippet#complete_target_snippets(arglead, cmdline, cursorpos)"{{{
return filter(keys(neosnippet#get_snippets()), return map(filter(values(neosnippet#get_snippets()),
\ 'stridx(v:val, a:arglead) == 0') \ "stridx(v:val.word, a:arglead) == 0
\ && v:val.snip =~# s:get_placeholder_target_marker_pattern()"), 'v:val.word')
endfunction"}}} endfunction"}}}
function! s:get_placeholder_target_marker_pattern()"{{{
return '\${\d\+:TARGET\%(:.\{-}\)\?\\\@<!}'
endfunction"}}}
function! s:get_placeholder_marker_pattern()"{{{ function! s:get_placeholder_marker_pattern()"{{{
return '<`\d\+\%(:.\{-}\)\?\\\@<!`>' return '<`\d\+\%(:.\{-}\)\?\\\@<!`>'
endfunction"}}} endfunction"}}}