lazy load variables until needed (#204).

this allows users to define section variables in their vimrc.
This commit is contained in:
Bailey Ling 2013-08-31 12:57:02 -04:00
parent 7e1206469c
commit fd68997398
4 changed files with 32 additions and 13 deletions

View File

@ -7,7 +7,11 @@ function! s:check_defined(variable, default)
endif
endfunction
function! airline#init#bootstrap()
let s:init_vars = 0
function airline#init#vars()
if s:init_vars | return | endif
let s:init_vars = 1
call s:check_defined('g:airline_left_sep', get(g:, 'airline_powerline_fonts', 0)?"":">")
call s:check_defined('g:airline_left_alt_sep', get(g:, 'airline_powerline_fonts', 0)?"":">")
call s:check_defined('g:airline_right_sep', get(g:, 'airline_powerline_fonts', 0)?"":"<")
@ -51,19 +55,10 @@ function! airline#init#bootstrap()
\ 'linenr': get(g:, 'airline_linecolumn_prefix', get(g:, 'airline_powerline_fonts', 0) ? '' : ':' ),
\ 'branch': get(g:, 'airline_branch_prefix', get(g:, 'airline_powerline_fonts', 0) ? '' : ''),
\ }, 'keep')
endfunction
call airline#parts#define_raw('mode', '%{get(w:, "airline_current_mode", "")}')
call airline#parts#define_function('iminsert', 'airline#parts#iminsert')
call airline#parts#define_function('paste', 'airline#parts#paste')
call airline#parts#define('readonly', {
\ 'function': 'airline#parts#readonly',
\ 'highlight': 'airline_file',
\ })
call airline#parts#define_raw('file', '%f%m')
call airline#parts#define_raw('ffenc', '%{printf("%s%s",&fenc,strlen(&ff)>0?"[".&ff."]":"")}')
call airline#parts#define_empty(['hunks', 'branch', 'tagbar', 'syntastic'])
function! airline#init#bootstrap()
call airline#init#vars()
call airline#extensions#load()
if !exists('g:airline_section_a')

View File

@ -38,6 +38,10 @@ endfunction
" }}}
function! airline#parts#mode()
return get(w:, 'airline_current_mode', '')
endfunction
function! airline#parts#paste()
return g:airline_detect_paste && &paste ? g:airline_symbols.paste : ''
endfunction
@ -53,3 +57,15 @@ function! airline#parts#readonly()
return &readonly ? g:airline_symbols.readonly : ''
endfunction
call airline#parts#define_function('mode', 'airline#parts#mode')
call airline#parts#define_function('iminsert', 'airline#parts#iminsert')
call airline#parts#define_function('paste', 'airline#parts#paste')
call airline#parts#define('readonly', {
\ 'function': 'airline#parts#readonly',
\ 'highlight': 'airline_file',
\ })
call airline#parts#define_raw('file', '%f%m')
call airline#parts#define_raw('ffenc', '%{printf("%s%s",&fenc,strlen(&ff)>0?"[".&ff."]":"")}')
call airline#parts#define_empty(['hunks', 'branch', 'tagbar', 'syntastic'])

View File

@ -1,6 +1,8 @@
" MIT License. Copyright (c) 2013 Bailey Ling.
" vim: et ts=2 sts=2 sw=2
call airline#init#vars()
function! airline#util#wrap(text, minwidth)
if a:minwidth > 0 && winwidth(0) < a:minwidth
return ''

View File

@ -42,5 +42,11 @@ describe 'airline'
call airline#update_statusline()
Expect &statusline =~ '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)}'
end
end