automatic separators.

This commit is contained in:
Bailey Ling 2013-08-29 00:57:58 +00:00
parent e13a4c8b1a
commit a927bf9475
3 changed files with 27 additions and 13 deletions

View File

@ -8,7 +8,7 @@ endfunction
function! airline#parts#prepend(name) function! airline#parts#prepend(name)
let val = function(a: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 endfunction
function! airline#parts#empty() function! airline#parts#empty()

View File

@ -1,11 +1,15 @@
" MIT License. Copyright (c) 2013 Bailey Ling. " MIT License. Copyright (c) 2013 Bailey Ling.
" vim: et ts=2 sts=2 sw=2 " 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) if has_key(g:airline_parts, a:part)
let val = g:airline_parts[a:part] let val = g:airline_parts[a:part]
if match(val, '%\| ') > -1 if match(val, '%\| ') > -1
return val return val
elseif a:append > 0
return '%{airline#parts#append("'.val.'")}'
elseif a:append < 0
return '%{airline#parts#prepend("'.val.'")}'
else else
return '%{'.val.'()}' return '%{'.val.'()}'
endif endif
@ -13,15 +17,25 @@ function! s:get_val(part)
return a:part return a:part
endfunction 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 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) 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 endfor
endif endif
endfunction 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 if v:version >= 704
function! airline#util#getwinvar(winnr, key, def) function! airline#util#getwinvar(winnr, key, def)
return getwinvar(a:winnr, a:key, a:def) return getwinvar(a:winnr, a:key, a:def)

View File

@ -80,14 +80,14 @@ function! s:init()
\ }, 'keep') \ }, 'keep')
call airline#extensions#load() call airline#extensions#load()
call airline#util#define_section('a', ['mode', 'paste', 'iminsert']) call airline#util#define_left_section('a', ['mode', 'paste', 'iminsert'])
call airline#util#define_section('b', ['hunks', 'branch']) call airline#util#define_left_section('b', ['hunks', 'branch'])
call airline#util#define_section('c', ['%<', 'file']) call airline#util#define_left_section('c', ['%<', 'file'])
call airline#util#define_section('gutter', ['readonly', '%=']) call airline#util#define_left_section('gutter', ['readonly', '%='])
call airline#util#define_section('x', ['tagbar', '%{&filetype}']) call airline#util#define_right_section('x', ['tagbar', '%{&filetype}'])
call airline#util#define_section('y', ['ffenc']) call airline#util#define_right_section('y', ['ffenc'])
call airline#util#define_section('z', ['%3p%% %{g:airline_symbols.linenr} %3l:%3c ']) call airline#util#define_right_section('z', ['%3p%% %{g:airline_symbols.linenr} %3l:%3c '])
call airline#util#define_section('warning', ['syntastic', 'whitespace']) call airline#util#define_right_section('warning', ['syntastic', '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()