tabline for combined buffers/tabs

This is a new tabline extension, that displays both the buffers open and
the available tabs. This has been requested by #639 and fixes #639.

This is based on blings work on branch spike.

This uses the new highlight groups tab*_right, so that the separators
have the correct color. Also this makes some configuration variable
obsolete and therefore, they have been removed.

remove unused combined config variable, remove space after tab
This commit is contained in:
Bailey Ling 2016-01-27 23:11:11 -05:00 committed by Christian Brabandt
parent 1dc8eac3d2
commit e4ef624ea8
3 changed files with 48 additions and 45 deletions

View File

@ -5,6 +5,7 @@ let s:formatter = get(g:, 'airline#extensions#tabline#formatter', 'default')
let s:show_buffers = get(g:, 'airline#extensions#tabline#show_buffers', 1) let s:show_buffers = get(g:, 'airline#extensions#tabline#show_buffers', 1)
let s:show_tabs = get(g:, 'airline#extensions#tabline#show_tabs', 1) let s:show_tabs = get(g:, 'airline#extensions#tabline#show_tabs', 1)
let s:ignore_bufadd_pat = get(g:, 'airline#extensions#tabline#ignore_bufadd_pat', '\c\vgundo|undotree|vimfiler|tagbar|nerd_tree') let s:ignore_bufadd_pat = get(g:, 'airline#extensions#tabline#ignore_bufadd_pat', '\c\vgundo|undotree|vimfiler|tagbar|nerd_tree')
let s:taboo = get(g:, 'airline#extensions#taboo#enabled', 1) && get(g:, 'loaded_taboo', 0) let s:taboo = get(g:, 'airline#extensions#taboo#enabled', 1) && get(g:, 'loaded_taboo', 0)
if s:taboo if s:taboo
let g:taboo_tabline = 0 let g:taboo_tabline = 0
@ -91,6 +92,7 @@ function! airline#extensions#tabline#load_theme(palette)
call airline#highlighter#exec('airline_tabhid', l:tabhid) call airline#highlighter#exec('airline_tabhid', l:tabhid)
" Theme for tabs on the right " Theme for tabs on the right
let l:tab_right = get(colors, 'airline_tab_right', a:palette.normal.airline_b)
let l:tabsel_right = get(colors, 'airline_tabsel_right', a:palette.normal.airline_a) let l:tabsel_right = get(colors, 'airline_tabsel_right', a:palette.normal.airline_a)
let l:tabmod_right = get(colors, 'airline_tabmod_right', a:palette.insert.airline_a) 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) let l:tabhid_right = get(colors, 'airline_tabhid_right', a:palette.normal.airline_c)
@ -100,6 +102,7 @@ function! airline#extensions#tabline#load_theme(palette)
"Fall back to normal airline_c if modified airline_c isn't present "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) let l:tabmodu_right = get(colors, 'airline_tabmod_unsel_right', a:palette.normal.airline_c)
endif endif
call airline#highlighter#exec('airline_tab_right', l:tab_right)
call airline#highlighter#exec('airline_tabsel_right', l:tabsel_right) 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_tabmod_right', l:tabmod_right)
call airline#highlighter#exec('airline_tabhid_right', l:tabhid_right) call airline#highlighter#exec('airline_tabhid_right', l:tabhid_right)
@ -163,3 +166,24 @@ function! airline#extensions#tabline#new_builder()
return airline#builder#new(builder_context) return airline#builder#new(builder_context)
endfunction 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
let s:current_modified = (group == 'airline_tabmod') ? 1 : 0
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

View File

@ -62,23 +62,7 @@ function! airline#extensions#tabline#buffers#get()
continue continue
endif endif
if cur == nr let group = airline#extensions#tabline#group_of_bufnr(tab_bufs, nr)
if g:airline_detect_modified && getbufvar(nr, '&modified')
let group = 'airline_tabmod'
else
let group = 'airline_tabsel'
endif
let s:current_modified = (group == 'airline_tabmod') ? 1 : 0
else
if g:airline_detect_modified && getbufvar(nr, '&modified')
let group = 'airline_tabmod_unsel'
elseif index(tab_bufs, nr) > -1
let group = 'airline_tab'
else
let group = 'airline_tabhid'
endif
endif
if s:buffer_idx_mode if s:buffer_idx_mode
if len(s:number_map) > 0 if len(s:number_map) > 0
call b.add_section(group, s:spc . get(s:number_map, l:index, '') . '%(%{airline#extensions#tabline#get_buffer_name('.nr.')}%)' . s:spc) call b.add_section(group, s:spc . get(s:number_map, l:index, '') . '%(%{airline#extensions#tabline#get_buffer_name('.nr.')}%)' . s:spc)

