2015-02-14 07:46:23 +08:00
|
|
|
" MIT License. Copyright (c) 2013-2015 Bailey Ling.
|
2013-08-27 08:56:54 +08:00
|
|
|
" vim: et ts=2 sts=2 sw=2
|
|
|
|
|
2013-08-27 09:12:00 +08:00
|
|
|
let s:section_truncate_width = get(g:, 'airline#extensions#default#section_truncate_width', {
|
2013-09-19 09:33:17 +08:00
|
|
|
\ 'b': 79,
|
2013-08-27 19:55:28 +08:00
|
|
|
\ 'x': 60,
|
|
|
|
\ 'y': 88,
|
|
|
|
\ 'z': 45,
|
2013-08-27 09:12:00 +08:00
|
|
|
\ })
|
2013-08-28 07:57:18 +08:00
|
|
|
let s:layout = get(g:, 'airline#extensions#default#layout', [
|
|
|
|
\ [ 'a', 'b', 'c' ],
|
|
|
|
\ [ 'x', 'y', 'z', 'warning' ]
|
|
|
|
\ ])
|
2013-08-27 09:12:00 +08:00
|
|
|
|
2013-08-27 08:56:54 +08:00
|
|
|
function! s:get_section(winnr, key, ...)
|
2013-08-27 09:12:00 +08:00
|
|
|
if has_key(s:section_truncate_width, a:key)
|
|
|
|
if winwidth(a:winnr) < s:section_truncate_width[a:key]
|
|
|
|
return ''
|
|
|
|
endif
|
|
|
|
endif
|
2013-09-23 05:43:14 +08:00
|
|
|
let spc = g:airline_symbols.space
|
2013-08-27 08:56:54 +08:00
|
|
|
let text = airline#util#getwinvar(a:winnr, 'airline_section_'.a:key, g:airline_section_{a:key})
|
2013-09-23 05:43:14 +08:00
|
|
|
let [prefix, suffix] = [get(a:000, 0, '%('.spc), get(a:000, 1, spc.'%)')]
|
2013-08-27 08:56:54 +08:00
|
|
|
return empty(text) ? '' : prefix.text.suffix
|
|
|
|
endfunction
|
|
|
|
|
2013-09-01 22:24:24 +08:00
|
|
|
function! s:build_sections(builder, context, keys)
|
2013-08-28 07:57:18 +08:00
|
|
|
for key in a:keys
|
2013-09-01 22:24:24 +08:00
|
|
|
if key == 'warning' && !a:context.active
|
|
|
|
continue
|
|
|
|
endif
|
2013-09-10 09:34:35 +08:00
|
|
|
call s:add_section(a:builder, a:context, key)
|
|
|
|
endfor
|
|
|
|
endfunction
|
2013-09-01 22:24:24 +08:00
|
|
|
|
2013-09-10 09:34:35 +08:00
|
|
|
if v:version >= 704 || (v:version >= 703 && has('patch81'))
|
|
|
|
function s:add_section(builder, context, key)
|
2013-08-28 07:57:18 +08:00
|
|
|
" i have no idea why the warning section needs special treatment, but it's
|
|
|
|
" needed to prevent separators from showing up
|
2013-09-10 09:34:35 +08:00
|
|
|
if a:key == 'warning'
|
2013-08-28 07:57:18 +08:00
|
|
|
call a:builder.add_raw('%(')
|
|
|
|
endif
|
2013-09-10 09:34:35 +08:00
|
|
|
call a:builder.add_section('airline_'.a:key, s:get_section(a:context.winnr, a:key))
|
|
|
|
if a:key == 'warning'
|
2013-08-28 07:57:18 +08:00
|
|
|
call a:builder.add_raw('%)')
|
|
|
|
endif
|
2013-09-10 09:34:35 +08:00
|
|
|
endfunction
|
|
|
|
else
|
|
|
|
" older version don't like the use of %(%)
|
|
|
|
function s:add_section(builder, context, key)
|
|
|
|
if a:key == 'warning'
|
|
|
|
call a:builder.add_raw('%#airline_warning#'.s:get_section(a:context.winnr, a:key))
|
|
|
|
else
|
|
|
|
call a:builder.add_section('airline_'.a:key, s:get_section(a:context.winnr, a:key))
|
|
|
|
endif
|
|
|
|
endfunction
|
|
|
|
endif
|
2013-08-28 07:57:18 +08:00
|
|
|
|
2013-08-27 08:56:54 +08: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))
|
2014-11-23 00:52:54 +08:00
|
|
|
call s:build_sections(a:builder, a:context, s:layout[0])
|
2013-08-27 08:56:54 +08:00
|
|
|
else
|
2014-11-23 00:52:54 +08:00
|
|
|
let text = s:get_section(winnr, 'c')
|
2014-08-16 03:18:56 +08:00
|
|
|
if empty(text)
|
|
|
|
let text = ' %f%m '
|
|
|
|
endif
|
|
|
|
call a:builder.add_section('airline_c'.(a:context.bufnr), text)
|
2013-08-27 08:56:54 +08:00
|
|
|
endif
|
|
|
|
|
|
|
|
call a:builder.split(s:get_section(winnr, 'gutter', '', ''))
|
|
|
|
|
|
|
|
if airline#util#getwinvar(winnr, 'airline_render_right', 1)
|
2014-11-23 00:52:54 +08:00
|
|
|
call s:build_sections(a:builder, a:context, s:layout[1])
|
2013-08-27 08:56:54 +08:00
|
|
|
endif
|
|
|
|
|
|
|
|
return 1
|
|
|
|
endfunction
|
2013-08-28 02:39:34 +08:00
|
|
|
|