fold exclude funcrefs into the default one.

This commit is contained in:
Bailey Ling 2013-08-22 03:25:22 +00:00
parent e83e12447e
commit 261dafca9d
5 changed files with 21 additions and 28 deletions

View File

@ -73,11 +73,6 @@ function! airline#get_statusline(winnr, active)
endfunction
function! airline#update_statusline()
if airline#util#exec_funcrefs(g:airline_exclude_funcrefs)
call setwinvar(winnr(), '&statusline', '')
return
endif
for nr in filter(range(1, winnr('$')), 'v:val != winnr()')
call setwinvar(nr, 'airline_active', 0)
call setwinvar(nr, '&statusline', airline#get_statusline(nr, 0))
@ -90,9 +85,11 @@ function! airline#update_statusline()
for section in s:sections
unlet! w:airline_section_{section}
endfor
call airline#util#exec_funcrefs(g:airline_statusline_funcrefs)
let err = airline#util#exec_funcrefs(g:airline_statusline_funcrefs)
if err == 0
call setwinvar(winnr(), '&statusline', airline#get_statusline(winnr(), 1))
endif
endfunction
function! airline#check_mode()

View File

@ -2,13 +2,9 @@
" vim: et ts=2 sts=2 sw=2
let s:ext = {}
let s:ext._cursormove_funcrefs = []
function! s:ext.add_statusline_funcref(funcref) dict
call add(g:airline_statusline_funcrefs, a:funcref)
endfunction
function! s:ext.add_cursormove_funcref(funcref) dict
call add(self._cursormove_funcrefs, a:funcref)
endfunction
let s:script_path = expand('<sfile>:p:h')
@ -35,6 +31,10 @@ endfunction
let s:active_winnr = -1
function! airline#extensions#update_statusline(...)
if s:is_excluded_window(a:000)
return -1
endif
let s:active_winnr = winnr()
if &buftype == 'quickfix'
@ -67,7 +67,7 @@ function! airline#extensions#update_statusline(...)
endfor
endfunction
function! airline#extensions#is_excluded_window(...)
function! s:is_excluded_window(...)
for matchft in g:airline_exclude_filetypes
if matchft ==# &ft
return 1
@ -95,9 +95,6 @@ endfunction
function! s:sync_active_winnr()
if exists('#airline') && winnr() != s:active_winnr
if airline#util#exec_funcrefs(s:ext._cursormove_funcrefs)
return
endif
call airline#update_statusline()
endif
endfunction
@ -107,7 +104,6 @@ function! airline#extensions#load()
autocmd CursorMoved * call <sid>sync_active_winnr()
" load core funcrefs
call add(g:airline_exclude_funcrefs, function('airline#extensions#is_excluded_window'))
call add(g:airline_statusline_funcrefs, function('airline#extensions#update_statusline'))
if get(g:, 'loaded_unite', 0)

View File

@ -49,8 +49,9 @@ function! airline#extensions#ctrlp#ctrlp_airline_status(...)
return len.dir
endfunction
function! airline#extensions#ctrlp#is_statusline_overwritten(...)
return match(&statusline, 'CtrlPlight') >= 0
function! airline#extensions#ctrlp#apply(...)
" disable statusline overwrite if ctrlp already did it
return match(&statusline, 'CtrlPlight') >= 0 ? -1 : 0
endfunction
function! airline#extensions#ctrlp#init(ext)
@ -58,6 +59,6 @@ function! airline#extensions#ctrlp#init(ext)
\ 'main': 'airline#extensions#ctrlp#ctrlp_airline',
\ 'prog': 'airline#extensions#ctrlp#ctrlp_airline_status',
\ }
call a:ext.add_cursormove_funcref(function('airline#extensions#ctrlp#is_statusline_overwritten'))
call a:ext.add_statusline_funcref(function('airline#extensions#ctrlp#apply'))
endfunction

View File

@ -259,15 +259,15 @@ is an example of how you can extend vim-airline to support a new plugin.
endfunction
call add(g:airline_statusline_funcrefs, function('MyPlugin'))
<
*g:airline_exclude_funcrefs*
The g:airline_exclude_funcrefs variable is an array that's returns 1 or 0 to
determine whether that particular window should be excluded from having its
statusline modified. Here is an example:
You can also control what happens by returning an error code. Note that
returning a value other than 0 will prevent any remaining extensions from
having their funcrefs invoked.
>
function! ExcludeFoo()
return &filetype == 'FooType'
function! MyPlugin(...)
return 0 " the default action, modify the statusline
return -1 " do not update the statusline
endfunction
call add(g:airline_exclude_funcrefs, function('ExcludeFoo'))
<
==============================================================================

View File

@ -25,7 +25,6 @@ call s:check_defined('g:airline_exclude_filenames', ['DebuggerWatch','DebuggerSt
call s:check_defined('g:airline_exclude_filetypes', [])
call s:check_defined('g:airline_exclude_preview', 0)
call s:check_defined('g:airline_statusline_funcrefs', [])
call s:check_defined('g:airline_exclude_funcrefs', [])
call s:check_defined('g:airline_mode_map', {
\ '__' : '------',
@ -90,7 +89,7 @@ function! s:on_colorscheme_changed()
call airline#load_theme()
endfunction
function airline#cmdwinenter()
function airline#cmdwinenter(...)
call airline#extensions#apply_left_override('Command Line', '')
endfunction