highlighter: Cache syntax highlighting attributes
Should in theory improve performance by quiet a lot.
This commit is contained in:
parent
e9a7a12d9e
commit
a96681d459
|
@ -10,6 +10,7 @@ let s:is_win32term = (has('win32') || has('win64')) &&
|
|||
|
||||
let s:separators = {}
|
||||
let s:accents = {}
|
||||
let s:hl_groups = {}
|
||||
|
||||
function! s:gui2cui(rgb, fallback)
|
||||
if a:rgb == ''
|
||||
|
@ -47,14 +48,24 @@ function! s:get_array(fg, bg, opts)
|
|||
\ : [ '', '', a:fg, a:bg, opts ]
|
||||
endfunction
|
||||
|
||||
function! airline#highlighter#reset_hlcache()
|
||||
let s:hl_groups = {}
|
||||
endfunction
|
||||
|
||||
function! airline#highlighter#get_highlight(group, ...)
|
||||
if has_key(s:hl_groups, a:group)
|
||||
return s:hl_groups[a:group]
|
||||
else
|
||||
let fg = s:get_syn(a:group, 'fg')
|
||||
let bg = s:get_syn(a:group, 'bg')
|
||||
let reverse = g:airline_gui_mode ==# 'gui'
|
||||
\ ? synIDattr(synIDtrans(hlID(a:group)), 'reverse', 'gui')
|
||||
\ : synIDattr(synIDtrans(hlID(a:group)), 'reverse', 'cterm')
|
||||
\|| synIDattr(synIDtrans(hlID(a:group)), 'reverse', 'term')
|
||||
return reverse ? s:get_array(bg, fg, a:000) : s:get_array(fg, bg, a:000)
|
||||
let res = reverse ? s:get_array(bg, fg, a:000) : s:get_array(fg, bg, a:000)
|
||||
endif
|
||||
let s:hl_groups[a:group] = res
|
||||
return res
|
||||
endfunction
|
||||
|
||||
function! airline#highlighter#get_highlight2(fg, bg, ...)
|
||||
|
@ -98,6 +109,9 @@ function! airline#highlighter#exec(group, colors)
|
|||
\ s:Get(colors, 4, 'gui='), s:Get(colors, 4, 'cterm='),
|
||||
\ s:Get(colors, 4, 'term='))
|
||||
exe cmd
|
||||
if has_key(s:hl_groups, a:group)
|
||||
let s:hl_groups[a:group] = colors
|
||||
endif
|
||||
endif
|
||||
endfunction
|
||||
|
||||
|
|
|
@ -57,6 +57,7 @@ endfunction
|
|||
function! s:on_colorscheme_changed()
|
||||
call s:init()
|
||||
unlet! g:airline#highlighter#normal_fg_hi
|
||||
call airline#highlighter#reset_hlcache()
|
||||
let g:airline_gui_mode = airline#init#gui_mode()
|
||||
if !s:theme_in_vimrc
|
||||
call airline#switch_matching_theme()
|
||||
|
|
Loading…
Reference in New Issue