Defer setting the omnifunc only the first time

Fix #1769
This commit is contained in:
Andrea Cedraro 2015-11-13 14:26:04 +01:00
parent f4c63d7b4b
commit b4beed4939

View File

@ -22,6 +22,7 @@ set cpo&vim
" This needs to be called outside of a function " This needs to be called outside of a function
let s:script_folder_path = escape( expand( '<sfile>:p:h' ), '\' ) let s:script_folder_path = escape( expand( '<sfile>:p:h' ), '\' )
let s:omnifunc_mode = 0 let s:omnifunc_mode = 0
let s:defer_omnifunc = 1
let s:old_cursor_position = [] let s:old_cursor_position = []
let s:cursor_moved = 0 let s:cursor_moved = 0
@ -88,6 +89,15 @@ function! youcompleteme#Enable()
autocmd CompleteDone * call s:OnCompleteDone() autocmd CompleteDone * call s:OnCompleteDone()
augroup END augroup END
if s:defer_omnifunc
augroup ycm_defer_omnifunc
autocmd!
autocmd InsertEnter * call s:SetOmnicompleteFunc()
\ | let s:defer_omnifunc = 0
\ | autocmd! ycm_defer_omnifunc
augroup END
endif
" Calling these once solves the problem of BufReadPre/BufRead/BufEnter not " Calling these once solves the problem of BufReadPre/BufRead/BufEnter not
" triggering for the first loaded file. This should be the last commands " triggering for the first loaded file. This should be the last commands
" executed in this function! " executed in this function!
@ -412,6 +422,11 @@ function! s:OnBufferVisit()
call s:SetUpCompleteopt() call s:SetUpCompleteopt()
call s:SetCompleteFunc() call s:SetCompleteFunc()
if !s:defer_omnifunc
call s:SetOmnicompleteFunc()
endif
py ycm_state.OnBufferVisit() py ycm_state.OnBufferVisit()
call s:OnFileReadyToParse() call s:OnFileReadyToParse()
endfunction endfunction
@ -544,11 +559,6 @@ function! s:OnInsertEnter()
return return
endif endif
if !get( b:, 'ycm_omnicomplete', 0 )
let b:ycm_omnicomplete = 1
call s:SetOmnicompleteFunc()
endif
let s:old_cursor_position = [] let s:old_cursor_position = []
endfunction endfunction