From 39c3ba360e3bcdaa5930bd2cd6344749b4155495 Mon Sep 17 00:00:00 2001 From: Bailey Ling Date: Tue, 27 Aug 2013 23:57:18 +0000 Subject: [PATCH] support configurable layouts. --- autoload/airline/extensions/default.vim | 33 ++++++++++++++--------- autoload/airline/extensions/syntastic.vim | 2 +- plugin/airline.vim | 6 ++--- 3 files changed, 25 insertions(+), 16 deletions(-) diff --git a/autoload/airline/extensions/default.vim b/autoload/airline/extensions/default.vim index 3af84dd..4821844 100644 --- a/autoload/airline/extensions/default.vim +++ b/autoload/airline/extensions/default.vim @@ -7,6 +7,10 @@ let s:section_truncate_width = get(g:, 'airline#extensions#default#section_trunc \ 'y': 88, \ 'z': 45, \ }) +let s:layout = get(g:, 'airline#extensions#default#layout', [ + \ [ 'a', 'b', 'c' ], + \ [ 'x', 'y', 'z', 'warning' ] + \ ]) function! s:get_section(winnr, 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 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) let winnr = a:context.winnr let active = a:context.active 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 a:builder.add_section('airline_b', s:get_section(winnr, 'b')) - call a:builder.add_section('airline_c', '%<'.s:get_section(winnr, 'c')) + call build_sections(a:builder, s:layout[0], winnr) else - call a:builder.add_section('airline_c', '%f%m') + call a:builder.add_section('airline_a', '%f%m') endif call a:builder.split(s:get_section(winnr, 'gutter', '', '')) if airline#util#getwinvar(winnr, 'airline_render_right', 1) - call a:builder.add_section('airline_x', s:get_section(winnr, 'x')) - 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 + call build_sections(a:builder, s:layout[1], winnr) endif return 1 diff --git a/autoload/airline/extensions/syntastic.vim b/autoload/airline/extensions/syntastic.vim index ef8d874..24308c5 100644 --- a/autoload/airline/extensions/syntastic.vim +++ b/autoload/airline/extensions/syntastic.vim @@ -4,7 +4,7 @@ function! airline#extensions#syntastic#get_warnings() let errors = SyntasticStatuslineFlag() if strlen(errors) > 0 - return ' '.errors + return errors.' ' endif return '' endfunction diff --git a/plugin/airline.vim b/plugin/airline.vim index 4c0f603..f6ebe0c 100644 --- a/plugin/airline.vim +++ b/plugin/airline.vim @@ -84,12 +84,12 @@ function! s:init() 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_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_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_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_z', '%3p%% %{g:airline_symbols.linenr} %3l:%3c ') + 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') if s:airline_theme_defined || !airline#switch_matching_theme()