Changed buflist.vim algorithm

This commit is contained in:
mg979 2018-03-03 23:39:14 +01:00
parent 55a9721c22
commit 3ebbc57725
1 changed files with 35 additions and 10 deletions

View File

@ -12,11 +12,28 @@ function! airline#extensions#tabline#buflist#list()
return s:current_buffer_list return s:current_buffer_list
endif endif
let excludes = get(g:, 'airline#extensions#tabline#excludes', []) let s:exclude_buffers = get(g:, 'airline#extensions#tabline#exclude_buffers', [])
let exclude_preview = get(g:, 'airline#extensions#tabline#exclude_preview', 1) let s:exclude_paths = get(g:, 'airline#extensions#tabline#exclude_paths', [])
let s:exclude_preview = get(g:, 'airline#extensions#tabline#exclude_preview', 1)
let list = (exists('g:did_bufmru') && g:did_bufmru) ? BufMRUList() : range(1, bufnr("$")) let list = (exists('g:did_bufmru') && g:did_bufmru) ? BufMRUList() : range(1, bufnr("$"))
" paths in excludes list
fun! s:ExcludePaths(nr)
let bpath = fnamemodify(bufname(a:nr), ":p")
for f in s:exclude_paths
if bpath =~ fnamemodify(f, ":p") | return 1 | endif
endfor
endfun
" other types to exclude
fun! s:ExcludeOther(nr)
if (getbufvar(a:nr, 'current_syntax') == 'qf') ||
\ (s:exclude_preview && getbufvar(a:nr, '&bufhidden') == 'wipe'
\ && getbufvar(a:nr, '&buftype') == 'nofile')
return 1 | endif
endfun
let buffers = [] let buffers = []
" If this is too slow, we can switch to a different algorithm. " If this is too slow, we can switch to a different algorithm.
" Basically branch 535 already does it, but since it relies on " Basically branch 535 already does it, but since it relies on
@ -24,16 +41,24 @@ function! airline#extensions#tabline#buflist#list()
for nr in list for nr in list
if buflisted(nr) if buflisted(nr)
" Do not add to the bufferlist, if either " Do not add to the bufferlist, if either
" 1) buffername matches exclude pattern " 1) bufnr is exclude_buffers list
" 2) buffer is a quickfix buffer " 2) buffername matches one of exclude_paths patterns
" 3) exclude preview windows (if 'bufhidden' == wipe " 3) buffer is a quickfix buffer
" and 'buftype' == nofile " 4) when excluding preview windows:
if (!empty(excludes) && match(bufname(nr), join(excludes, '\|')) > -1) || " 'bufhidden' == wipe
\ (getbufvar(nr, 'current_syntax') == 'qf') || " 'buftype' == nofile
\ (exclude_preview && getbufvar(nr, '&bufhidden') == 'wipe'
\ && getbufvar(nr, '&buftype') == 'nofile') " check buffer numbers first
if index(s:exclude_buffers, nr) >= 0
continue
" check paths second
elseif !empty(s:exclude_paths) && s:ExcludePaths(nr)
continue
" check other types last
elseif s:ExcludeOther(nr)
continue continue
endif endif
call add(buffers, nr) call add(buffers, nr)
endif endif
endfor endfor