vim-css-color
vim-css-color copied to clipboard
Do not update each CursorMove, use a throttle or CursorHold
It's unnecessary to regexp buffer for colours each time on CursorMove, on CursorHold it's ok or use a throttling.
I agree that CursorMoved
is too often.
But I deeply dislike the way CursorHold
feels, with the computer always lagging behind and constantly catching up when you type or move around, and stuff popping into place. It just doesn’t update often enough.
What I’d really like to do do is parse the buffer every time that the buffer is modified, and every time there’s a change in which portion of the buffer is visible.
CursorMoved
is the only way to immediately detect a change to which portion of the buffer is visible. Of course it also fires when the cursor just moved without any scrolling. Unfortunately it also fires when there is a change to the buffer without moving the cursor. And of course there may be a change to the buffer that causes the cursor to move (e.g. pasting). So if the cursor moves without scrolling, maybe there were changes (so I want to parse the buffer) or maybe there weren’t (so I want to do nothing) – no way to know.
Actually, re-reading the docs now, I think b:changedtick
gives me everything I need.
Is there any update?
Not yet, sorry. Well, the ultra-barebones version is just this:
diff --git i/autoload/css_color.vim w/autoload/css_color.vim
index 439fbed8df2..cb51430a414 100644
--- i/autoload/css_color.vim
+++ w/autoload/css_color.vim
@@ -218,8 +218,11 @@ let s:_csscolor = s:_hexcolor . '\|' . s:_funcexpr
" match() and friends do not allow finding all matches in a single
" scan without examining the start of the string over and over
function! s:parse_screen()
- let leftcol = winsaveview().leftcol
- let left = max([ leftcol - 15, 0 ])
+ let wv = winsaveview()
+ let upd = [ wv.topline, wv.leftcol, b:changedtick ]
+ if b:css_color_upd == upd | return | endif
+ let b:css_color_upd = upd
+ let left = max([ wv.leftcol - 15, 0 ])
let width = &columns * 4
call filter( range( line('w0'), line('w$') ), 'substitute( strpart( getline(v:val), col([v:val, left]), width ), b:css_color_pat, ''\=s:create_syn_match()'', ''g'' )' )
endfunction
@@ -262,6 +265,7 @@ function! css_color#init(type, keywords, groups)
let b:css_color_grp = extend( get( b:, 'css_color_grp', [] ), split( a:groups, ',' ), 0 )
let b:css_color_hi = {}
let b:css_color_syn = {}
+ let b:css_color_upd = [0,0,0]
augroup CSSColor
autocmd! * <buffer>
This will skip parsing as long as there are no changes to either the buffer or the scroll position.
But I wanted to go a step further and not parse the screen at all during scrolling, only after the cursor settles down. And it turns out that CursorHold
is useless for that… because updatetime
is an interminable 4 seconds by default. That’s way too long to rely on for “has the user stopped scrolling?” triggers. So I need to use CursorMoved
for that too, with some of my own logic to debounce it… I think. I have not quite figured it out yet.
Maybe I should just commit the barebones version in the meantime.
I’ve been running this patch but haven’t moved forward any with it. However I’ve been seeing missed updates recently under circumstances I haven’t yet reproduced, and this patch may be the cause. Hmm.
I know this is an old issue but I get significant performance issues because of the frequent updates. It seems like this is something that would be best left to the user to decide if they prefer accuracy over performance, perhaps this can be put behind an option to decide which event the update hooks to?