From 19861861fd175c8e67d80f8f81101bd61a3ccd70 Mon Sep 17 00:00:00 2001 From: Christian Date: Wed, 18 Nov 2020 09:00:29 +0100 Subject: [PATCH] highlighter: vim9 script implementation of get_highlight --- autoload/airline/highlighter.vim | 33 ++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/autoload/airline/highlighter.vim b/autoload/airline/highlighter.vim index 8f807001..3b71d58b 100644 --- a/autoload/airline/highlighter.vim +++ b/autoload/airline/highlighter.vim @@ -353,4 +353,37 @@ else def airline#highlighter#reset_hlcache(): void # {{{2 s:hl_groups = {} enddef + def airline#highlighter#get_highlight(group: string, rest: list = ['']): list # {{{2 + # only check for the cterm reverse attribute + # TODO: do we need to check all modes (gui, term, as well)? + var reverse = false + var res = [] + var ctermfg: string + var ctermbg: string + var guifg: string + var guibg: string + var bold: bool + if hlID(group)->synIDtrans()->synIDattr('reverse', 'cterm') + reverse = true + endif + if get(g:, 'airline_highlighting_cache', 0) && has_key(s:hl_groups, group) + res = s:hl_groups[group] + return reverse ? [ res[1], res[0], res[3], res[2], res[4] ] : res + else + ctermfg = s:get_syn(group, 'fg', 'cterm') + ctermbg = s:get_syn(group, 'bg', 'cterm') + guifg = s:get_syn(group, 'fg', 'gui') + guibg = s:get_syn(group, 'bg', 'gui') + if hlID(group)->synIDtrans()->synIDattr('bold') + bold = true + endif + if reverse + res = s:get_array(guibg, guifg, ctermbg, ctermfg, bold ? ['bold'] : rest) + else + res = s:get_array(guifg, guibg, ctermfg, ctermbg, bold ? ['bold'] : rest) + endif + endif + s:hl_groups[group] = res + return res + enddef endif