tabline: allow custom formatter for tabnr_type

closes #1418
This commit is contained in:
Christian Brabandt 2018-01-04 20:41:55 +01:00
parent 133a76d2d4
commit ce83c39bed
No known key found for this signature in database
GPG Key ID: F3F92DA383FDDE09
3 changed files with 24 additions and 7 deletions

View File

@ -0,0 +1,14 @@
" MIT License. Copyright (c) 2017 C.Brabandt
" vim: et ts=2 sts=2 sw=2
scriptencoding utf-8
function! airline#extensions#tabline#formatters#tabnr#format(tab_nr_type, nr)
if a:tab_nr_type == 0 " nr of splits
return (g:airline_symbols.space).'%{len(tabpagebuflist('.a:nr.'))}'
elseif a:tab_nr_type == 1 " tab number
return (g:airline_symbols.space).a:nr
else "== 2 splits and tab number
return (g:airline_symbols.space).a:nr.'.%{len(tabpagebuflist('.a:nr.'))}'
endif
endfunction

View File

@ -68,13 +68,7 @@ function! airline#extensions#tabline#tabs#get()
let val = '%(' let val = '%('
if get(g:, 'airline#extensions#tabline#show_tab_nr', 1) if get(g:, 'airline#extensions#tabline#show_tab_nr', 1)
if tab_nr_type == 0 let val .= airline#extensions#tabline#tabs#tabnr_formatter(tab_nr_type, i)
let val .= (g:airline_symbols.space).'%{len(tabpagebuflist('.i.'))}'
elseif 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 endif
call b.add_section(group, val.'%'.i.'T %{airline#extensions#tabline#title('.i.')} %)') call b.add_section(group, val.'%'.i.'T %{airline#extensions#tabline#title('.i.')} %)')
endfor endfor
@ -121,3 +115,8 @@ function! airline#extensions#tabline#tabs#map_keys()
noremap <silent> <Plug>AirlineSelectNextTab :<C-U>exe repeat(':tabn\|', v:count1)<cr> noremap <silent> <Plug>AirlineSelectNextTab :<C-U>exe repeat(':tabn\|', v:count1)<cr>
let s:airline_tabline_map_key = 1 let s:airline_tabline_map_key = 1
endfunction endfunction
function! airline#extensions#tabline#tabs#tabnr_formatter(nr, i)
let formatter = get(g:, 'airline#extensions#tabline#tabnr_formatter', 'tabnr')
return airline#extensions#tabline#formatters#{formatter}#format(a:nr, a:i)
endfunction

View File

@ -685,6 +685,10 @@ with the middle mouse button to delete that buffer.
let g:airline#extensions#tabline#tab_nr_type = 0 " # of splits (default) let g:airline#extensions#tabline#tab_nr_type = 0 " # of splits (default)
let g:airline#extensions#tabline#tab_nr_type = 1 " tab number let g:airline#extensions#tabline#tab_nr_type = 1 " tab number
let g:airline#extensions#tabline#tab_nr_type = 2 " splits and tab number let g:airline#extensions#tabline#tab_nr_type = 2 " splits and tab number
let g:airline#extensions#tabline#tabnr_formatter = 'tabnr'
Note: last option can be used to specify a different formatter for
displaying the numbers. By default tabline/formatter/tabnr.vim is used
< <
* enable/disable displaying tab number in tabs mode. > * enable/disable displaying tab number in tabs mode. >
let g:airline#extensions#tabline#show_tab_nr = 1 let g:airline#extensions#tabline#show_tab_nr = 1