Make sure, the highlighting group will be defined

If a color value of ['', '', 'NONE', 'NONE', ''] is given as value to
the highlighting group, the resulting group definition would look like
this:

hi Normal ctermfg=NONE ctermbg=NONE

which would result in the highlighting group being cleared (or even no
set at all), therefore check that at least one other value exists and if
not fall back to the highlighting definition of the Normal group.
This commit is contained in:
Christian Brabandt 2017-02-20 21:02:36 +01:00
parent 583121bbc9
commit 69b132a6f4
No known key found for this signature in database
GPG Key ID: F3F92DA383FDDE09

View File

@ -72,6 +72,7 @@ function! airline#highlighter#exec(group, colors)
if len(colors) == 4
call add(colors, '')
endif
let colors = s:CheckDefined(colors)
if old_hi != colors
let cmd = printf('hi %s %s %s %s %s %s %s %s',
\ a:group, s:Get(colors, 0, 'guifg=', ''), s:Get(colors, 1, 'guibg=', ''),
@ -82,6 +83,24 @@ function! airline#highlighter#exec(group, colors)
endif
endfunction
function! s:CheckDefined(colors)
" Checks, whether the definition of the colors is valid and is not empty or NONE
" e.g. if the colors would expand to this:
" hi airline_c ctermfg=NONE ctermbg=NONE
" that means to clear that highlighting group, therefore, add a special term=NONE
" argument
for val in a:colors
if !empty(val) && val !=# 'NONE'
return a:colors
endif
endfor
" this adds the bold attribute to the term argument of the :hi command,
" but at least this makes sure, the group will be defined
let fg = synIDattr(synIDtrans(hlID('Normal')), 'fg', 'cterm')
let bg = synIDattr(synIDtrans(hlID('Normal')), 'bg', 'cterm')
return a:colors[0:1] + [fg, bg] + [a:colors[4]]
endfunction
function! s:Get(dict, key, prefix, default)
if get(a:dict, a:key, a:default) isnot# a:default
return a:prefix. get(a:dict, a:key)