85 Commits

Author SHA1 Message Date
kazukazuinaina
a6886f2997 [add] fail fast options 2021-01-02 16:09:32 +09:00
kazukazuinaina
1962371666 add vim9script branch in CI
NOTE: CI didn't work without explicitly specifying the branch.
2021-01-02 15:58:54 +09:00
kazukazuinaina
2062dd2f98 delete travis.yml 2021-01-02 15:54:05 +09:00
kazukazuinaina
0e91eeb548 [add] github-actions
Note: According to an email from travis-ci, travis-ci.org will be officially closed down completely on December 31st, 2020
2021-01-02 15:51:33 +09:00
Christian
4b02724d0c highglighter: Vim9 script correctly convert hex string to number 2020-11-27 10:43:54 +01:00
Christian
f54f7859a3 tabline: disable Vim9 script add_tab_label 2020-11-27 10:43:54 +01:00
Christian
4bce179ed3 themes: fix syntax errors in Vim9 script for patch func 2020-11-27 10:43:54 +01:00
Christian
2083bfe890 highlighter: correctly get the colors from global palette for Vim9 2020-11-27 10:43:54 +01:00
Christian
084dfe017d highlighter: cast Vim9 variables to correct type 2020-11-27 10:43:54 +01:00
Christian
ad7dcbdece tabline: disable Vim9 script functions that do not work currently 2020-11-27 10:43:54 +01:00
Christian
bb204d1fee tabline: fix vim9 syntax error in group_of_bufnr 2020-11-27 10:43:53 +01:00
Christian
a678556366 dark: convert theme to Vim9 script 2020-11-27 10:43:53 +01:00
Christian
def61b1450 themes: fix Vim9 syntax error in patch func 2020-11-27 10:43:53 +01:00
Christian
3de44bc58f themes: fix Vim9 syntax error in get_highlight2 2020-11-27 10:43:53 +01:00
Christian
dcb36f0480 themes: fix vim9 syntax errors in generate_color_map 2020-11-27 10:43:53 +01:00
Christian
21f329cd70 themes: Vim9 script implementation of patch 2020-11-27 10:43:53 +01:00
Christian
0eee611a0e themes: Vim9 script implementation of get_highlight and get_highlight2 2020-11-27 10:43:53 +01:00
Christian
4e4663c71c themes: Vim9 script implementation of generate_color_map 2020-11-27 10:43:52 +01:00
Christian
0a80997100 themes: prepare for vim9script implementation 2020-11-27 10:43:52 +01:00
Christian
f08b7912c6 themes: add modeline 2020-11-27 10:43:52 +01:00
Christian
d49b655e72 tabline: fix possible vim9script error in init func 2020-11-27 10:43:52 +01:00
Christian
70dc69fcd8 tabline: fix errors in Vim9script get_buffer_name 2020-11-27 10:43:52 +01:00
Christian
cdb265c410 tabline: fix errors in Vim9script title function 2020-11-27 10:43:52 +01:00
Christian
de3dbfcb3c tabline: fix errors in Vim9script load_theme 2020-11-27 10:43:51 +01:00
Christian
cc2a836b9a tabline: Vim9 script implementation of add_tab_label 2020-11-27 10:43:51 +01:00
Christian
6ff95bac4e tabline: Vim9 script implementation of add_label 2020-11-27 10:43:51 +01:00
Christian
c8c30c9e3e tabline: Vim9 script implementation of group_of_bufnr 2020-11-27 10:43:51 +01:00
Christian
a77cd28ecc tabline: Vim9 script implementation of new_builder 2020-11-27 10:43:51 +01:00
Christian
6a6945d45d tabline: Vim9 script implementation of get_buffer_name func 2020-11-27 10:43:51 +01:00
Christian
d5ffa5fd58 tabline: Vim9 script implementation of #title func 2020-11-27 10:43:50 +01:00
Christian
b10c1107e1 tabline: init function, do call autocommand functions 2020-11-27 10:43:50 +01:00
Christian
4f59fef538 move script local variable current_tabcnt to top 2020-11-27 10:43:50 +01:00
Christian
e59a654d17 tabline: Vim9 script implementation of get() 2020-11-27 10:43:50 +01:00
Christian
18ae588bad tabline: remove bang attribute in load_theme func definition 2020-11-27 10:43:50 +01:00
Christian
86c466d81e tabline: fix vim9 error in enable func 2020-11-27 10:43:50 +01:00
Christian
c08b1c0c75 tabline: fix vim9 error in toggle_on func 2020-11-27 10:43:49 +01:00
Christian
3d536ef950 tabline: fix vim9 error in init func 2020-11-27 10:43:49 +01:00
Christian
02aaaf94e8 tabline: Vim9 script implementation of load_theme 2020-11-27 10:43:49 +01:00
Christian
bbc70019f6 tabline: Vim9 script implementation of enable 2020-11-27 10:43:49 +01:00
Christian
0bc7ff3629 tabline: Vim9 script implementation of redraw 2020-11-27 10:43:49 +01:00
Christian
7880f0a73c tabline: Vim9 script implementation of update_tabline 2020-11-27 10:43:49 +01:00
Christian
5502e5302d tabline: Vim9 script implementation of toggle_on 2020-11-27 10:43:48 +01:00
Christian
59c906da4d tabline: Vim9 script implementation of toggle_off 2020-11-27 10:43:48 +01:00
Christian
19f8be42b6 tabline: Vim9 script implementation of #init function 2020-11-27 10:43:48 +01:00
Christian
e81d400b09 tabline: check existence of "e" flag in guioptions 2020-11-27 10:43:48 +01:00
Christian
5062eeeaed tabline: add foldmarkers and remove some empty lines 2020-11-27 10:43:48 +01:00
Christian
e6bd342293 tabline: prepare for vim9script implementation 2020-11-27 10:43:48 +01:00
Christian
caaa553ce9 tabline: set expandtab and foldmarker to modeline 2020-11-27 10:43:47 +01:00
Christian
b4e38be8b8 highlighter: fix indentation (tabs) 2020-11-27 10:43:47 +01:00
Christian
252b89bb1f default tabline formmatter: fix indentation 2020-11-27 10:43:47 +01:00
Christian
b271c279d6 default tablineformmter: get rid of s: vars in legacy implementation 2020-11-27 10:43:44 +01:00
Christian
9387517f01 default tablineformatter: implement as vim9 script 2020-11-27 10:42:16 +01:00
Christian
8ec6f1e40f tabline formatter: prepare for vim9 script implementation 2020-11-27 10:42:13 +01:00
Christian
0d0c380940 highlighter: fix a couple of vim9script errors and fix indentation 2020-11-27 10:40:38 +01:00
Christian
9f7557df44 highlighter: remove ! from :def in vim9script 2020-11-27 10:40:38 +01:00
Christian
f615f8bad3 autoload: bufnr argument of #highlight function is actually a string 2020-11-27 10:40:38 +01:00
Christian
f5e2f97003 highlighter: vim9 script implementation of #highlight() 2020-11-27 10:40:38 +01:00
Christian
14fd943dc6 highlighter: vim9 script implementation of highlight_modified_inactive 2020-11-27 10:40:37 +01:00
Christian
e9d4ff75da highlighter: vim9 script implementation of add_accent 2020-11-27 10:40:37 +01:00
Christian
9b32ed3229 highlighter: remove ! from :def in vim9script 2020-11-27 10:40:37 +01:00
Christian
58b2a8bbc8 highlighter: add foldmarker at final endif 2020-11-27 10:40:37 +01:00
Christian
5ac55ea4e5 highlighter: vim9 script implementation of add_separator 2020-11-27 10:40:37 +01:00
Christian
56ba4b34a7 highlighter: vim9 fix duplicate variable name in s:exec_separator function 2020-11-27 10:40:37 +01:00
Christian
798a346a91 highlighter: vim9 script implementation of load_theme 2020-11-27 10:40:36 +01:00
Christian
4f8675434a highlighter: get rid of superflous l: var prefix 2020-11-27 10:40:36 +01:00
Christian
5391b3e246 highlighter: vim9 script implementation of s:exec_separator 2020-11-27 10:40:36 +01:00
Christian
7310ca6cbf highlighter: run ex command with leading colon in vim9 function #exec 2020-11-27 10:40:36 +01:00
Christian
9ae38b43e4 highlighter: vim9 script implementation of s:GetHiCmd 2020-11-27 10:40:36 +01:00
Christian
2441084898 highlighter: vim9 script implementation of s:CheckDefined 2020-11-27 10:40:36 +01:00
Christian
d9947beb0f highlighter: vim9 script implementation of #exec 2020-11-27 10:40:36 +01:00
Christian
a6b7267979 highlighter: vim9 script implementation of s:hl_group_exists 2020-11-27 10:40:35 +01:00
Christian
90de76359f highlighter: use synIDtrans() in s:hl_group_exists (legacy vimscript)
When checking the defined foreground color in the function that checks
whether a highlighting group exists, it should follow the syntax group
links and check the final color.
2020-11-27 10:40:35 +01:00
Christian
0238d386bb highlighter: vim9 script implementation of get_highlight2 2020-11-27 10:40:35 +01:00
Christian
19861861fd highlighter: vim9 script implementation of get_highlight 2020-11-27 10:40:35 +01:00
Christian
687fb52d9f fix indentation of legacy vimscript (remove tabs) 2020-11-27 10:40:35 +01:00
Christian
aa8bd171f3 highlighter: vim9 script implementation of reset_hlcache 2020-11-27 10:40:35 +01:00
Christian
b152059a98 highlighter: vim9 script implementation of s:get_array 2020-11-27 10:40:34 +01:00
Christian
4d75c9940c highlighter: vim9 script implementation of s:get_syn 2020-11-27 10:40:34 +01:00
Christian
ae3af85ca2 highlighter: remove a couple of empty lines in legacy vimscript implementation 2020-11-27 10:40:34 +01:00
Christian
a9f525f8da highlighter: vim9 script implementation of s:group_not_done 2020-11-27 10:40:34 +01:00
Christian
3e93c212cc highlighter: vim9 script implementation of s:gui2cui 2020-11-27 10:40:34 +01:00
Christian
a8afa434e3 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.
2020-11-27 10:40:34 +01:00
Christian
b0d4a44f0c add foldmarker to highlighter.vim 2020-11-27 10:40:33 +01:00
Christian
0abcdbeba5 convert msdos.vim 2020-11-27 10:40:33 +01:00
Christian
609205f1e8 remove trailing whitespace 2020-11-27 10:40:33 +01:00
9 changed files with 1367 additions and 689 deletions

