From 583121bbc9ed8b1142c14a938bca4a652c4dcfa9 Mon Sep 17 00:00:00 2001 From: Christian Brabandt Date: Mon, 20 Feb 2017 20:24:43 +0100 Subject: [PATCH 1/3] 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. --- autoload/airline/highlighter.vim | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/autoload/airline/highlighter.vim b/autoload/airline/highlighter.vim index 5cbf590..a38d93a 100644 --- a/autoload/airline/highlighter.vim +++ b/autoload/airline/highlighter.vim @@ -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 From 69b132a6f4349732ad8c147f736822d54d09f071 Mon Sep 17 00:00:00 2001 From: Christian Brabandt Date: Mon, 20 Feb 2017 21:02:36 +0100 Subject: [PATCH 2/3] 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. --- autoload/airline/highlighter.vim | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/autoload/airline/highlighter.vim b/autoload/airline/highlighter.vim index a38d93a..6af3207 100644 --- a/autoload/airline/highlighter.vim +++ b/autoload/airline/highlighter.vim @@ -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) From f1574c4e0aeb56bcbefe2e38892c6e97e3fd612c Mon Sep 17 00:00:00 2001 From: Christian Brabandt Date: Mon, 20 Feb 2017 21:08:38 +0100 Subject: [PATCH 3/3] define highlighting group, if it not exists previously, it could have been skipped, if the old highlighting attribute was the same as the current one. However, if the group does not exist, it should still be defined closes #1404 --- autoload/airline/highlighter.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/autoload/airline/highlighter.vim b/autoload/airline/highlighter.vim index 6af3207..e4e83e8 100644 --- a/autoload/airline/highlighter.vim +++ b/autoload/airline/highlighter.vim @@ -73,7 +73,7 @@ function! airline#highlighter#exec(group, colors) call add(colors, '') endif let colors = s:CheckDefined(colors) - if old_hi != colors + if old_hi != colors || !hlexists(a:group) let cmd = printf('hi %s %s %s %s %s %s %s %s', \ a:group, s:Get(colors, 0, 'guifg=', ''), s:Get(colors, 1, 'guibg=', ''), \ s:Get(colors, 2, 'ctermfg=', ''), s:Get(colors, 3, 'ctermbg=', ''),