buflist.vim 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. " MIT License. Copyright (c) 2013-2021 Bailey Ling et al.
  2. " vim: et ts=2 sts=2 sw=2
  3. scriptencoding utf-8
  4. function! airline#extensions#tabline#buflist#invalidate()
  5. unlet! s:current_buffer_list
  6. endfunction
  7. function! airline#extensions#tabline#buflist#clean()
  8. if !exists('#airline')
  9. " airline disabled
  10. return
  11. endif
  12. call airline#extensions#tabline#buflist#invalidate()
  13. call airline#extensions#tabline#buffers#invalidate()
  14. endfunction
  15. " paths in excludes list
  16. function! s:ExcludePaths(nr, exclude_paths)
  17. let bname = bufname(a:nr)
  18. if empty(bname)
  19. return 0
  20. endif
  21. let bpath = fnamemodify(bname, ":p")
  22. for f in a:exclude_paths
  23. if bpath =~# f | return 1 | endif
  24. endfor
  25. endfunction
  26. " other types to exclude
  27. function! s:ExcludeOther(nr, exclude_preview)
  28. if (getbufvar(a:nr, 'current_syntax') == 'qf') ||
  29. \ (a:exclude_preview && getbufvar(a:nr, '&bufhidden') == 'wipe'
  30. \ && getbufvar(a:nr, '&buftype') == 'nofile')
  31. return 1 | endif
  32. endfunction
  33. function! airline#extensions#tabline#buflist#list()
  34. if exists('s:current_buffer_list')
  35. return s:current_buffer_list
  36. endif
  37. let exclude_buffers = get(g:, 'airline#extensions#tabline#exclude_buffers', [])
  38. let exclude_paths = get(g:, 'airline#extensions#tabline#excludes', [])
  39. let exclude_preview = get(g:, 'airline#extensions#tabline#exclude_preview', 1)
  40. let list = (exists('g:did_bufmru') && g:did_bufmru) ? BufMRUList() : range(1, bufnr("$"))
  41. let buffers = []
  42. " If this is too slow, we can switch to a different algorithm.
  43. " Basically branch 535 already does it, but since it relies on
  44. " BufAdd autocommand, I'd like to avoid this if possible.
  45. for nr in list
  46. if buflisted(nr)
  47. " Do not add to the bufferlist, if either
  48. " 1) bufnr is exclude_buffers list
  49. " 2) buffername matches one of exclude_paths patterns
  50. " 3) buffer is a quickfix buffer
  51. " 4) when excluding preview windows:
  52. " 'bufhidden' == wipe
  53. " 'buftype' == nofile
  54. " 5) ignore buffers matching airline#extensions#tabline#ignore_bufadd_pat
  55. " check buffer numbers first
  56. if index(exclude_buffers, nr) >= 0
  57. continue
  58. " check paths second
  59. elseif !empty(exclude_paths) && s:ExcludePaths(nr, exclude_paths)
  60. continue
  61. " ignore buffers matching airline#extensions#tabline#ignore_bufadd_pat
  62. elseif airline#util#ignore_buf(bufname(nr))
  63. continue
  64. " check other types last
  65. elseif s:ExcludeOther(nr, exclude_preview)
  66. continue
  67. endif
  68. call add(buffers, nr)
  69. endif
  70. endfor
  71. let s:current_buffer_list = buffers
  72. return buffers
  73. endfunction