From ce83c39bed2d0574bdeeac89f191b2ee1815d650 Mon Sep 17 00:00:00 2001 From: Christian Brabandt Date: Thu, 4 Jan 2018 20:41:55 +0100 Subject: [PATCH] tabline: allow custom formatter for tabnr_type closes #1418 --- .../extensions/tabline/formatters/tabnr.vim | 14 ++++++++++++++ autoload/airline/extensions/tabline/tabs.vim | 13 ++++++------- doc/airline.txt | 4 ++++ 3 files changed, 24 insertions(+), 7 deletions(-) create mode 100644 autoload/airline/extensions/tabline/formatters/tabnr.vim diff --git a/autoload/airline/extensions/tabline/formatters/tabnr.vim b/autoload/airline/extensions/tabline/formatters/tabnr.vim new file mode 100644 index 0000000..87fa7d4 --- /dev/null +++ b/autoload/airline/extensions/tabline/formatters/tabnr.vim @@ -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 diff --git a/autoload/airline/extensions/tabline/tabs.vim b/autoload/airline/extensions/tabline/tabs.vim index 3f3993f..b7a365b 100644 --- a/autoload/airline/extensions/tabline/tabs.vim +++ b/autoload/airline/extensions/tabline/tabs.vim @@ -68,13 +68,7 @@ function! airline#extensions#tabline#tabs#get() let val = '%(' if get(g:, 'airline#extensions#tabline#show_tab_nr', 1) - if tab_nr_type == 0 - 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 + let val .= airline#extensions#tabline#tabs#tabnr_formatter(tab_nr_type, i) endif call b.add_section(group, val.'%'.i.'T %{airline#extensions#tabline#title('.i.')} %)') endfor @@ -121,3 +115,8 @@ function! airline#extensions#tabline#tabs#map_keys() noremap AirlineSelectNextTab :exe repeat(':tabn\|', v:count1) let s:airline_tabline_map_key = 1 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 diff --git a/doc/airline.txt b/doc/airline.txt index e9299e5..fda7453 100644 --- a/doc/airline.txt +++ b/doc/airline.txt @@ -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 = 1 " 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. > let g:airline#extensions#tabline#show_tab_nr = 1