Tabline: Make specifying formatter more easy

closes #1863
This commit is contained in:
Christian Brabandt 2019-02-02 17:45:55 +01:00
parent d372b5bc46
commit dc7d991007
No known key found for this signature in database
GPG Key ID: F3F92DA383FDDE09
2 changed files with 17 additions and 2 deletions

View File

@ -118,7 +118,15 @@ 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>
endfunction 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') 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 endfunction

View File

@ -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 Note: last option can be used to specify a different formatter for
displaying the numbers. By default tabline/formatter/tabnr.vim is used 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. > * 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