2015-02-13 23:46:23 +00:00
|
|
|
" MIT License. Copyright (c) 2013-2015 Bailey Ling.
|
2013-08-28 13:51:54 +00:00
|
|
|
" vim: et ts=2 sts=2 sw=2
|
|
|
|
|
2013-09-07 00:43:51 +00:00
|
|
|
let s:formatter = get(g:, 'airline#extensions#tabline#formatter', 'default')
|
2013-09-04 20:17:02 +00:00
|
|
|
let s:show_buffers = get(g:, 'airline#extensions#tabline#show_buffers', 1)
|
2014-12-26 21:48:06 +00:00
|
|
|
let s:show_tabs = get(g:, 'airline#extensions#tabline#show_tabs', 1)
|
2014-09-17 13:52:08 +00:00
|
|
|
|
2013-08-28 13:51:54 +00:00
|
|
|
function! airline#extensions#tabline#init(ext)
|
2013-09-03 18:48:08 +00:00
|
|
|
if has('gui_running')
|
|
|
|
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()
|
2013-10-13 22:01:38 +00:00
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! s:toggle_on()
|
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()
|
2015-02-19 02:24:05 +00:00
|
|
|
|
|
|
|
set tabline=%!airline#extensions#tabline#get()
|
2013-09-01 23:39:06 +00:00
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! airline#extensions#tabline#load_theme(palette)
|
2013-09-04 17:16:23 +00:00
|
|
|
let colors = get(a:palette, 'tabline', {})
|
|
|
|
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)
|
2014-09-08 13:43:15 +00: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-05 22:34:15 +00:00
|
|
|
let l:tabhid = get(colors, 'airline_tabhid', a:palette.normal.airline_c)
|
2013-09-04 15:54:48 +00: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-04 19:38:12 +00:00
|
|
|
call airline#highlighter#exec('airline_tabmod_unsel', l:tabmodu)
|
2013-09-05 22:34:15 +00:00
|
|
|
call airline#highlighter#exec('airline_tabhid', l:tabhid)
|
2013-08-28 13:51:54 +00:00
|
|
|
endfunction
|
|
|
|
|
2015-02-19 02:37:13 +00:00
|
|
|
let s:current_tabcnt = -1
|
2013-08-28 13:51:54 +00:00
|
|
|
function! airline#extensions#tabline#get()
|
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()
|
2014-08-13 00:26:52 +00:00
|
|
|
endif
|
2015-02-19 02:24:05 +00:00
|
|
|
|
2014-12-26 21:48:06 +00:00
|
|
|
if s:show_buffers && curtabcnt == 1 || !s:show_tabs
|
2015-02-19 02:37:13 +00:00
|
|
|
return airline#extensions#tabline#buffers#get()
|
2013-08-28 13:51:54 +00:00
|
|
|
else
|
2015-02-19 02:24:05 +00:00
|
|
|
return airline#extensions#tabline#tabs#get()
|
2013-08-28 13:51:54 +00:00
|
|
|
endif
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! airline#extensions#tabline#title(n)
|
|
|
|
let buflist = tabpagebuflist(a:n)
|
|
|
|
let winnr = tabpagewinnr(a:n)
|
2013-09-02 03:03:36 +00:00
|
|
|
return airline#extensions#tabline#get_buffer_name(buflist[winnr - 1])
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! airline#extensions#tabline#get_buffer_name(nr)
|
2015-02-18 23:48:47 +00:00
|
|
|
return airline#extensions#tabline#formatters#{s:formatter}#format(a:nr, airline#extensions#tabline#buflist#list())
|
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,
|
|
|
|
\ '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
|