View File

@ -1,11 +1,9 @@
" MIT License. Copyright (c) 2013-2016 Bailey Ling. " MIT License. Copyright (c) 2013-2016 Bailey Ling.
" vim: et ts=2 sts=2 sw=2 " vim: et ts=2 sts=2 sw=2
let s:show_tab_nr = get(g:, 'airline#extensions#tabline#show_tab_nr', 1)
let s:tab_nr_type = get(g:, 'airline#extensions#tabline#tab_nr_type', 0)
let s:show_close_button = get(g:, 'airline#extensions#tabline#show_close_button', 1) let s:show_close_button = get(g:, 'airline#extensions#tabline#show_close_button', 1)
let s:show_tab_type = get(g:, 'airline#extensions#tabline#show_tab_type', 1)
let s:close_symbol = get(g:, 'airline#extensions#tabline#close_symbol', 'X') let s:close_symbol = get(g:, 'airline#extensions#tabline#close_symbol', 'X')
let s:spc = g:airline_symbols.space
let s:current_bufnr = -1 let s:current_bufnr = -1
let s:current_tabnr = -1 let s:current_tabnr = -1
@ -39,41 +37,38 @@ function! airline#extensions#tabline#tabs#get()
endif endif
let b = airline#extensions#tabline#new_builder() let b = airline#extensions#tabline#new_builder()
let buffers = tabpagebuflist(curtab)
for nr in buffers
let group = airline#extensions#tabline#group_of_bufnr(buffers, nr)
call b.add_section_spaced(group, '%(%{airline#extensions#tabline#get_buffer_name('.nr.')}%)')
endfor
" truncate
call b.add_raw('%<')
call b.add_section('airline_tabfill', '')
call b.split()
call b.add_section('airline_tabfill', '')
for i in range(1, tabpagenr('$')) for i in range(1, tabpagenr('$'))
if i == curtab if i == curtab
let group = 'airline_tabsel' let group = 'airline_tabsel_right'
if g:airline_detect_modified if g:airline_detect_modified
for bi in tabpagebuflist(i) for bi in tabpagebuflist(i)
if getbufvar(bi, '&modified') if getbufvar(bi, '&modified')
let group = 'airline_tabmod' let group = 'airline_tabmod_right'
endif endif
endfor endfor
endif endif
let s:current_modified = (group == 'airline_tabmod') ? 1 : 0 let s:current_modified = (group == 'airline_tabmod_right') ? 1 : 0
else else
let group = 'airline_tab' let group = 'airline_tab_right'
endif endif
let val = '%(' call b.add_section(group, '%'.i.'Ttab '.i)
if s:show_tab_nr
if s:tab_nr_type == 0
let val .= (g:airline_symbols.space).'%{len(tabpagebuflist('.i.'))}'
elseif s:tab_nr_type == 1
let val .= (g:airline_symbols.space).i
else "== 2
let val .= (g:airline_symbols.space).i.'.%{len(tabpagebuflist('.i.'))}'
endif
endif
call b.add_section(group, val.'%'.i.'T %{airline#extensions#tabline#title('.i.')} %)')
endfor endfor
call b.add_raw('%<')
call b.add_raw('%T')
call b.add_section('airline_tabfill', '')
call b.split()
if s:show_close_button if s:show_close_button
call b.add_section('airline_tab', ' %999X'.s:close_symbol.' ') call b.add_section('airline_tab_right', ' %999X'.s:close_symbol.' ')
endif
if s:show_tab_type
call b.add_section('airline_tabtype', ' tabs ')
endif endif
let s:current_bufnr = curbuf let s:current_bufnr = curbuf