2020-01-06 02:22:49 +00:00
|
|
|
" MIT License. Copyright (c) 2013-2020 Bailey Ling et al.
|
2013-08-28 13:51:54 +00:00
|
|
|
" vim: et ts=2 sts=2 sw=2
|
|
|
|
|
2016-09-24 00:16:30 +00:00
|
|
|
scriptencoding utf-8
|
|
|
|
|
2015-02-28 02:12:45 +00:00
|
|
|
let s:taboo = get(g:, 'airline#extensions#taboo#enabled', 1) && get(g:, 'loaded_taboo', 0)
|
|
|
|
if s:taboo
|
|
|
|
let g:taboo_tabline = 0
|
|
|
|
endif
|
|
|
|
|
2016-01-12 12:47:44 +00:00
|
|
|
let s:ctrlspace = get(g:, 'CtrlSpaceLoaded', 0)
|
2019-06-28 12:21:50 +00:00
|
|
|
let s:tabws = get(g:, 'tabws_loaded', 0)
|
2015-02-28 02:12:45 +00:00
|
|
|
|
2013-08-28 13:51:54 +00:00
|
|
|
function! airline#extensions#tabline#init(ext)
|
2016-02-05 21:19:48 +00:00
|
|
|
if has('gui_running')
|
2013-09-03 18:48:08 +00:00
|
|
|
set guioptions-=e
|
|
|
|
endif
|
2013-09-04 19:53:04 +00:00
|
|
|
|
2013-10-13 22:01:38 +00:00
|
|
|
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
|
2013-09-01 23:39:06 +00:00
|
|
|
|
2013-10-13 22:01:38 +00:00
|
|
|
function! s:toggle_off()
|
2015-02-18 23:58:37 +00:00
|
|
|
call airline#extensions#tabline#autoshow#off()
|
2015-02-19 02:24:05 +00:00
|
|
|
call airline#extensions#tabline#tabs#off()
|
2015-02-19 02:37:13 +00:00
|
|
|
call airline#extensions#tabline#buffers#off()
|
2017-10-16 08:33:40 +00:00
|
|
|
if s:ctrlspace
|
|
|
|
call airline#extensions#tabline#ctrlspace#off()
|
|
|
|
endif
|
2019-06-28 12:21:50 +00:00
|
|
|
if s:tabws
|
|
|
|
call airline#extensions#tabline#tabws#off()
|
|
|
|
endif
|
2013-10-13 22:01:38 +00:00
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! s:toggle_on()
|
2019-02-03 16:30:55 +00:00
|
|
|
if get(g:, 'airline_statusline_ontop', 0)
|
|
|
|
call airline#extensions#tabline#enable()
|
|
|
|
let &tabline='%!airline#statusline('.winnr().')'
|
|
|
|
return
|
|
|
|
endif
|
2015-02-18 23:58:37 +00:00
|
|
|
call airline#extensions#tabline#autoshow#on()
|
2015-02-19 02:24:05 +00:00
|
|
|
call airline#extensions#tabline#tabs#on()
|
2015-02-19 02:37:13 +00:00
|
|
|
call airline#extensions#tabline#buffers#on()
|
2017-10-16 08:33:40 +00:00
|
|
|
if s:ctrlspace
|
|
|
|
call airline#extensions#tabline#ctrlspace#on()
|
|
|
|
endif
|
2019-06-28 12:21:50 +00:00
|
|
|
if s:tabws
|
|
|
|
call airline#extensions#tabline#tabws#on()
|
|
|
|
endif
|
2015-02-19 02:24:05 +00:00
|
|
|
|
|
|
|
set tabline=%!airline#extensions#tabline#get()
|
2013-09-01 23:39:06 +00:00
|
|
|
endfunction
|
|
|
|
|
2019-12-13 07:44:15 +00:00
|
|
|
function! s:update_tabline(forceit)
|
2016-02-23 19:23:29 +00:00
|
|
|
if get(g:, 'airline#extensions#tabline#disable_refresh', 0)
|
|
|
|
return
|
|
|
|
endif
|
2019-12-13 07:44:15 +00:00
|
|
|
" loading a session file
|
|
|
|
" On SessionLoadPost, g:SessionLoad variable is still set :/
|
|
|
|
if !a:forceit && get(g:, 'SessionLoad', 0)
|
|
|
|
return
|
|
|
|
endif
|
2016-01-25 20:29:40 +00:00
|
|
|
let match = expand('<afile>')
|
2016-01-21 09:00:06 +00:00
|
|
|
if pumvisible()
|
|
|
|
return
|
|
|
|
elseif !get(g:, 'airline#extensions#tabline#enabled', 0)
|
|
|
|
return
|
2016-01-25 20:29:40 +00:00
|
|
|
" return, if buffer matches ignore pattern or is directory (netrw)
|
2019-12-12 08:58:21 +00:00
|
|
|
elseif empty(match) || airline#util#ignore_buf(match) || isdirectory(match)
|
2016-01-25 20:29:40 +00:00
|
|
|
return
|
2016-01-21 09:00:06 +00:00
|
|
|
endif
|
2018-09-25 14:03:30 +00:00
|
|
|
call airline#util#doautocmd('BufMRUChange')
|
2019-02-03 16:30:55 +00:00
|
|
|
call airline#extensions#tabline#redraw()
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! airline#extensions#tabline#redraw()
|
2017-10-19 09:36:35 +00:00
|
|
|
" sometimes, the tabline is not correctly updated see #1580
|
|
|
|
" so force redraw here
|
2019-01-09 07:26:07 +00:00
|
|
|
if exists(":redrawtabline") == 2
|
2019-01-09 06:42:32 +00:00
|
|
|
redrawtabline
|
|
|
|
else
|
2019-02-03 16:30:55 +00:00
|
|
|
" 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
|
2019-01-09 06:42:32 +00:00
|
|
|
endif
|
2016-01-21 09:00:06 +00:00
|
|
|
endfunction
|
|
|
|
|
2013-09-01 23:39:06 +00:00
|
|
|
function! airline#extensions#tabline#load_theme(palette)
|
2016-01-28 16:27:17 +00:00
|
|
|
if pumvisible()
|
|
|
|
return
|
|
|
|
endif
|
2013-09-04 17:16:23 +00:00
|
|
|
let colors = get(a:palette, 'tabline', {})
|
2018-01-04 17:56:24 +00:00
|
|
|
let tablabel = get(colors, 'airline_tablabel', a:palette.normal.airline_b)
|
2016-01-12 12:47:44 +00:00
|
|
|
" Theme for tabs on the left
|
2020-04-30 18:13:55 +00:00
|
|
|
let tab = get(colors, 'airline_tab', a:palette.inactive.airline_c)
|
2018-01-04 17:29:51 +00:00
|
|
|
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)
|
2014-09-08 13:43:15 +00:00
|
|
|
if has_key(a:palette, 'normal_modified') && has_key(a:palette.normal_modified, 'airline_c')
|
2018-01-04 17:29:51 +00:00
|
|
|
let tabmodu = get(colors, 'airline_tabmod_unsel', a:palette.normal_modified.airline_c)
|
2014-09-08 13:43:15 +00:00
|
|
|
else
|
|
|
|
"Fall back to normal airline_c if modified airline_c isn't present
|
2018-01-04 17:29:51 +00:00
|
|
|
let tabmodu = get(colors, 'airline_tabmod_unsel', a:palette.normal.airline_c)
|
2014-09-08 13:43:15 +00:00
|
|
|
endif
|
2018-01-04 17:56:24 +00:00
|
|
|
call airline#highlighter#exec('airline_tablabel', tablabel)
|
2018-01-04 17:29:51 +00:00
|
|
|
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)
|
2016-01-12 12:47:44 +00:00
|
|
|
|
|
|
|
" Theme for tabs on the right
|
2019-04-17 07:04:56 +00:00
|
|
|
" label on the right
|
|
|
|
let tablabel_r = get(colors, 'airline_tablabel', a:palette.normal.airline_b)
|
2018-01-04 17:29:51 +00:00
|
|
|
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)
|
2016-01-12 12:47:44 +00:00
|
|
|
if has_key(a:palette, 'normal_modified') && has_key(a:palette.normal_modified, 'airline_c')
|
2018-01-04 17:29:51 +00:00
|
|
|
let tabmodu_right = get(colors, 'airline_tabmod_unsel_right', a:palette.normal_modified.airline_c)
|
2016-01-12 12:47:44 +00:00
|
|
|
else
|
|
|
|
"Fall back to normal airline_c if modified airline_c isn't present
|
2018-01-04 17:29:51 +00:00
|
|
|
let tabmodu_right = get(colors, 'airline_tabmod_unsel_right', a:palette.normal.airline_c)
|
2016-01-12 12:47:44 +00:00
|
|
|
endif
|
2019-04-17 07:04:56 +00:00
|
|
|
call airline#highlighter#exec('airline_tablabel_right', tablabel_r)
|
2018-01-04 17:29:51 +00:00
|
|
|
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)
|
2013-08-28 13:51:54 +00:00
|
|
|
endfunction
|
|
|
|
|
2015-02-19 02:37:13 +00:00
|
|
|
let s:current_tabcnt = -1
|
2018-01-04 13:09:49 +00:00
|
|
|
|
2013-08-28 13:51:54 +00:00
|
|
|
function! airline#extensions#tabline#get()
|
2018-01-04 13:09:49 +00:00
|
|
|
let show_buffers = get(g:, 'airline#extensions#tabline#show_buffers', 1)
|
|
|
|
let show_tabs = get(g:, 'airline#extensions#tabline#show_tabs', 1)
|
|
|
|
|
2014-08-13 00:26:52 +00:00
|
|
|
let curtabcnt = tabpagenr('$')
|
|
|
|
if curtabcnt != s:current_tabcnt
|
|
|
|
let s:current_tabcnt = curtabcnt
|
2015-02-19 02:37:13 +00:00
|
|
|
call airline#extensions#tabline#tabs#invalidate()
|
|
|
|
call airline#extensions#tabline#buffers#invalidate()
|
2016-01-12 12:47:44 +00:00
|
|
|
call airline#extensions#tabline#ctrlspace#invalidate()
|
2019-06-28 12:21:50 +00:00
|
|
|
call airline#extensions#tabline#tabws#invalidate()
|
2014-08-13 00:26:52 +00:00
|
|
|
endif
|
2015-02-19 02:24:05 +00:00
|
|
|
|
2016-01-21 09:00:06 +00:00
|
|
|
if !exists('#airline#BufAdd#*')
|
2019-12-13 07:44:15 +00:00
|
|
|
autocmd airline BufAdd * call <sid>update_tabline(0)
|
|
|
|
endif
|
2019-12-15 12:28:51 +00:00
|
|
|
if !exists('#airline#SessionLoadPost')
|
2019-12-13 07:44:15 +00:00
|
|
|
autocmd airline SessionLoadPost * call <sid>update_tabline(1)
|
2016-01-21 09:00:06 +00:00
|
|
|
endif
|
2017-06-27 12:44:49 +00:00
|
|
|
if s:ctrlspace
|
|
|
|
return airline#extensions#tabline#ctrlspace#get()
|
2019-06-28 12:21:50 +00:00
|
|
|
elseif s:tabws
|
|
|
|
return airline#extensions#tabline#tabws#get()
|
2018-01-04 13:09:49 +00:00
|
|
|
elseif show_buffers && curtabcnt == 1 || !show_tabs
|
2017-06-27 12:44:49 +00:00
|
|
|
return airline#extensions#tabline#buffers#get()
|
|
|
|
else
|
|
|
|
return airline#extensions#tabline#tabs#get()
|
|
|
|
endif
|
2013-08-28 13:51:54 +00:00
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! airline#extensions#tabline#title(n)
|
2015-02-28 02:12:45 +00:00
|
|
|
let title = ''
|
|
|
|
if s:taboo
|
|
|
|
let title = TabooTabTitle(a:n)
|
|
|
|
endif
|
|
|
|
|
2016-03-22 18:14:47 +00:00
|
|
|
if empty(title) && exists('*gettabvar')
|
|
|
|
let title = gettabvar(a:n, 'title')
|
|
|
|
endif
|
|
|
|
|
2020-08-21 05:07:47 +00:00
|
|
|
let formatter = get(g:, 'airline#extensions#tabline#tabtitle_formatter')
|
|
|
|
if empty(title) && formatter !=# '' && exists("*".formatter)
|
|
|
|
let title = call(formatter, [a:n])
|
|
|
|
endif
|
|
|
|
|
2015-02-28 02:12:45 +00:00
|
|
|
if empty(title)
|
|
|
|
let buflist = tabpagebuflist(a:n)
|
|
|
|
let winnr = tabpagewinnr(a:n)
|
2016-06-17 13:07:55 +00:00
|
|
|
let all_buffers = airline#extensions#tabline#buflist#list()
|
2020-06-21 20:24:36 +00:00
|
|
|
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)
|
2015-02-28 02:12:45 +00:00
|
|
|
endif
|
|
|
|
|
|
|
|
return title
|
2013-09-02 03:03:36 +00:00
|
|
|
endfunction
|
|
|
|
|
2016-07-02 14:24:47 +00:00
|
|
|
function! airline#extensions#tabline#get_buffer_name(nr, ...)
|
|
|
|
let buffers = a:0 ? a:1 : airline#extensions#tabline#buflist#list()
|
2018-01-04 13:09:49 +00:00
|
|
|
let formatter = get(g:, 'airline#extensions#tabline#formatter', 'default')
|
|
|
|
return airline#extensions#tabline#formatters#{formatter}#format(a:nr, buffers)
|
2013-09-21 18:13:19 +00:00
|
|
|
endfunction
|
|
|
|
|
2015-02-19 02:24:05 +00:00
|
|
|
function! airline#extensions#tabline#new_builder()
|
2014-11-04 19:48:00 +00:00
|
|
|
let builder_context = {
|
|
|
|
\ 'active' : 1,
|
2016-09-27 19:44:00 +00:00
|
|
|
\ 'tabline' : 1,
|
2014-11-04 19:48:00 +00:00
|
|
|
\ '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
|
|
|
|
|
2018-03-15 01:23:43 +00:00
|
|
|
return airline#extensions#tabline#builder#new(builder_context)
|
2014-11-04 19:48:00 +00:00
|
|
|
endfunction
|
2016-01-28 04:11:11 +00:00
|
|
|
|
|
|
|
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
|
2018-01-04 17:43:03 +00:00
|
|
|
|
2019-04-17 07:04:56 +00:00
|
|
|
function! airline#extensions#tabline#add_label(dict, type, right)
|
2018-01-04 17:43:03 +00:00
|
|
|
if get(g:, 'airline#extensions#tabline#show_tab_type', 1)
|
2019-04-17 07:04:56 +00:00
|
|
|
call a:dict.add_section_spaced('airline_tablabel'.
|
|
|
|
\ (a:right ? '_right' : ''),
|
2018-01-26 06:52:38 +00:00
|
|
|
\ get(g:, 'airline#extensions#tabline#'.a:type.'_label', a:type))
|
2018-01-04 17:43:03 +00:00
|
|
|
endif
|
|
|
|
endfunction
|
2019-03-08 13:05:38 +00:00
|
|
|
|
|
|
|
function! airline#extensions#tabline#add_tab_label(dict)
|
2020-03-30 06:27:20 +00:00
|
|
|
let show_tab_count = get(g:, 'airline#extensions#tabline#show_tab_count', 1)
|
2020-03-29 16:06:06 +00:00
|
|
|
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
|
2019-03-08 13:05:38 +00:00
|
|
|
call a:dict.add_section_spaced('airline_tabmod', printf('%s %d/%d', "tab", tabpagenr(), tabpagenr('$')))
|
|
|
|
endif
|
|
|
|
endfunction
|