Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Try to fix #559 #560

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 20 additions & 6 deletions plugin/clang_complete.vim
Original file line number Diff line number Diff line change
Expand Up @@ -493,9 +493,9 @@ function! ClangComplete(findstart, base)
augroup ClangComplete
au CursorMovedI <buffer> call <SID>TriggerSnippet()
if exists('##CompleteDone')
au CompleteDone,InsertLeave <buffer> call <SID>StopMonitoring()
au CompleteDone,InsertLeave <buffer> call <SID>StopMonitoring('all')
else
au InsertLeave <buffer> call <SID>StopMonitoring()
au InsertLeave <buffer> call <SID>StopMonitoring('all')
endif
augroup end
let b:snippet_chosen = 0
Expand Down Expand Up @@ -524,7 +524,9 @@ function! s:HandlePossibleSelectionCtrlY()
return "\<C-Y>"
endfunction

function! s:StopMonitoring()
" what argument should be "cr" to restore <cr> mapping only or "all" to undo
" everything
function! s:StopMonitoring(what)
if b:snippet_chosen
call s:TriggerSnippet()
return
Expand All @@ -549,9 +551,17 @@ function! s:StopMonitoring()
silent! execute substitute(g:clang_restore_cr_imap, '<SID>', s:old_snr, 'g')
endif

if a:what == 'cr'
return
endif

silent! iunmap <buffer> <C-Y>
endif

if a:what == 'cr'
return
endif

augroup ClangComplete
au! CursorMovedI,InsertLeave <buffer>
if exists('##CompleteDone')
Expand All @@ -561,14 +571,18 @@ function! s:StopMonitoring()
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()
call s:StopMonitoring('all')

" Trigger the snippet
execute s:py_cmd 'snippetsTrigger()'
Expand Down