From edae6fd0a28cbff0cb995e0d4c262b9fb74de1c5 Mon Sep 17 00:00:00 2001 From: Strahinja Val Markovic Date: Sat, 3 Aug 2013 15:05:25 -0700 Subject: [PATCH] Using b:changedtick for change detection For now, doing it just for detecting whether a change was made on move in insert mode. Using b:changedtick instead of our homebrew way of detecting the changed should be both faster and more robust. --- autoload/youcompleteme.vim | 37 ++++++++++++++++++------------------- 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/autoload/youcompleteme.vim b/autoload/youcompleteme.vim index 46cc12a2..3d72853d 100644 --- a/autoload/youcompleteme.vim +++ b/autoload/youcompleteme.vim @@ -28,8 +28,6 @@ let s:omnifunc_mode = 0 let s:old_cursor_position = [] let s:cursor_moved = 0 -let s:moved_vertically_in_insert_mode = 0 -let s:previous_num_chars_on_current_line = -1 function! youcompleteme#Enable() " When vim is in diff mode, don't run @@ -206,6 +204,20 @@ function! s:SetUpCompleteopt() endif endfunction + +" For various functions/use-cases, we want to keep track of whether the buffer +" has changed since the last time they were invoked. We keep the state of +" b:changedtick of the last time the specific function was called in +" b:ycm_changedtick. +function! s:SetUpYcmChangedTick() + let b:ycm_changedtick = + \ get( b:, 'ycm_changedtick', { + \ 'insert_mode_move' : -1, + \ 'file_ready_to_parse' : -1, + \ } ) +endfunction + + function! s:OnVimLeave() py ycm_state.OnVimLeave() py extra_conf_store.CallExtraConfVimCloseIfExists() @@ -217,6 +229,7 @@ function! s:OnBufferVisit() return endif + call s:SetUpYcmChangedTick() call s:SetUpCompleteopt() call s:SetCompleteFunc() py ycm_state.OnBufferVisit() @@ -340,23 +353,9 @@ endfunction function! s:BufferTextChangedSinceLastMoveInInsertMode() - if s:moved_vertically_in_insert_mode - let s:previous_num_chars_on_current_line = -1 - return 0 - endif - - let num_chars_in_current_cursor_line = strlen( getline('.') ) - - if s:previous_num_chars_on_current_line == -1 - let s:previous_num_chars_on_current_line = num_chars_in_current_cursor_line - return 0 - endif - - let changed_text_on_current_line = num_chars_in_current_cursor_line != - \ s:previous_num_chars_on_current_line - let s:previous_num_chars_on_current_line = num_chars_in_current_cursor_line - - return changed_text_on_current_line + let buffer_changed = b:changedtick != b:ycm_changedtick.insert_mode_move + let b:ycm_changedtick.insert_mode_move = b:changedtick + return buffer_changed endfunction