From 3b631ef0c4bb8c3e8e98416d0755ad6fc06f9420 Mon Sep 17 00:00:00 2001 From: Christian Brabandt Date: Thu, 4 Jan 2018 18:43:03 +0100 Subject: [PATCH] tabline: refactor label function --- autoload/airline/extensions/tabline.vim | 7 +++++++ autoload/airline/extensions/tabline/buffers.vim | 5 +---- autoload/airline/extensions/tabline/tabs.vim | 10 ++-------- 3 files changed, 10 insertions(+), 12 deletions(-) diff --git a/autoload/airline/extensions/tabline.vim b/autoload/airline/extensions/tabline.vim index 167cf8a..60d2d2f 100644 --- a/autoload/airline/extensions/tabline.vim +++ b/autoload/airline/extensions/tabline.vim @@ -201,3 +201,10 @@ function! airline#extensions#tabline#group_of_bufnr(tab_bufs, bufnr) endif return group endfunction + +function! airline#extensions#tabline#add_label(dict, type) + if get(g:, 'airline#extensions#tabline#show_tab_type', 1) + call a:dict.add_section_spaced('airline_tab', + \ get(g:, 'airline#extensions#tabline#'.a:type.'_label', '['.a:type.']')) + endif +endfunction diff --git a/autoload/airline/extensions/tabline/buffers.vim b/autoload/airline/extensions/tabline/buffers.vim index 706f297..2846734 100644 --- a/autoload/airline/extensions/tabline/buffers.vim +++ b/autoload/airline/extensions/tabline/buffers.vim @@ -97,10 +97,7 @@ function! airline#extensions#tabline#buffers#get() call b.add_section('airline_tabfill', '') call b.split() call b.add_section('airline_tabfill', '') - if get(g:, 'airline#extensions#tabline#show_tab_type', 1) - call b.add_section_spaced('airline_tab', - \ get(g:, 'airline#extensions#tabline#buffers_label', '[buffers]')) - endif + call airline#extensions#tabline#add_label(b, 'buffers') if tabpagenr('$') > 1 call b.add_section_spaced('airline_tabmod', printf('%s %d/%d', "tab", tabpagenr(), tabpagenr('$'))) diff --git a/autoload/airline/extensions/tabline/tabs.vim b/autoload/airline/extensions/tabline/tabs.vim index 79f3f00..f4ff674 100644 --- a/autoload/airline/extensions/tabline/tabs.vim +++ b/autoload/airline/extensions/tabline/tabs.vim @@ -42,10 +42,7 @@ function! airline#extensions#tabline#tabs#get() let tab_nr_type = get(g:, 'airline#extensions#tabline#tab_nr_type', 0) let b = airline#extensions#tabline#new_builder() - if get(g:, 'airline#extensions#tabline#show_tab_type', 1) - call b.add_section_spaced('airline_tab', - \ get(g:, 'airline#extensions#tabline#buffers_label', '[buffers]')) - endif + call airline#extensions#tabline#add_label(b, 'buffers') for i in range(1, tabpagenr('$')) if i == curtab let group = 'airline_tabsel' @@ -90,10 +87,7 @@ function! airline#extensions#tabline#tabs#get() call b.add_section_spaced(group, '%(%{airline#extensions#tabline#get_buffer_name('.nr.')}%)') endfor endif - if get(g:, 'airline#extensions#tabline#show_tab_type', 1) == 1 - call b.add_section_spaced('airline_tab', - \ get(g:, 'airline#extensions#tabline#tabs_label', '[tabs]')) - endif + call airline#extensions#tabline#add_label(b, 'tabs') let s:current_bufnr = curbuf let s:current_tabnr = curtab