From 1b91c71fc9e488145c1033a24a7072d93d18b07c Mon Sep 17 00:00:00 2001 From: Bailey Ling Date: Sat, 31 Aug 2013 17:42:09 -0400 Subject: [PATCH] make it possible to declare sections in the vimrc (#204). --- autoload/airline/init.vim | 13 ++++--------- autoload/airline/section.vim | 2 ++ autoload/airline/util.vim | 2 +- plugin/airline.vim | 3 ++- t/airline.vim | 1 + t/commands.vim | 2 ++ t/extensions_default.vim | 1 + t/init.vim | 1 + t/section.vim | 5 +++++ 9 files changed, 19 insertions(+), 11 deletions(-) diff --git a/autoload/airline/init.vim b/autoload/airline/init.vim index a03f4d2b..1ad8bbad 100644 --- a/autoload/airline/init.vim +++ b/autoload/airline/init.vim @@ -7,11 +7,7 @@ function! s:check_defined(variable, default) endif endfunction -let s:init_vars = 0 -function airline#init#vars() - if s:init_vars | return | endif - let s:init_vars = 1 - +function! airline#init#bootstrap() 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)?"":"<") @@ -55,12 +51,11 @@ function airline#init#vars() \ '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') + + call airline#extensions#load() endfunction -function! airline#init#bootstrap() - call airline#init#vars() - call airline#extensions#load() - +function! airline#init#sections() if !exists('g:airline_section_a') let g:airline_section_a = airline#section#create_left(['mode', 'paste', 'iminsert']) endif diff --git a/autoload/airline/section.vim b/autoload/airline/section.vim index 4ad881ba..95b5e5a8 100644 --- a/autoload/airline/section.vim +++ b/autoload/airline/section.vim @@ -1,6 +1,8 @@ " MIT License. Copyright (c) 2013 Bailey Ling. " vim: et ts=2 sts=2 sw=2 +call airline#init#bootstrap() + function! s:get_val(key, append) let part = airline#parts#get(a:key) diff --git a/autoload/airline/util.vim b/autoload/airline/util.vim index c2306f88..fbc06d9c 100644 --- a/autoload/airline/util.vim +++ b/autoload/airline/util.vim @@ -1,7 +1,7 @@ " MIT License. Copyright (c) 2013 Bailey Ling. " vim: et ts=2 sts=2 sw=2 -call airline#init#vars() +call airline#init#bootstrap() function! airline#util#wrap(text, minwidth) if a:minwidth > 0 && winwidth(0) < a:minwidth diff --git a/plugin/airline.vim b/plugin/airline.vim index 055c065a..65685cea 100644 --- a/plugin/airline.vim +++ b/plugin/airline.vim @@ -15,6 +15,7 @@ function! s:init() let s:airline_initialized = 1 call airline#init#bootstrap() + call airline#init#sections() let s:airline_theme_defined = exists('g:airline_theme') if s:airline_theme_defined || !airline#switch_matching_theme() @@ -69,7 +70,7 @@ function! s:airline_toggle() autocmd CmdwinLeave * call airline#remove_statusline_func('airline#cmdwinenter') autocmd ColorScheme * call on_colorscheme_changed() - autocmd WinEnter,BufWinEnter,FileType,BufUnload,ShellCmdPost,VimResized * + autocmd VimEnter,WinEnter,BufWinEnter,FileType,BufUnload,VimResized * \ call on_window_changed() autocmd BufWritePost */autoload/airline/themes/*.vim diff --git a/t/airline.vim b/t/airline.vim index 2040b0f5..179277ea 100644 --- a/t/airline.vim +++ b/t/airline.vim @@ -1,4 +1,5 @@ call airline#init#bootstrap() +call airline#init#sections() function! MyFuncref(...) call a:1.add_raw('hello world') diff --git a/t/commands.vim b/t/commands.vim index 8038ffd3..e4933d9f 100644 --- a/t/commands.vim +++ b/t/commands.vim @@ -1,4 +1,6 @@ call airline#init#bootstrap() +call airline#init#sections() + source plugin/airline.vim describe 'commands' diff --git a/t/extensions_default.vim b/t/extensions_default.vim index 9eb80235..5387e3bc 100644 --- a/t/extensions_default.vim +++ b/t/extensions_default.vim @@ -1,4 +1,5 @@ call airline#init#bootstrap() +call airline#init#sections() describe 'default' before diff --git a/t/init.vim b/t/init.vim index f5293811..0685527d 100644 --- a/t/init.vim +++ b/t/init.vim @@ -10,6 +10,7 @@ describe 'init' before call s:clear() call airline#init#bootstrap() + call airline#init#sections() end after diff --git a/t/section.vim b/t/section.vim index b3af070a..5c86b077 100644 --- a/t/section.vim +++ b/t/section.vim @@ -33,5 +33,10 @@ describe 'section' let s = airline#section#create(['hi']) Expect s == '%#hlgroup#hello' end + + it 'should parse out a section from the vimrc' + let s = airline#section#create(['whitespace']) + Expect s =~ 'airline#extensions#whitespace#check' + end end