From 9132237f3cf445911830c546782d81b1e0504ded Mon Sep 17 00:00:00 2001 From: Shougo Matsushita Date: Fri, 4 Nov 2016 18:19:34 +0900 Subject: [PATCH] Fix #291 expand completed_snippet when expand key mapping --- autoload/neosnippet/handlers.vim | 21 ------------- autoload/neosnippet/init.vim | 5 --- autoload/neosnippet/mappings.vim | 53 ++++++++++++++++++++++---------- doc/neosnippet.txt | 6 ++-- 4 files changed, 38 insertions(+), 47 deletions(-) diff --git a/autoload/neosnippet/handlers.vim b/autoload/neosnippet/handlers.vim index 142ab15..761c3d2 100644 --- a/autoload/neosnippet/handlers.vim +++ b/autoload/neosnippet/handlers.vim @@ -26,23 +26,6 @@ let s:save_cpo = &cpo set cpo&vim -function! neosnippet#handlers#_complete_done() abort "{{{ - if empty(v:completed_item) - \ || !g:neosnippet#enable_completed_snippet - \ || s:is_auto_pairs() - return - endif - - let snippet = neosnippet#parser#_get_completed_snippet( - \ v:completed_item, neosnippet#util#get_next_text()) - if snippet == '' - return - endif - - let [cur_text, col, _] = neosnippet#mappings#_pre_trigger() - call neosnippet#view#_insert(snippet, {}, cur_text, col) -endfunction"}}} - function! neosnippet#handlers#_cursor_moved() abort "{{{ let expand_stack = neosnippet#variables#expand_stack() @@ -87,10 +70,6 @@ function! neosnippet#handlers#_restore_unnamed_register() abort "{{{ endif endfunction"}}} -function! s:is_auto_pairs() abort "{{{ - return get(g:, 'neopairs#enable', 0) -endfunction"}}} - let &cpo = s:save_cpo unlet s:save_cpo diff --git a/autoload/neosnippet/init.vim b/autoload/neosnippet/init.vim index 75d7924..885da11 100644 --- a/autoload/neosnippet/init.vim +++ b/autoload/neosnippet/init.vim @@ -66,11 +66,6 @@ function! s:initialize_others() abort "{{{ \ call neosnippet#handlers#_all_clear_markers() endif - if exists('v:completed_item') - autocmd neosnippet CompleteDone * - \ call neosnippet#handlers#_complete_done() - endif - if exists('##TextChanged') && exists('##TextChangedI') autocmd neosnippet TextChanged,TextChangedI * \ call neosnippet#handlers#_restore_unnamed_register() diff --git a/autoload/neosnippet/mappings.vim b/autoload/neosnippet/mappings.vim index 65a5746..5810e67 100644 --- a/autoload/neosnippet/mappings.vim +++ b/autoload/neosnippet/mappings.vim @@ -31,15 +31,30 @@ function! neosnippet#mappings#expandable_or_jumpable() abort "{{{ endfunction"}}} function! neosnippet#mappings#expandable() abort "{{{ " Check snippet trigger. - return neosnippet#helpers#get_cursor_snippet( - \ neosnippet#helpers#get_snippets('i'), - \ neosnippet#util#get_cur_text()) != '' + return neosnippet#mappings#completed_expandable() + \ || neosnippet#helpers#get_cursor_snippet( + \ neosnippet#helpers#get_snippets('i'), + \ neosnippet#util#get_cur_text()) != '' endfunction"}}} function! neosnippet#mappings#jumpable() abort "{{{ " Found snippet placeholder. return search(neosnippet#get_placeholder_marker_pattern(). '\|' \ .neosnippet#get_sync_placeholder_marker_pattern(), 'nw') > 0 endfunction"}}} +function! neosnippet#mappings#completed_expandable() abort "{{{ + if !s:enabled_completed_snippet() + return 0 + endif + + let snippet = neosnippet#parser#_get_completed_snippet( + \ v:completed_item, neosnippet#util#get_next_text()) + return snippet != '' +endfunction"}}} +function! s:enabled_completed_snippet() abort "{{{ + return exists('v:completed_item') + \ && !empty(v:completed_item) + \ && g:neosnippet#enable_completed_snippet +endfunction"}}} function! neosnippet#mappings#_clear_select_mode_mappings() abort "{{{ if !g:neosnippet#disable_select_mode_mappings @@ -153,37 +168,41 @@ function! neosnippet#mappings#_expand(trigger) abort "{{{ endfunction"}}} function! s:snippets_expand(cur_text, col) abort "{{{ + if s:enabled_completed_snippet() + let snippet = neosnippet#parser#_get_completed_snippet( + \ v:completed_item, neosnippet#util#get_next_text()) + if snippet != '' + call neosnippet#view#_insert(snippet, {}, a:cur_text, a:col) + return 0 + endif + endif + let cur_word = neosnippet#helpers#get_cursor_snippet( \ neosnippet#helpers#get_snippets('i'), \ a:cur_text) - - call neosnippet#view#_expand( - \ neosnippet#util#get_cur_text(), a:col, cur_word) -endfunction"}}} - -function! s:snippets_expand_or_jump(cur_text, col) abort "{{{ - let cur_word = neosnippet#helpers#get_cursor_snippet( - \ neosnippet#helpers#get_snippets('i'), a:cur_text) - if cur_word != '' " Found snippet trigger. call neosnippet#view#_expand( \ neosnippet#util#get_cur_text(), a:col, cur_word) - else + return 0 + endif + + return 1 +endfunction"}}} + +function! s:snippets_expand_or_jump(cur_text, col) abort "{{{ + if s:snippets_expand(a:cur_text, a:col) call neosnippet#view#_jump('', a:col) endif endfunction"}}} function! s:snippets_jump_or_expand(cur_text, col) abort "{{{ - let cur_word = neosnippet#helpers#get_cursor_snippet( - \ neosnippet#helpers#get_snippets('i'), a:cur_text) if search(neosnippet#get_placeholder_marker_pattern(). '\|' \ .neosnippet#get_sync_placeholder_marker_pattern(), 'nw') > 0 " Found snippet placeholder. call neosnippet#view#_jump('', a:col) else - call neosnippet#view#_expand( - \ neosnippet#util#get_cur_text(), a:col, cur_word) + return s:snippets_expand(a:cur_text, a:col) endif endfunction"}}} diff --git a/doc/neosnippet.txt b/doc/neosnippet.txt index 1bea28d..5c7a521 100755 --- a/doc/neosnippet.txt +++ b/doc/neosnippet.txt @@ -230,10 +230,8 @@ g:neosnippet#enable_conceal_markers *g:neosnippet#enable_completed_snippet* g:neosnippet#enable_completed_snippet - If this variable is not 0, neosnippet will expand the function - prototype when |CompleteDone| autocmd. - Note: It is disabled if you have installed - |neopairs.vim| plugin. + If this variable is not 0, neosnippet can expand the function + prototype. The default value is 0.