From 2322f4ad67b8193857e0f4c695d76f672cb37c6e Mon Sep 17 00:00:00 2001 From: Julian Prein Date: Mon, 4 Nov 2024 17:19:48 +0100 Subject: [PATCH] vim:au: Work around additional call of _highlight_cword Sometimes `_highlight_cword` is called without the existence of w:cword_timer_id but with a w:cword_match_id. No idea why. I thought that it might be a race condition, but does not seem like it. (Also not sure if this could even run in parallel) TODO: Investigate how _highlight_cword can be called without w:cword_timer_id --- .config/vim/vimrc.d/80-autocommands.vim | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/.config/vim/vimrc.d/80-autocommands.vim b/.config/vim/vimrc.d/80-autocommands.vim index 9ce8bba..fd18c5c 100644 --- a/.config/vim/vimrc.d/80-autocommands.vim +++ b/.config/vim/vimrc.d/80-autocommands.vim @@ -84,6 +84,11 @@ function! s:highlight_cword() endfunction function! s:_highlight_cword(timer_id) + " TODO: this should never exist, but sometimes it does. How? To reproduce: + " Select something and then nr. + if exists('w:cword_match_id') + return + endif unlet w:cword_timer_id let l:cword = expand('') @@ -160,27 +165,27 @@ endfunction " Clear the highlights of and visual selection function! s:clear_highlights(what = s:CLEAR_HIGHS_ALL) if and(a:what, s:CLEAR_HIGHS_CWORD) + if exists('w:cword_timer_id') + call timer_stop(w:cword_timer_id) + unlet w:cword_timer_id + endif if exists('w:cword_match_id') call matchdelete(w:cword_match_id) unlet w:cword_match_id unlet w:old_cword endif - if exists('w:cword_timer_id') - call timer_stop(w:cword_timer_id) - unlet w:cword_timer_id - endif endif if and(a:what, s:CLEAR_HIGHS_VISUAL) + if exists('w:selection_timer_id') + call timer_stop(w:selection_timer_id) + unlet w:selection_timer_id + endif if exists('w:visual_match_ids') for [l:win, l:id] in items(w:visual_match_ids) call matchdelete(l:id, l:win) endfor unlet w:visual_match_ids endif - if exists('w:selection_timer_id') - call timer_stop(w:selection_timer_id) - unlet w:selection_timer_id - endif endif endfunction