52
.github/workflows/ci.yml vendored Normal file
View File

@@ -0,0 +1,52 @@
name: CI
on:
push:
branches:
- master
- vim9script
pull_request:
branches:
- master
jobs:
test:
name: Test
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
vim_version:
- 'v8.2.1000'
- 'v8.2.0000'
- 'v8.1.0000'
- 'v8.0.0000'
- 'v7.4'
steps:
- name: Checkout code
uses: actions/checkout@master
- name: Setup Ruby
uses: actions/setup-ruby@v1
with:
ruby-version: '2.6'
- name: Setup Bundle
run: |
gem install bundler
bundle install --jobs 4 --retry 3
- name: Setup Vim
uses: thinca/action-setup-vim@v1
with:
vim_version: ${{ matrix.vim_version }}
- name: Install Dependencies
run: |
curl -f -L "https://raw.githubusercontent.com/vim-airline/vim-airline-themes/master/autoload/airline/themes/simple.vim" -o autoload/airline/themes/simple.vim
curl -f -L "https://raw.githubusercontent.com/vim-airline/vim-airline-themes/master/autoload/airline/themes/molokai.vim" -o autoload/airline/themes/molokai.vim
mkdir colors && curl -f -L 'https://raw.githubusercontent.com/tomasr/molokai/master/colors/molokai.vim' -o colors/molokai.vim
- name: Run Test
run: rake ci

View File

@@ -1,34 +0,0 @@
# This config is based on lightline.vim <https://github.com/itchyny/lightline.vim/blob/master/.travis.yml>
arch:
- amd64
- ppc64le
language: ruby
before_install:
- curl -f -L "https://raw.githubusercontent.com/vim-airline/vim-airline-themes/master/autoload/airline/themes/simple.vim" -o autoload/airline/themes/simple.vim
- curl -f -L "https://raw.githubusercontent.com/vim-airline/vim-airline-themes/master/autoload/airline/themes/molokai.vim" -o autoload/airline/themes/molokai.vim
- mkdir colors && curl -f -L 'https://raw.githubusercontent.com/tomasr/molokai/master/colors/molokai.vim' -o colors/molokai.vim
- (if ! test -d $HOME/vim-$VIM_VERSION/bin; then
git clone https://github.com/vim/vim $HOME/vim &&
cd $HOME/vim &&
git checkout v$VIM_VERSION &&
./configure --prefix=$HOME/vim-$VIM_VERSION &&
make &&
make install;
fi)
#rvm:
# - 1.9.3
cache:
directories:
- $HOME/vim-$VIM_VERSION
env:
- VIM_VERSION=8.2.1000
- VIM_VERSION=8.2.0000
- VIM_VERSION=8.1.0000
- VIM_VERSION=8.0.0000
- VIM_VERSION=7.4
script:
- export PATH=$HOME/vim-$VIM_VERSION/bin:$PATH
- cd $TRAVIS_BUILD_DIR
- rake ci

View File

@@ -262,7 +262,7 @@ function! airline#check_mode(winnr)
let mode_string = join(l:mode)
if get(w:, 'airline_lastmode', '') != mode_string
call airline#highlighter#highlight_modified_inactive(context.bufnr)
call airline#highlighter#highlight(l:mode, context.bufnr)
call airline#highlighter#highlight(l:mode, string(context.bufnr))
call airline#util#doautocmd('AirlineModeChanged')
let w:airline_lastmode = mode_string
endif

View File

