highlighter: Add condition for new vim9 script implementation

Add a new condition that will contain the new vim9script implementation
of the highlighter logic. Not done yet.

To test it out, you need a recent Vim 8.2 and in addition set the
configuration variable

    :let g:airline_experimental=1

Implementation for all the functions will follow.
This commit is contained in:
Christian 2020-11-18 08:12:58 +01:00 committed by Christian Brabandt
parent b0d4a44f0c
commit a8afa434e3
No known key found for this signature in database
GPG Key ID: F3F92DA383FDDE09

View File

@ -13,7 +13,9 @@ let s:separators = {}
let s:accents = {} let s:accents = {}
let s:hl_groups = {} let s:hl_groups = {}
function! s:gui2cui(rgb, fallback) abort " {{{2 if !exists(":def") || (exists(":def") && get(g:, "airline_experimental", 0)==0)
" Legacy VimScript implementation {{{1
function! s:gui2cui(rgb, fallback) abort " {{{2
if a:rgb == '' if a:rgb == ''
return a:fallback return a:fallback
elseif match(a:rgb, '^\%(NONE\|[fb]g\)$') > -1 elseif match(a:rgb, '^\%(NONE\|[fb]g\)$') > -1
@ -21,9 +23,9 @@ function! s:gui2cui(rgb, fallback) abort " {{{2
endif endif
let rgb = map(split(a:rgb[1:], '..\zs'), '0 + ("0x".v:val)') let rgb = map(split(a:rgb[1:], '..\zs'), '0 + ("0x".v:val)')
return airline#msdos#round_msdos_colors(rgb) return airline#msdos#round_msdos_colors(rgb)
endfunction endfunction
function! s:group_not_done(list, name) abort " {{{2 function! s:group_not_done(list, name) abort " {{{2
if index(a:list, a:name) == -1 if index(a:list, a:name) == -1
call add(a:list, a:name) call add(a:list, a:name)
return 1 return 1
@ -33,8 +35,8 @@ function! s:group_not_done(list, name) abort " {{{2
endif endif
return 0 return 0
endif endif
endfu endfu
function! s:get_syn(group, what, mode) abort "{{{2 function! s:get_syn(group, what, mode) abort "{{{2
let color = '' let color = ''
if hlexists(a:group) if hlexists(a:group)
let color = synIDattr(synIDtrans(hlID(a:group)), a:what, a:mode) let color = synIDattr(synIDtrans(hlID(a:group)), a:what, a:mode)
@ -48,15 +50,15 @@ function! s:get_syn(group, what, mode) abort "{{{2
endif endif
endif endif
return color return color
endfunction endfunction
function! s:get_array(guifg, guibg, ctermfg, ctermbg, opts) abort " {{{2 function! s:get_array(guifg, guibg, ctermfg, ctermbg, opts) abort " {{{2
return [ a:guifg, a:guibg, a:ctermfg, a:ctermbg, empty(a:opts) ? '' : join(a:opts, ',') ] return [ a:guifg, a:guibg, a:ctermfg, a:ctermbg, empty(a:opts) ? '' : join(a:opts, ',') ]
endfunction endfunction
function! airline#highlighter#reset_hlcache() abort " {{{2 function! airline#highlighter#reset_hlcache() abort " {{{2
let s:hl_groups = {} let s:hl_groups = {}
endfunction endfunction
function! airline#highlighter#get_highlight(group, ...) abort " {{{2 function! airline#highlighter#get_highlight(group, ...) abort " {{{2
" only check for the cterm reverse attribute " only check for the cterm reverse attribute
" TODO: do we need to check all modes (gui, term, as well)? " TODO: do we need to check all modes (gui, term, as well)?
let reverse = synIDattr(synIDtrans(hlID(a:group)), 'reverse', 'cterm') let reverse = synIDattr(synIDtrans(hlID(a:group)), 'reverse', 'cterm')
@ -77,23 +79,23 @@ function! airline#highlighter#get_highlight(group, ...) abort " {{{2
endif endif
let s:hl_groups[a:group] = res let s:hl_groups[a:group] = res
return res return res
endfunction endfunction
function! airline#highlighter#get_highlight2(fg, bg, ...) abort " {{{2 function! airline#highlighter#get_highlight2(fg, bg, ...) abort " {{{2
let guifg = s:get_syn(a:fg[0], a:fg[1], 'gui') let guifg = s:get_syn(a:fg[0], a:fg[1], 'gui')
let guibg = s:get_syn(a:bg[0], a:bg[1], 'gui') let guibg = s:get_syn(a:bg[0], a:bg[1], 'gui')
let ctermfg = s:get_syn(a:fg[0], a:fg[1], 'cterm') let ctermfg = s:get_syn(a:fg[0], a:fg[1], 'cterm')
let ctermbg = s:get_syn(a:bg[0], a:bg[1], 'cterm') let ctermbg = s:get_syn(a:bg[0], a:bg[1], 'cterm')
return s:get_array(guifg, guibg, ctermfg, ctermbg, a:000) return s:get_array(guifg, guibg, ctermfg, ctermbg, a:000)
endfunction endfunction
function! s:hl_group_exists(group) abort " {{{2 function! s:hl_group_exists(group) abort " {{{2
if !hlexists(a:group) if !hlexists(a:group)
return 0 return 0
elseif empty(synIDattr(hlID(a:group), 'fg')) elseif empty(synIDattr(hlID(a:group), 'fg'))
return 0 return 0
endif endif
return 1 return 1
endfunction endfunction
function! airline#highlighter#exec(group, colors) abort " {{{2 function! airline#highlighter#exec(group, colors) abort " {{{2
if pumvisible() if pumvisible()
return return
endif endif
@ -119,8 +121,8 @@ function! airline#highlighter#exec(group, colors) abort " {{{2
let s:hl_groups[a:group] = colors let s:hl_groups[a:group] = colors
endif endif
endif endif
endfunction endfunction
function! s:CheckDefined(colors) abort " {{{2 function! s:CheckDefined(colors) abort " {{{2
" Checks, whether the definition of the colors is valid and is not empty or NONE " Checks, whether the definition of the colors is valid and is not empty or NONE
" e.g. if the colors would expand to this: " e.g. if the colors would expand to this:
" hi airline_c ctermfg=NONE ctermbg=NONE " hi airline_c ctermfg=NONE ctermbg=NONE
@ -150,9 +152,9 @@ function! s:CheckDefined(colors) abort " {{{2
let bg = a:colors[3] let bg = a:colors[3]
endif endif
return a:colors[0:1] + [fg, bg] + [a:colors[4]] return a:colors[0:1] + [fg, bg] + [a:colors[4]]
endfunction endfunction
function! s:GetHiCmd(list) abort " {{{2 function! s:GetHiCmd(list) abort " {{{2
" a:list needs to have 5 items! " a:list needs to have 5 items!
let res = '' let res = ''
let i = -1 let i = -1
@ -175,8 +177,8 @@ function! s:GetHiCmd(list) abort " {{{2
endif endif
endwhile endwhile
return res return res
endfunction endfunction
function! s:exec_separator(dict, from, to, inverse, suffix) abort " {{{2 function! s:exec_separator(dict, from, to, inverse, suffix) abort " {{{2
if pumvisible() if pumvisible()
return return
endif endif
@ -190,8 +192,8 @@ function! s:exec_separator(dict, from, to, inverse, suffix) abort " {{{2
endif endif
let a:dict[group] = colors let a:dict[group] = colors
call airline#highlighter#exec(group, colors) call airline#highlighter#exec(group, colors)
endfunction endfunction
function! airline#highlighter#load_theme() abort " {{{2 function! airline#highlighter#load_theme() abort " {{{2
if pumvisible() if pumvisible()
return return
endif endif
@ -204,15 +206,15 @@ function! airline#highlighter#load_theme() abort " {{{2
else else
call airline#highlighter#highlight(['normal']) call airline#highlighter#highlight(['normal'])
endif endif
endfunction endfunction
function! airline#highlighter#add_separator(from, to, inverse) abort " {{{2 function! airline#highlighter#add_separator(from, to, inverse) abort " {{{2
let s:separators[a:from.a:to] = [a:from, a:to, a:inverse] let s:separators[a:from.a:to] = [a:from, a:to, a:inverse]
call <sid>exec_separator({}, a:from, a:to, a:inverse, '') call <sid>exec_separator({}, a:from, a:to, a:inverse, '')
endfunction endfunction
function! airline#highlighter#add_accent(accent) abort " {{{2 function! airline#highlighter#add_accent(accent) abort " {{{2
let s:accents[a:accent] = 1 let s:accents[a:accent] = 1
endfunction endfunction
function! airline#highlighter#highlight_modified_inactive(bufnr) abort " {{{2 function! airline#highlighter#highlight_modified_inactive(bufnr) abort " {{{2
if getbufvar(a:bufnr, '&modified') if getbufvar(a:bufnr, '&modified')
let colors = exists('g:airline#themes#{g:airline_theme}#palette.inactive_modified.airline_c') let colors = exists('g:airline#themes#{g:airline_theme}#palette.inactive_modified.airline_c')
\ ? g:airline#themes#{g:airline_theme}#palette.inactive_modified.airline_c : [] \ ? g:airline#themes#{g:airline_theme}#palette.inactive_modified.airline_c : []
@ -224,8 +226,8 @@ function! airline#highlighter#highlight_modified_inactive(bufnr) abort " {{{2
if !empty(colors) if !empty(colors)
call airline#highlighter#exec('airline_c'.(a:bufnr).'_inactive', colors) call airline#highlighter#exec('airline_c'.(a:bufnr).'_inactive', colors)
endif endif
endfunction endfunction
function! airline#highlighter#highlight(modes, ...) abort " {{{2 function! airline#highlighter#highlight(modes, ...) abort " {{{2
let bufnr = a:0 ? a:1 : '' let bufnr = a:0 ? a:1 : ''
let p = g:airline#themes#{g:airline_theme}#palette let p = g:airline#themes#{g:airline_theme}#palette
@ -307,4 +309,9 @@ function! airline#highlighter#highlight(modes, ...) abort " {{{2
endfor endfor
endif endif
endfor endfor
endfunction endfunction
finish
else
" This is using Vim9 script " {{{1
endif