From e9d32830509bbb32ceed34da8533266702bd3a8c Mon Sep 17 00:00:00 2001 From: xaizek Date: Mon, 13 Aug 2018 23:56:00 +0300 Subject: [PATCH 1/2] Try to fix #559 Looks like 72eabd5516ce19801a691022d4ac9d5b04b09df2 partially undone #427. --- plugin/clang_complete.vim | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/plugin/clang_complete.vim b/plugin/clang_complete.vim index 5302329c..113525f0 100644 --- a/plugin/clang_complete.vim +++ b/plugin/clang_complete.vim @@ -493,9 +493,9 @@ function! ClangComplete(findstart, base) augroup ClangComplete au CursorMovedI call TriggerSnippet() if exists('##CompleteDone') - au CompleteDone,InsertLeave call StopMonitoring() + au CompleteDone,InsertLeave call StopMonitoring('all') else - au InsertLeave call StopMonitoring() + au InsertLeave call StopMonitoring('all') endif augroup end let b:snippet_chosen = 0 @@ -524,7 +524,9 @@ function! s:HandlePossibleSelectionCtrlY() return "\" endfunction -function! s:StopMonitoring() +" what argument should be "cr" to restore mapping only or "all" to undo +" everything +function! s:StopMonitoring(what) if b:snippet_chosen call s:TriggerSnippet() return @@ -549,9 +551,17 @@ function! s:StopMonitoring() silent! execute substitute(g:clang_restore_cr_imap, '', s:old_snr, 'g') endif + if a:what == 'cr' + return + endif + silent! iunmap endif + if a:what == 'cr' + return + endif + augroup ClangComplete au! CursorMovedI,InsertLeave if exists('##CompleteDone') @@ -561,6 +571,8 @@ function! s:StopMonitoring() endfunction function! s:TriggerSnippet() + call s:StopMonitoring('cr') + " Dont bother doing anything until we're sure the user exited the menu if !b:snippet_chosen return @@ -568,7 +580,7 @@ function! s:TriggerSnippet() " Stop monitoring as we'll trigger a snippet let b:snippet_chosen = 0 - call s:StopMonitoring() + call s:StopMonitoring('all') " Trigger the snippet execute s:py_cmd 'snippetsTrigger()' From 2bdcbc944b132c832a0cd0209290cd1d8004d1e9 Mon Sep 17 00:00:00 2001 From: xaizek Date: Thu, 23 Aug 2018 15:39:13 +0300 Subject: [PATCH 2/2] Fix recursion in new code Described in https://github.com/Rip-Rip/clang_complete/issues/559#issuecomment-415356918 --- plugin/clang_complete.vim | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/plugin/clang_complete.vim b/plugin/clang_complete.vim index 113525f0..3a92575c 100644 --- a/plugin/clang_complete.vim +++ b/plugin/clang_complete.vim @@ -571,15 +571,17 @@ function! s:StopMonitoring(what) endfunction function! s:TriggerSnippet() + let l:snippet_chosen = b:snippet_chosen + let b:snippet_chosen = 0 + call s:StopMonitoring('cr') " Dont bother doing anything until we're sure the user exited the menu - if !b:snippet_chosen + if !l:snippet_chosen return endif " Stop monitoring as we'll trigger a snippet - let b:snippet_chosen = 0 call s:StopMonitoring('all') " Trigger the snippet