use statusline function for better control.

This commit is contained in:
Bailey Ling 2013-09-02 18:55:15 +00:00
parent 9966b3d9f3
commit 301fcdc64a
5 changed files with 18 additions and 14 deletions

View File

@ -43,7 +43,6 @@ function! airline#switch_theme(name)
let w:airline_lastmode = '' let w:airline_lastmode = ''
call airline#update_statusline() call airline#update_statusline()
call airline#load_theme() call airline#load_theme()
call airline#check_mode()
endfunction endfunction
function! airline#switch_matching_theme() function! airline#switch_matching_theme()
@ -82,6 +81,7 @@ function! airline#update_statusline()
call s:invoke_funcrefs(context, g:airline_statusline_funcrefs) call s:invoke_funcrefs(context, g:airline_statusline_funcrefs)
endfunction endfunction
let s:contexts = {}
let s:core_funcrefs = [ let s:core_funcrefs = [
\ function('airline#extensions#apply'), \ function('airline#extensions#apply'),
\ function('airline#extensions#default#apply') ] \ function('airline#extensions#default#apply') ]
@ -89,11 +89,13 @@ function! s:invoke_funcrefs(context, funcrefs)
let builder = airline#builder#new(a:context) let builder = airline#builder#new(a:context)
let err = airline#util#exec_funcrefs(a:funcrefs + s:core_funcrefs, builder, a:context) let err = airline#util#exec_funcrefs(a:funcrefs + s:core_funcrefs, builder, a:context)
if err == 1 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 endif
endfunction endfunction
function! airline#check_mode() function! airline#statusline(winnr)
if get(w:, 'airline_active', 1) if get(w:, 'airline_active', 1)
let l:m = mode() let l:m = mode()
if l:m ==# "i" if l:m ==# "i"
@ -123,6 +125,7 @@ function! airline#check_mode()
call airline#highlighter#highlight(l:mode) call airline#highlighter#highlight(l:mode)
let w:airline_lastmode = mode_string let w:airline_lastmode = mode_string
endif endif
return ''
return s:contexts[a:winnr].line
endfunction endfunction

View File

@ -39,7 +39,7 @@ function! airline#builder#new(context)
let builder._context = a:context let builder._context = a:context
let builder._side = 1 let builder._side = 1
let builder._curgroup = '' let builder._curgroup = ''
let builder._line = '%{airline#check_mode()}' let builder._line = ''
return builder return builder
endfunction endfunction

View File

@ -1,3 +1,4 @@
let g:airline_theme = 'dark'
call airline#init#bootstrap() call airline#init#bootstrap()
call airline#init#sections() call airline#init#sections()
source plugin/airline.vim source plugin/airline.vim
@ -28,7 +29,7 @@ describe 'airline'
call airline#add_statusline_func('MyFuncref') call airline#add_statusline_func('MyFuncref')
let &statusline = '' let &statusline = ''
call airline#update_statusline() call airline#update_statusline()
Expect &statusline =~ 'hello world' Expect airline#statusline(1) =~ 'hello world'
end end
it 'should not change the statusline with -1' 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('MyAppend1')
call airline#add_statusline_func('MyAppend2') call airline#add_statusline_func('MyAppend2')
call airline#update_statusline() call airline#update_statusline()
Expect &statusline =~ 'helloworld' Expect airline#statusline(1) =~ 'helloworld'
end end
it 'should allow users to redefine sections' it 'should allow users to redefine sections'
let g:airline_section_a = airline#section#create(['mode', 'mode']) let g:airline_section_a = airline#section#create(['mode', 'mode'])
call airline#update_statusline() 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 end
it 'should remove funcrefs properly' it 'should remove funcrefs properly'
@ -60,8 +61,8 @@ describe 'airline'
it 'should overwrite the statusline with active and inactive splits' it 'should overwrite the statusline with active and inactive splits'
wincmd s wincmd s
Expect getwinvar(1, '&statusline') !~ 'inactive' Expect airline#statusline(1) !~ 'inactive'
Expect getwinvar(2, '&statusline') =~ 'inactive' Expect airline#statusline(2) =~ 'inactive'
wincmd c wincmd c
end end

View File

@ -5,9 +5,9 @@ describe 'active builder'
let s:builder = airline#builder#new({'active': 1}) let s:builder = airline#builder#new({'active': 1})
end end
it 'should have a call to check mode' it 'should start with an empty statusline'
let stl = s:builder.build() let stl = s:builder.build()
Expect stl =~ '%{airline#check_mode()}' Expect stl == ''
end end
it 'should transition colors from one to the next' it 'should transition colors from one to the next'

View File

@ -23,8 +23,8 @@ describe 'default'
it 'should only render warning section in active splits' it 'should only render warning section in active splits'
wincmd s wincmd s
Expect getwinvar(1, '&statusline') =~ 'whitespace' Expect airline#statusline(1) =~ 'whitespace'
Expect getwinvar(2, '&statusline') !~ 'whitespace' Expect airline#statusline(2) !~ 'whitespace'
wincmd c wincmd c
end end
end end