before trying to return hi attributes, check the group exists

This prevents trying to access twice the highlighting groups
and should slightly speed up airline.
This commit is contained in:
Christian Brabandt 2017-02-20 20:24:43 +01:00
parent b66c1ef070
commit 583121bbc9
No known key found for this signature in database
GPG Key ID: F3F92DA383FDDE09
1 changed files with 9 additions and 4 deletions

View File

@ -22,12 +22,17 @@ function! s:get_syn(group, what)
if !exists("g:airline_gui_mode")
let g:airline_gui_mode = airline#init#gui_mode()
endif
let color = synIDattr(synIDtrans(hlID(a:group)), a:what, g:airline_gui_mode)
if empty(color) || color == -1
let color = synIDattr(synIDtrans(hlID('Normal')), a:what, g:airline_gui_mode)
let color = ''
if hlexists(a:group)
let color = synIDattr(synIDtrans(hlID(a:group)), a:what, g:airline_gui_mode)
endif
if empty(color) || color == -1
let color = 'NONE'
" should always exists
let color = synIDattr(synIDtrans(hlID('Normal')), a:what, g:airline_gui_mode)
" however, just in case
if empty(color) || color == -1
let color = 'NONE'
endif
endif
return color
endfunction