@@ -1,5 +1,5 @@
" MIT License. Copyright (c) 2013-2020 Bailey Ling et al.
" vim: et ts=2 sts=2 sw=2
" vim: et ts=2 sts=2 sw=2 et fdm=marker
scriptencoding utf-8
@@ -10,20 +10,40 @@ endif
let s:ctrlspace = get(g:, 'CtrlSpaceLoaded', 0)
let s:tabws = get(g:, 'tabws_loaded', 0)
let s:current_tabcnt = -1
function! airline#extensions#tabline#init(ext)
if has('gui_running')
if has('gui_running') && match(&guioptions, 'e') > -1
set guioptions-=e
endif
autocmd User AirlineToggledOn call s:toggle_on()
autocmd User AirlineToggledOff call s:toggle_off()
call s:toggle_on()
call a:ext.add_theme_func('airline#extensions#tabline#load_theme')
endfunction
function! s:toggle_off()
function! airline#extensions#tabline#add_label(dict, type, right)
if get(g:, 'airline#extensions#tabline#show_tab_type', 1)
call a:dict.add_section_spaced('airline_tablabel'.
\ (a:right ? '_right' : ''),
\ get(g:, 'airline#extensions#tabline#'.a:type.'_label', a:type))
endif
endfunction
function! airline#extensions#tabline#add_tab_label(dict)
let show_tab_count = get(g:, 'airline#extensions#tabline#show_tab_count', 1)
if show_tab_count == 2
call a:dict.add_section_spaced('airline_tabmod', printf('%s %d/%d', "tab", tabpagenr(), tabpagenr('$')))
elseif show_tab_count == 1 && tabpagenr('$') > 1
call a:dict.add_section_spaced('airline_tabmod', printf('%s %d/%d', "tab", tabpagenr(), tabpagenr('$')))
endif
endfunction
if !exists(":def") || (exists(":def") && get(g:, "airline_experimental", 0)==0)
" Legacy VimScript implementation " {{{1
function! s:toggle_off() " {{{2
call airline#extensions#tabline#autoshow#off()
call airline#extensions#tabline#tabs#off()
call airline#extensions#tabline#buffers#off()
@@ -33,9 +53,8 @@ function! s:toggle_off()
if s:tabws
call airline#extensions#tabline#tabws#off()
endif
endfunction
function! s:toggle_on()
endfunction
function! s:toggle_on() " {{{2
if get(g:, 'airline_statusline_ontop', 0)
call airline#extensions#tabline#enable()
let &tabline='%!airline#statusline('.winnr().')'
@@ -52,9 +71,8 @@ function! s:toggle_on()
endif
set tabline=%!airline#extensions#tabline#get()
endfunction
function! s:update_tabline(forceit)
endfunction
function! s:update_tabline(forceit) " {{{2
if get(g:, 'airline#extensions#tabline#disable_refresh', 0)
return
endif
@@ -74,9 +92,8 @@ function! s:update_tabline(forceit)
endif
call airline#util#doautocmd('BufMRUChange')
call airline#extensions#tabline#redraw()
endfunction
function! airline#extensions#tabline#redraw()
endfunction
function! airline#extensions#tabline#redraw() " {{{2
" sometimes, the tabline is not correctly updated see #1580
" so force redraw here
if exists(":redrawtabline") == 2
@@ -87,15 +104,13 @@ function! airline#extensions#tabline#redraw()
" need something less invasive.
let &ro = &ro
endif
endfunction
function! airline#extensions#tabline#enable()
endfunction
function! airline#extensions#tabline#enable() " {{{2
if &lines > 3
set showtabline=2
endif
endfunction
function! airline#extensions#tabline#load_theme(palette)
endfunction
function! airline#extensions#tabline#load_theme(palette) " {{{2
if pumvisible()
return
endif
@@ -142,11 +157,8 @@ function! airline#extensions#tabline#load_theme(palette)
call airline#highlighter#exec('airline_tabmod_right', tabmod_right)
call airline#highlighter#exec('airline_tabhid_right', tabhid_right)
call airline#highlighter#exec('airline_tabmod_unsel_right', tabmodu_right)
endfunction
let s:current_tabcnt = -1
function! airline#extensions#tabline#get()
endfunction
function! airline#extensions#tabline#get() " {{{2
let show_buffers = get(g:, 'airline#extensions#tabline#show_buffers', 1)
let show_tabs = get(g:, 'airline#extensions#tabline#show_tabs', 1)
@@ -174,9 +186,8 @@ function! airline#extensions#tabline#get()
else
return airline#extensions#tabline#tabs#get()
endif
endfunction
function! airline#extensions#tabline#title(n)
endfunction
function! airline#extensions#tabline#title(n) " {{{2
let title = ''
if s:taboo
let title = TabooTabTitle(a:n)
@@ -201,17 +212,14 @@ function! airline#extensions#tabline#title(n)
endif
return airline#extensions#tabline#get_buffer_name(curbuf[0], curbuf)
endif
return title
endfunction
function! airline#extensions#tabline#get_buffer_name(nr, ...)
endfunction
function! airline#extensions#tabline#get_buffer_name(nr, ...) " {{{2
let buffers = a:0 ? a:1 : airline#extensions#tabline#buflist#list()
let formatter = get(g:, 'airline#extensions#tabline#formatter', 'default')
return airline#extensions#tabline#formatters#{formatter}#format(a:nr, buffers)
endfunction
function! airline#extensions#tabline#new_builder()
endfunction
function! airline#extensions#tabline#new_builder() " {{{2
let builder_context = {
\ 'active' : 1,
\ 'tabline' : 1,
@@ -225,11 +233,9 @@ function! airline#extensions#tabline#new_builder()
let builder_context.left_sep = get(g:, 'airline#extensions#tabline#left_sep' , ' ')
let builder_context.left_alt_sep = get(g:, 'airline#extensions#tabline#left_alt_sep' , '|')
endif
return airline#extensions#tabline#builder#new(builder_context)
endfunction
function! airline#extensions#tabline#group_of_bufnr(tab_bufs, bufnr)
endfunction
function! airline#extensions#tabline#group_of_bufnr(tab_bufs, bufnr) " {{{2
let cur = bufnr('%')
if cur == a:bufnr
if g:airline_detect_modified && getbufvar(a:bufnr, '&modified')
@@ -247,21 +253,235 @@ function! airline#extensions#tabline#group_of_bufnr(tab_bufs, bufnr)
endif
endif
return group
endfunction
function! airline#extensions#tabline#add_label(dict, type, right)
if get(g:, 'airline#extensions#tabline#show_tab_type', 1)
call a:dict.add_section_spaced('airline_tablabel'.
\ (a:right ? '_right' : ''),
\ get(g:, 'airline#extensions#tabline#'.a:type.'_label', a:type))
endif
endfunction
function! airline#extensions#tabline#add_tab_label(dict)
endfunction
function! airline#extensions#tabline#add_tab_label(dict) " {{{2
let show_tab_count = get(g:, 'airline#extensions#tabline#show_tab_count', 1)
if show_tab_count == 2
call a:dict.add_section_spaced('airline_tabmod', printf('%s %d/%d', "tab", tabpagenr(), tabpagenr('$')))
elseif show_tab_count == 1 && tabpagenr('$') > 1
call a:dict.add_section_spaced('airline_tabmod', printf('%s %d/%d', "tab", tabpagenr(), tabpagenr('$')))
endif
endfunction
endfunction
else
" Vim9 Script implementation
"def airline#extensions#tabline#init(ext: dict<any>): void # {{{2
" Seems not to work yet :(
" if has('gui_running') && match(&guioptions, 'e') > -1
" :set guioptions-=e
" endif
" autocmd User AirlineToggledOn call s:toggle_on()
" autocmd User AirlineToggledOff call s:toggle_off()
" s:toggle_on()
" try
" ext.add_theme_func('airline#extensions#tabline#load_theme')
" catch
" endtry
"enddef
def s:toggle_off(): void # {{{2
airline#extensions#tabline#autoshow#off()
airline#extensions#tabline#tabs#off()
airline#extensions#tabline#buffers#off()
if s:ctrlspace
airline#extensions#tabline#ctrlspace#off()
endif
if s:tabws
airline#extensions#tabline#tabws#off()
endif
enddef
def s:toggle_on(): void # {{{2
if get(g:, 'airline_statusline_ontop', 0)
airline#extensions#tabline#enable()
&tabline = '%!airline#statusline(' .. winnr() .. ')'
return
endif
airline#extensions#tabline#autoshow#on()
airline#extensions#tabline#tabs#on()
airline#extensions#tabline#buffers#on()
if s:ctrlspace
airline#extensions#tabline#ctrlspace#on()
endif
if s:tabws
airline#extensions#tabline#tabws#on()
endif
&tabline = '%!airline#extensions#tabline#get()'
enddef
def s:update_tabline(forceit: number): void # {{{2
if get(g:, 'airline#extensions#tabline#disable_refresh', 0)
return
endif
if !forceit && get(g:, 'SessionLoad', 0)
return
endif
var match = expand('<afile>')
if pumvisible()
return
elseif !get(g:, 'airline#extensions#tabline#enabled', 0)
return
# return, if buffer matches ignore pattern or is directory (netrw)
elseif empty(match) || airline#util#ignore_buf(match) || isdirectory(match)
return
endif
airline#util#doautocmd('BufMRUChange')
airline#extensions#tabline#redraw()
enddef
def airline#extensions#tabline#redraw(): void # {{{2
# TODO: Is this still needed?
:redrawtabline
enddef
def airline#extensions#tabline#enable(): void # {{{2
if &lines > 3
&showtabline = 2
endif
enddef
def airline#extensions#tabline#load_theme(palette: dict<any>): void # {{{2
if pumvisible()
return
endif
var colors = get(palette, 'tabline', {})
var tablabel = get(colors, 'airline_tablabel', palette.normal.airline_b)
# Theme for tabs on the left
var tab = get(colors, 'airline_tab', palette.inactive.airline_c)
var tabsel = get(colors, 'airline_tabsel', palette.normal.airline_a)
var tabtype = get(colors, 'airline_tabtype', palette.visual.airline_a)
var tabfill = get(colors, 'airline_tabfill', palette.normal.airline_c)
var tabmod = get(colors, 'airline_tabmod', palette.insert.airline_a)
var tabhid = get(colors, 'airline_tabhid', palette.normal.airline_c)
var tabmodu = tabhid
var tabmodu_right = tabhid
if has_key(palette, 'normal_modified') && has_key(palette.normal_modified, 'airline_c')
tabmodu = get(colors, 'airline_tabmod_unsel', palette.normal_modified.airline_c)
tabmodu_right = get(colors, 'airline_tabmod_unsel_right', palette.normal_modified.airline_c)
else
# Fall back to normal airline_c if modified airline_c isn't present
tabmodu = get(colors, 'airline_tabmod_unsel', palette.normal.airline_c)
tabmodu_right = get(colors, 'airline_tabmod_unsel_right', palette.normal.airline_c)
endif
airline#highlighter#exec('airline_tablabel', tablabel)
airline#highlighter#exec('airline_tab', tab)
airline#highlighter#exec('airline_tabsel', tabsel)
airline#highlighter#exec('airline_tabtype', tabtype)
airline#highlighter#exec('airline_tabfill', tabfill)
airline#highlighter#exec('airline_tabmod', tabmod)
airline#highlighter#exec('airline_tabmod_unsel', tabmodu)
airline#highlighter#exec('airline_tabmod_unsel_right', tabmodu_right)
airline#highlighter#exec('airline_tabhid', tabhid)
# Theme for tabs on the right
var tablabel_r = get(colors, 'airline_tablabel', palette.normal.airline_b)
var tabsel_right = get(colors, 'airline_tabsel_right', palette.normal.airline_a)
var tab_right = get(colors, 'airline_tab_right', palette.inactive.airline_c)
var tabmod_right = get(colors, 'airline_tabmod_right', palette.insert.airline_a)
var tabhid_right = get(colors, 'airline_tabhid_right', palette.normal.airline_c)
airline#highlighter#exec('airline_tablabel_right', tablabel_r)
airline#highlighter#exec('airline_tab_right', tab_right)
airline#highlighter#exec('airline_tabsel_right', tabsel_right)
airline#highlighter#exec('airline_tabmod_right', tabmod_right)
airline#highlighter#exec('airline_tabhid_right', tabhid_right)
enddef
def airline#extensions#tabline#get(): string # {{{2
var show_buffers = get(g:, 'airline#extensions#tabline#show_buffers', 1)
var show_tabs = get(g:, 'airline#extensions#tabline#show_tabs', 1)
var curtabcnt = tabpagenr('$')
if curtabcnt != s:current_tabcnt
s:current_tabcnt = curtabcnt
airline#extensions#tabline#tabs#invalidate()
airline#extensions#tabline#buffers#invalidate()
airline#extensions#tabline#ctrlspace#invalidate()
airline#extensions#tabline#tabws#invalidate()
endif
if !exists('#airline#BufAdd#*')
autocmd airline BufAdd * call <sid>update_tabline(0)
endif
if !exists('#airline#SessionLoadPost')
autocmd airline SessionLoadPost * call <sid>update_tabline(1)
endif
if s:ctrlspace
return airline#extensions#tabline#ctrlspace#get()
elseif s:tabws
return airline#extensions#tabline#tabws#get()
elseif show_buffers && curtabcnt == 1 || !show_tabs
return airline#extensions#tabline#buffers#get()
else
return airline#extensions#tabline#tabs#get()
endif
enddef
def airline#extensions#tabline#title(n: number): string # {{{2
var title = ''
if get(g:, 'airline#extensions#taboo#enabled', 1) &&
get(g:, 'loaded_taboo', 0) && exists("*TabooTabTitle")
title = call("TabooTabTitle", [n])
endif
if empty(title)
title = gettabvar(n, 'title')
endif
var formatter = get(g:, 'airline#extensions#tabline#tabtitle_formatter', '')
if empty(title) && !empty(formatter) && exists("*" .. formatter)
title = call(formatter, [n])
endif
if empty(title)
var buflist = tabpagebuflist(n)
var winnr = tabpagewinnr(n)
var all_buffers = airline#extensions#tabline#buflist#list()
var curbuf = filter(buflist, {_, v -> index(all_buffers, v) != -1})
if len(curbuf) == 0
add(curbuf, tabpagebuflist()[0])
endif
return airline#extensions#tabline#get_buffer_name(curbuf[0], curbuf)
endif
return title
enddef
def airline#extensions#tabline#get_buffer_name(nr: number, buffers = airline#extensions#tabline#buflist#list()): string # {{{2
var Formatter = 'airline#extensions#tabline#formatters#' .. get(g:, 'airline#extensions#tabline#formatter', 'default') .. '#format'
return call(Formatter, [ nr, buffers] )
enddef
def airline#extensions#tabline#new_builder(): dict<any> # {{{2
var builder_context = {
'active': 1,
'tabline': 1,
'right_sep': get(g:, 'airline#extensions#tabline#right_sep', g:airline_right_sep),
'right_alt_sep': get(g:, 'airline#extensions#tabline#right_alt_sep', g:airline_right_alt_sep),
'left_sep': get(g:, 'airline#extensions#tabline#left_sep', g:airline_left_sep),
'left_alt_sep': get(g:, 'airline#extensions#tabline#left_alt_sep', g:airline_left_alt_sep),
}
return airline#extensions#tabline#builder#new(builder_context)
enddef
def airline#extensions#tabline#group_of_bufnr(tab_bufs: list<number>, bufnr: number): string # {{{2
var cur = bufnr('%')
var group = ''
if cur == bufnr
if g:airline_detect_modified && getbufvar(bufnr, '&modified')
group = 'airline_tabmod'
else
group = 'airline_tabsel'
endif
else
if g:airline_detect_modified && getbufvar(bufnr, '&modified')
group = 'airline_tabmod_unsel'
elseif index(tab_bufs, bufnr) > -1
group = 'airline_tab'
else
group = 'airline_tabhid'
endif
endif
return group
enddef
"def airline#extensions#tabline#add_label(dict: dict<any>, type: string, right: number): void # {{{2
" # Seems not to work yet :(
" if get(g:, 'airline#extensions#tabline#show_tab_type', 1)
" dict.add_section_spaced('airline_tablabel' .. (right ? '_right' : ''),
" get(g:, 'airline#extensions#tabline#' .. type .. '_label', type))
" endif
"enddef
" def airline#extensions#tabline#add_tab_label(dict: dict<any>): void # {{{2
" var show_tab_count = get(g:, 'airline#extensions#tabline#show_tab_count', 1)
" if show_tab_count == 2
" dict.add_section_spaced('airline_tabmod', printf('%s %d/%d', "tab", tabpagenr(), tabpagenr('$')))
" elseif show_tab_count == 1 && tabpagenr('$') > 1
" dict.add_section_spaced('airline_tabmod', printf('%s %d/%d', "tab", tabpagenr(), tabpagenr('$')))
" endif
" enddef
endif

View File

@@ -1,9 +1,11 @@
" MIT License. Copyright (c) 2013-2020 Bailey Ling et al.
" vim: et ts=2 sts=2 sw=2
" vim: et ts=2 sts=2 sw=2 et fdm=marker
scriptencoding utf-8
function! airline#extensions#tabline#formatters#default#format(bufnr, buffers)
if !exists(":def") || (exists(":def") && get(g:, "airline_experimental", 0)==0)
" Legacy VimScript implementation {{{1
function! airline#extensions#tabline#formatters#default#format(bufnr, buffers) " {{{2
let fnametruncate = get(g:, 'airline#extensions#tabline#fnametruncate', 0)
let fmod = get(g:, 'airline#extensions#tabline#fnamemod', ':~:.')
let _ = ''
@@ -28,18 +30,53 @@ function! airline#extensions#tabline#formatters#default#format(bufnr, buffers)
endif
return airline#extensions#tabline#formatters#default#wrap_name(a:bufnr, _)
endfunction
endfunction
function! airline#extensions#tabline#formatters#default#wrap_name(bufnr, buffer_name)
function! airline#extensions#tabline#formatters#default#wrap_name(bufnr, buffer_name) " {{{2
let buf_nr_format = get(g:, 'airline#extensions#tabline#buffer_nr_format', '%s: ')
let buf_nr_show = get(g:, 'airline#extensions#tabline#buffer_nr_show', 0)
let buf_modified_symbol = g:airline_symbols.modified
let _ = buf_nr_show ? printf(buf_nr_format, a:bufnr) : ''
let _ .= substitute(a:buffer_name, '\\', '/', 'g')
if getbufvar(a:bufnr, '&modified') == 1
let _ .= buf_modified_symbol
let _ .= g:airline_symbols.modified
endif
return _
endfunction
endfunction
else
" New Vim9 script implementation {{{1
def airline#extensions#tabline#formatters#default#format(bufnr: number, buffers: list<number>): string # {{{2
var fmod = get(g:, 'airline#extensions#tabline#fnamemod', ':~:.')
var result = ''
var fnametruncate = get(g:, 'airline#extensions#tabline#fnametruncate', 0)
var name = bufname(bufnr)
if empty(name)
result = '[No Name]'
elseif name =~ 'term://'
# Neovim Terminal
result = substitute(name, '\(term:\)//.*:\(.*\)', '\1 \2', '')
else
if get(g:, 'airline#extensions#tabline#fnamecollapse', 1)
result = pathshorten(fnamemodify(name, fmod))
else
result = fnamemodify(name, fmod)
endif
if bufnr != bufnr('%') && fnametruncate && strlen(result) > fnametruncate
result = airline#util#strcharpart(result, 0, fnametruncate)
endif
endif
return airline#extensions#tabline#formatters#default#wrap_name(bufnr, result)
enddef
def airline#extensions#tabline#formatters#default#wrap_name(bufnr: number, buffer_name: string): string # {{{2
var buf_nr_show = get(g:, 'airline#extensions#tabline#buffer_nr_show', 0)
var buf_nr_format = get(g:, 'airline#extensions#tabline#buffer_nr_format', '%s: ')
var result = buf_nr_show ? printf(buf_nr_format, bufnr) : ''
result = result .. substitute(buffer_name, '\\', '/', 'g')
if getbufvar(bufnr, '&modified') == 1
result = result .. g:airline_symbols.modified
endif
return result
enddef
endif

View File

@@ -1,5 +1,5 @@
" MIT License. Copyright (c) 2013-2020 Bailey Ling Christian Brabandt et al.
" vim: et ts=2 sts=2 sw=2
" vim: et ts=2 sts=2 sw=2 fdm=marker et
scriptencoding utf-8
@@ -13,7 +13,9 @@ let s:separators = {}
let s:accents = {}
let s:hl_groups = {}
function! s:gui2cui(rgb, fallback) abort
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,8 @@ function! s:gui2cui(rgb, fallback) abort
endif
let rgb = map(split(a:rgb[1:], '..\zs'), '0 + ("0x".v:val)')
return airline#msdos#round_msdos_colors(rgb)
endfunction
function! s:group_not_done(list, name) abort
endfunction
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,9 +34,8 @@ function! s:group_not_done(list, name) abort
endif
return 0
endif
endfu
function! s:get_syn(group, what, mode) abort
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)
@@ -49,17 +49,14 @@ function! s:get_syn(group, what, mode) abort
endif
endif
return color
endfunction
function! s:get_array(guifg, guibg, ctermfg, ctermbg, opts) abort
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
function! airline#highlighter#reset_hlcache() abort
endfunction
function! airline#highlighter#reset_hlcache() abort " {{{2
let s:hl_groups = {}
endfunction
function! airline#highlighter#get_highlight(group, ...) abort
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')
@@ -80,26 +77,23 @@ function! airline#highlighter#get_highlight(group, ...) abort
endif
let s:hl_groups[a:group] = res
return res
endfunction
function! airline#highlighter#get_highlight2(fg, bg, ...) abort
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
endfunction
function! s:hl_group_exists(group) abort " {{{2
if !hlexists(a:group)
return 0
elseif empty(synIDattr(hlID(a:group), 'fg'))
elseif empty(synIDattr(synIDtrans(hlID(a:group)), 'fg'))
return 0
endif
return 1
endfunction
function! airline#highlighter#exec(group, colors) abort
endfunction
function! airline#highlighter#exec(group, colors) abort " {{{2
if pumvisible()
return
endif
@@ -116,14 +110,17 @@ 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))
try
exe cmd
catch
echoerr "Error when running command: ". cmd
endtry
if has_key(s:hl_groups, a:group)
let s:hl_groups[a:group] = colors
endif
endif
endfunction
function! s:CheckDefined(colors) abort
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
@@ -153,9 +150,8 @@ function! s:CheckDefined(colors) abort
let bg = a:colors[3]
endif
return a:colors[0:1] + [fg, bg] + [a:colors[4]]
endfunction
function! s:GetHiCmd(list) abort
endfunction
function! s:GetHiCmd(list) abort " {{{2
" a:list needs to have 5 items!
let res = ''
let i = -1
@@ -178,25 +174,23 @@ function! s:GetHiCmd(list) abort
endif
endwhile
return res
endfunction
function! s:exec_separator(dict, from, to, inverse, suffix) abort
endfunction
function! s:exec_separator(dict, from, to, inverse, suffix) abort " {{{2
if pumvisible()
return
endif
let group = a:from.'_to_'.a:to.a:suffix
let l:from = airline#themes#get_highlight(a:from.a:suffix)
let l:to = airline#themes#get_highlight(a:to.a:suffix)
let from = airline#themes#get_highlight(a:from.a:suffix)
let to = airline#themes#get_highlight(a:to.a:suffix)
if a:inverse
let colors = [ l:from[1], l:to[1], l:from[3], l:to[3] ]
let colors = [ from[1], to[1], from[3], to[3] ]
else
let colors = [ l:to[1], l:from[1], l:to[3], l:from[3] ]
let colors = [ to[1], from[1], to[3], from[3] ]
endif
let a:dict[group] = colors
call airline#highlighter#exec(group, colors)
endfunction
function! airline#highlighter#load_theme() abort
endfunction
function! airline#highlighter#load_theme() abort " {{{2
if pumvisible()
return
endif
@@ -209,18 +203,15 @@ function! airline#highlighter#load_theme() abort
else
call airline#highlighter#highlight(['normal'])
endif
endfunction
function! airline#highlighter#add_separator(from, to, inverse) abort
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
endfunction
function! airline#highlighter#add_accent(accent) abort " {{{2
let s:accents[a:accent] = 1
endfunction
function! airline#highlighter#highlight_modified_inactive(bufnr) abort
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 : []
@@ -232,9 +223,8 @@ function! airline#highlighter#highlight_modified_inactive(bufnr) abort
if !empty(colors)
call airline#highlighter#exec('airline_c'.(a:bufnr).'_inactive', colors)
endif
endfunction
function! airline#highlighter#highlight(modes, ...) abort
endfunction
function! airline#highlighter#highlight(modes, ...) abort " {{{2
let bufnr = a:0 ? a:1 : ''
let p = g:airline#themes#{g:airline_theme}#palette
@@ -316,4 +306,324 @@ function! airline#highlighter#highlight(modes, ...) abort
endfor
endif
endfor
endfunction
endfunction
finish
else
" This is using Vim9 script " {{{1
def s:gui2cui(rgb: string, fallback: string): string # {{{2
if empty(rgb)
return fallback
elseif match(rgb, '^\%(NONE\|[fb]g\)$') > -1
return rgb
endif
var _rgb = []
_rgb = map(split(rgb[1:], '..\zs'), {_, v -> ("0x" .. v)->str2nr(16)})
return airline#msdos#round_msdos_colors(_rgb)
enddef
def s:group_not_done(list: list<string>, name: string): bool # {{{2
if index(list, name) == -1
add(list, name)
return true
else
if &vbs
:echomsg printf("airline: group: %s already done, skipping", name)
endif
return false
endif
enddef
def s:get_syn(group: string, what: string, mode: string): string # {{{2
var color = ''
if hlexists(group)
color = hlID(group)->synIDtrans()->synIDattr(what, mode)
endif
if empty(color) || str2nr(color) == -1
# Normal highlighting group should always exist
color = hlID('Normal')->synIDtrans()->synIDattr(what, mode)
# however, just in case
if empty(color) || str2nr(color) == -1
color = 'NONE'
endif
endif
return color
enddef
def s:get_array(guifg: string, guibg: string, ctermfg: string, ctermbg: string, opts: list<string>): list<string> # {{{2
return [ guifg, guibg, ctermfg, ctermbg, empty(opts) ? '' : join(opts, ',') ]
enddef
def airline#highlighter#reset_hlcache(): void # {{{2
s:hl_groups = {}
enddef
def airline#highlighter#get_highlight(group: string, rest: list<string> = ['']): list<string> # {{{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')->str2nr()
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')->str2nr()
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
def airline#highlighter#get_highlight2(fg: list<string>, bg: list<string>, rest1: string = '', rest2: string = '', rest3: string = ''): list<string> # {{{2
var guifg = s:get_syn(fg[0], fg[1], 'gui')
var guibg = s:get_syn(bg[0], bg[1], 'gui')
var ctermfg = s:get_syn(fg[0], fg[1], 'cterm')
var ctermbg = s:get_syn(bg[0], bg[1], 'cterm')
var rest = [ rest1, rest2, rest3 ]
return s:get_array(guifg, guibg, ctermfg, ctermbg, filter(rest, {_, v -> !empty(v)}))
enddef
def s:hl_group_exists(group: string): bool # {{{2
if !hlexists(group)
return false
elseif hlID(group)->synIDtrans()->synIDattr('fg')->empty()
return false
endif
return true
enddef
def s:CheckDefined(colors: list<any>): list<any> # {{{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
# that means to clear that highlighting group, therefore, fallback to Normal
# highlighting group for the cterm values
# This only works, if the Normal highlighting group is actually defined,
# so return early, if it has been cleared
if !exists("g:airline#highlighter#normal_fg_hi")
g:airline#highlighter#normal_fg_hi = hlID('Normal')->synIDtrans()->synIDattr('fg', 'cterm')
endif
if empty(g:airline#highlighter#normal_fg_hi) || str2nr(g:airline#highlighter#normal_fg_hi) < 0
return colors
endif
for val in colors
if !empty(val) && val !=# 'NONE'
return 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
var fg = g:airline#highlighter#normal_fg_hi
var bg = hlID('Normal')->synIDtrans()->synIDattr('bg', 'cterm')
if str2nr(bg) < 0
# in case there is no background color defined for Normal
bg = colors[3]
endif
return colors[0:1] + [fg, bg] + [colors[4]]
enddef
def s:GetHiCmd(list: list<string>): string # {{{2
# list needs to have 5 items!
var res: string
var i = -1
var item: string
while i < 4
i += 1
item = get(list, i, '')
if item is ''
continue
endif
if i == 0
res = res .. ' guifg=' .. item
elseif i == 1
res = res .. ' guibg=' .. item
elseif i == 2
res = res .. ' ctermfg=' .. item
elseif i == 3
res = res .. ' ctermbg=' .. item
elseif i == 4
res = res .. printf(' gui=%s cterm=%s term=%s', item, item, item)
endif
endwhile
return res
enddef
def airline#highlighter#exec(group: string, clrs: list<any>): void # {{{2
# TODO: is clrs: list<any> correct? Should probably be list<number> instead
# convert all themes to use strings in cterm color definition
if pumvisible()
return
endif
var colors: list<string>
colors = map(copy(clrs), { _, v -> type(v) != type('') ? string(v) : v})
if len(colors) == 4
add(colors, '')
endif
if s:is_win32term
colors[2] = s:gui2cui(get(colors, 0, ''), get(colors, 2, ''))
colors[3] = s:gui2cui(get(colors, 1, ''), get(colors, 3, ''))
endif
var old_hi: list<string> = airline#highlighter#get_highlight(group)
var new_hi: list<string> = colors
colors = s:CheckDefined(colors)
if old_hi != new_hi || !s:hl_group_exists(group)
var cmd = ''
cmd = printf('hi %s%s', group, s:GetHiCmd(colors))
:exe cmd
if has_key(s:hl_groups, group)
s:hl_groups[group] = colors
endif
endif
enddef
def s:exec_separator(dict: dict<any>, from_arg: string, to_arg: string, inverse: bool, suffix: string): void # {{{2
if pumvisible()
return
endif
var group = from_arg .. '_to_' .. to_arg .. suffix
var from = map(airline#themes#get_highlight(from_arg .. suffix),
{_, v -> type(v) != type('') ? string(v) : v})
var colors = []
var to = map(airline#themes#get_highlight(to_arg .. suffix),
{_, v -> type(v) != type('') ? string(v) : v})
if inverse
colors = [ from[1], to[1], from[3], to[3] ]
else
colors = [ to[1], from[1], to[3], from[3] ]
endif
dict[group] = colors
airline#highlighter#exec(group, colors)
enddef
def airline#highlighter#load_theme(): void # {{{2
if pumvisible()
return
endif
for winnr in filter(range(1, winnr('$')), {_, v -> v != winnr()})
airline#highlighter#highlight_modified_inactive(winbufnr(winnr))
endfor
airline#highlighter#highlight(['inactive'])
if getbufvar( bufnr('%'), '&modified' )
airline#highlighter#highlight(['normal', 'modified'])
else
airline#highlighter#highlight(['normal'])
endif
enddef
def airline#highlighter#add_separator(from: string, to: string, inverse: bool): void # {{{2
s:separators[from .. to] = [from, to, inverse]
s:exec_separator({}, from, to, inverse, '')
enddef
def airline#highlighter#add_accent(accent: string): void # {{{2
s:accents[accent] = 1
enddef
def airline#highlighter#highlight_modified_inactive(bufnr: number): void # {{{2
var colors: list<any>
var dict1 = eval('g:airline#themes#' .. g:airline_theme .. '#palette')->get('inactive_modified', {})
var dict2 = eval('g:airline#themes#' .. g:airline_theme .. '#palette')->get('inactive', {})
if empty(dict2)
return
endif
if getbufvar(bufnr, '&modified')
colors = get(dict1, 'airline_c', [])
else
colors = get(dict2, 'airline_c', [])
endif
if !empty(colors)
airline#highlighter#exec('airline_c' .. bufnr .. '_inactive', colors)
endif
enddef
def airline#highlighter#highlight(modes: list<string>, bufnr: string = ''): void # {{{2
var p: dict<any> = eval('g:airline#themes#' .. g:airline_theme .. '#palette')
# draw the base mode, followed by any overrides
var mapped = map(modes, {_, v -> v == modes[0] ? v : modes[0] .. "_" .. v})
var suffix = ''
if modes[0] == 'inactive'
suffix = '_inactive'
endif
var airline_grouplist = []
var dict: dict<any>
var bnr: number = 0
var buffers_in_tabpage: list<number> = uniq(sort(tabpagebuflist()))
# mapped might be something like ['normal', 'normal_modified']
# if a group is in both modes available, only define the second
# that is how this was done previously overwrite the previous definition
for mode in reverse(mapped)
if exists('g:airline#themes#' .. g:airline_theme .. '#palette.' .. mode)
dict = eval('g:airline#themes#' .. g:airline_theme .. '#palette.' .. mode)
for kvp in items(dict)
var mode_colors = kvp[1]
var name = kvp[0]
if name == 'airline_c' && !empty(bufnr) && suffix == '_inactive'
name = 'airline_c' .. bufnr
endif
# do not re-create highlighting for buffers that are no longer visible
# in the current tabpage
if name =~# 'airline_c\d\+'
bnr = str2nr(matchstr(name, 'airline_c\zs\d\+'))
if bnr > 0 && index(buffers_in_tabpage, bnr) == -1
continue
endif
elseif (name =~ '_to_') || (name[0:10] == 'airline_tab' && !empty(suffix))
# group will be redefined below at exec_separator
# or is not needed for tabline with '_inactive' suffix
# since active flag is 1 for builder)
continue
endif
if s:group_not_done(airline_grouplist, name .. suffix)
airline#highlighter#exec(name .. suffix, mode_colors)
endif
if !has_key(p, 'accents')
# shouldn't actually happen, p should always contain accents
continue
endif
for accent in keys(s:accents)
if !has_key(p.accents, accent)
continue
endif
var colors = copy(mode_colors)
if p.accents[accent][0] != ''
colors[0] = p.accents[accent][0]
endif
if type(get(p.accents[accent], 2, '')) == type('')
colors[2] = get(p.accents[accent], 2, '')
else
colors[2] = string(p.accents[accent][2])
endif
if len(colors) >= 5
colors[4] = get(p.accents[accent], 4, '')
else
add(colors, get(p.accents[accent], 4, ''))
endif
if s:group_not_done(airline_grouplist, name .. suffix .. '_' .. accent)
airline#highlighter#exec(name .. suffix .. '_' .. accent, colors)
endif
endfor
endfor
if empty(s:separators)
continue
endif
for sep in items(s:separators)
# we cannot check, that the group already exists, else the separators
# might not be correctly defined. But perhaps we can skip above groups
# that match the '_to_' name, because they would be redefined here...
s:exec_separator(dict, sep[1][0], sep[1][1], sep[1][2], suffix)
endfor
endif
endfor
enddef
endif " }}}1

View File

@@ -22,7 +22,7 @@ scriptencoding utf-8
" 14 Yellow
" 15 White
let s:basic16 = [
const s:basic16 = [
\ [ 0x00, 0x00, 0x00 ],
\ [ 0x00, 0x00, 0x80 ],
\ [ 0x00, 0x80, 0x00 ],
@@ -41,6 +41,26 @@ let s:basic16 = [
\ [ 0xFF, 0xFF, 0xFF ]
\ ]
if exists(":def")
def airline#msdos#round_msdos_colors(rgblist: list<number>): string
# Check for values from MSDOS 16 color terminal
var best = []
var min = 100000
var t = 0
for value in s:basic16
t = abs(value[0] - rgblist[0]) +
abs(value[1] - rgblist[1]) +
abs(value[2] - rgblist[2])
if min > t
min = t
best = value
endif
endfor
return string(index(s:basic16, best))
enddef
finish
endif
function! airline#msdos#round_msdos_colors(rgblist)
" Check for values from MSDOS 16 color terminal
let best = []

View File

@@ -1,10 +1,11 @@
" MIT License. Copyright (c) 2013-2020 Bailey Ling et al.
" vim: et ts=2 sts=2 sw=2
" vim: et ts=2 sts=2 sw=2 et
scriptencoding utf-8
" generates a dictionary which defines the colors for each highlight group
function! airline#themes#generate_color_map(sect1, sect2, sect3, ...)
if !exists(":def") || (exists(":def") && get(g:, "airline_experimental", 0)==0)
" generates a dictionary which defines the colors for each highlight group
function! airline#themes#generate_color_map(sect1, sect2, sect3, ...)
let palette = {
\ 'airline_a': [ a:sect1[0] , a:sect1[1] , a:sect1[2] , a:sect1[3] , get(a:sect1 , 4 , '') ] ,
\ 'airline_b': [ a:sect2[0] , a:sect2[1] , a:sect2[2] , a:sect2[3] , get(a:sect2 , 4 , '') ] ,
@@ -26,17 +27,17 @@ function! airline#themes#generate_color_map(sect1, sect2, sect3, ...)
endif
return palette
endfunction
endfunction
function! airline#themes#get_highlight(group, ...)
function! airline#themes#get_highlight(group, ...)
return call('airline#highlighter#get_highlight', [a:group] + a:000)
endfunction
endfunction
function! airline#themes#get_highlight2(fg, bg, ...)
function! airline#themes#get_highlight2(fg, bg, ...)
return call('airline#highlighter#get_highlight2', [a:fg, a:bg] + a:000)
endfunction
endfunction
function! airline#themes#patch(palette)
function! airline#themes#patch(palette)
for mode in keys(a:palette)
if mode == 'accents'
continue
@@ -75,4 +76,76 @@ function! airline#themes#patch(palette)
if !has_key(a:palette.accents, 'purple')
let a:palette.accents.purple = [ '#af00df' , '' , 128 , '' ]
endif
endfunction
endfunction
else
" New Vim9script implementation
def airline#themes#generate_color_map(sect1: list<string>, sect2: list<any>, sect3: list<any>): dict<any>
# Only allows for 3 arguments currently, because Vim9 Script does not
# allow for a:000
# all sections should be string
map(sect2, {_, v -> type(v) != type('') ? string(v) : v})
var palette = {
'airline_a': [ sect1[0], sect1[1], sect1[2], sect1[3], get(sect1, 4, '') ],
'airline_b': [ sect2[0], sect2[1], sect2[2], sect2[3], get(sect2, 4, '') ],
'airline_c': [ sect3[0], sect3[1], sect3[2], sect3[3], get(sect3, 4, '') ],
}
extend(palette, {
'airline_x': [ sect3[0], sect3[1], sect3[2], sect3[3], '' ],
'airline_y': [ sect2[0], sect2[1], sect2[2], sect2[3], '' ],
'airline_z': [ sect1[0], sect1[1], sect1[2], sect1[3], '' ],
})
return palette
enddef
def airline#themes#get_highlight(group: string): list<string>
return call('airline#highlighter#get_highlight', [group])
enddef
def airline#themes#get_highlight2(fg: list<string>, bg: list<string>): list<string>
return call('airline#highlighter#get_highlight2', [fg, bg])
enddef
def airline#themes#patch(palette: dict<any>): void
for mode in keys(palette)
if mode == 'accents'
continue
endif
if !has_key(palette[mode], 'airline_warning')
extend(palette[mode], #{airline_warning: [ '#000000', '#df5f00', '232', '166', '' ]})
endif
if !has_key(palette[mode], 'airline_error')
extend(palette[mode], #{airline_error: [ '#000000', '#990000', '232', '160', '' ]})
endif
if !has_key(palette[mode], 'airline_term')
extend(palette[mode], #{airline_term: [ '#9cffd3', '#202020', '85', '232', '']})
endif
endfor
palette.accents = get(palette, 'accents', {})
extend(palette.accents, #{none: [ '', '', '', '', '' ]})
extend(palette.accents, #{bold: [ '', '', '', '', 'bold' ]})
extend(palette.accents, #{italic: [ '', '', '', '', 'italic' ]})
if !has_key(palette.accents, 'red')
extend(palette.accents, #{red: [ '#ff0000', '', '160', '' ]})
endif
if !has_key(palette.accents, 'green')
extend(palette.accents, #{green: [ '#008700', '', '22', '' ]})
endif
if !has_key(palette.accents, 'blue')
extend(palette.accents, #{blue: [ '#005fff', '', '27', '' ]})
endif
if !has_key(palette.accents, 'yellow')
extend(palette.accents, #{yellow: [ '#dfff00', '', '190', '' ]})
endif
if !has_key(palette.accents, 'orange')
extend(palette.accents, #{orange: [ '#df5f00', '', '166', '' ]})
endif
if !has_key(palette.accents, 'purple')
extend(palette.accents, #{purple: [ '#af00df', '', '128', '' ]})
endif
enddef
endif

View File

@@ -61,9 +61,9 @@ let g:airline#themes#dark#palette = {}
" airline_x/y/z, respectively.
" The dark.vim theme:
let s:airline_a_normal = [ '#00005f' , '#dfff00' , 17 , 190 ]
let s:airline_b_normal = [ '#ffffff' , '#444444' , 255 , 238 ]
let s:airline_c_normal = [ '#9cffd3' , '#202020' , 85 , 234 ]
let s:airline_a_normal = [ '#00005f' , '#dfff00' , '17' , '190' ]
let s:airline_b_normal = [ '#ffffff' , '#444444' , '255' , '238' ]
let s:airline_c_normal = [ '#9cffd3' , '#202020' , '85' , '234' ]
let g:airline#themes#dark#palette.normal = airline#themes#generate_color_map(s:airline_a_normal, s:airline_b_normal, s:airline_c_normal)
" It should be noted the above is equivalent to:
@@ -93,50 +93,50 @@ let g:airline#themes#dark#palette.normal = airline#themes#generate_color_map(s:a
" applied after g:airline#themes#dark#palette.normal, hence why only certain keys are
" declared.
let g:airline#themes#dark#palette.normal_modified = {
\ 'airline_c': [ '#ffffff' , '#5f005f' , 255 , 53 , '' ] ,
\ 'airline_c': [ '#ffffff' , '#5f005f' , '255' , '53' , '' ] ,
\ }
let s:airline_a_insert = [ '#00005f' , '#00dfff' , 17 , 45 ]
let s:airline_b_insert = [ '#ffffff' , '#005fff' , 255 , 27 ]
let s:airline_c_insert = [ '#ffffff' , '#000080' , 15 , 17 ]
let s:airline_a_insert = [ '#00005f' , '#00dfff' , '17' , '45' ]
let s:airline_b_insert = [ '#ffffff' , '#005fff' , '255' , '27' ]
let s:airline_c_insert = [ '#ffffff' , '#000080' , '15' , '17' ]
let g:airline#themes#dark#palette.insert = airline#themes#generate_color_map(s:airline_a_insert, s:airline_b_insert, s:airline_c_insert)
let g:airline#themes#dark#palette.insert_modified = {
\ 'airline_c': [ '#ffffff' , '#5f005f' , 255 , 53 , '' ] ,
\ 'airline_c': [ '#ffffff' , '#5f005f' , '255' , '53' , '' ] ,
\ }
let g:airline#themes#dark#palette.insert_paste = {
\ 'airline_a': [ s:airline_a_insert[0] , '#d78700' , s:airline_a_insert[2] , 172 , '' ] ,
\ 'airline_a': [ s:airline_a_insert[0] , '#d78700' , s:airline_a_insert[2] , '172' , '' ] ,
\ }
let g:airline#themes#dark#palette.terminal = airline#themes#generate_color_map(s:airline_a_insert, s:airline_b_insert, s:airline_c_insert)
let g:airline#themes#dark#palette.replace = copy(g:airline#themes#dark#palette.insert)
let g:airline#themes#dark#palette.replace.airline_a = [ s:airline_b_insert[0] , '#af0000' , s:airline_b_insert[2] , 124 , '' ]
let g:airline#themes#dark#palette.replace.airline_a = [ s:airline_b_insert[0] , '#af0000' , s:airline_b_insert[2] , '124' , '' ]
let g:airline#themes#dark#palette.replace_modified = g:airline#themes#dark#palette.insert_modified
let s:airline_a_visual = [ '#000000' , '#ffaf00' , 232 , 214 ]
let s:airline_b_visual = [ '#000000' , '#ff5f00' , 232 , 202 ]
let s:airline_c_visual = [ '#ffffff' , '#5f0000' , 15 , 52 ]
let s:airline_a_visual = [ '#000000' , '#ffaf00' , '232' , '214' ]
let s:airline_b_visual = [ '#000000' , '#ff5f00' , '232' , '202' ]
let s:airline_c_visual = [ '#ffffff' , '#5f0000' , '15' , '52' ]
let g:airline#themes#dark#palette.visual = airline#themes#generate_color_map(s:airline_a_visual, s:airline_b_visual, s:airline_c_visual)
let g:airline#themes#dark#palette.visual_modified = {
\ 'airline_c': [ '#ffffff' , '#5f005f' , 255 , 53 , '' ] ,
\ 'airline_c': [ '#ffffff' , '#5f005f' , '255' , '53' , '' ] ,
\ }
let s:airline_a_inactive = [ '#4e4e4e' , '#1c1c1c' , 239 , 234 , '' ]
let s:airline_b_inactive = [ '#4e4e4e' , '#262626' , 239 , 235 , '' ]
let s:airline_c_inactive = [ '#4e4e4e' , '#303030' , 239 , 236 , '' ]
let s:airline_a_inactive = [ '#4e4e4e' , '#1c1c1c' , '239' , '234' , '' ]
let s:airline_b_inactive = [ '#4e4e4e' , '#262626' , '239' , '235' , '' ]
let s:airline_c_inactive = [ '#4e4e4e' , '#303030' , '239' , '236' , '' ]
let g:airline#themes#dark#palette.inactive = airline#themes#generate_color_map(s:airline_a_inactive, s:airline_b_inactive, s:airline_c_inactive)
let g:airline#themes#dark#palette.inactive_modified = {
\ 'airline_c': [ '#875faf' , '' , 97 , '' , '' ] ,
\ 'airline_c': [ '#875faf' , '' , '97' , '' , '' ] ,
\ }
" For commandline mode, we use the colors from normal mode, except the mode
" indicator should be colored differently, e.g. light green
let s:airline_a_commandline = [ '#0000ff' , '#0cff00' , 17 , 40 ]
let s:airline_b_commandline = [ '#ffffff' , '#444444' , 255 , 238 ]
let s:airline_c_commandline = [ '#9cffd3' , '#202020' , 85 , 234 ]
let s:airline_a_commandline = [ '#0000ff' , '#0cff00' , '17' , '40' ]
let s:airline_b_commandline = [ '#ffffff' , '#444444' , '255' , '238' ]
let s:airline_c_commandline = [ '#9cffd3' , '#202020' , '85' , '234' ]
let g:airline#themes#dark#palette.commandline = airline#themes#generate_color_map(s:airline_a_commandline, s:airline_b_commandline, s:airline_c_commandline)
" Accents are used to give parts within a section a slightly different look or
@@ -147,7 +147,7 @@ let g:airline#themes#dark#palette.commandline = airline#themes#generate_color_ma
" will be red instead of the section's foreground color. You can also have
" multiple parts with accents within a section.
let g:airline#themes#dark#palette.accents = {
\ 'red': [ '#ff0000' , '' , 160 , '' ]
\ 'red': [ '#ff0000' , '' , '160' , '' ]
\ }
@@ -157,7 +157,7 @@ let g:airline#themes#dark#palette.accents = {
" they will be chosen automatically from the existing palette.
if get(g:, 'loaded_ctrlp', 0)
let g:airline#themes#dark#palette.ctrlp = airline#extensions#ctrlp#generate_color_map(
\ [ '#d7d7ff' , '#5f00af' , 189 , 55 , '' ],
\ [ '#ffffff' , '#875fd7' , 231 , 98 , '' ],
\ [ '#5f00af' , '#ffffff' , 55 , 231 , 'bold' ])
\ [ '#d7d7ff' , '#5f00af' , '189' , '55' , '' ],
\ [ '#ffffff' , '#875fd7' , '231' , '98' , '' ],
\ [ '#5f00af' , '#ffffff' , '55' , '231' , 'bold' ])
endif