Drop BufRead event

Considering that a buffer won't be parsed if no filetype is set and that it's
already parsed if the filetype is set when reading a buffer, there is no point
in parsing a buffer on the BufRead event.
This commit is contained in:
micbou 2017-05-14 14:13:36 +02:00
parent 5a806dcb30
commit 31be11572a
No known key found for this signature in database
GPG Key ID: C7E8FD1F3BDA1E05

View File

@ -85,12 +85,12 @@ function! youcompleteme#Enable()
" Note that these events will NOT trigger for the file vim is started with; " Note that these events will NOT trigger for the file vim is started with;
" so if you do "vim foo.cc", these events will not trigger when that buffer " so if you do "vim foo.cc", these events will not trigger when that buffer
" is read. This is because youcompleteme#Enable() is called on VimEnter and " is read. This is because youcompleteme#Enable() is called on VimEnter and
" that happens *after* BufRead/FileType has already triggered for the " that happens *after* FileType has already triggered for the initial file.
" initial file. " We don't parse the buffer on the BufRead event since it would only be
" We also need to trigger buf init code on the FileType event because when " useful if the buffer filetype is set (we ignore the buffer if there is no
" the user does :enew and then :set ft=something, we need to run buf init " filetype) and if so, the FileType event has triggered before and thus the
" code again. " buffer is already parsed.
autocmd BufRead,FileType * call s:OnBufferRead() autocmd FileType * call s:OnFileTypeSet()
autocmd BufEnter * call s:OnBufferEnter() autocmd BufEnter * call s:OnBufferEnter()
autocmd BufUnload * call s:OnBufferUnload() autocmd BufUnload * call s:OnBufferUnload()
autocmd CursorHold,CursorHoldI * call s:OnCursorHold() autocmd CursorHold,CursorHoldI * call s:OnCursorHold()
@ -100,10 +100,10 @@ function! youcompleteme#Enable()
autocmd CompleteDone * call s:OnCompleteDone() autocmd CompleteDone * call s:OnCompleteDone()
augroup END augroup END
" BufRead/FileType events are not triggered for the first loaded file. " The FileType event is not triggered for the first loaded file. However, we
" However, we don't directly call the s:OnBufferRead function because it " don't directly call the s:OnFileTypeSet function because it would send
" would send requests that can't succeed as the server is not ready yet and " requests that can't succeed as the server is not ready yet and would slow
" would slow down startup. " down startup.
if s:AllowedToCompleteInCurrentBuffer() if s:AllowedToCompleteInCurrentBuffer()
call s:SetCompleteFunc() call s:SetCompleteFunc()
endif endif
@ -414,7 +414,7 @@ function! s:OnCompleteDone()
endfunction endfunction
function! s:OnBufferRead() function! s:OnFileTypeSet()
if !s:AllowedToCompleteInCurrentBuffer() if !s:AllowedToCompleteInCurrentBuffer()
return return
endif endif