From ad5194244b3ed27c0c2eb42092eb2231a3ca7f13 Mon Sep 17 00:00:00 2001 From: Kevin Sapper Date: Thu, 25 Feb 2016 11:03:50 +0100 Subject: [PATCH 1/3] Problem: Cannot switch position of tabs and buffers for ctrlspace tabline Solution: Add a new option which inverses the position of buffer and tabs If switch_buffer_and_tabs is 0 (default) buffer are on the left and tabs on the right else if is 1 the order is reversed. --- .../airline/extensions/tabline/ctrlspace.vim | 130 +++++++++++------- 1 file changed, 82 insertions(+), 48 deletions(-) diff --git a/autoload/airline/extensions/tabline/ctrlspace.vim b/autoload/airline/extensions/tabline/ctrlspace.vim index a27a37e4..95d16a35 100644 --- a/autoload/airline/extensions/tabline/ctrlspace.vim +++ b/autoload/airline/extensions/tabline/ctrlspace.vim @@ -9,6 +9,7 @@ let s:current_tabline = '' let s:buffers_label = get(g:, 'airline#extensions#tabline#buffers_label', 'buffers') let s:tabs_label = get(g:, 'airline#extensions#tabline#tabs_label', 'tabs') +let s:switch_buffers_and_tabs = get(g:, 'airline#extensions#tabline#switch_buffers_and_tabs', 1) function! airline#extensions#tabline#ctrlspace#off() augroup airline_tabline_ctrlspace @@ -28,6 +29,72 @@ function! airline#extensions#tabline#ctrlspace#invalidate() let s:current_tabnr = -1 endfunction +function! airline#extensions#tabline#ctrlspace#add_buffer_section(builder, cur_tab, cur_buf, pos) + if a:pos == 0 + call a:builder.add_section_spaced('airline_tabtype', s:buffers_label) + let pos_extension = '' + else + let pos_extension = '_right' + endif + + let s:buffer_list = ctrlspace#api#BufferList(a:cur_tab) + for buffer in s:buffer_list + if a:cur_buf == buffer.index + if buffer.modified + let group = 'airline_tabmod'.pos_extension + else + let group = 'airline_tabsel'.pos_extension + endif + else + if buffer.modified + let group = 'airline_tabmod_unsel'.pos_extension + elseif buffer.visible + let group = 'airline_tab'.pos_extension + else + let group = 'airline_tabhid'.pos_extension + endif + endif + + let buf_name = '%(%{airline#extensions#tabline#get_buffer_name('.buffer.index.')}%)' + call a:builder.add_section_spaced(group, buf_name) + endfor + + if a:pos == 1 + call a:builder.add_section_spaced('airline_tabtype', s:buffers_label) + endif +endfunction + +function! airline#extensions#tabline#ctrlspace#add_tab_section(builder, pos) + if a:pos == 0 + call a:builder.add_section_spaced('airline_tabtype', s:tabs_label) + let pos_extension = '' + else + let pos_extension = '_right' + endif + + for tab in s:tab_list + if tab.current + if tab.modified + let group = 'airline_tabmod'.pos_extension + else + let group = 'airline_tabsel'.pos_extension + endif + else + if tab.modified + let group = 'airline_tabmod_unsel'.pos_extension + else + let group = 'airline_tabhid'.pos_extension + endif + endif + + call a:builder.add_section_spaced(group, tab.title.ctrlspace#api#TabBuffersNumber(tab.index)) + endfor + + if a:pos == 1 + call a:builder.add_section_spaced('airline_tabtype', s:tabs_label) + endif +endfunction + function! airline#extensions#tabline#ctrlspace#get() let cur_buf = bufnr('%') @@ -42,59 +109,26 @@ function! airline#extensions#tabline#ctrlspace#get() return s:current_tabline endif - let b = airline#extensions#tabline#new_builder() + let builder = airline#extensions#tabline#new_builder() - call b.add_section_spaced('airline_tabtype', s:buffers_label) + if s:switch_buffers_and_tabs == 0 + call airline#extensions#tabline#ctrlspace#add_buffer_section(builder, cur_tab, cur_buf, 0) + else + call airline#extensions#tabline#ctrlspace#add_tab_section(builder, 0) + endif - let s:buffer_list = ctrlspace#api#BufferList(cur_tab) - for buffer in s:buffer_list - if cur_buf == buffer.index - if buffer.modified - let group = 'airline_tabmod' - else - let group = 'airline_tabsel' - endif - else - if buffer.modified - let group = 'airline_tabmod_unsel' - elseif buffer.visible - let group = 'airline_tab' - else - let group = 'airline_tabhid' - endif - endif + call builder.add_section('airline_tabfill', '') + call builder.split() + call builder.add_section('airline_tabfill', '') - let buf_name = '%(%{airline#extensions#tabline#get_buffer_name('.buffer.index.')}%)' - call b.add_section_spaced(group, buf_name) - endfor - - - call b.add_section('airline_tabfill', '') - call b.split() - call b.add_section('airline_tabfill', '') - - for tab in s:tab_list - if tab.current - if tab.modified - let group = 'airline_tabmod_right' - else - let group = 'airline_tabsel_right' - endif - else - if tab.modified - let group = 'airline_tabmod_unsel_right' - else - let group = 'airline_tabhid_right' - endif - endif - - call b.add_section_spaced(group, tab.title.ctrlspace#api#TabBuffersNumber(tab.index)) - endfor - - call b.add_section_spaced('airline_tabtype', s:tabs_label) + if s:switch_buffers_and_tabs == 0 + call airline#extensions#tabline#ctrlspace#add_tab_section(builder, 1) + else + call airline#extensions#tabline#ctrlspace#add_buffer_section(builder, cur_tab, cur_buf, 1) + endif let s:current_bufnr = cur_buf let s:current_tabnr = cur_tab - let s:current_tabline = b.build() + let s:current_tabline = builder.build() return s:current_tabline endfunction From 2f2797becb874c5651a25ec976b23a699ab8b158 Mon Sep 17 00:00:00 2001 From: Kevin Sapper Date: Thu, 25 Feb 2016 11:19:52 +0100 Subject: [PATCH 2/3] Problem: Cannot disable displaying buffers for ctrlspace tabline Solution: Implement the show_buffers option which is used by the default airline tab as well. --- .../airline/extensions/tabline/ctrlspace.vim | 39 +++++++++++-------- 1 file changed, 22 insertions(+), 17 deletions(-) diff --git a/autoload/airline/extensions/tabline/ctrlspace.vim b/autoload/airline/extensions/tabline/ctrlspace.vim index 95d16a35..946540dd 100644 --- a/autoload/airline/extensions/tabline/ctrlspace.vim +++ b/autoload/airline/extensions/tabline/ctrlspace.vim @@ -9,7 +9,8 @@ let s:current_tabline = '' let s:buffers_label = get(g:, 'airline#extensions#tabline#buffers_label', 'buffers') let s:tabs_label = get(g:, 'airline#extensions#tabline#tabs_label', 'tabs') -let s:switch_buffers_and_tabs = get(g:, 'airline#extensions#tabline#switch_buffers_and_tabs', 1) +let s:switch_buffers_and_tabs = get(g:, 'airline#extensions#tabline#switch_buffers_and_tabs', 0) +let s:show_buffers = get(g:, 'airline#extensions#tabline#show_buffers', 1) function! airline#extensions#tabline#ctrlspace#off() augroup airline_tabline_ctrlspace @@ -31,7 +32,6 @@ endfunction function! airline#extensions#tabline#ctrlspace#add_buffer_section(builder, cur_tab, cur_buf, pos) if a:pos == 0 - call a:builder.add_section_spaced('airline_tabtype', s:buffers_label) let pos_extension = '' else let pos_extension = '_right' @@ -58,15 +58,10 @@ function! airline#extensions#tabline#ctrlspace#add_buffer_section(builder, cur_t let buf_name = '%(%{airline#extensions#tabline#get_buffer_name('.buffer.index.')}%)' call a:builder.add_section_spaced(group, buf_name) endfor - - if a:pos == 1 - call a:builder.add_section_spaced('airline_tabtype', s:buffers_label) - endif endfunction function! airline#extensions#tabline#ctrlspace#add_tab_section(builder, pos) if a:pos == 0 - call a:builder.add_section_spaced('airline_tabtype', s:tabs_label) let pos_extension = '' else let pos_extension = '_right' @@ -89,10 +84,6 @@ function! airline#extensions#tabline#ctrlspace#add_tab_section(builder, pos) call a:builder.add_section_spaced(group, tab.title.ctrlspace#api#TabBuffersNumber(tab.index)) endfor - - if a:pos == 1 - call a:builder.add_section_spaced('airline_tabtype', s:tabs_label) - endif endfunction function! airline#extensions#tabline#ctrlspace#get() @@ -111,20 +102,34 @@ function! airline#extensions#tabline#ctrlspace#get() let builder = airline#extensions#tabline#new_builder() - if s:switch_buffers_and_tabs == 0 - call airline#extensions#tabline#ctrlspace#add_buffer_section(builder, cur_tab, cur_buf, 0) + " Add left tabline content + if s:show_buffers == 0 + call airline#extensions#tabline#ctrlspace#add_tab_section(builder, 0) else - call airline#extensions#tabline#ctrlspace#add_tab_section(builder, 0) + if s:switch_buffers_and_tabs == 0 + call builder.add_section_spaced('airline_tabtype', s:buffers_label) + call airline#extensions#tabline#ctrlspace#add_buffer_section(builder, cur_tab, cur_buf, 0) + else + call builder.add_section_spaced('airline_tabtype', s:tabs_label) + call airline#extensions#tabline#ctrlspace#add_tab_section(builder, 0) + endif endif call builder.add_section('airline_tabfill', '') call builder.split() call builder.add_section('airline_tabfill', '') - if s:switch_buffers_and_tabs == 0 - call airline#extensions#tabline#ctrlspace#add_tab_section(builder, 1) + " Add right tabline content + if s:show_buffers == 0 + call builder.add_section_spaced('airline_tabtype', s:tabs_label) else - call airline#extensions#tabline#ctrlspace#add_buffer_section(builder, cur_tab, cur_buf, 1) + if s:switch_buffers_and_tabs == 0 + call airline#extensions#tabline#ctrlspace#add_tab_section(builder, 1) + call builder.add_section_spaced('airline_tabtype', s:tabs_label) + else + call airline#extensions#tabline#ctrlspace#add_buffer_section(builder, cur_tab, cur_buf, 1) + call builder.add_section_spaced('airline_tabtype', s:buffers_label) + endif endif let s:current_bufnr = cur_buf From ab948735be2ac4abda07d9dd75dc532925970472 Mon Sep 17 00:00:00 2001 From: Kevin Sapper Date: Thu, 25 Feb 2016 11:35:52 +0100 Subject: [PATCH 3/3] Problem: Cannot disable tabs for ctrlspace tabline Solution: Implement the show_tabs option which is used by the default tabline. --- .../airline/extensions/tabline/ctrlspace.vim | 5 +++ doc/airline.txt | 33 ++++++++++--------- 2 files changed, 22 insertions(+), 16 deletions(-) diff --git a/autoload/airline/extensions/tabline/ctrlspace.vim b/autoload/airline/extensions/tabline/ctrlspace.vim index 946540dd..5b0ff59b 100644 --- a/autoload/airline/extensions/tabline/ctrlspace.vim +++ b/autoload/airline/extensions/tabline/ctrlspace.vim @@ -11,6 +11,7 @@ let s:buffers_label = get(g:, 'airline#extensions#tabline#buffers_label', 'buffe let s:tabs_label = get(g:, 'airline#extensions#tabline#tabs_label', 'tabs') let s:switch_buffers_and_tabs = get(g:, 'airline#extensions#tabline#switch_buffers_and_tabs', 0) let s:show_buffers = get(g:, 'airline#extensions#tabline#show_buffers', 1) +let s:show_tabs = get(g:, 'airline#extensions#tabline#show_tabs', 1) function! airline#extensions#tabline#ctrlspace#off() augroup airline_tabline_ctrlspace @@ -105,6 +106,8 @@ function! airline#extensions#tabline#ctrlspace#get() " Add left tabline content if s:show_buffers == 0 call airline#extensions#tabline#ctrlspace#add_tab_section(builder, 0) + elseif s:show_tabs == 0 + call airline#extensions#tabline#ctrlspace#add_buffer_section(builder, cur_tab, cur_buf, 0) else if s:switch_buffers_and_tabs == 0 call builder.add_section_spaced('airline_tabtype', s:buffers_label) @@ -122,6 +125,8 @@ function! airline#extensions#tabline#ctrlspace#get() " Add right tabline content if s:show_buffers == 0 call builder.add_section_spaced('airline_tabtype', s:tabs_label) + elseif s:show_tabs == 0 + call builder.add_section_spaced('airline_tabtype', s:buffers_label) else if s:switch_buffers_and_tabs == 0 call airline#extensions#tabline#ctrlspace#add_tab_section(builder, 1) diff --git a/doc/airline.txt b/doc/airline.txt index d123858d..80f16abe 100644 --- a/doc/airline.txt +++ b/doc/airline.txt @@ -489,16 +489,22 @@ eclim let g:airline#extensions#whitespace#trailing_regexp = '\s$' < ------------------------------------- *airline-tabline* -* enable/disable enhanced tabline. > +Note: If you're using the ctrlspace tabline only the option marked with (c) +are supported! + +* enable/disable enhanced tabline. (c) let g:airline#extensions#tabline#enabled = 0 -< + * enable/disable displaying open splits per tab (only when tabs are opened). > let g:airline#extensions#tabline#show_splits = 1 -< -* enable/disable displaying buffers with a single tab. > + * +* switch position of buffers and tabs on splited tabline (c) + let g:airline#extensions#tabline#switch_buffers_and_tabs = 0 + +* enable/disable displaying buffers with a single tab. (c) let g:airline#extensions#tabline#show_buffers = 1 < -* enable/disable displaying tabs, regardless of number. > +* enable/disable displaying tabs, regardless of number. (c) let g:airline#extensions#tabline#show_tabs = 1 < * configure filename match rules to exclude from the tabline. > @@ -518,18 +524,14 @@ eclim * enable/disable displaying tab type (far right) > let g:airline#extensions#tabline#show_tab_type = 1 -* enable/disable displaying index of the buffer. - - Note: If you're using ctrlspace the tabline shows your tabs on the right and - buffer on the left. Also none of the above tabline switches is currently - supported! - -* rename label for buffers (default: 'buffers') > +* rename label for buffers (default: 'buffers') (c) let g:airline#extensions#tabline#buffers_label = 'b' -* rename label for tabs (default: 'tabs') > +* rename label for tabs (default: 'tabs') (c) let g:airline#extensions#tabline#tabs_label = 't' -< + +* enable/disable displaying index of the buffer. + When enabled, numbers will be displayed in the tabline and mappings will be exposed to allow you to select a buffer directly. Up to 9 mappings will be exposed. > @@ -554,7 +556,7 @@ eclim Use |gt| for switching tabs. In tabmode, those mappings will switch to the specified tab. -* defines the name of a formatter for how buffer names are displayed. > +* defines the name of a formatter for how buffer names are displayed. (c) let g:airline#extensions#tabline#formatter = 'default' " here is how you can define a 'foo' formatter: @@ -623,7 +625,6 @@ eclim let airline#extensions#tabline#ignore_bufadd_pat = \ '\c\vgundo|undotree|vimfiler|tagbar|nerd_tree' -< Note: Enabling this extension will modify 'showtabline' and 'guioptions'. * enable Refresh of tabline buffers on |BufAdd| autocommands