2016-01-15 03:38:38 +01:00
|
|
|
" MIT License. Copyright (c) 2013-2016 Bailey Ling.
|
2013-08-27 02:56:54 +02:00
|
|
|
" vim: et ts=2 sts=2 sw=2
|
|
|
|
|
2016-09-24 02:16:30 +02:00
|
|
|
scriptencoding utf-8
|
|
|
|
|
2016-02-02 20:32:30 +01:00
|
|
|
let s:section_use_groups = get(g:, 'airline#extensions#default#section_use_groupitems', 1)
|
2013-08-27 03:12:00 +02:00
|
|
|
let s:section_truncate_width = get(g:, 'airline#extensions#default#section_truncate_width', {
|
2013-09-19 03:33:17 +02:00
|
|
|
\ 'b': 79,
|
2013-08-27 13:55:28 +02:00
|
|
|
\ 'x': 60,
|
|
|
|
\ 'y': 88,
|
|
|
|
\ 'z': 45,
|
2016-01-30 16:47:40 +01:00
|
|
|
\ 'warning': 80,
|
|
|
|
\ 'error': 80,
|
2013-08-27 03:12:00 +02:00
|
|
|
\ })
|
2013-08-28 01:57:18 +02:00
|
|
|
let s:layout = get(g:, 'airline#extensions#default#layout', [
|
|
|
|
\ [ 'a', 'b', 'c' ],
|
2016-01-30 16:47:40 +01:00
|
|
|
\ [ 'x', 'y', 'z', 'warning', 'error' ]
|
2013-08-28 01:57:18 +02:00
|
|
|
\ ])
|
2013-08-27 03:12:00 +02:00
|
|
|
|
2013-08-27 02:56:54 +02:00
|
|
|
function! s:get_section(winnr, key, ...)
|
2013-08-27 03:12:00 +02: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-22 23:43:14 +02:00
|
|
|
let spc = g:airline_symbols.space
|
2016-04-27 20:11:40 +02:00
|
|
|
if !exists('g:airline_section_{a:key}')
|
|
|
|
return ''
|
|
|
|
endif
|
2013-08-27 02:56:54 +02:00
|
|
|
let text = airline#util#getwinvar(a:winnr, 'airline_section_'.a:key, g:airline_section_{a:key})
|
2013-09-22 23:43:14 +02:00
|
|
|
let [prefix, suffix] = [get(a:000, 0, '%('.spc), get(a:000, 1, spc.'%)')]
|
2013-08-27 02:56:54 +02:00
|
|
|
return empty(text) ? '' : prefix.text.suffix
|
|
|
|
endfunction
|
|
|
|
|
2013-09-01 16:24:24 +02:00
|
|
|
function! s:build_sections(builder, context, keys)
|
2013-08-28 01:57:18 +02:00
|
|
|
for key in a:keys
|
2015-12-26 06:10:55 +01:00
|
|
|
if (key == 'warning' || key == 'error') && !a:context.active
|
2013-09-01 16:24:24 +02:00
|
|
|
continue
|
|
|
|
endif
|
2013-09-10 03:34:35 +02:00
|
|
|
call s:add_section(a:builder, a:context, key)
|
|
|
|
endfor
|
|
|
|
endfunction
|
2013-09-01 16:24:24 +02:00
|
|
|
|
2016-02-02 20:32:30 +01:00
|
|
|
" There still is a highlighting bug when using groups %(%) in the statusline,
|
2016-12-13 21:14:51 +01:00
|
|
|
" deactivate it, unless it is fixed (7.4.1511)
|
2016-02-02 20:32:30 +01:00
|
|
|
if s:section_use_groups && (v:version >= 704 || (v:version >= 703 && has('patch81')))
|
2016-04-20 21:10:28 +02:00
|
|
|
function! s:add_section(builder, context, key)
|
2016-12-13 21:14:51 +01:00
|
|
|
let condition = '(a:key is# "warning" || a:key is# "error")'.
|
|
|
|
\ '&& (v:version == 704 && !has("patch1511"))'
|
2013-08-28 01:57:18 +02:00
|
|
|
" i have no idea why the warning section needs special treatment, but it's
|
|
|
|
" needed to prevent separators from showing up
|
2016-01-28 19:01:05 +01:00
|
|
|
if ((a:key == 'error' || a:key == 'warning') && empty(s:get_section(a:context.winnr, a:key)))
|
|
|
|
return
|
|
|
|
endif
|
2016-12-13 21:14:51 +01:00
|
|
|
if condition
|
2013-08-28 01:57:18 +02:00
|
|
|
call a:builder.add_raw('%(')
|
|
|
|
endif
|
2013-09-10 03:34:35 +02:00
|
|
|
call a:builder.add_section('airline_'.a:key, s:get_section(a:context.winnr, a:key))
|
2016-12-13 21:14:51 +01:00
|
|
|
if condition
|
2013-08-28 01:57:18 +02:00
|
|
|
call a:builder.add_raw('%)')
|
|
|
|
endif
|
2013-09-10 03:34:35 +02:00
|
|
|
endfunction
|
|
|
|
else
|
|
|
|
" older version don't like the use of %(%)
|
2016-04-20 21:10:28 +02:00
|
|
|
function! s:add_section(builder, context, key)
|
2016-01-30 16:47:40 +01:00
|
|
|
if ((a:key == 'error' || a:key == 'warning') && empty(s:get_section(a:context.winnr, a:key)))
|
|
|
|
return
|
|
|
|
endif
|
2013-09-10 03:34:35 +02:00
|
|
|
if a:key == 'warning'
|
|
|
|
call a:builder.add_raw('%#airline_warning#'.s:get_section(a:context.winnr, a:key))
|
2016-01-28 11:15:25 +01:00
|
|
|
elseif a:key == 'error'
|
2015-12-26 06:10:55 +01:00
|
|
|
call a:builder.add_raw('%#airline_error#'.s:get_section(a:context.winnr, a:key))
|
2013-09-10 03:34:35 +02:00
|
|
|
else
|
|
|
|
call a:builder.add_section('airline_'.a:key, s:get_section(a:context.winnr, a:key))
|
|
|
|
endif
|
|
|
|
endfunction
|
|
|
|
endif
|
2013-08-28 01:57:18 +02:00
|
|
|
|
2013-08-27 02:56:54 +02: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-22 17:52:54 +01:00
|
|
|
call s:build_sections(a:builder, a:context, s:layout[0])
|
2013-08-27 02:56:54 +02:00
|
|
|
else
|
2014-11-22 17:52:54 +01:00
|
|
|
let text = s:get_section(winnr, 'c')
|
2014-08-15 21:18:56 +02:00
|
|
|
if empty(text)
|
|
|
|
let text = ' %f%m '
|
|
|
|
endif
|
|
|
|
call a:builder.add_section('airline_c'.(a:context.bufnr), text)
|
2013-08-27 02:56:54 +02:00
|
|
|
endif
|
|
|
|
|
|
|
|
call a:builder.split(s:get_section(winnr, 'gutter', '', ''))
|
|
|
|
|
|
|
|
if airline#util#getwinvar(winnr, 'airline_render_right', 1)
|
2014-11-22 17:52:54 +01:00
|
|
|
call s:build_sections(a:builder, a:context, s:layout[1])
|
2013-08-27 02:56:54 +02:00
|
|
|
endif
|
|
|
|
|
|
|
|
return 1
|
|
|
|
endfunction
|
2013-08-27 20:39:34 +02:00
|
|
|
|