From 8693a525b9b932341df6270a3c3e8a6a0cefffc6 Mon Sep 17 00:00:00 2001 From: Bailey Ling Date: Wed, 18 Feb 2015 18:48:47 -0500 Subject: [PATCH] extract buffer listing to its own file --- autoload/airline/extensions/tabline.vim | 40 +++---------------- .../airline/extensions/tabline/buflist.vim | 38 ++++++++++++++++++ 2 files changed, 43 insertions(+), 35 deletions(-) create mode 100644 autoload/airline/extensions/tabline/buflist.vim diff --git a/autoload/airline/extensions/tabline.vim b/autoload/airline/extensions/tabline.vim index 137314dc..91f124db 100644 --- a/autoload/airline/extensions/tabline.vim +++ b/autoload/airline/extensions/tabline.vim @@ -4,7 +4,6 @@ scriptencoding utf-8 let s:formatter = get(g:, 'airline#extensions#tabline#formatter', 'default') -let s:excludes = get(g:, 'airline#extensions#tabline#excludes', []) let s:tab_nr_type = get(g:, 'airline#extensions#tabline#tab_nr_type', 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) @@ -65,8 +64,8 @@ function! s:toggle_on() set showtabline=2 else if s:show_buffers == 1 - autocmd BufEnter * call show_tabline(s:buf_min_count, len(s:get_buffer_list())) - autocmd BufUnload * call show_tabline(s:buf_min_count, len(s:get_buffer_list()) - 1) + autocmd BufEnter * call show_tabline(s:buf_min_count, len(airline#extensions#tabline#buflist#list())) + autocmd BufUnload * call show_tabline(s:buf_min_count, len(airline#extensions#tabline#buflist#list()) - 1) else autocmd TabEnter * call show_tabline(s:tab_min_count, tabpagenr('$')) endif @@ -74,7 +73,7 @@ function! s:toggle_on() " Invalidate cache. This has to come after the BufUnload for " s:show_buffers, to invalidate the cache for BufEnter. - autocmd BufAdd,BufUnload * unlet! s:current_buffer_list + autocmd BufAdd,BufUnload * call airline#extensions#tabline#buflist#invalidate() augroup END endfunction @@ -134,40 +133,11 @@ function! airline#extensions#tabline#title(n) endfunction function! airline#extensions#tabline#get_buffer_name(nr) - return airline#extensions#tabline#formatters#{s:formatter}#format(a:nr, s:get_buffer_list()) -endfunction - -function! s:get_buffer_list() - if exists('s:current_buffer_list') - return s:current_buffer_list - endif - - let buffers = [] - let cur = bufnr('%') - for nr in range(1, bufnr('$')) - if buflisted(nr) && bufexists(nr) - let toadd = 1 - for ex in s:excludes - if match(bufname(nr), ex) >= 0 - let toadd = 0 - break - endif - endfor - if getbufvar(nr, 'current_syntax') == 'qf' - let toadd = 0 - endif - if toadd - call add(buffers, nr) - endif - endif - endfor - - let s:current_buffer_list = buffers - return buffers + return airline#extensions#tabline#formatters#{s:formatter}#format(a:nr, airline#extensions#tabline#buflist#list()) endfunction function! s:get_visible_buffers() - let buffers = s:get_buffer_list() + let buffers = airline#extensions#tabline#buflist#list() let cur = bufnr('%') let total_width = 0 diff --git a/autoload/airline/extensions/tabline/buflist.vim b/autoload/airline/extensions/tabline/buflist.vim new file mode 100644 index 00000000..95873ba6 --- /dev/null +++ b/autoload/airline/extensions/tabline/buflist.vim @@ -0,0 +1,38 @@ +" MIT License. Copyright (c) 2013-2015 Bailey Ling. +" vim: et ts=2 sts=2 sw=2 + +let s:excludes = get(g:, 'airline#extensions#tabline#excludes', []) + +function! airline#extensions#tabline#buflist#invalidate() + unlet! s:current_buffer_list +endfunction + +function! airline#extensions#tabline#buflist#list() + if exists('s:current_buffer_list') + return s:current_buffer_list + endif + + let buffers = [] + let cur = bufnr('%') + for nr in range(1, bufnr('$')) + if buflisted(nr) && bufexists(nr) + let toadd = 1 + for ex in s:excludes + if match(bufname(nr), ex) >= 0 + let toadd = 0 + break + endif + endfor + if getbufvar(nr, 'current_syntax') == 'qf' + let toadd = 0 + endif + if toadd + call add(buffers, nr) + endif + endif + endfor + + let s:current_buffer_list = buffers + return buffers +endfunction +