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