From 301fcdc64ad786164478580ad3fe810dbf6bc80a Mon Sep 17 00:00:00 2001 From: Bailey Ling Date: Mon, 2 Sep 2013 18:55:15 +0000 Subject: [PATCH] use statusline function for better control. --- autoload/airline.vim | 11 +++++++---- autoload/airline/builder.vim | 2 +- t/airline.vim | 11 ++++++----- t/builder.vim | 4 ++-- t/extensions_default.vim | 4 ++-- 5 files changed, 18 insertions(+), 14 deletions(-) diff --git a/autoload/airline.vim b/autoload/airline.vim index 202920ad..4d1eb785 100644 --- a/autoload/airline.vim +++ b/autoload/airline.vim @@ -43,7 +43,6 @@ function! airline#switch_theme(name) let w:airline_lastmode = '' call airline#update_statusline() call airline#load_theme() - call airline#check_mode() endfunction function! airline#switch_matching_theme() @@ -82,6 +81,7 @@ function! airline#update_statusline() call s:invoke_funcrefs(context, g:airline_statusline_funcrefs) endfunction +let s:contexts = {} let s:core_funcrefs = [ \ function('airline#extensions#apply'), \ function('airline#extensions#default#apply') ] @@ -89,11 +89,13 @@ function! s:invoke_funcrefs(context, funcrefs) let builder = airline#builder#new(a:context) let err = airline#util#exec_funcrefs(a:funcrefs + s:core_funcrefs, builder, a:context) if err == 1 - call setwinvar(a:context.winnr, '&statusline', builder.build()) + let a:context.line = builder.build() + let s:contexts[a:context.winnr] = a:context + call setwinvar(a:context.winnr, '&statusline', '%!airline#statusline('.a:context.winnr.')') endif endfunction -function! airline#check_mode() +function! airline#statusline(winnr) if get(w:, 'airline_active', 1) let l:m = mode() if l:m ==# "i" @@ -123,6 +125,7 @@ function! airline#check_mode() call airline#highlighter#highlight(l:mode) let w:airline_lastmode = mode_string endif - return '' + + return s:contexts[a:winnr].line endfunction diff --git a/autoload/airline/builder.vim b/autoload/airline/builder.vim index e4430fe4..2d38ba12 100644 --- a/autoload/airline/builder.vim +++ b/autoload/airline/builder.vim @@ -39,7 +39,7 @@ function! airline#builder#new(context) let builder._context = a:context let builder._side = 1 let builder._curgroup = '' - let builder._line = '%{airline#check_mode()}' + let builder._line = '' return builder endfunction diff --git a/t/airline.vim b/t/airline.vim index 8cb0054a..b523d439 100644 --- a/t/airline.vim +++ b/t/airline.vim @@ -1,3 +1,4 @@ +let g:airline_theme = 'dark' call airline#init#bootstrap() call airline#init#sections() source plugin/airline.vim @@ -28,7 +29,7 @@ describe 'airline' call airline#add_statusline_func('MyFuncref') let &statusline = '' call airline#update_statusline() - Expect &statusline =~ 'hello world' + Expect airline#statusline(1) =~ 'hello world' end it 'should not change the statusline with -1' @@ -42,13 +43,13 @@ describe 'airline' call airline#add_statusline_func('MyAppend1') call airline#add_statusline_func('MyAppend2') call airline#update_statusline() - Expect &statusline =~ 'helloworld' + Expect airline#statusline(1) =~ 'helloworld' end it 'should allow users to redefine sections' let g:airline_section_a = airline#section#create(['mode', 'mode']) call airline#update_statusline() - Expect &statusline =~ '%{airline#util#wrap(airline#parts#mode(),0)}%{airline#util#wrap(airline#parts#mode(),0)}' + Expect airline#statusline(1) =~ '%{airline#util#wrap(airline#parts#mode(),0)}%{airline#util#wrap(airline#parts#mode(),0)}' end it 'should remove funcrefs properly' @@ -60,8 +61,8 @@ describe 'airline' it 'should overwrite the statusline with active and inactive splits' wincmd s - Expect getwinvar(1, '&statusline') !~ 'inactive' - Expect getwinvar(2, '&statusline') =~ 'inactive' + Expect airline#statusline(1) !~ 'inactive' + Expect airline#statusline(2) =~ 'inactive' wincmd c end diff --git a/t/builder.vim b/t/builder.vim index b96d8deb..0c12d329 100644 --- a/t/builder.vim +++ b/t/builder.vim @@ -5,9 +5,9 @@ describe 'active builder' let s:builder = airline#builder#new({'active': 1}) end - it 'should have a call to check mode' + it 'should start with an empty statusline' let stl = s:builder.build() - Expect stl =~ '%{airline#check_mode()}' + Expect stl == '' end it 'should transition colors from one to the next' diff --git a/t/extensions_default.vim b/t/extensions_default.vim index d9d719e6..71cc3c16 100644 --- a/t/extensions_default.vim +++ b/t/extensions_default.vim @@ -23,8 +23,8 @@ describe 'default' it 'should only render warning section in active splits' wincmd s - Expect getwinvar(1, '&statusline') =~ 'whitespace' - Expect getwinvar(2, '&statusline') !~ 'whitespace' + Expect airline#statusline(1) =~ 'whitespace' + Expect airline#statusline(2) !~ 'whitespace' wincmd c end end