highlighter: do not error out, if defined hi-color does not exist

if a color definition is being used, that Vim does not seem to
recognize, instead of erroring out fallback to a hard-coded value of
grey. Otherwise we do have potentially a bad user experience for
throwing too many error messages at the user in very short time, which
may prevent him from doing the actual work (as just happened to me)

Grey should always be defined and it should be rather easy to spot
(I hope). Also just mention for what group this happens.

This should give the user a clue, where and when this happens (so he may
be able to adjust the theme).
This commit is contained in:
Christian Brabandt 2021-04-14 12:36:00 +02:00
parent ed60e1d369
commit 70b06be4b0
No known key found for this signature in database
GPG Key ID: F3F92DA383FDDE09
1 changed files with 9 additions and 1 deletions

View File

@ -119,7 +119,15 @@ function! airline#highlighter#exec(group, colors) abort
let colors = s:CheckDefined(colors)
if old_hi != new_hi || !s:hl_group_exists(a:group)
let cmd = printf('hi %s%s', a:group, s:GetHiCmd(colors))
exe cmd
try
exe cmd
catch /^Vim\%((\a\+)\)\=:E421:/ " color definition not found
let group=matchstr(v:exception, '\w\+\ze=')
let color=matchstr(v:exception, '=\zs\w\+')
let cmd=substitute(cmd, color, 'grey', 'g')
exe cmd
call airline#util#warning('color definition for group ' . a:group . ' not found, using grey as fallback')
endtry
if has_key(s:hl_groups, a:group)
let s:hl_groups[a:group] = colors
endif