vim-airline/autoload/airline/extensions/default.vim

96 lines
3.3 KiB
VimL
Raw Normal View History

2016-01-14 21:38:38 -05:00
" MIT License. Copyright (c) 2013-2016 Bailey Ling.
" vim: et ts=2 sts=2 sw=2
let s:section_use_groups = get(g:, 'airline#extensions#default#section_use_groupitems', 1)
let s:section_truncate_width = get(g:, 'airline#extensions#default#section_truncate_width', {
\ 'b': 79,
2013-08-27 07:55:28 -04:00
\ 'x': 60,
\ 'y': 88,
\ 'z': 45,
2016-01-30 10:47:40 -05:00
\ 'warning': 80,
\ 'error': 80,
\ })
2013-08-27 19:57:18 -04:00
let s:layout = get(g:, 'airline#extensions#default#layout', [
\ [ 'a', 'b', 'c' ],
2016-01-30 10:47:40 -05:00
\ [ 'x', 'y', 'z', 'warning', 'error' ]
2013-08-27 19:57:18 -04:00
\ ])
function! s:get_section(winnr, key, ...)
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 17:43:14 -04:00
let spc = g:airline_symbols.space
let text = airline#util#getwinvar(a:winnr, 'airline_section_'.a:key, g:airline_section_{a:key})
2013-09-22 17:43:14 -04:00
let [prefix, suffix] = [get(a:000, 0, '%('.spc), get(a:000, 1, spc.'%)')]
return empty(text) ? '' : prefix.text.suffix
endfunction
function! s:build_sections(builder, context, keys)
2013-08-27 19:57:18 -04:00
for key in a:keys
if (key == 'warning' || key == 'error') && !a:context.active
continue
endif
call s:add_section(a:builder, a:context, key)
endfor
endfunction
" There still is a highlighting bug when using groups %(%) in the statusline,
" deactivate it, until this is properly fixed:
" https://groups.google.com/d/msg/vim_dev/sb1jmVirXPU/mPhvDnZ-CwAJ
if s:section_use_groups && (v:version >= 704 || (v:version >= 703 && has('patch81')))
function! s:add_section(builder, context, key)
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 ((a:key == 'error' || a:key == 'warning') && empty(s:get_section(a:context.winnr, a:key)))
return
endif
if (a:key == 'warning' || a:key == 'error')
2013-08-27 19:57:18 -04:00
call a:builder.add_raw('%(')
endif
call a:builder.add_section('airline_'.a:key, s:get_section(a:context.winnr, a:key))
if (a:key == 'warning' || a:key == 'error')
2013-08-27 19:57:18 -04:00
call a:builder.add_raw('%)')
endif
endfunction
else
" older version don't like the use of %(%)
function! s:add_section(builder, context, key)
2016-01-30 10:47:40 -05:00
if ((a:key == 'error' || a:key == 'warning') && empty(s:get_section(a:context.winnr, a:key)))
return
endif
if a:key == 'warning'
call a:builder.add_raw('%#airline_warning#'.s:get_section(a:context.winnr, a:key))
2016-01-28 05:15:25 -05:00
elseif a:key == 'error'
call a:builder.add_raw('%#airline_error#'.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-27 19:57:18 -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))
call s:build_sections(a:builder, a:context, s:layout[0])
else
let text = s:get_section(winnr, 'c')
if empty(text)
let text = ' %f%m '
endif
call a:builder.add_section('airline_c'.(a:context.bufnr), text)
endif
call a:builder.split(s:get_section(winnr, 'gutter', '', ''))
if airline#util#getwinvar(winnr, 'airline_render_right', 1)
call s:build_sections(a:builder, a:context, s:layout[1])
endif
return 1
endfunction
2013-08-27 14:39:34 -04:00