From 7a286639c520b7972fc67de81ff4d8c087746f0b Mon Sep 17 00:00:00 2001 From: mrmr1993 Date: Mon, 12 Mar 2018 20:27:52 +0000 Subject: [PATCH] Attach tabs to tabline last --- autoload/airline/builder.vim | 12 ++++++ autoload/airline/extensions/tabline/tabs.vim | 45 +++++++++++--------- 2 files changed, 37 insertions(+), 20 deletions(-) diff --git a/autoload/airline/builder.vim b/autoload/airline/builder.vim index 38dc83c9..b536d4cd 100644 --- a/autoload/airline/builder.vim +++ b/autoload/airline/builder.vim @@ -22,6 +22,18 @@ function! s:prototype.add_raw(text) dict call add(self._sections, ['', a:text]) endfunction +function! s:prototype.insert_section(group, contents, position) dict + call insert(self._sections, [a:group, a:contents], a:position) +endfunction + +function! s:prototype.insert_raw(text, position) dict + call insert(self._sections, ['', a:text], a:position) +endfunction + +function! s:prototype.get_position() dict + return len(self._sections) +endfunction + function! s:get_prev_group(sections, i) let x = a:i - 1 while x >= 0 diff --git a/autoload/airline/extensions/tabline/tabs.vim b/autoload/airline/extensions/tabline/tabs.vim index 596013a6..3db6d928 100644 --- a/autoload/airline/extensions/tabline/tabs.vim +++ b/autoload/airline/extensions/tabline/tabs.vim @@ -102,9 +102,31 @@ function! airline#extensions#tabline#tabs#get() let b = airline#extensions#tabline#new_builder() call airline#extensions#tabline#add_label(b, 'tabs') + + let tabs_position = b.get_position() + + call b.add_section('airline_tabfill', '') + call b.split() + call b.add_section('airline_tabfill', '') + + if get(g:, 'airline#extensions#tabline#show_close_button', 1) + call b.add_section('airline_tab_right', ' %999X'. + \ get(g:, 'airline#extensions#tabline#close_symbol', 'X').' ') + endif + + if get(g:, 'airline#extensions#tabline#show_splits', 1) == 1 + let buffers = tabpagebuflist(curtab) + for nr in buffers + let group = airline#extensions#tabline#group_of_bufnr(buffers, nr) . "_right" + call b.add_section_spaced(group, '%(%{airline#extensions#tabline#get_buffer_name('.nr.')}%)') + endfor + call airline#extensions#tabline#add_label(b, 'buffers') + endif + for i in s:get_visible_tabs(&columns) if i < 0 - call b.add_raw('%#airline_tab#...') + call b.insert_raw('%#airline_tab#...', tabs_position) + let tabs_position += 1 continue endif if i == curtab @@ -125,27 +147,10 @@ function! airline#extensions#tabline#tabs#get() if get(g:, 'airline#extensions#tabline#show_tab_nr', 1) 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.')} %)') + call b.insert_section(group, val.'%'.i.'T %{airline#extensions#tabline#title('.i.')} %)', tabs_position) + let tabs_position += 1 endfor - call b.add_section('airline_tabfill', '') - call b.split() - call b.add_section('airline_tabfill', '') - - if get(g:, 'airline#extensions#tabline#show_close_button', 1) - call b.add_section('airline_tab_right', ' %999X'. - \ get(g:, 'airline#extensions#tabline#close_symbol', 'X').' ') - endif - - if get(g:, 'airline#extensions#tabline#show_splits', 1) == 1 - let buffers = tabpagebuflist(curtab) - for nr in buffers - let group = airline#extensions#tabline#group_of_bufnr(buffers, nr) . "_right" - call b.add_section_spaced(group, '%(%{airline#extensions#tabline#get_buffer_name('.nr.')}%)') - endfor - call airline#extensions#tabline#add_label(b, 'buffers') - endif - let s:current_bufnr = curbuf let s:current_tabnr = curtab let s:current_tabline = b.build()