Skip to content

Commit 0ba0e42

Browse files
committed
queue :syn and :hi commands during parse
This means only a single :exe is run per frame for all highlighting- related commands, which *drastically* speeds up processing for frames with a very large number of newly encountered colors in the viewport. The magnitude of improvement is enough to make opening or paging through the torture test CSS file nearly tolerable (or maybe better put, reduces lag to almost purely the sluggishness of Vim’s own repaint).
1 parent cabad5f commit 0ba0e42

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

autoload/css_color.vim

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,14 @@ for i in range(0, 255)
4343
let s:hex[ printf( '%02x', i ) ] = i
4444
endfor
4545

46+
let s:exe=[]
47+
function! s:flush_exe()
48+
if len(s:exe) | exe join( remove( s:exe, 0, -1 ), ' | ' ) | endif
49+
endfunction
50+
4651
if has('gui_running')
4752
function! s:create_highlight(color, is_bright)
48-
exe 'hi BG'.a:color 'guibg=#'.a:color 'guifg=#'.( a:is_bright ? '000000' : 'ffffff' )
53+
call add( s:exe, 'hi BG'.a:color.' guibg=#'.a:color.' guifg=#'.( a:is_bright ? '000000' : 'ffffff' ) )
4954
endfunction
5055
else
5156
" preset 16 vt100 colors
@@ -121,8 +126,11 @@ else
121126
let color_idx = s:rgb2xterm(a:color)
122127
let s:color_idx[a:color] = color_idx
123128
endif
124-
exe 'hi BG'.a:color 'ctermbg='.color_idx 'ctermfg='.( a:is_bright ? 0 : 15 )
125-
\ 'guibg=#'.a:color 'guifg=#'.( a:is_bright ? '000000' : 'ffffff' )
129+
call add( s:exe,
130+
\ 'hi BG'.a:color
131+
\ . ' guibg=#' .a:color .' guifg=#' .( a:is_bright ? '000000' : 'ffffff' )
132+
\ . ' ctermbg='.color_idx.' ctermfg='.( a:is_bright ? 0 : 15 )
133+
\ )
126134
endfunction
127135
endif
128136

@@ -168,7 +176,7 @@ function! s:create_syn_match()
168176

169177
" iff pattern ends on word character, require word break to match
170178
if pattern =~ '\>$' | let pattern .= '\>' | endif
171-
exe 'syn match BG'.rgb_color.' /'.escape(pattern, '/').'/ contained containedin=@colorableGroup'
179+
call add( s:exe, 'syn match BG'.rgb_color.' /'.escape(pattern, '/').'/ contained containedin=@colorableGroup' )
172180

173181
return ''
174182
endfunction
@@ -219,12 +227,14 @@ function! s:parse_screen()
219227
let left = max([ leftcol - 15, 0 ])
220228
let width = &columns * 4
221229
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'' )' )
230+
call s:flush_exe()
222231
endfunction
223232

224233
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
225234

226235
function! css_color#reinit()
227236
call filter( keys( b:css_color_hi ), 's:create_highlight( v:val, s:color_bright[v:val] )' )
237+
call s:flush_exe()
228238
endfunction
229239

230240
function! css_color#enable()

0 commit comments

Comments
 (0)