quickfix.vim 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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. if !exists('g:airline#extensions#quickfix#quickfix_text')
  5. let g:airline#extensions#quickfix#quickfix_text = 'Quickfix'
  6. endif
  7. if !exists('g:airline#extensions#quickfix#location_text')
  8. let g:airline#extensions#quickfix#location_text = 'Location'
  9. endif
  10. function! airline#extensions#quickfix#apply(...)
  11. if &buftype == 'quickfix'
  12. let w:airline_section_a = airline#extensions#quickfix#get_type()
  13. let w:airline_section_b = '%{get(w:, "quickfix_title", "")}'
  14. let w:airline_section_c = ''
  15. let w:airline_section_x = ''
  16. endif
  17. endfunction
  18. function! airline#extensions#quickfix#init(ext)
  19. call a:ext.add_statusline_func('airline#extensions#quickfix#apply')
  20. call a:ext.add_inactive_statusline_func('airline#extensions#quickfix#inactive_qf_window')
  21. endfunction
  22. function! airline#extensions#quickfix#inactive_qf_window(...)
  23. if getbufvar(a:2.bufnr, '&filetype') is# 'qf' && !empty(airline#util#getwinvar(a:2.winnr, 'quickfix_title', ''))
  24. call setwinvar(a:2.winnr, 'airline_section_c', '[%{get(w:, "quickfix_title", "")}] %f %m')
  25. endif
  26. endfunction
  27. function! airline#extensions#quickfix#get_type()
  28. if exists("*win_getid") && exists("*getwininfo")
  29. let dict = getwininfo(win_getid())
  30. if len(dict) > 0 && get(dict[0], 'quickfix', 0) && !get(dict[0], 'loclist', 0)
  31. return g:airline#extensions#quickfix#quickfix_text
  32. elseif len(dict) > 0 && get(dict[0], 'quickfix', 0) && get(dict[0], 'loclist', 0)
  33. return g:airline#extensions#quickfix#location_text
  34. endif
  35. endif
  36. redir => buffers
  37. silent ls
  38. redir END
  39. let nr = bufnr('%')
  40. for buf in split(buffers, '\n')
  41. if match(buf, '\v^\s*'.nr) > -1
  42. if match(buf, '\cQuickfix') > -1
  43. return g:airline#extensions#quickfix#quickfix_text
  44. else
  45. return g:airline#extensions#quickfix#location_text
  46. endif
  47. endif
  48. endfor
  49. return ''
  50. endfunction