support configurable layouts.

This commit is contained in:
Bailey Ling 2013-08-27 23:57:18 +00:00
parent ea4e0280fb
commit 39c3ba360e
3 changed files with 25 additions and 16 deletions

View File

@ -7,6 +7,10 @@ let s:section_truncate_width = get(g:, 'airline#extensions#default#section_trunc
\ 'y': 88, \ 'y': 88,
\ 'z': 45, \ 'z': 45,
\ }) \ })
let s:layout = get(g:, 'airline#extensions#default#layout', [
\ [ 'a', 'b', 'c' ],
\ [ 'x', 'y', 'z', 'warning' ]
\ ])
function! s:get_section(winnr, key, ...) function! s:get_section(winnr, key, ...)
if has_key(s:section_truncate_width, a:key) if has_key(s:section_truncate_width, a:key)
@ -19,29 +23,34 @@ function! s:get_section(winnr, key, ...)
return empty(text) ? '' : prefix.text.suffix return empty(text) ? '' : prefix.text.suffix
endfunction endfunction
function! s:build_sections(builder, keys, winnr)
for key in a:keys
" i have no idea why the warning section needs special treatment, but it's
" needed to prevent separators from showing up
if key == 'warning'
call a:builder.add_raw('%(')
endif
call a:builder.add_section('airline_'.key, s:get_section(a:winnr, key))
if key == 'warning'
call a:builder.add_raw('%)')
endif
endfor
endfunction
function! airline#extensions#default#apply(builder, context) function! airline#extensions#default#apply(builder, context)
let winnr = a:context.winnr let winnr = a:context.winnr
let active = a:context.active let active = a:context.active
if airline#util#getwinvar(winnr, 'airline_render_left', active || (!active && !g:airline_inactive_collapse)) if airline#util#getwinvar(winnr, 'airline_render_left', active || (!active && !g:airline_inactive_collapse))
call a:builder.add_section('airline_a', s:get_section(winnr, 'a')) call <sid>build_sections(a:builder, s:layout[0], winnr)
call a:builder.add_section('airline_b', s:get_section(winnr, 'b'))
call a:builder.add_section('airline_c', '%<'.s:get_section(winnr, 'c'))
else else
call a:builder.add_section('airline_c', '%f%m') call a:builder.add_section('airline_a', '%f%m')
endif endif
call a:builder.split(s:get_section(winnr, 'gutter', '', '')) call a:builder.split(s:get_section(winnr, 'gutter', '', ''))
if airline#util#getwinvar(winnr, 'airline_render_right', 1) if airline#util#getwinvar(winnr, 'airline_render_right', 1)
call a:builder.add_section('airline_x', s:get_section(winnr, 'x')) call <sid>build_sections(a:builder, s:layout[1], winnr)
call a:builder.add_section('airline_y', s:get_section(winnr, 'y'))
call a:builder.add_section('airline_z', s:get_section(winnr, 'z'))
if active
call a:builder.add_raw('%(')
call a:builder.add_section('airline_warning', s:get_section(winnr, 'warning', '', ''))
call a:builder.add_raw('%)')
endif
endif endif
return 1 return 1

View File

@ -4,7 +4,7 @@
function! airline#extensions#syntastic#get_warnings() function! airline#extensions#syntastic#get_warnings()
let errors = SyntasticStatuslineFlag() let errors = SyntasticStatuslineFlag()
if strlen(errors) > 0 if strlen(errors) > 0
return ' '.errors return errors.' '
endif endif
return '' return ''
endfunction endfunction

View File

@ -84,12 +84,12 @@ function! s:init()
call airline#extensions#load() call airline#extensions#load()
call s:check_defined('g:airline_section_a', (g:airline_parts.mode).(g:airline_parts.paste).(g:airline_parts.iminsert)) call s:check_defined('g:airline_section_a', (g:airline_parts.mode).(g:airline_parts.paste).(g:airline_parts.iminsert))
call s:check_defined('g:airline_section_b', (g:airline_parts.hunks).(g:airline_parts.branch)) call s:check_defined('g:airline_section_b', (g:airline_parts.hunks).(g:airline_parts.branch))
call s:check_defined('g:airline_section_c', (g:airline_parts.file)) call s:check_defined('g:airline_section_c', '%<'.(g:airline_parts.file))
call s:check_defined('g:airline_section_gutter', ' '.(g:airline_parts.readonly).'%=') call s:check_defined('g:airline_section_gutter', ' '.(g:airline_parts.readonly).'%=')
call s:check_defined('g:airline_section_x', (g:airline_parts.tagbar).'%{&filetype}') call s:check_defined('g:airline_section_x', (g:airline_parts.tagbar).'%{&filetype}')
call s:check_defined('g:airline_section_y', g:airline_parts.ffenc) call s:check_defined('g:airline_section_y', g:airline_parts.ffenc)
call s:check_defined('g:airline_section_z', '%3p%% %{g:airline_symbols.linenr} %3l:%3c ') call s:check_defined('g:airline_section_z', '%3p%% %{g:airline_symbols.linenr} %3l:%3c ')
call s:check_defined('g:airline_section_warning', (g:airline_parts.syntastic).' '.(g:airline_parts.whitespace)) call s:check_defined('g:airline_section_warning', (g:airline_parts.syntastic).(g:airline_parts.whitespace))
let s:airline_theme_defined = exists('g:airline_theme') let s:airline_theme_defined = exists('g:airline_theme')
if s:airline_theme_defined || !airline#switch_matching_theme() if s:airline_theme_defined || !airline#switch_matching_theme()