From c7d4710f76096514eaddcbf9096e4f4053191642 Mon Sep 17 00:00:00 2001 From: Hana Shiro Date: Sat, 2 Jun 2018 23:41:15 +0800 Subject: [PATCH] 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}