From a927bf947592fe865c668887355ab9938545407a Mon Sep 17 00:00:00 2001 From: Bailey Ling Date: Thu, 29 Aug 2013 00:57:58 +0000 Subject: [PATCH] automatic separators. --- autoload/airline/parts.vim | 2 +- autoload/airline/util.vim | 22 ++++++++++++++++++---- plugin/airline.vim | 16 ++++++++-------- 3 files changed, 27 insertions(+), 13 deletions(-) diff --git a/autoload/airline/parts.vim b/autoload/airline/parts.vim index 917a469..63fe741 100644 --- a/autoload/airline/parts.vim +++ b/autoload/airline/parts.vim @@ -8,7 +8,7 @@ endfunction function! airline#parts#prepend(name) let val = function(a:name)() - return empty(val) ? '' : val.' '.g:airline_right_alt_sep + return empty(val) ? '' : val.' '.g:airline_right_alt_sep.' ' endfunction function! airline#parts#empty() diff --git a/autoload/airline/util.vim b/autoload/airline/util.vim index 624e5e8..3de33c3 100644 --- a/autoload/airline/util.vim +++ b/autoload/airline/util.vim @@ -1,11 +1,15 @@ " MIT License. Copyright (c) 2013 Bailey Ling. " vim: et ts=2 sts=2 sw=2 -function! s:get_val(part) +function! s:get_val(part, append) if has_key(g:airline_parts, a:part) let val = g:airline_parts[a:part] if match(val, '%\| ') > -1 return val + elseif a:append > 0 + return '%{airline#parts#append("'.val.'")}' + elseif a:append < 0 + return '%{airline#parts#prepend("'.val.'")}' else return '%{'.val.'()}' endif @@ -13,15 +17,25 @@ function! s:get_val(part) return a:part endfunction -function! airline#util#define_section(key, parts) +function! airline#util#define_left_section(key, parts) if !exists('g:airline_section_{a:key}') && len(a:parts) > 0 - let g:airline_section_{a:key} = s:get_val(a:parts[0]) + let g:airline_section_{a:key} = s:get_val(a:parts[0], 0) for i in range(1, len(a:parts) - 1) - let g:airline_section_{a:key} .= s:get_val(a:parts[i]) + let g:airline_section_{a:key} .= s:get_val(a:parts[i], 1) endfor endif endfunction +function! airline#util#define_right_section(key, parts) + if !exists('g:airline_section_{a:key}') && len(a:parts) > 0 + let g:airline_section_{a:key} = '' + for i in range(0, len(a:parts) - 2) + let g:airline_section_{a:key} .= s:get_val(a:parts[i], -1) + endfor + let g:airline_section_{a:key} .= s:get_val(a:parts[-1], 0) + endif +endfunction + if v:version >= 704 function! airline#util#getwinvar(winnr, key, def) return getwinvar(a:winnr, a:key, a:def) diff --git a/plugin/airline.vim b/plugin/airline.vim index 179446f..7e64569 100644 --- a/plugin/airline.vim +++ b/plugin/airline.vim @@ -80,14 +80,14 @@ function! s:init() \ }, 'keep') call airline#extensions#load() - call airline#util#define_section('a', ['mode', 'paste', 'iminsert']) - call airline#util#define_section('b', ['hunks', 'branch']) - call airline#util#define_section('c', ['%<', 'file']) - call airline#util#define_section('gutter', ['readonly', '%=']) - call airline#util#define_section('x', ['tagbar', '%{&filetype}']) - call airline#util#define_section('y', ['ffenc']) - call airline#util#define_section('z', ['%3p%% %{g:airline_symbols.linenr} %3l:%3c ']) - call airline#util#define_section('warning', ['syntastic', 'whitespace']) + call airline#util#define_left_section('a', ['mode', 'paste', 'iminsert']) + call airline#util#define_left_section('b', ['hunks', 'branch']) + call airline#util#define_left_section('c', ['%<', 'file']) + call airline#util#define_left_section('gutter', ['readonly', '%=']) + call airline#util#define_right_section('x', ['tagbar', '%{&filetype}']) + call airline#util#define_right_section('y', ['ffenc']) + call airline#util#define_right_section('z', ['%3p%% %{g:airline_symbols.linenr} %3l:%3c ']) + call airline#util#define_right_section('warning', ['syntastic', 'whitespace']) let s:airline_theme_defined = exists('g:airline_theme') if s:airline_theme_defined || !airline#switch_matching_theme()