From 70b06be4b067fec44756e843e2445cce5c97082f Mon Sep 17 00:00:00 2001 From: Christian Brabandt Date: Wed, 14 Apr 2021 12:36:00 +0200 Subject: [PATCH] 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). --- autoload/airline/highlighter.vim | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/autoload/airline/highlighter.vim b/autoload/airline/highlighter.vim index b35ae793..3de3174b 100644 --- a/autoload/airline/highlighter.vim +++ b/autoload/airline/highlighter.vim @@ -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