diff --git a/autoload/airline/init.vim b/autoload/airline/init.vim index 37ac856..aa93e1e 100644 --- a/autoload/airline/init.vim +++ b/autoload/airline/init.vim @@ -61,6 +61,10 @@ function! airline#init#bootstrap() \ 'modified': '+', \ 'space': ' ', \ }, 'keep') +endfunction + +function! airline#init#sections() + let g:airline#init#initializing_sections = 1 call airline#parts#define('mode', { \ 'function': 'airline#parts#mode', @@ -77,9 +81,7 @@ function! airline#init#bootstrap() call airline#parts#define_raw('linenr', (g:airline_symbols.linenr).'%#__accent_bold#%4l%#__restore__#') call airline#parts#define_function('ffenc', 'airline#parts#ffenc') call airline#parts#define_empty(['hunks', 'branch', 'tagbar', 'syntastic', 'whitespace']) -endfunction -function! airline#init#sections() let spc = g:airline_symbols.space if !exists('g:airline_section_a') let g:airline_section_a = airline#section#create_left(['mode', 'paste', 'iminsert']) @@ -105,5 +107,7 @@ function! airline#init#sections() if !exists('g:airline_section_warning') let g:airline_section_warning = airline#section#create(['syntastic', 'whitespace']) endif + + unlet g:airline#init#initializing_sections endfunction diff --git a/autoload/airline/parts.vim b/autoload/airline/parts.vim index e5cbd38..0a43b97 100644 --- a/autoload/airline/parts.vim +++ b/autoload/airline/parts.vim @@ -7,7 +7,11 @@ let s:parts = {} function! airline#parts#define(key, config) let s:parts[a:key] = get(s:parts, a:key, {}) - call extend(s:parts[a:key], a:config) + if exists('g:airline#init#initializing_sections') + call extend(s:parts[a:key], a:config, 'keep') + else + call extend(s:parts[a:key], a:config, 'force') + endif endfunction function! airline#parts#define_function(key, name) diff --git a/t/init.vim b/t/init.vim index 9891c2d..e6e3eb6 100644 --- a/t/init.vim +++ b/t/init.vim @@ -6,10 +6,11 @@ function! s:clear() endfor endfunction -describe 'init' +call airline#init#bootstrap() + +describe 'init sections' before call s:clear() - call airline#init#bootstrap() call airline#init#sections() end @@ -65,3 +66,11 @@ describe 'init' end end +describe 'init parts' + it 'should not redefine parts already defined' + call airline#parts#define_raw('linenr', 'bar') + call airline#init#sections() + Expect g:airline_section_z =~ 'bar' + end +end +