add inactive statusline funcrefs into the pipeline.

This commit is contained in:
Bailey Ling 2013-08-24 09:31:30 -04:00
parent 04daa66b48
commit f6d8a981b6
3 changed files with 24 additions and 8 deletions

View File

@ -5,6 +5,7 @@ let g:airline_statusline_funcrefs = get(g:, 'airline_statusline_funcrefs', [])
let s:sections = ['a','b','c','gutter','x','y','z','warning'] let s:sections = ['a','b','c','gutter','x','y','z','warning']
let s:highlighter = airline#highlighter#new() let s:highlighter = airline#highlighter#new()
let s:inactive_funcrefs = []
function! airline#add_statusline_func(name) function! airline#add_statusline_func(name)
call airline#add_statusline_funcref(function(a:name)) call airline#add_statusline_funcref(function(a:name))
@ -21,6 +22,10 @@ function! airline#remove_statusline_func(name)
endif endif
endfunction endfunction
function! airline#add_inactive_statusline_func(name)
call add(s:inactive_funcrefs, function(a:name))
endfunction
function! airline#load_theme() function! airline#load_theme()
call s:highlighter.load_theme() call s:highlighter.load_theme()
call airline#extensions#load_theme() call airline#extensions#load_theme()
@ -96,25 +101,27 @@ function! airline#update_statusline()
for nr in filter(range(1, winnr('$')), 'v:val != winnr()') for nr in filter(range(1, winnr('$')), 'v:val != winnr()')
call setwinvar(nr, 'airline_active', 0) call setwinvar(nr, 'airline_active', 0)
let context = { 'winnr': nr, 'active': 0 } let context = { 'winnr': nr, 'active': 0 }
let builder = airline#builder#new(context, s:highlighter) call s:invoke_funcrefs(context, s:inactive_funcrefs)
call setwinvar(nr, '&statusline', airline#get_statusline(builder, nr, 0))
endfor endfor
let w:airline_active = 1
unlet! w:airline_render_left unlet! w:airline_render_left
unlet! w:airline_render_right unlet! w:airline_render_right
for section in s:sections for section in s:sections
unlet! w:airline_section_{section} unlet! w:airline_section_{section}
endfor endfor
let w:airline_active = 1
let context = { 'winnr': winnr(), 'active': 1 } let context = { 'winnr': winnr(), 'active': 1 }
let builder = airline#builder#new(context, s:highlighter) call s:invoke_funcrefs(context, g:airline_statusline_funcrefs)
let err = airline#util#exec_funcrefs(g:airline_statusline_funcrefs, builder) endfunction
function! s:invoke_funcrefs(context, funcrefs)
let builder = airline#builder#new(a:context, s:highlighter)
let err = airline#util#exec_funcrefs(a:funcrefs, builder, a:context)
if err == 0 if err == 0
call setwinvar(winnr(), '&statusline', airline#get_statusline(builder, winnr(), 1)) call setwinvar(a:context.winnr, '&statusline', airline#get_statusline(builder, a:context.winnr, a:context.active))
elseif err == 1 elseif err == 1
call setwinvar(winnr(), '&statusline', builder.build()) call setwinvar(a:context.winnr, '&statusline', builder.build())
endif endif
endfunction endfunction

View File

@ -8,6 +8,9 @@ endfunction
function! s:ext.add_statusline_funcref(function) dict function! s:ext.add_statusline_funcref(function) dict
call airline#add_statusline_funcref(a:function) call airline#add_statusline_funcref(a:function)
endfunction endfunction
function! s:ext.add_inactive_statusline_func(name) dict
call airline#add_inactive_statusline_func(a:name)
endfunction
let s:script_path = expand('<sfile>:p:h') let s:script_path = expand('<sfile>:p:h')

View File

@ -302,6 +302,12 @@ statuslines to your liking. Here is an example: >
< <
The second variable is the context, which is a dictionary containing various The second variable is the context, which is a dictionary containing various
values such as whether the statusline is active or not, and the window number. values such as whether the statusline is active or not, and the window number.
>
context = {
'winnr': 'the window number for the statusline',
'active': 'whether the window is active or not',
}
<
*airline-pipeline-return-codes* *airline-pipeline-return-codes*
The pipeline accepts various return codes and can be used to determine the The pipeline accepts various return codes and can be used to determine the