mirror of
https://github.com/vim-airline/vim-airline.git
synced 2025-12-07 20:54:26 +08:00
Compare commits
85 Commits
e78a7eda20
...
vim9script
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a6886f2997 | ||
|
|
1962371666 | ||
|
|
2062dd2f98 | ||
|
|
0e91eeb548 | ||
|
|
4b02724d0c | ||
|
|
f54f7859a3 | ||
|
|
4bce179ed3 | ||
|
|
2083bfe890 | ||
|
|
084dfe017d | ||
|
|
ad7dcbdece | ||
|
|
bb204d1fee | ||
|
|
a678556366 | ||
|
|
def61b1450 | ||
|
|
3de44bc58f | ||
|
|
dcb36f0480 | ||
|
|
21f329cd70 | ||
|
|
0eee611a0e | ||
|
|
4e4663c71c | ||
|
|
0a80997100 | ||
|
|
f08b7912c6 | ||
|
|
d49b655e72 | ||
|
|
70dc69fcd8 | ||
|
|
cdb265c410 | ||
|
|
de3dbfcb3c | ||
|
|
cc2a836b9a | ||
|
|
6ff95bac4e | ||
|
|
c8c30c9e3e | ||
|
|
a77cd28ecc | ||
|
|
6a6945d45d | ||
|
|
d5ffa5fd58 | ||
|
|
b10c1107e1 | ||
|
|
4f59fef538 | ||
|
|
e59a654d17 | ||
|
|
18ae588bad | ||
|
|
86c466d81e | ||
|
|
c08b1c0c75 | ||
|
|
3d536ef950 | ||
|
|
02aaaf94e8 | ||
|
|
bbc70019f6 | ||
|
|
0bc7ff3629 | ||
|
|
7880f0a73c | ||
|
|
5502e5302d | ||
|
|
59c906da4d | ||
|
|
19f8be42b6 | ||
|
|
e81d400b09 | ||
|
|
5062eeeaed | ||
|
|
e6bd342293 | ||
|
|
caaa553ce9 | ||
|
|
b4e38be8b8 | ||
|
|
252b89bb1f | ||
|
|
b271c279d6 | ||
|
|
9387517f01 | ||
|
|
8ec6f1e40f | ||
|
|
0d0c380940 | ||
|
|
9f7557df44 | ||
|
|
f615f8bad3 | ||
|
|
f5e2f97003 | ||
|
|
14fd943dc6 | ||
|
|
e9d4ff75da | ||
|
|
9b32ed3229 | ||
|
|
58b2a8bbc8 | ||
|
|
5ac55ea4e5 | ||
|
|
56ba4b34a7 | ||
|
|
798a346a91 | ||
|
|
4f8675434a | ||
|
|
5391b3e246 | ||
|
|
7310ca6cbf | ||
|
|
9ae38b43e4 | ||
|
|
2441084898 | ||
|
|
d9947beb0f | ||
|
|
a6b7267979 | ||
|
|
90de76359f | ||
|
|
0238d386bb | ||
|
|
19861861fd | ||
|
|
687fb52d9f | ||
|
|
aa8bd171f3 | ||
|
|
b152059a98 | ||
|
|
4d75c9940c | ||
|
|
ae3af85ca2 | ||
|
|
a9f525f8da | ||
|
|
3e93c212cc | ||
|
|
a8afa434e3 | ||
|
|
b0d4a44f0c | ||
|
|
0abcdbeba5 | ||
|
|
609205f1e8 |
52
.github/workflows/ci.yml
vendored
Normal file
52
.github/workflows/ci.yml
vendored
Normal 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
|
||||
34
.travis.yml
34
.travis.yml
@@ -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
|
||||
@@ -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
|
||||
|
||||
@@ -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,245 +10,19 @@ 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()
|
||||
call airline#extensions#tabline#autoshow#off()
|
||||
call airline#extensions#tabline#tabs#off()
|
||||
call airline#extensions#tabline#buffers#off()
|
||||
if s:ctrlspace
|
||||
call airline#extensions#tabline#ctrlspace#off()
|
||||
endif
|
||||
if s:tabws
|
||||
call airline#extensions#tabline#tabws#off()
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! s:toggle_on()
|
||||
if get(g:, 'airline_statusline_ontop', 0)
|
||||
call airline#extensions#tabline#enable()
|
||||
let &tabline='%!airline#statusline('.winnr().')'
|
||||
return
|
||||
endif
|
||||
call airline#extensions#tabline#autoshow#on()
|
||||
call airline#extensions#tabline#tabs#on()
|
||||
call airline#extensions#tabline#buffers#on()
|
||||
if s:ctrlspace
|
||||
call airline#extensions#tabline#ctrlspace#on()
|
||||
endif
|
||||
if s:tabws
|
||||
call airline#extensions#tabline#tabws#on()
|
||||
endif
|
||||
|
||||
set tabline=%!airline#extensions#tabline#get()
|
||||
endfunction
|
||||
|
||||
function! s:update_tabline(forceit)
|
||||
if get(g:, 'airline#extensions#tabline#disable_refresh', 0)
|
||||
return
|
||||
endif
|
||||
" loading a session file
|
||||
" On SessionLoadPost, g:SessionLoad variable is still set :/
|
||||
if !a:forceit && get(g:, 'SessionLoad', 0)
|
||||
return
|
||||
endif
|
||||
let 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
|
||||
call airline#util#doautocmd('BufMRUChange')
|
||||
call airline#extensions#tabline#redraw()
|
||||
endfunction
|
||||
|
||||
function! airline#extensions#tabline#redraw()
|
||||
" sometimes, the tabline is not correctly updated see #1580
|
||||
" so force redraw here
|
||||
if exists(":redrawtabline") == 2
|
||||
redrawtabline
|
||||
else
|
||||
" Have to set a property equal to itself to get airline to re-eval.
|
||||
" Setting `let &tabline=&tabline` destroys the cursor position so we
|
||||
" need something less invasive.
|
||||
let &ro = &ro
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! airline#extensions#tabline#enable()
|
||||
if &lines > 3
|
||||
set showtabline=2
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! airline#extensions#tabline#load_theme(palette)
|
||||
if pumvisible()
|
||||
return
|
||||
endif
|
||||
let colors = get(a:palette, 'tabline', {})
|
||||
let tablabel = get(colors, 'airline_tablabel', a:palette.normal.airline_b)
|
||||
" Theme for tabs on the left
|
||||
let tab = get(colors, 'airline_tab', a:palette.inactive.airline_c)
|
||||
let tabsel = get(colors, 'airline_tabsel', a:palette.normal.airline_a)
|
||||
let tabtype = get(colors, 'airline_tabtype', a:palette.visual.airline_a)
|
||||
let tabfill = get(colors, 'airline_tabfill', a:palette.normal.airline_c)
|
||||
let tabmod = get(colors, 'airline_tabmod', a:palette.insert.airline_a)
|
||||
let tabhid = get(colors, 'airline_tabhid', a:palette.normal.airline_c)
|
||||
if has_key(a:palette, 'normal_modified') && has_key(a:palette.normal_modified, 'airline_c')
|
||||
let tabmodu = get(colors, 'airline_tabmod_unsel', a:palette.normal_modified.airline_c)
|
||||
else
|
||||
"Fall back to normal airline_c if modified airline_c isn't present
|
||||
let tabmodu = get(colors, 'airline_tabmod_unsel', a:palette.normal.airline_c)
|
||||
endif
|
||||
call airline#highlighter#exec('airline_tablabel', tablabel)
|
||||
call airline#highlighter#exec('airline_tab', tab)
|
||||
call airline#highlighter#exec('airline_tabsel', tabsel)
|
||||
call airline#highlighter#exec('airline_tabtype', tabtype)
|
||||
call airline#highlighter#exec('airline_tabfill', tabfill)
|
||||
call airline#highlighter#exec('airline_tabmod', tabmod)
|
||||
call airline#highlighter#exec('airline_tabmod_unsel', tabmodu)
|
||||
call airline#highlighter#exec('airline_tabhid', tabhid)
|
||||
|
||||
" Theme for tabs on the right
|
||||
" label on the right
|
||||
let tablabel_r = get(colors, 'airline_tablabel', a:palette.normal.airline_b)
|
||||
let tabsel_right = get(colors, 'airline_tabsel_right', a:palette.normal.airline_a)
|
||||
let tab_right = get(colors, 'airline_tab_right', a:palette.inactive.airline_c)
|
||||
let tabmod_right = get(colors, 'airline_tabmod_right', a:palette.insert.airline_a)
|
||||
let tabhid_right = get(colors, 'airline_tabhid_right', a:palette.normal.airline_c)
|
||||
if has_key(a:palette, 'normal_modified') && has_key(a:palette.normal_modified, 'airline_c')
|
||||
let tabmodu_right = get(colors, 'airline_tabmod_unsel_right', a:palette.normal_modified.airline_c)
|
||||
else
|
||||
"Fall back to normal airline_c if modified airline_c isn't present
|
||||
let tabmodu_right = get(colors, 'airline_tabmod_unsel_right', a:palette.normal.airline_c)
|
||||
endif
|
||||
call airline#highlighter#exec('airline_tablabel_right', tablabel_r)
|
||||
call airline#highlighter#exec('airline_tab_right', tab_right)
|
||||
call airline#highlighter#exec('airline_tabsel_right', tabsel_right)
|
||||
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()
|
||||
let show_buffers = get(g:, 'airline#extensions#tabline#show_buffers', 1)
|
||||
let show_tabs = get(g:, 'airline#extensions#tabline#show_tabs', 1)
|
||||
|
||||
let curtabcnt = tabpagenr('$')
|
||||
if curtabcnt != s:current_tabcnt
|
||||
let s:current_tabcnt = curtabcnt
|
||||
call airline#extensions#tabline#tabs#invalidate()
|
||||
call airline#extensions#tabline#buffers#invalidate()
|
||||
call airline#extensions#tabline#ctrlspace#invalidate()
|
||||
call 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
|
||||
endfunction
|
||||
|
||||
function! airline#extensions#tabline#title(n)
|
||||
let title = ''
|
||||
if s:taboo
|
||||
let title = TabooTabTitle(a:n)
|
||||
endif
|
||||
|
||||
if empty(title) && exists('*gettabvar')
|
||||
let title = gettabvar(a:n, 'title')
|
||||
endif
|
||||
|
||||
let formatter = get(g:, 'airline#extensions#tabline#tabtitle_formatter')
|
||||
if empty(title) && formatter !=# '' && exists("*".formatter)
|
||||
let title = call(formatter, [a:n])
|
||||
endif
|
||||
|
||||
if empty(title)
|
||||
let buflist = tabpagebuflist(a:n)
|
||||
let winnr = tabpagewinnr(a:n)
|
||||
let all_buffers = airline#extensions#tabline#buflist#list()
|
||||
let curbuf = filter(buflist, 'index(all_buffers, v:val) != -1')
|
||||
if len(curbuf) == 0
|
||||
call add(curbuf, tabpagebuflist()[0])
|
||||
endif
|
||||
return airline#extensions#tabline#get_buffer_name(curbuf[0], curbuf)
|
||||
endif
|
||||
|
||||
return title
|
||||
endfunction
|
||||
|
||||
function! airline#extensions#tabline#get_buffer_name(nr, ...)
|
||||
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()
|
||||
let 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),
|
||||
\ }
|
||||
if get(g:, 'airline_powerline_fonts', 0)
|
||||
let builder_context.left_sep = get(g:, 'airline#extensions#tabline#left_sep' , g:airline_left_sep)
|
||||
let builder_context.left_alt_sep = get(g:, 'airline#extensions#tabline#left_alt_sep' , g:airline_left_alt_sep)
|
||||
else
|
||||
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)
|
||||
let cur = bufnr('%')
|
||||
if cur == a:bufnr
|
||||
if g:airline_detect_modified && getbufvar(a:bufnr, '&modified')
|
||||
let group = 'airline_tabmod'
|
||||
else
|
||||
let group = 'airline_tabsel'
|
||||
endif
|
||||
else
|
||||
if g:airline_detect_modified && getbufvar(a:bufnr, '&modified')
|
||||
let group = 'airline_tabmod_unsel'
|
||||
elseif index(a:tab_bufs, a:bufnr) > -1
|
||||
let group = 'airline_tab'
|
||||
else
|
||||
let group = 'airline_tabhid'
|
||||
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'.
|
||||
@@ -265,3 +39,449 @@ function! airline#extensions#tabline#add_tab_label(dict)
|
||||
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()
|
||||
if s:ctrlspace
|
||||
call airline#extensions#tabline#ctrlspace#off()
|
||||
endif
|
||||
if s:tabws
|
||||
call airline#extensions#tabline#tabws#off()
|
||||
endif
|
||||
endfunction
|
||||
function! s:toggle_on() " {{{2
|
||||
if get(g:, 'airline_statusline_ontop', 0)
|
||||
call airline#extensions#tabline#enable()
|
||||
let &tabline='%!airline#statusline('.winnr().')'
|
||||
return
|
||||
endif
|
||||
call airline#extensions#tabline#autoshow#on()
|
||||
call airline#extensions#tabline#tabs#on()
|
||||
call airline#extensions#tabline#buffers#on()
|
||||
if s:ctrlspace
|
||||
call airline#extensions#tabline#ctrlspace#on()
|
||||
endif
|
||||
if s:tabws
|
||||
call airline#extensions#tabline#tabws#on()
|
||||
endif
|
||||
|
||||
set tabline=%!airline#extensions#tabline#get()
|
||||
endfunction
|
||||
function! s:update_tabline(forceit) " {{{2
|
||||
if get(g:, 'airline#extensions#tabline#disable_refresh', 0)
|
||||
return
|
||||
endif
|
||||
" loading a session file
|
||||
" On SessionLoadPost, g:SessionLoad variable is still set :/
|
||||
if !a:forceit && get(g:, 'SessionLoad', 0)
|
||||
return
|
||||
endif
|
||||
let 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
|
||||
call airline#util#doautocmd('BufMRUChange')
|
||||
call 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
|
||||
redrawtabline
|
||||
else
|
||||
" Have to set a property equal to itself to get airline to re-eval.
|
||||
" Setting `let &tabline=&tabline` destroys the cursor position so we
|
||||
" need something less invasive.
|
||||
let &ro = &ro
|
||||
endif
|
||||
endfunction
|
||||
function! airline#extensions#tabline#enable() " {{{2
|
||||
if &lines > 3
|
||||
set showtabline=2
|
||||
endif
|
||||
endfunction
|
||||
function! airline#extensions#tabline#load_theme(palette) " {{{2
|
||||
if pumvisible()
|
||||
return
|
||||
endif
|
||||
let colors = get(a:palette, 'tabline', {})
|
||||
let tablabel = get(colors, 'airline_tablabel', a:palette.normal.airline_b)
|
||||
" Theme for tabs on the left
|
||||
let tab = get(colors, 'airline_tab', a:palette.inactive.airline_c)
|
||||
let tabsel = get(colors, 'airline_tabsel', a:palette.normal.airline_a)
|
||||
let tabtype = get(colors, 'airline_tabtype', a:palette.visual.airline_a)
|
||||
let tabfill = get(colors, 'airline_tabfill', a:palette.normal.airline_c)
|
||||
let tabmod = get(colors, 'airline_tabmod', a:palette.insert.airline_a)
|
||||
let tabhid = get(colors, 'airline_tabhid', a:palette.normal.airline_c)
|
||||
if has_key(a:palette, 'normal_modified') && has_key(a:palette.normal_modified, 'airline_c')
|
||||
let tabmodu = get(colors, 'airline_tabmod_unsel', a:palette.normal_modified.airline_c)
|
||||
else
|
||||
"Fall back to normal airline_c if modified airline_c isn't present
|
||||
let tabmodu = get(colors, 'airline_tabmod_unsel', a:palette.normal.airline_c)
|
||||
endif
|
||||
call airline#highlighter#exec('airline_tablabel', tablabel)
|
||||
call airline#highlighter#exec('airline_tab', tab)
|
||||
call airline#highlighter#exec('airline_tabsel', tabsel)
|
||||
call airline#highlighter#exec('airline_tabtype', tabtype)
|
||||
call airline#highlighter#exec('airline_tabfill', tabfill)
|
||||
call airline#highlighter#exec('airline_tabmod', tabmod)
|
||||
call airline#highlighter#exec('airline_tabmod_unsel', tabmodu)
|
||||
call airline#highlighter#exec('airline_tabhid', tabhid)
|
||||
|
||||
" Theme for tabs on the right
|
||||
" label on the right
|
||||
let tablabel_r = get(colors, 'airline_tablabel', a:palette.normal.airline_b)
|
||||
let tabsel_right = get(colors, 'airline_tabsel_right', a:palette.normal.airline_a)
|
||||
let tab_right = get(colors, 'airline_tab_right', a:palette.inactive.airline_c)
|
||||
let tabmod_right = get(colors, 'airline_tabmod_right', a:palette.insert.airline_a)
|
||||
let tabhid_right = get(colors, 'airline_tabhid_right', a:palette.normal.airline_c)
|
||||
if has_key(a:palette, 'normal_modified') && has_key(a:palette.normal_modified, 'airline_c')
|
||||
let tabmodu_right = get(colors, 'airline_tabmod_unsel_right', a:palette.normal_modified.airline_c)
|
||||
else
|
||||
"Fall back to normal airline_c if modified airline_c isn't present
|
||||
let tabmodu_right = get(colors, 'airline_tabmod_unsel_right', a:palette.normal.airline_c)
|
||||
endif
|
||||
call airline#highlighter#exec('airline_tablabel_right', tablabel_r)
|
||||
call airline#highlighter#exec('airline_tab_right', tab_right)
|
||||
call airline#highlighter#exec('airline_tabsel_right', tabsel_right)
|
||||
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
|
||||
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)
|
||||
|
||||
let curtabcnt = tabpagenr('$')
|
||||
if curtabcnt != s:current_tabcnt
|
||||
let s:current_tabcnt = curtabcnt
|
||||
call airline#extensions#tabline#tabs#invalidate()
|
||||
call airline#extensions#tabline#buffers#invalidate()
|
||||
call airline#extensions#tabline#ctrlspace#invalidate()
|
||||
call 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
|
||||
endfunction
|
||||
function! airline#extensions#tabline#title(n) " {{{2
|
||||
let title = ''
|
||||
if s:taboo
|
||||
let title = TabooTabTitle(a:n)
|
||||
endif
|
||||
|
||||
if empty(title) && exists('*gettabvar')
|
||||
let title = gettabvar(a:n, 'title')
|
||||
endif
|
||||
|
||||
let formatter = get(g:, 'airline#extensions#tabline#tabtitle_formatter')
|
||||
if empty(title) && formatter !=# '' && exists("*".formatter)
|
||||
let title = call(formatter, [a:n])
|
||||
endif
|
||||
|
||||
if empty(title)
|
||||
let buflist = tabpagebuflist(a:n)
|
||||
let winnr = tabpagewinnr(a:n)
|
||||
let all_buffers = airline#extensions#tabline#buflist#list()
|
||||
let curbuf = filter(buflist, 'index(all_buffers, v:val) != -1')
|
||||
if len(curbuf) == 0
|
||||
call add(curbuf, tabpagebuflist()[0])
|
||||
endif
|
||||
return airline#extensions#tabline#get_buffer_name(curbuf[0], curbuf)
|
||||
endif
|
||||
return title
|
||||
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() " {{{2
|
||||
let 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),
|
||||
\ }
|
||||
if get(g:, 'airline_powerline_fonts', 0)
|
||||
let builder_context.left_sep = get(g:, 'airline#extensions#tabline#left_sep' , g:airline_left_sep)
|
||||
let builder_context.left_alt_sep = get(g:, 'airline#extensions#tabline#left_alt_sep' , g:airline_left_alt_sep)
|
||||
else
|
||||
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) " {{{2
|
||||
let cur = bufnr('%')
|
||||
if cur == a:bufnr
|
||||
if g:airline_detect_modified && getbufvar(a:bufnr, '&modified')
|
||||
let group = 'airline_tabmod'
|
||||
else
|
||||
let group = 'airline_tabsel'
|
||||
endif
|
||||
else
|
||||
if g:airline_detect_modified && getbufvar(a:bufnr, '&modified')
|
||||
let group = 'airline_tabmod_unsel'
|
||||
elseif index(a:tab_bufs, a:bufnr) > -1
|
||||
let group = 'airline_tab'
|
||||
else
|
||||
let group = 'airline_tabhid'
|
||||
endif
|
||||
endif
|
||||
return group
|
||||
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
|
||||
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
|
||||
|
||||
@@ -1,45 +1,82 @@
|
||||
" 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)
|
||||
let fnametruncate = get(g:, 'airline#extensions#tabline#fnametruncate', 0)
|
||||
let fmod = get(g:, 'airline#extensions#tabline#fnamemod', ':~:.')
|
||||
let _ = ''
|
||||
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 _ = ''
|
||||
|
||||
let name = bufname(a:bufnr)
|
||||
if empty(name)
|
||||
let _ .= '[No Name]'
|
||||
elseif name =~ 'term://'
|
||||
" Neovim Terminal
|
||||
let _ = substitute(name, '\(term:\)//.*:\(.*\)', '\1 \2', '')
|
||||
else
|
||||
if get(g:, 'airline#extensions#tabline#fnamecollapse', 1)
|
||||
" Does not handle non-ascii characters like Cyrillic: 'D/Учёба/t.c'
|
||||
"let _ .= substitute(fnamemodify(name, fmod), '\v\w\zs.{-}\ze(\\|/)', '', 'g')
|
||||
let _ .= pathshorten(fnamemodify(name, fmod))
|
||||
let name = bufname(a:bufnr)
|
||||
if empty(name)
|
||||
let _ .= '[No Name]'
|
||||
elseif name =~ 'term://'
|
||||
" Neovim Terminal
|
||||
let _ = substitute(name, '\(term:\)//.*:\(.*\)', '\1 \2', '')
|
||||
else
|
||||
let _ .= fnamemodify(name, fmod)
|
||||
if get(g:, 'airline#extensions#tabline#fnamecollapse', 1)
|
||||
" Does not handle non-ascii characters like Cyrillic: 'D/Учёба/t.c'
|
||||
"let _ .= substitute(fnamemodify(name, fmod), '\v\w\zs.{-}\ze(\\|/)', '', 'g')
|
||||
let _ .= pathshorten(fnamemodify(name, fmod))
|
||||
else
|
||||
let _ .= fnamemodify(name, fmod)
|
||||
endif
|
||||
if a:bufnr != bufnr('%') && fnametruncate && strlen(_) > fnametruncate
|
||||
let _ = airline#util#strcharpart(_, 0, fnametruncate)
|
||||
endif
|
||||
endif
|
||||
if a:bufnr != bufnr('%') && fnametruncate && strlen(_) > fnametruncate
|
||||
let _ = airline#util#strcharpart(_, 0, fnametruncate)
|
||||
|
||||
return airline#extensions#tabline#formatters#default#wrap_name(a:bufnr, _)
|
||||
endfunction
|
||||
|
||||
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_nr_show ? printf(buf_nr_format, a:bufnr) : ''
|
||||
let _ .= substitute(a:buffer_name, '\\', '/', 'g')
|
||||
|
||||
if getbufvar(a:bufnr, '&modified') == 1
|
||||
let _ .= g:airline_symbols.modified
|
||||
endif
|
||||
endif
|
||||
return _
|
||||
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)
|
||||
|
||||
return airline#extensions#tabline#formatters#default#wrap_name(a:bufnr, _)
|
||||
endfunction
|
||||
|
||||
function! airline#extensions#tabline#formatters#default#wrap_name(bufnr, buffer_name)
|
||||
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
|
||||
endif
|
||||
return _
|
||||
endfunction
|
||||
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
|
||||
|
||||
@@ -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,307 +13,617 @@ let s:separators = {}
|
||||
let s:accents = {}
|
||||
let s:hl_groups = {}
|
||||
|
||||
function! s:gui2cui(rgb, fallback) abort
|
||||
if a:rgb == ''
|
||||
return a:fallback
|
||||
elseif match(a:rgb, '^\%(NONE\|[fb]g\)$') > -1
|
||||
return a:rgb
|
||||
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
|
||||
if index(a:list, a:name) == -1
|
||||
call add(a:list, a:name)
|
||||
return 1
|
||||
else
|
||||
if &vbs
|
||||
echomsg printf("airline: group: %s already done, skipping", a:name)
|
||||
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
|
||||
return a:rgb
|
||||
endif
|
||||
return 0
|
||||
endif
|
||||
endfu
|
||||
|
||||
function! s:get_syn(group, what, mode) abort
|
||||
let color = ''
|
||||
if hlexists(a:group)
|
||||
let color = synIDattr(synIDtrans(hlID(a:group)), a:what, a:mode)
|
||||
endif
|
||||
if empty(color) || color == -1
|
||||
" should always exist
|
||||
let color = synIDattr(synIDtrans(hlID('Normal')), a:what, a:mode)
|
||||
" however, just in case
|
||||
if empty(color) || color == -1
|
||||
let color = 'NONE'
|
||||
endif
|
||||
endif
|
||||
return color
|
||||
endfunction
|
||||
|
||||
function! s:get_array(guifg, guibg, ctermfg, ctermbg, opts) abort
|
||||
return [ a:guifg, a:guibg, a:ctermfg, a:ctermbg, empty(a:opts) ? '' : join(a:opts, ',') ]
|
||||
endfunction
|
||||
|
||||
function! airline#highlighter#reset_hlcache() abort
|
||||
let s:hl_groups = {}
|
||||
endfunction
|
||||
|
||||
function! airline#highlighter#get_highlight(group, ...) abort
|
||||
" 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')
|
||||
if get(g:, 'airline_highlighting_cache', 0) && has_key(s:hl_groups, a:group)
|
||||
let res = s:hl_groups[a:group]
|
||||
return reverse ? [ res[1], res[0], res[3], res[2], res[4] ] : res
|
||||
else
|
||||
let ctermfg = s:get_syn(a:group, 'fg', 'cterm')
|
||||
let ctermbg = s:get_syn(a:group, 'bg', 'cterm')
|
||||
let guifg = s:get_syn(a:group, 'fg', 'gui')
|
||||
let guibg = s:get_syn(a:group, 'bg', 'gui')
|
||||
let bold = synIDattr(synIDtrans(hlID(a:group)), 'bold')
|
||||
if reverse
|
||||
let res = s:get_array(guibg, guifg, ctermbg, ctermfg, bold ? ['bold'] : a:000)
|
||||
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 " {{{2
|
||||
if index(a:list, a:name) == -1
|
||||
call add(a:list, a:name)
|
||||
return 1
|
||||
else
|
||||
let res = s:get_array(guifg, guibg, ctermfg, ctermbg, bold ? ['bold'] : a:000)
|
||||
if &vbs
|
||||
echomsg printf("airline: group: %s already done, skipping", a:name)
|
||||
endif
|
||||
return 0
|
||||
endif
|
||||
endif
|
||||
let s:hl_groups[a:group] = res
|
||||
return res
|
||||
endfunction
|
||||
|
||||
function! airline#highlighter#get_highlight2(fg, bg, ...) abort
|
||||
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
|
||||
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
|
||||
if pumvisible()
|
||||
return
|
||||
endif
|
||||
let colors = a:colors
|
||||
if s:is_win32term
|
||||
let colors[2] = s:gui2cui(get(colors, 0, ''), get(colors, 2, ''))
|
||||
let colors[3] = s:gui2cui(get(colors, 1, ''), get(colors, 3, ''))
|
||||
endif
|
||||
let old_hi = airline#highlighter#get_highlight(a:group)
|
||||
if len(colors) == 4
|
||||
call add(colors, '')
|
||||
endif
|
||||
let new_hi = [colors[0], colors[1], printf('%s', colors[2]), printf('%s', colors[3]), colors[4]]
|
||||
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))
|
||||
exe cmd
|
||||
if has_key(s:hl_groups, a:group)
|
||||
let s:hl_groups[a:group] = colors
|
||||
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)
|
||||
endif
|
||||
endif
|
||||
endfunction
|
||||
if empty(color) || color == -1
|
||||
" should always exist
|
||||
let color = synIDattr(synIDtrans(hlID('Normal')), a:what, a:mode)
|
||||
" however, just in case
|
||||
if empty(color) || color == -1
|
||||
let color = 'NONE'
|
||||
endif
|
||||
endif
|
||||
return color
|
||||
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 " {{{2
|
||||
let s:hl_groups = {}
|
||||
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')
|
||||
if get(g:, 'airline_highlighting_cache', 0) && has_key(s:hl_groups, a:group)
|
||||
let res = s:hl_groups[a:group]
|
||||
return reverse ? [ res[1], res[0], res[3], res[2], res[4] ] : res
|
||||
else
|
||||
let ctermfg = s:get_syn(a:group, 'fg', 'cterm')
|
||||
let ctermbg = s:get_syn(a:group, 'bg', 'cterm')
|
||||
let guifg = s:get_syn(a:group, 'fg', 'gui')
|
||||
let guibg = s:get_syn(a:group, 'bg', 'gui')
|
||||
let bold = synIDattr(synIDtrans(hlID(a:group)), 'bold')
|
||||
if reverse
|
||||
let res = s:get_array(guibg, guifg, ctermbg, ctermfg, bold ? ['bold'] : a:000)
|
||||
else
|
||||
let res = s:get_array(guifg, guibg, ctermfg, ctermbg, bold ? ['bold'] : a:000)
|
||||
endif
|
||||
endif
|
||||
let s:hl_groups[a:group] = res
|
||||
return res
|
||||
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
|
||||
if !hlexists(a:group)
|
||||
return 0
|
||||
elseif empty(synIDattr(synIDtrans(hlID(a:group)), 'fg'))
|
||||
return 0
|
||||
endif
|
||||
return 1
|
||||
endfunction
|
||||
function! airline#highlighter#exec(group, colors) abort " {{{2
|
||||
if pumvisible()
|
||||
return
|
||||
endif
|
||||
let colors = a:colors
|
||||
if s:is_win32term
|
||||
let colors[2] = s:gui2cui(get(colors, 0, ''), get(colors, 2, ''))
|
||||
let colors[3] = s:gui2cui(get(colors, 1, ''), get(colors, 3, ''))
|
||||
endif
|
||||
let old_hi = airline#highlighter#get_highlight(a:group)
|
||||
if len(colors) == 4
|
||||
call add(colors, '')
|
||||
endif
|
||||
let new_hi = [colors[0], colors[1], printf('%s', colors[2]), printf('%s', colors[3]), colors[4]]
|
||||
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 " {{{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
|
||||
|
||||
function! s:CheckDefined(colors) abort
|
||||
" 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")
|
||||
let g:airline#highlighter#normal_fg_hi = synIDattr(synIDtrans(hlID('Normal')), 'fg', 'cterm')
|
||||
endif
|
||||
if empty(g:airline#highlighter#normal_fg_hi) || g:airline#highlighter#normal_fg_hi < 0
|
||||
return a:colors
|
||||
endif
|
||||
|
||||
for val in a:colors
|
||||
if !empty(val) && val !=# 'NONE'
|
||||
" 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")
|
||||
let g:airline#highlighter#normal_fg_hi = synIDattr(synIDtrans(hlID('Normal')), 'fg', 'cterm')
|
||||
endif
|
||||
if empty(g:airline#highlighter#normal_fg_hi) || g:airline#highlighter#normal_fg_hi < 0
|
||||
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 = g:airline#highlighter#normal_fg_hi
|
||||
let bg = synIDattr(synIDtrans(hlID('Normal')), 'bg', 'cterm')
|
||||
if bg < 0
|
||||
" in case there is no background color defined for Normal
|
||||
let bg = a:colors[3]
|
||||
endif
|
||||
return a:colors[0:1] + [fg, bg] + [a:colors[4]]
|
||||
endfunction
|
||||
|
||||
function! s:GetHiCmd(list) abort
|
||||
" a:list needs to have 5 items!
|
||||
let res = ''
|
||||
let i = -1
|
||||
while i < 4
|
||||
let i += 1
|
||||
let item = get(a:list, i, '')
|
||||
if item is ''
|
||||
continue
|
||||
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 = g:airline#highlighter#normal_fg_hi
|
||||
let bg = synIDattr(synIDtrans(hlID('Normal')), 'bg', 'cterm')
|
||||
if bg < 0
|
||||
" in case there is no background color defined for Normal
|
||||
let bg = a:colors[3]
|
||||
endif
|
||||
if i == 0
|
||||
let res .= ' guifg='.item
|
||||
elseif i == 1
|
||||
let res .= ' guibg='.item
|
||||
elseif i == 2
|
||||
let res .= ' ctermfg='.item
|
||||
elseif i == 3
|
||||
let res .= ' ctermbg='.item
|
||||
elseif i == 4
|
||||
let res .= printf(' gui=%s cterm=%s term=%s', item, item, item)
|
||||
endif
|
||||
endwhile
|
||||
return res
|
||||
endfunction
|
||||
|
||||
function! s:exec_separator(dict, from, to, inverse, suffix) abort
|
||||
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)
|
||||
if a:inverse
|
||||
let colors = [ l:from[1], l:to[1], l:from[3], l:to[3] ]
|
||||
else
|
||||
let colors = [ l:to[1], l:from[1], l:to[3], l:from[3] ]
|
||||
endif
|
||||
let a:dict[group] = colors
|
||||
call airline#highlighter#exec(group, colors)
|
||||
endfunction
|
||||
|
||||
function! airline#highlighter#load_theme() abort
|
||||
if pumvisible()
|
||||
return
|
||||
endif
|
||||
for winnr in filter(range(1, winnr('$')), 'v:val != winnr()')
|
||||
call airline#highlighter#highlight_modified_inactive(winbufnr(winnr))
|
||||
endfor
|
||||
call airline#highlighter#highlight(['inactive'])
|
||||
if getbufvar( bufnr('%'), '&modified' )
|
||||
call airline#highlighter#highlight(['normal', 'modified'])
|
||||
else
|
||||
call airline#highlighter#highlight(['normal'])
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! airline#highlighter#add_separator(from, to, inverse) abort
|
||||
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
|
||||
let s:accents[a:accent] = 1
|
||||
endfunction
|
||||
|
||||
function! airline#highlighter#highlight_modified_inactive(bufnr) abort
|
||||
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 : []
|
||||
else
|
||||
let colors = exists('g:airline#themes#{g:airline_theme}#palette.inactive.airline_c')
|
||||
\ ? g:airline#themes#{g:airline_theme}#palette.inactive.airline_c : []
|
||||
endif
|
||||
|
||||
if !empty(colors)
|
||||
call airline#highlighter#exec('airline_c'.(a:bufnr).'_inactive', colors)
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! airline#highlighter#highlight(modes, ...) abort
|
||||
let bufnr = a:0 ? a:1 : ''
|
||||
let p = g:airline#themes#{g:airline_theme}#palette
|
||||
|
||||
" draw the base mode, followed by any overrides
|
||||
let mapped = map(a:modes, 'v:val == a:modes[0] ? v:val : a:modes[0]."_".v:val')
|
||||
let suffix = a:modes[0] == 'inactive' ? '_inactive' : ''
|
||||
let airline_grouplist = []
|
||||
let buffers_in_tabpage = sort(tabpagebuflist())
|
||||
if exists("*uniq")
|
||||
let buffers_in_tabpage = uniq(buffers_in_tabpage)
|
||||
endif
|
||||
" 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]')
|
||||
let dict = g:airline#themes#{g:airline_theme}#palette[mode]
|
||||
for kvp in items(dict)
|
||||
let mode_colors = kvp[1]
|
||||
let name = kvp[0]
|
||||
if name is# 'airline_c' && !empty(bufnr) && suffix is# '_inactive'
|
||||
let 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\+'
|
||||
let bnr = matchstr(name, 'airline_c\zs\d\+') + 0
|
||||
if bnr > 0 && index(buffers_in_tabpage, bnr) == -1
|
||||
continue
|
||||
endif
|
||||
elseif (name =~# '_to_') || (name[0:10] is# '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)
|
||||
call airline#highlighter#exec(name.suffix, mode_colors)
|
||||
endif
|
||||
|
||||
if !has_key(p, 'accents')
|
||||
" work around a broken installation
|
||||
" 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
|
||||
let colors = copy(mode_colors)
|
||||
if p.accents[accent][0] != ''
|
||||
let colors[0] = p.accents[accent][0]
|
||||
endif
|
||||
if p.accents[accent][2] != ''
|
||||
let colors[2] = p.accents[accent][2]
|
||||
endif
|
||||
if len(colors) >= 5
|
||||
let colors[4] = get(p.accents[accent], 4, '')
|
||||
else
|
||||
call add(colors, get(p.accents[accent], 4, ''))
|
||||
endif
|
||||
if s:group_not_done(airline_grouplist, name.suffix.'_'.accent)
|
||||
call airline#highlighter#exec(name.suffix.'_'.accent, colors)
|
||||
endif
|
||||
endfor
|
||||
endfor
|
||||
|
||||
if empty(s:separators)
|
||||
" nothing to be done
|
||||
return a:colors[0:1] + [fg, bg] + [a:colors[4]]
|
||||
endfunction
|
||||
function! s:GetHiCmd(list) abort " {{{2
|
||||
" a:list needs to have 5 items!
|
||||
let res = ''
|
||||
let i = -1
|
||||
while i < 4
|
||||
let i += 1
|
||||
let item = get(a:list, i, '')
|
||||
if item is ''
|
||||
continue
|
||||
endif
|
||||
" TODO: optimize this
|
||||
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...
|
||||
call <sid>exec_separator(dict, sep[1][0], sep[1][1], sep[1][2], suffix)
|
||||
endfor
|
||||
if i == 0
|
||||
let res .= ' guifg='.item
|
||||
elseif i == 1
|
||||
let res .= ' guibg='.item
|
||||
elseif i == 2
|
||||
let res .= ' ctermfg='.item
|
||||
elseif i == 3
|
||||
let res .= ' ctermbg='.item
|
||||
elseif i == 4
|
||||
let res .= printf(' gui=%s cterm=%s term=%s', item, item, item)
|
||||
endif
|
||||
endwhile
|
||||
return res
|
||||
endfunction
|
||||
function! s:exec_separator(dict, from, to, inverse, suffix) abort " {{{2
|
||||
if pumvisible()
|
||||
return
|
||||
endif
|
||||
endfor
|
||||
endfunction
|
||||
let group = a:from.'_to_'.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 = [ from[1], to[1], from[3], to[3] ]
|
||||
else
|
||||
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 " {{{2
|
||||
if pumvisible()
|
||||
return
|
||||
endif
|
||||
for winnr in filter(range(1, winnr('$')), 'v:val != winnr()')
|
||||
call airline#highlighter#highlight_modified_inactive(winbufnr(winnr))
|
||||
endfor
|
||||
call airline#highlighter#highlight(['inactive'])
|
||||
if getbufvar( bufnr('%'), '&modified' )
|
||||
call airline#highlighter#highlight(['normal', 'modified'])
|
||||
else
|
||||
call airline#highlighter#highlight(['normal'])
|
||||
endif
|
||||
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
|
||||
let s:accents[a:accent] = 1
|
||||
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 : []
|
||||
else
|
||||
let colors = exists('g:airline#themes#{g:airline_theme}#palette.inactive.airline_c')
|
||||
\ ? g:airline#themes#{g:airline_theme}#palette.inactive.airline_c : []
|
||||
endif
|
||||
|
||||
if !empty(colors)
|
||||
call airline#highlighter#exec('airline_c'.(a:bufnr).'_inactive', colors)
|
||||
endif
|
||||
endfunction
|
||||
function! airline#highlighter#highlight(modes, ...) abort " {{{2
|
||||
let bufnr = a:0 ? a:1 : ''
|
||||
let p = g:airline#themes#{g:airline_theme}#palette
|
||||
|
||||
" draw the base mode, followed by any overrides
|
||||
let mapped = map(a:modes, 'v:val == a:modes[0] ? v:val : a:modes[0]."_".v:val')
|
||||
let suffix = a:modes[0] == 'inactive' ? '_inactive' : ''
|
||||
let airline_grouplist = []
|
||||
let buffers_in_tabpage = sort(tabpagebuflist())
|
||||
if exists("*uniq")
|
||||
let buffers_in_tabpage = uniq(buffers_in_tabpage)
|
||||
endif
|
||||
" 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]')
|
||||
let dict = g:airline#themes#{g:airline_theme}#palette[mode]
|
||||
for kvp in items(dict)
|
||||
let mode_colors = kvp[1]
|
||||
let name = kvp[0]
|
||||
if name is# 'airline_c' && !empty(bufnr) && suffix is# '_inactive'
|
||||
let 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\+'
|
||||
let bnr = matchstr(name, 'airline_c\zs\d\+') + 0
|
||||
if bnr > 0 && index(buffers_in_tabpage, bnr) == -1
|
||||
continue
|
||||
endif
|
||||
elseif (name =~# '_to_') || (name[0:10] is# '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)
|
||||
call airline#highlighter#exec(name.suffix, mode_colors)
|
||||
endif
|
||||
|
||||
if !has_key(p, 'accents')
|
||||
" work around a broken installation
|
||||
" 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
|
||||
let colors = copy(mode_colors)
|
||||
if p.accents[accent][0] != ''
|
||||
let colors[0] = p.accents[accent][0]
|
||||
endif
|
||||
if p.accents[accent][2] != ''
|
||||
let colors[2] = p.accents[accent][2]
|
||||
endif
|
||||
if len(colors) >= 5
|
||||
let colors[4] = get(p.accents[accent], 4, '')
|
||||
else
|
||||
call add(colors, get(p.accents[accent], 4, ''))
|
||||
endif
|
||||
if s:group_not_done(airline_grouplist, name.suffix.'_'.accent)
|
||||
call airline#highlighter#exec(name.suffix.'_'.accent, colors)
|
||||
endif
|
||||
endfor
|
||||
endfor
|
||||
|
||||
if empty(s:separators)
|
||||
" nothing to be done
|
||||
continue
|
||||
endif
|
||||
" TODO: optimize this
|
||||
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...
|
||||
call <sid>exec_separator(dict, sep[1][0], sep[1][1], sep[1][2], suffix)
|
||||
endfor
|
||||
endif
|
||||
endfor
|
||||
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
|
||||
|
||||
@@ -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 = []
|
||||
|
||||
@@ -1,78 +1,151 @@
|
||||
" 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, ...)
|
||||
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 , '') ] ,
|
||||
\ 'airline_c': [ a:sect3[0] , a:sect3[1] , a:sect3[2] , a:sect3[3] , get(a:sect3 , 4 , '') ] ,
|
||||
\ }
|
||||
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 , '') ] ,
|
||||
\ 'airline_c': [ a:sect3[0] , a:sect3[1] , a:sect3[2] , a:sect3[3] , get(a:sect3 , 4 , '') ] ,
|
||||
\ }
|
||||
|
||||
if a:0 > 0
|
||||
call extend(palette, {
|
||||
\ 'airline_x': [ a:1[0] , a:1[1] , a:1[2] , a:1[3] , get(a:1 , 4 , '' ) ] ,
|
||||
\ 'airline_y': [ a:2[0] , a:2[1] , a:2[2] , a:2[3] , get(a:2 , 4 , '' ) ] ,
|
||||
\ 'airline_z': [ a:3[0] , a:3[1] , a:3[2] , a:3[3] , get(a:3 , 4 , '' ) ] ,
|
||||
\ })
|
||||
else
|
||||
call extend(palette, {
|
||||
\ 'airline_x': [ a:sect3[0] , a:sect3[1] , a:sect3[2] , a:sect3[3] , '' ] ,
|
||||
\ 'airline_y': [ a:sect2[0] , a:sect2[1] , a:sect2[2] , a:sect2[3] , '' ] ,
|
||||
\ 'airline_z': [ a:sect1[0] , a:sect1[1] , a:sect1[2] , a:sect1[3] , '' ] ,
|
||||
\ })
|
||||
endif
|
||||
|
||||
return palette
|
||||
endfunction
|
||||
|
||||
function! airline#themes#get_highlight(group, ...)
|
||||
return call('airline#highlighter#get_highlight', [a:group] + a:000)
|
||||
endfunction
|
||||
|
||||
function! airline#themes#get_highlight2(fg, bg, ...)
|
||||
return call('airline#highlighter#get_highlight2', [a:fg, a:bg] + a:000)
|
||||
endfunction
|
||||
|
||||
function! airline#themes#patch(palette)
|
||||
for mode in keys(a:palette)
|
||||
if mode == 'accents'
|
||||
continue
|
||||
if a:0 > 0
|
||||
call extend(palette, {
|
||||
\ 'airline_x': [ a:1[0] , a:1[1] , a:1[2] , a:1[3] , get(a:1 , 4 , '' ) ] ,
|
||||
\ 'airline_y': [ a:2[0] , a:2[1] , a:2[2] , a:2[3] , get(a:2 , 4 , '' ) ] ,
|
||||
\ 'airline_z': [ a:3[0] , a:3[1] , a:3[2] , a:3[3] , get(a:3 , 4 , '' ) ] ,
|
||||
\ })
|
||||
else
|
||||
call extend(palette, {
|
||||
\ 'airline_x': [ a:sect3[0] , a:sect3[1] , a:sect3[2] , a:sect3[3] , '' ] ,
|
||||
\ 'airline_y': [ a:sect2[0] , a:sect2[1] , a:sect2[2] , a:sect2[3] , '' ] ,
|
||||
\ 'airline_z': [ a:sect1[0] , a:sect1[1] , a:sect1[2] , a:sect1[3] , '' ] ,
|
||||
\ })
|
||||
endif
|
||||
if !has_key(a:palette[mode], 'airline_warning')
|
||||
let a:palette[mode]['airline_warning'] = [ '#000000', '#df5f00', 232, 166 ]
|
||||
endif
|
||||
if !has_key(a:palette[mode], 'airline_error')
|
||||
let a:palette[mode]['airline_error'] = [ '#000000', '#990000', 232, 160 ]
|
||||
endif
|
||||
if !has_key(a:palette[mode], 'airline_term')
|
||||
let a:palette[mode]['airline_term'] = [ '#9cffd3', '#202020', 85, 232]
|
||||
endif
|
||||
endfor
|
||||
|
||||
let a:palette.accents = get(a:palette, 'accents', {})
|
||||
let a:palette.accents.none = [ '', '', '', '', '' ]
|
||||
let a:palette.accents.bold = [ '', '', '', '', 'bold' ]
|
||||
let a:palette.accents.italic = [ '', '', '', '', 'italic' ]
|
||||
return palette
|
||||
endfunction
|
||||
|
||||
if !has_key(a:palette.accents, 'red')
|
||||
let a:palette.accents.red = [ '#ff0000' , '' , 160 , '' ]
|
||||
endif
|
||||
if !has_key(a:palette.accents, 'green')
|
||||
let a:palette.accents.green = [ '#008700' , '' , 22 , '' ]
|
||||
endif
|
||||
if !has_key(a:palette.accents, 'blue')
|
||||
let a:palette.accents.blue = [ '#005fff' , '' , 27 , '' ]
|
||||
endif
|
||||
if !has_key(a:palette.accents, 'yellow')
|
||||
let a:palette.accents.yellow = [ '#dfff00' , '' , 190 , '' ]
|
||||
endif
|
||||
if !has_key(a:palette.accents, 'orange')
|
||||
let a:palette.accents.orange = [ '#df5f00' , '' , 166 , '' ]
|
||||
endif
|
||||
if !has_key(a:palette.accents, 'purple')
|
||||
let a:palette.accents.purple = [ '#af00df' , '' , 128 , '' ]
|
||||
endif
|
||||
endfunction
|
||||
function! airline#themes#get_highlight(group, ...)
|
||||
return call('airline#highlighter#get_highlight', [a:group] + a:000)
|
||||
endfunction
|
||||
|
||||
function! airline#themes#get_highlight2(fg, bg, ...)
|
||||
return call('airline#highlighter#get_highlight2', [a:fg, a:bg] + a:000)
|
||||
endfunction
|
||||
|
||||
function! airline#themes#patch(palette)
|
||||
for mode in keys(a:palette)
|
||||
if mode == 'accents'
|
||||
continue
|
||||
endif
|
||||
if !has_key(a:palette[mode], 'airline_warning')
|
||||
let a:palette[mode]['airline_warning'] = [ '#000000', '#df5f00', 232, 166 ]
|
||||
endif
|
||||
if !has_key(a:palette[mode], 'airline_error')
|
||||
let a:palette[mode]['airline_error'] = [ '#000000', '#990000', 232, 160 ]
|
||||
endif
|
||||
if !has_key(a:palette[mode], 'airline_term')
|
||||
let a:palette[mode]['airline_term'] = [ '#9cffd3', '#202020', 85, 232]
|
||||
endif
|
||||
endfor
|
||||
|
||||
let a:palette.accents = get(a:palette, 'accents', {})
|
||||
let a:palette.accents.none = [ '', '', '', '', '' ]
|
||||
let a:palette.accents.bold = [ '', '', '', '', 'bold' ]
|
||||
let a:palette.accents.italic = [ '', '', '', '', 'italic' ]
|
||||
|
||||
if !has_key(a:palette.accents, 'red')
|
||||
let a:palette.accents.red = [ '#ff0000' , '' , 160 , '' ]
|
||||
endif
|
||||
if !has_key(a:palette.accents, 'green')
|
||||
let a:palette.accents.green = [ '#008700' , '' , 22 , '' ]
|
||||
endif
|
||||
if !has_key(a:palette.accents, 'blue')
|
||||
let a:palette.accents.blue = [ '#005fff' , '' , 27 , '' ]
|
||||
endif
|
||||
if !has_key(a:palette.accents, 'yellow')
|
||||
let a:palette.accents.yellow = [ '#dfff00' , '' , 190 , '' ]
|
||||
endif
|
||||
if !has_key(a:palette.accents, 'orange')
|
||||
let a:palette.accents.orange = [ '#df5f00' , '' , 166 , '' ]
|
||||
endif
|
||||
if !has_key(a:palette.accents, 'purple')
|
||||
let a:palette.accents.purple = [ '#af00df' , '' , 128 , '' ]
|
||||
endif
|
||||
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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user