2013-08-26 20:56:54 -04:00
|
|
|
" MIT License. Copyright (c) 2013 Bailey Ling.
|
|
|
|
" vim: et ts=2 sts=2 sw=2
|
|
|
|
|
2013-08-26 21:12:00 -04:00
|
|
|
let s:section_truncate_width = get(g:, 'airline#extensions#default#section_truncate_width', {
|
2013-08-27 07:55:28 -04:00
|
|
|
\ 'b': 88,
|
|
|
|
\ 'x': 60,
|
|
|
|
\ 'y': 88,
|
|
|
|
\ 'z': 45,
|
2013-08-26 21:12:00 -04:00
|
|
|
\ })
|
2013-08-27 19:57:18 -04:00
|
|
|
let s:layout = get(g:, 'airline#extensions#default#layout', [
|
|
|
|
\ [ 'a', 'b', 'c' ],
|
|
|
|
\ [ 'x', 'y', 'z', 'warning' ]
|
|
|
|
\ ])
|
2013-08-26 21:12:00 -04:00
|
|
|
|
2013-08-26 20:56:54 -04:00
|
|
|
function! s:get_section(winnr, key, ...)
|
2013-08-26 21:12:00 -04:00
|
|
|
if has_key(s:section_truncate_width, a:key)
|
|
|
|
if winwidth(a:winnr) < s:section_truncate_width[a:key]
|
|
|
|
return ''
|
|
|
|
endif
|
|
|
|
endif
|
2013-08-26 20:56:54 -04:00
|
|
|
let text = airline#util#getwinvar(a:winnr, 'airline_section_'.a:key, g:airline_section_{a:key})
|
|
|
|
let [prefix, suffix] = [get(a:000, 0, '%( '), get(a:000, 1, ' %)')]
|
|
|
|
return empty(text) ? '' : prefix.text.suffix
|
|
|
|
endfunction
|
|
|
|
|
2013-09-01 10:24:24 -04:00
|
|
|
function! s:build_sections(builder, context, keys)
|
2013-08-27 19:57:18 -04:00
|
|
|
for key in a:keys
|
2013-09-01 10:24:24 -04:00
|
|
|
if key == 'warning' && !a:context.active
|
|
|
|
continue
|
|
|
|
endif
|
|
|
|
|
2013-08-27 19:57:18 -04:00
|
|
|
" 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
|
2013-09-01 10:24:24 -04:00
|
|
|
call a:builder.add_section('airline_'.key, s:get_section(a:context.winnr, key))
|
2013-08-27 19:57:18 -04:00
|
|
|
if key == 'warning'
|
|
|
|
call a:builder.add_raw('%)')
|
|
|
|
endif
|
|
|
|
endfor
|
|
|
|
endfunction
|
|
|
|
|
2013-08-26 20:56:54 -04:00
|
|
|
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))
|
2013-09-01 10:24:24 -04:00
|
|
|
call <sid>build_sections(a:builder, a:context, s:layout[0])
|
2013-08-26 20:56:54 -04:00
|
|
|
else
|
2013-09-02 23:24:41 -04:00
|
|
|
call a:builder.add_section('airline_b', ' %f%m ')
|
2013-08-28 11:40:04 -04:00
|
|
|
call a:builder.add_section('airline_c', '')
|
2013-08-26 20:56:54 -04:00
|
|
|
endif
|
|
|
|
|
|
|
|
call a:builder.split(s:get_section(winnr, 'gutter', '', ''))
|
|
|
|
|
|
|
|
if airline#util#getwinvar(winnr, 'airline_render_right', 1)
|
2013-09-01 10:24:24 -04:00
|
|
|
call <sid>build_sections(a:builder, a:context, s:layout[1])
|
2013-08-26 20:56:54 -04:00
|
|
|
endif
|
|
|
|
|
|
|
|
return 1
|
|
|
|
endfunction
|
2013-08-27 14:39:34 -04:00
|
|
|
|