vim-airline/autoload/airline/extensions/tabline/buflist.vim

69 lines
2.1 KiB
VimL
Raw Normal View History

2018-01-05 09:37:59 +00:00
" MIT License. Copyright (c) 2013-2018 Bailey Ling et al.
2015-02-18 23:48:47 +00:00
" vim: et ts=2 sts=2 sw=2
scriptencoding utf-8
2015-02-18 23:48:47 +00:00
function! airline#extensions#tabline#buflist#invalidate()
unlet! s:current_buffer_list
endfunction
" paths in excludes list
function! s:ExcludePaths(nr, exclude_paths)
let bpath = fnamemodify(bufname(a:nr), ":p")
for f in a:exclude_paths
if bpath =~# f | return 1 | endif
endfor
endfunction
" other types to exclude
function! s:ExcludeOther(nr, exclude_preview)
if (getbufvar(a:nr, 'current_syntax') == 'qf') ||
\ (a:exclude_preview && getbufvar(a:nr, '&bufhidden') == 'wipe'
\ && getbufvar(a:nr, '&buftype') == 'nofile')
return 1 | endif
endfunction
2015-02-18 23:48:47 +00:00
function! airline#extensions#tabline#buflist#list()
if exists('s:current_buffer_list')
return s:current_buffer_list
endif
let exclude_buffers = get(g:, 'airline#extensions#tabline#exclude_buffers', [])
let exclude_paths = get(g:, 'airline#extensions#tabline#excludes', [])
let exclude_preview = get(g:, 'airline#extensions#tabline#exclude_preview', 1)
2016-02-16 20:16:55 +00:00
let list = (exists('g:did_bufmru') && g:did_bufmru) ? BufMRUList() : range(1, bufnr("$"))
2015-02-18 23:48:47 +00:00
let buffers = []
" If this is too slow, we can switch to a different algorithm.
" Basically branch 535 already does it, but since it relies on
" BufAdd autocommand, I'd like to avoid this if possible.
2016-02-16 20:16:55 +00:00
for nr in list
if buflisted(nr)
" Do not add to the bufferlist, if either
2018-03-03 22:39:14 +00:00
" 1) bufnr is exclude_buffers list
" 2) buffername matches one of exclude_paths patterns
" 3) buffer is a quickfix buffer
" 4) when excluding preview windows:
" 'bufhidden' == wipe
" 'buftype' == nofile
" check buffer numbers first
if index(exclude_buffers, nr) >= 0
2018-03-03 22:39:14 +00:00
continue
" check paths second
elseif !empty(exclude_paths) && s:ExcludePaths(nr, exclude_paths)
2018-03-03 22:39:14 +00:00
continue
" check other types last
elseif s:ExcludeOther(nr, exclude_preview)
continue
2015-02-18 23:48:47 +00:00
endif
2018-03-03 22:39:14 +00:00
call add(buffers, nr)
2015-02-18 23:48:47 +00:00
endif
endfor
let s:current_buffer_list = buffers
return buffers
endfunction