2016-01-15 10:38:38 +08:00
|
|
|
" MIT License. Copyright (c) 2013-2016 Bailey Ling.
|
2013-08-28 21:51:54 +08:00
|
|
|
" vim: et ts=2 sts=2 sw=2
|
|
|
|
|
2016-09-24 08:16:30 +08:00
|
|
|
scriptencoding utf-8
|
|
|
|
|
2013-09-07 08:43:51 +08:00
|
|
|
let s:formatter = get(g:, 'airline#extensions#tabline#formatter', 'default')
|
2013-09-05 04:17:02 +08:00
|
|
|
let s:show_buffers = get(g:, 'airline#extensions#tabline#show_buffers', 1)
|
2014-12-27 05:48:06 +08:00
|
|
|
let s:show_tabs = get(g:, 'airline#extensions#tabline#show_tabs', 1)
|
2016-01-26 04:29:40 +08:00
|
|
|
let s:ignore_bufadd_pat = get(g:, 'airline#extensions#tabline#ignore_bufadd_pat', '\c\vgundo|undotree|vimfiler|tagbar|nerd_tree')
|
2016-01-28 12:11:11 +08:00
|
|
|
|
2015-02-28 10:12:45 +08: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 20:47:44 +08:00
|
|
|
let s:ctrlspace = get(g:, 'CtrlSpaceLoaded', 0)
|
2015-02-28 10:12:45 +08:00
|
|
|
|
2013-08-28 21:51:54 +08:00
|
|
|
function! airline#extensions#tabline#init(ext)
|
2016-02-06 05:19:48 +08:00
|
|
|
if has('gui_running')
|
2013-09-04 02:48:08 +08:00
|
|
|
set guioptions-=e
|
|
|
|
endif
|
2013-09-05 03:53:04 +08:00
|
|
|
|
2013-10-14 06:01:38 +08: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-02 07:39:06 +08:00
|
|
|
|
2013-10-14 06:01:38 +08:00
|
|
|
function! s:toggle_off()
|
2015-02-19 07:58:37 +08:00
|
|
|
call airline#extensions#tabline#autoshow#off()
|
2015-02-19 10:24:05 +08:00
|
|
|
call airline#extensions#tabline#tabs#off()
|
2015-02-19 10:37:13 +08:00
|
|
|
call airline#extensions#tabline#buffers#off()
|
2016-01-12 20:47:44 +08:00
|
|
|
call airline#extensions#tabline#ctrlspace#off()
|
2013-10-14 06:01:38 +08:00
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! s:toggle_on()
|
2015-02-19 07:58:37 +08:00
|
|
|
call airline#extensions#tabline#autoshow#on()
|
2015-02-19 10:24:05 +08:00
|
|
|
call airline#extensions#tabline#tabs#on()
|
2015-02-19 10:37:13 +08:00
|
|
|
call airline#extensions#tabline#buffers#on()
|
2016-01-12 20:47:44 +08:00
|
|
|
call airline#extensions#tabline#ctrlspace#on()
|
2015-02-19 10:24:05 +08:00
|
|
|
|
|
|
|
set tabline=%!airline#extensions#tabline#get()
|
2013-09-02 07:39:06 +08:00
|
|
|
endfunction
|
|
|
|
|
2016-01-21 17:00:06 +08:00
|
|
|
function! s:update_tabline()
|
2016-02-24 03:23:29 +08:00
|
|
|
if get(g:, 'airline#extensions#tabline#disable_refresh', 0)
|
|
|
|
return
|
|
|
|
endif
|
2016-01-26 04:29:40 +08:00
|
|
|
let match = expand('<afile>')
|
2016-01-21 17:00:06 +08:00
|
|
|
if pumvisible()
|
|
|
|
return
|
|
|
|
elseif !get(g:, 'airline#extensions#tabline#enabled', 0)
|
|
|
|
return
|
2016-01-26 04:29:40 +08:00
|
|
|
" return, if buffer matches ignore pattern or is directory (netrw)
|
2016-01-28 12:11:11 +08:00
|
|
|
elseif empty(match)
|
2016-01-26 04:29:40 +08:00
|
|
|
\ || match(match, s:ignore_bufadd_pat) > -1
|
|
|
|
\ || isdirectory(expand("<afile>"))
|
|
|
|
return
|
2016-01-21 17:00:06 +08:00
|
|
|
endif
|
2016-03-02 05:07:31 +08:00
|
|
|
doautocmd User BufMRUChange
|
2016-01-21 17:00:06 +08:00
|
|
|
endfunction
|
|
|
|
|
2013-09-02 07:39:06 +08:00
|
|
|
function! airline#extensions#tabline#load_theme(palette)
|
2016-01-29 00:27:17 +08:00
|
|
|
if pumvisible()
|
|
|
|
return
|
|
|
|
endif
|
2013-09-05 01:16:23 +08:00
|
|
|
let colors = get(a:palette, 'tabline', {})
|
2016-01-12 20:47:44 +08:00
|
|
|
" Theme for tabs on the left
|
2013-09-05 01:16:23 +08:00
|
|
|
let l:tab = get(colors, 'airline_tab', a:palette.normal.airline_b)
|
|
|
|
let l:tabsel = get(colors, 'airline_tabsel', a:palette.normal.airline_a)
|
|
|
|
let l:tabtype = get(colors, 'airline_tabtype', a:palette.visual.airline_a)
|
|
|
|
let l:tabfill = get(colors, 'airline_tabfill', a:palette.normal.airline_c)
|
|
|
|
let l:tabmod = get(colors, 'airline_tabmod', a:palette.insert.airline_a)
|
2016-01-12 20:47:44 +08:00
|
|
|
let l:tabhid = get(colors, 'airline_tabhid', a:palette.normal.airline_c)
|
2014-09-08 21:43:15 +08:00
|
|
|
if has_key(a:palette, 'normal_modified') && has_key(a:palette.normal_modified, 'airline_c')
|
|
|
|
let l: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 l:tabmodu = get(colors, 'airline_tabmod_unsel', a:palette.normal.airline_c)
|
|
|
|
endif
|
2013-09-04 23:54:48 +08:00
|
|
|
call airline#highlighter#exec('airline_tab', l:tab)
|
|
|
|
call airline#highlighter#exec('airline_tabsel', l:tabsel)
|
|
|
|
call airline#highlighter#exec('airline_tabtype', l:tabtype)
|
|
|
|
call airline#highlighter#exec('airline_tabfill', l:tabfill)
|
|
|
|
call airline#highlighter#exec('airline_tabmod', l:tabmod)
|
2014-09-05 03:38:12 +08:00
|
|
|
call airline#highlighter#exec('airline_tabmod_unsel', l:tabmodu)
|
2013-09-06 06:34:15 +08:00
|
|
|
call airline#highlighter#exec('airline_tabhid', l:tabhid)
|
2016-01-12 20:47:44 +08:00
|
|
|
|
|
|
|
" Theme for tabs on the right
|
|
|
|
let l:tabsel_right = get(colors, 'airline_tabsel_right', a:palette.normal.airline_a)
|
2016-02-12 00:22:09 +08:00
|
|
|
let l:tab_right = get(colors, 'airline_tab_right', a:palette.inactive.airline_c)
|
2016-01-12 20:47:44 +08:00
|
|
|
let l:tabmod_right = get(colors, 'airline_tabmod_right', a:palette.insert.airline_a)
|
|
|
|
let l: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 l: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 l:tabmodu_right = get(colors, 'airline_tabmod_unsel_right', a:palette.normal.airline_c)
|
|
|
|
endif
|
2016-01-28 12:11:11 +08:00
|
|
|
call airline#highlighter#exec('airline_tab_right', l:tab_right)
|
2016-01-12 20:47:44 +08:00
|
|
|
call airline#highlighter#exec('airline_tabsel_right', l:tabsel_right)
|
|
|
|
call airline#highlighter#exec('airline_tabmod_right', l:tabmod_right)
|
|
|
|
call airline#highlighter#exec('airline_tabhid_right', l:tabhid_right)
|
|
|
|
call airline#highlighter#exec('airline_tabmod_unsel_right', l:tabmodu_right)
|
2013-08-28 21:51:54 +08:00
|
|
|
endfunction
|
|
|
|
|
2015-02-19 10:37:13 +08:00
|
|
|
let s:current_tabcnt = -1
|
2013-08-28 21:51:54 +08:00
|
|
|
function! airline#extensions#tabline#get()
|
2014-08-13 08:26:52 +08:00
|
|
|
let curtabcnt = tabpagenr('$')
|
|
|
|
if curtabcnt != s:current_tabcnt
|
|
|
|
let s:current_tabcnt = curtabcnt
|
2015-02-19 10:37:13 +08:00
|
|
|
call airline#extensions#tabline#tabs#invalidate()
|
|
|
|
call airline#extensions#tabline#buffers#invalidate()
|
2016-01-12 20:47:44 +08:00
|
|
|
call airline#extensions#tabline#ctrlspace#invalidate()
|
2014-08-13 08:26:52 +08:00
|
|
|
endif
|
2015-02-19 10:24:05 +08:00
|
|
|
|
2016-01-21 17:00:06 +08:00
|
|
|
if !exists('#airline#BufAdd#*')
|
|
|
|
autocmd airline BufAdd * call <sid>update_tabline()
|
|
|
|
endif
|
2017-06-27 05:06:46 +08:00
|
|
|
try
|
|
|
|
let g:airline_theme_dict = {}
|
|
|
|
if s:ctrlspace
|
|
|
|
return airline#extensions#tabline#ctrlspace#get()
|
|
|
|
elseif s:show_buffers && curtabcnt == 1 || !s:show_tabs
|
|
|
|
return airline#extensions#tabline#buffers#get()
|
|
|
|
else
|
|
|
|
return airline#extensions#tabline#tabs#get()
|
|
|
|
endif
|
|
|
|
finally
|
|
|
|
unlet g:airline_theme_dict
|
|
|
|
endtry
|
2013-08-28 21:51:54 +08:00
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! airline#extensions#tabline#title(n)
|
2015-02-28 10:12:45 +08:00
|
|
|
let title = ''
|
|
|
|
if s:taboo
|
|
|
|
let title = TabooTabTitle(a:n)
|
|
|
|
endif
|
|
|
|
|
2016-03-23 02:14:47 +08:00
|
|
|
if empty(title) && exists('*gettabvar')
|
|
|
|
let title = gettabvar(a:n, 'title')
|
|
|
|
endif
|
|
|
|
|
2015-02-28 10:12:45 +08:00
|
|
|
if empty(title)
|
|
|
|
let buflist = tabpagebuflist(a:n)
|
|
|
|
let winnr = tabpagewinnr(a:n)
|
2016-06-17 21:07:55 +08:00
|
|
|
let all_buffers = airline#extensions#tabline#buflist#list()
|
2017-06-27 20:39:11 +08:00
|
|
|
let title = airline#extensions#tabline#get_buffer_name(
|
2016-06-17 21:07:55 +08:00
|
|
|
\ buflist[winnr - 1],
|
|
|
|
\ filter(buflist, 'index(all_buffers, v:val) != -1'))
|
2015-02-28 10:12:45 +08:00
|
|
|
endif
|
|
|
|
|
2017-06-27 20:39:11 +08:00
|
|
|
if exists("*settabvar") && !empty(title)
|
|
|
|
call settabvar(a:n, 'title', title)
|
|
|
|
endif
|
2015-02-28 10:12:45 +08:00
|
|
|
return title
|
2013-09-02 11:03:36 +08:00
|
|
|
endfunction
|
|
|
|
|
2016-07-02 22:24:47 +08:00
|
|
|
function! airline#extensions#tabline#get_buffer_name(nr, ...)
|
|
|
|
let buffers = a:0 ? a:1 : airline#extensions#tabline#buflist#list()
|
|
|
|
return airline#extensions#tabline#formatters#{s:formatter}#format(a:nr, buffers)
|
2013-09-22 02:13:19 +08:00
|
|
|
endfunction
|
|
|
|
|
2015-02-19 10:24:05 +08:00
|
|
|
function! airline#extensions#tabline#new_builder()
|
2014-11-05 03:48:00 +08:00
|
|
|
let builder_context = {
|
|
|
|
\ 'active' : 1,
|
2016-09-28 03:44:00 +08:00
|
|
|
\ 'tabline' : 1,
|
2014-11-05 03:48:00 +08: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
|
|
|
|
|
|
|
|
return airline#builder#new(builder_context)
|
|
|
|
endfunction
|
2016-01-28 12:11:11 +08: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
|