From 92bf1b0b399f8154c5e849dc4f78b33b7a6b6462 Mon Sep 17 00:00:00 2001 From: Hana Shiro Date: Sat, 2 Jun 2018 13:02:49 +0800 Subject: [PATCH 1/6] Use ternary-operator --- .../airline/extensions/tabline/ctrlspace.vim | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/autoload/airline/extensions/tabline/ctrlspace.vim b/autoload/airline/extensions/tabline/ctrlspace.vim index 357bcd7..39ab23a 100644 --- a/autoload/airline/extensions/tabline/ctrlspace.vim +++ b/autoload/airline/extensions/tabline/ctrlspace.vim @@ -26,16 +26,14 @@ function! airline#extensions#tabline#ctrlspace#invalidate() endfunction function! airline#extensions#tabline#ctrlspace#add_buffer_section(builder, cur_tab, cur_buf, pos) - if a:pos == 0 - let pos_extension = '' - else - let pos_extension = '_right' - endif + let pos_extension = (a:pos == 0) + \ ? '' + \ : '_right' let s:buffer_list = ctrlspace#api#BufferList(a:cur_tab) " add by tenfy(tenfyzhong@qq.com) " if the current buffer no in the buffer list - " return false and no redraw tabline. + " return false and no redraw tabline. " Fixes #1515. if there a BufEnter autocmd execute redraw. The tabline may no update. let bufnr_list = map(copy(s:buffer_list), 'v:val["index"]') if index(bufnr_list, a:cur_buf) == -1 @@ -74,11 +72,9 @@ function! airline#extensions#tabline#ctrlspace#add_buffer_section(builder, cur_t endfunction function! airline#extensions#tabline#ctrlspace#add_tab_section(builder, pos) - if a:pos == 0 - let pos_extension = '' - else - let pos_extension = '_right' - endif + let pos_extension = (a:pos == 0) + \ ? '' + \ : '_right' for tab in s:tab_list if tab.current From ac799f6021cc9988d3de690b259b73daa5645d6d Mon Sep 17 00:00:00 2001 From: Hana Shiro Date: Sat, 2 Jun 2018 13:49:32 +0800 Subject: [PATCH 2/6] Rename parameters for better readability --- autoload/airline/extensions/tabline/ctrlspace.vim | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/autoload/airline/extensions/tabline/ctrlspace.vim b/autoload/airline/extensions/tabline/ctrlspace.vim index 39ab23a..4cad3a3 100644 --- a/autoload/airline/extensions/tabline/ctrlspace.vim +++ b/autoload/airline/extensions/tabline/ctrlspace.vim @@ -25,10 +25,8 @@ 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) - let pos_extension = (a:pos == 0) - \ ? '' - \ : '_right' +function! airline#extensions#tabline#ctrlspace#add_buffer_section(builder, cur_tab, cur_buf, pull_right) + let pos_extension = (a:pull_right ? '_right' : '') let s:buffer_list = ctrlspace#api#BufferList(a:cur_tab) " add by tenfy(tenfyzhong@qq.com) @@ -71,10 +69,8 @@ function! airline#extensions#tabline#ctrlspace#add_buffer_section(builder, cur_t return 1 endfunction -function! airline#extensions#tabline#ctrlspace#add_tab_section(builder, pos) - let pos_extension = (a:pos == 0) - \ ? '' - \ : '_right' +function! airline#extensions#tabline#ctrlspace#add_tab_section(builder, pull_right) + let pos_extension = (a:pull_right ? '_right' : '') for tab in s:tab_list if tab.current From 4db6d11962b7c8832937aa364a014518fb0a68bc Mon Sep 17 00:00:00 2001 From: Hana Shiro Date: Sat, 2 Jun 2018 13:59:08 +0800 Subject: [PATCH 3/6] Fix indentation --- .../airline/extensions/tabline/ctrlspace.vim | 54 +++++++++---------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/autoload/airline/extensions/tabline/ctrlspace.vim b/autoload/airline/extensions/tabline/ctrlspace.vim index 4cad3a3..6eaf68e 100644 --- a/autoload/airline/extensions/tabline/ctrlspace.vim +++ b/autoload/airline/extensions/tabline/ctrlspace.vim @@ -39,29 +39,29 @@ function! airline#extensions#tabline#ctrlspace#add_buffer_section(builder, cur_t endif 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 + if a:cur_buf == buffer.index + if buffer.modified + let group = 'airline_tabmod'.pos_extension 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 + let group = 'airline_tabsel'.pos_extension endif - - let buf_name = '%(%{airline#extensions#tabline#get_buffer_name('.buffer.index.')}%)' - - if has("tablineat") - let buf_name = '%'.buffer.index.'@airline#extensions#tabline#buffers#clickbuf@'.buf_name.'%X' + 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 - call a:builder.add_section_spaced(group, buf_name) + let buf_name = '%(%{airline#extensions#tabline#get_buffer_name('.buffer.index.')}%)' + + if has("tablineat") + let buf_name = '%'.buffer.index.'@airline#extensions#tabline#buffers#clickbuf@'.buf_name.'%X' + endif + + call a:builder.add_section_spaced(group, buf_name) endfor " add by tenfy(tenfyzhong@qq.com) " if the selected buffer was updated @@ -117,13 +117,13 @@ function! airline#extensions#tabline#ctrlspace#get() " Add left tabline content if get(g:, 'airline#extensions#tabline#show_buffers', 1) == 0 - call airline#extensions#tabline#ctrlspace#add_tab_section(builder, 0) + call airline#extensions#tabline#ctrlspace#add_tab_section(builder, 0) elseif get(g:, 'airline#extensions#tabline#show_tabs', 1) == 0 - " add by tenfy(tenfyzhong@qq.com) - " if current buffer no in the buffer list, does't update tabline - if airline#extensions#tabline#ctrlspace#add_buffer_section(builder, cur_tab, cur_buf, 0) == 0 - return s:current_tabline - endif + " add by tenfy(tenfyzhong@qq.com) + " if current buffer no in the buffer list, does't update tabline + if airline#extensions#tabline#ctrlspace#add_buffer_section(builder, cur_tab, cur_buf, 0) == 0 + return s:current_tabline + endif else if switch_buffers_and_tabs == 0 call builder.add_section_spaced('airline_tabtype', buffer_label) @@ -144,9 +144,9 @@ function! airline#extensions#tabline#ctrlspace#get() " Add right tabline content if get(g:, 'airline#extensions#tabline#show_buffers', 1) == 0 - call builder.add_section_spaced('airline_tabtype', tab_label) + call builder.add_section_spaced('airline_tabtype', tab_label) elseif get(g:, 'airline#extensions#tabline#show_tabs', 1) == 0 - call builder.add_section_spaced('airline_tabtype', buffer_label) + call builder.add_section_spaced('airline_tabtype', buffer_label) else if switch_buffers_and_tabs == 0 call airline#extensions#tabline#ctrlspace#add_tab_section(builder, 1) From a6e07b6a55a43efba179e58effcbe6766731d9da Mon Sep 17 00:00:00 2001 From: Hana Shiro Date: Sat, 2 Jun 2018 14:04:25 +0800 Subject: [PATCH 4/6] Remove unused catch block --- autoload/airline/extensions/tabline/ctrlspace.vim | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/autoload/airline/extensions/tabline/ctrlspace.vim b/autoload/airline/extensions/tabline/ctrlspace.vim index 6eaf68e..75a6e7e 100644 --- a/autoload/airline/extensions/tabline/ctrlspace.vim +++ b/autoload/airline/extensions/tabline/ctrlspace.vim @@ -99,9 +99,8 @@ function! airline#extensions#tabline#ctrlspace#get() try call airline#extensions#tabline#tabs#map_keys() - catch - " no-op endtry + let s:tab_list = ctrlspace#api#TabList() for tab in s:tab_list if tab.current From 6e1e6686e73e01b7843bfb8706eb09730cfee345 Mon Sep 17 00:00:00 2001 From: Hana Shiro Date: Sat, 2 Jun 2018 21:22:00 +0800 Subject: [PATCH 5/6] Fix problems caused by #1524 --- autoload/airline/extensions/tabline/ctrlspace.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/autoload/airline/extensions/tabline/ctrlspace.vim b/autoload/airline/extensions/tabline/ctrlspace.vim index 75a6e7e..9222ef7 100644 --- a/autoload/airline/extensions/tabline/ctrlspace.vim +++ b/autoload/airline/extensions/tabline/ctrlspace.vim @@ -34,7 +34,7 @@ function! airline#extensions#tabline#ctrlspace#add_buffer_section(builder, cur_t " return false and no redraw tabline. " Fixes #1515. if there a BufEnter autocmd execute redraw. The tabline may no update. let bufnr_list = map(copy(s:buffer_list), 'v:val["index"]') - if index(bufnr_list, a:cur_buf) == -1 + if index(bufnr_list, a:cur_buf) == -1 && a:cur_tab == s:current_tabnr return 0 endif From c7d4710f76096514eaddcbf9096e4f4053191642 Mon Sep 17 00:00:00 2001 From: Hana Shiro Date: Sat, 2 Jun 2018 23:41:15 +0800 Subject: [PATCH 6/6] Refactor airline#extentions#tabline#ctrlspace#* --- .../airline/extensions/tabline/ctrlspace.vim | 116 ++++++++---------- 1 file changed, 48 insertions(+), 68 deletions(-) diff --git a/autoload/airline/extensions/tabline/ctrlspace.vim b/autoload/airline/extensions/tabline/ctrlspace.vim index 9222ef7..941f792 100644 --- a/autoload/airline/extensions/tabline/ctrlspace.vim +++ b/autoload/airline/extensions/tabline/ctrlspace.vim @@ -6,6 +6,7 @@ scriptencoding utf-8 let s:current_bufnr = -1 let s:current_tabnr = -1 let s:current_tabline = '' +let s:highlight_groups = ['hid', 0, '', 'sel', 'mod_unsel', 0, 'mod_unsel', 'mod'] function! airline#extensions#tabline#ctrlspace#off() augroup airline_tabline_ctrlspace @@ -27,33 +28,21 @@ endfunction function! airline#extensions#tabline#ctrlspace#add_buffer_section(builder, cur_tab, cur_buf, pull_right) let pos_extension = (a:pull_right ? '_right' : '') + let buffer_list = ctrlspace#api#BufferList(a:cur_tab) - let s:buffer_list = ctrlspace#api#BufferList(a:cur_tab) " add by tenfy(tenfyzhong@qq.com) " if the current buffer no in the buffer list " return false and no redraw tabline. " Fixes #1515. if there a BufEnter autocmd execute redraw. The tabline may no update. - let bufnr_list = map(copy(s:buffer_list), 'v:val["index"]') + let bufnr_list = map(copy(buffer_list), 'v:val["index"]') if index(bufnr_list, a:cur_buf) == -1 && a:cur_tab == s:current_tabnr return 0 endif - 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 + for buffer in buffer_list + let group = 'airline_tab' + \ .s:highlight_groups[(4 * buffer.modified) + (2 * buffer.visible) + (a:cur_buf == buffer.index)] + \ .pos_extension let buf_name = '%(%{airline#extensions#tabline#get_buffer_name('.buffer.index.')}%)' @@ -71,21 +60,12 @@ endfunction function! airline#extensions#tabline#ctrlspace#add_tab_section(builder, pull_right) let pos_extension = (a:pull_right ? '_right' : '') + let tab_list = ctrlspace#api#TabList() - 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 + for tab in tab_list + let group = 'airline_tab' + \ .s:highlight_groups[(4 * tab.modified) + (3 * tab.current)] + \ .pos_extension call a:builder.add_section_spaced(group, '%'.tab.index.'T'.tab.title.ctrlspace#api#TabBuffersNumber(tab.index).'%T') endfor @@ -101,12 +81,7 @@ function! airline#extensions#tabline#ctrlspace#get() call airline#extensions#tabline#tabs#map_keys() endtry - let s:tab_list = ctrlspace#api#TabList() - for tab in s:tab_list - if tab.current - let cur_tab = tab.index - endif - endfor + let cur_tab = tabpagenr() if cur_buf == s:current_bufnr && cur_tab == s:current_tabnr return s:current_tabline @@ -114,52 +89,57 @@ function! airline#extensions#tabline#ctrlspace#get() let builder = airline#extensions#tabline#new_builder() + let show_buffers = get(g:, 'airline#extensions#tabline#show_buffers', 1) + let show_tabs = get(g:, 'airline#extensions#tabline#show_tabs', 1) + + let AppendBuffers = function('airline#extensions#tabline#ctrlspace#add_buffer_section', [builder, cur_tab, cur_buf]) + let AppendTabs = function('airline#extensions#tabline#ctrlspace#add_tab_section', [builder]) + let AppendLabel = function(builder.add_section_spaced, ['airline_tabtype'], builder) + + " <= 1: |{Tabs} {Buffers} {Tabs}