detect whether quickfix or location list is open.

This commit is contained in:
Bailey Ling 2013-10-21 13:22:07 -04:00
parent 592cc412cf
commit dd2be8ac8d
3 changed files with 52 additions and 6 deletions

View File

@ -63,12 +63,7 @@ function! airline#extensions#apply(...)
return -1
endif
if &buftype == 'quickfix'
let w:airline_section_a = '%q'
let w:airline_section_b = '%{get(w:, "quickfix_title", "")}'
let w:airline_section_c = ''
let w:airline_section_x = ''
elseif &buftype == 'help'
if &buftype == 'help'
call airline#extensions#apply_left_override('Help', '%f')
let w:airline_section_x = ''
let w:airline_section_y = ''
@ -127,6 +122,8 @@ function! airline#extensions#load()
" non-trivial number of external plugins use eventignore=all, so we need to account for that
autocmd CursorMoved * call <sid>sync_active_winnr()
call airline#extensions#quickfix#init(s:ext)
if get(g:, 'loaded_unite', 0)
call airline#extensions#unite#init(s:ext)
endif

View File

@ -0,0 +1,37 @@
" MIT License. Copyright (c) 2013 Bailey Ling.
" vim: et ts=2 sts=2 sw=2
let g:airline#extensions#quickfix#quickfix_text = 'Quickfix'
let g:airline#extensions#quickfix#location_text = 'Location'
function! airline#extensions#quickfix#apply(...)
if &buftype == 'quickfix'
let w:airline_section_a = s:get_text()
let w:airline_section_b = '%{get(w:, "quickfix_title", "")}'
let w:airline_section_c = ''
let w:airline_section_x = ''
endif
endfunction
function! airline#extensions#quickfix#init(ext)
call a:ext.add_statusline_func('airline#extensions#quickfix#apply')
endfunction
function! s:get_text()
redir => buffers
silent ls
redir END
let nr = bufnr('%')
for buf in split(buffers, '\n')
if match(buf, '\v^\s+'.nr) > -1
if match(buf, '\[Quickfix List\]') > -1
return g:airline#extensions#quickfix#quickfix_text
else
return g:airline#extensions#quickfix#location_text
endif
endif
endfor
return ''
endfunction

View File

@ -233,6 +233,18 @@ configuration values that you can use.
" Note: set to an empty dictionary to disable truncation.
let g:airline#extensions#default#section_truncate_width = {}
<
------------------------------------- *airline-quickfix*
The quickfix extension is a simple built-in extension which determines
whether the buffer is a quickfix or location list buffer, and adjusts the
title accordingly.
* configure the title text for quickfix buffers >
let g:airline#extensions#quickfix#quickfix_text = 'Quickfix'
<
* configure the title text for location list buffers >
let g:airline#extensions#quickfix#location_text = 'Location'
<
------------------------------------- *airline-bufferline*
vim-bufferline <https://github.com/bling/vim-bufferline>