From 31be11572aa1e1e4b25e8d03618f4925e3f806c6 Mon Sep 17 00:00:00 2001 From: micbou Date: Sun, 14 May 2017 14:13:36 +0200 Subject: [PATCH] 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. --- autoload/youcompleteme.vim | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/autoload/youcompleteme.vim b/autoload/youcompleteme.vim index 332928e3..252b8bf2 100644 --- a/autoload/youcompleteme.vim +++ b/autoload/youcompleteme.vim @@ -85,12 +85,12 @@ function! youcompleteme#Enable() " 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 " is read. This is because youcompleteme#Enable() is called on VimEnter and - " that happens *after* BufRead/FileType has already triggered for the - " initial file. - " We also need to trigger buf init code on the FileType event because when - " the user does :enew and then :set ft=something, we need to run buf init - " code again. - autocmd BufRead,FileType * call s:OnBufferRead() + " that happens *after* FileType has already triggered for the initial file. + " We don't parse the buffer on the BufRead event since it would only be + " useful if the buffer filetype is set (we ignore the buffer if there is no + " filetype) and if so, the FileType event has triggered before and thus the + " buffer is already parsed. + autocmd FileType * call s:OnFileTypeSet() autocmd BufEnter * call s:OnBufferEnter() autocmd BufUnload * call s:OnBufferUnload() autocmd CursorHold,CursorHoldI * call s:OnCursorHold() @@ -100,10 +100,10 @@ function! youcompleteme#Enable() autocmd CompleteDone * call s:OnCompleteDone() augroup END - " BufRead/FileType events are not triggered for the first loaded file. - " However, we don't directly call the s:OnBufferRead function because it - " would send requests that can't succeed as the server is not ready yet and - " would slow down startup. + " The FileType event is not triggered for the first loaded file. However, we + " don't directly call the s:OnFileTypeSet function because it would send + " requests that can't succeed as the server is not ready yet and would slow + " down startup. if s:AllowedToCompleteInCurrentBuffer() call s:SetCompleteFunc() endif @@ -414,7 +414,7 @@ function! s:OnCompleteDone() endfunction -function! s:OnBufferRead() +function! s:OnFileTypeSet() if !s:AllowedToCompleteInCurrentBuffer() return endif