From dc7d9910079d2d4426b69c9b71544ed810b9c387 Mon Sep 17 00:00:00 2001 From: Christian Brabandt Date: Sat, 2 Feb 2019 17:45:55 +0100 Subject: [PATCH] Tabline: Make specifying formatter more easy closes #1863 --- autoload/airline/extensions/tabline/tabs.vim | 12 ++++++++++-- doc/airline.txt | 7 +++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/autoload/airline/extensions/tabline/tabs.vim b/autoload/airline/extensions/tabline/tabs.vim index a74ab5b..c90967c 100644 --- a/autoload/airline/extensions/tabline/tabs.vim +++ b/autoload/airline/extensions/tabline/tabs.vim @@ -118,7 +118,15 @@ function! airline#extensions#tabline#tabs#map_keys() noremap AirlineSelectNextTab :exe repeat(':tabn\|', v:count1) endfunction -function! airline#extensions#tabline#tabs#tabnr_formatter(nr, i) +function! airline#extensions#tabline#tabs#tabnr_formatter(nr, i) abort let formatter = get(g:, 'airline#extensions#tabline#tabnr_formatter', 'tabnr') - return airline#extensions#tabline#formatters#{formatter}#format(a:nr, a:i) + try + return airline#extensions#formatters#{formatter}#format(a:nr, a:i) + catch /^Vim\%((\a\+)\)\=:E117/ " catch E117, unknown function + " Function not found + return call(formatter, [a:nr, a:i]) + catch + " something went wrong, return an empty string + return "" + endtry endfunction diff --git a/doc/airline.txt b/doc/airline.txt index 5ef18d3..2de016f 100644 --- a/doc/airline.txt +++ b/doc/airline.txt @@ -809,6 +809,13 @@ with the middle mouse button to delete that buffer. Note: last option can be used to specify a different formatter for displaying the numbers. By default tabline/formatter/tabnr.vim is used + The argument of that setting should either be a filename that exists + autoload/airline/extensions/tabline/formatter/ (without .vim extension) + and needs to provide a format() function. Alternatively you can use a + custom function name, that is defined e.g. in your .vimrc file. In any + case, the function needs to take 2 arguments, tab_nr_type and tabpage + number. + For an example, have a look at the default tabline/formatter/tabnr.vim < * enable/disable displaying tab number in tabs mode. > let g:airline#extensions#tabline#show_tab_nr = 1