From 14dacaab683fee0d06c225760b2e18fd3967fd78 Mon Sep 17 00:00:00 2001 From: Bailey Ling Date: Sun, 11 Aug 2013 19:20:41 +0000 Subject: [PATCH] improve bufferline integration; revert to default in inactive splits. --- autoload/airline.vim | 12 +++++------- autoload/airline/extensions/bufferline.vim | 19 +++++++++++++++++-- 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/autoload/airline.vim b/autoload/airline.vim index 29e4e14..b9ab8f2 100644 --- a/autoload/airline.vim +++ b/autoload/airline.vim @@ -70,7 +70,7 @@ function! s:get_section(winnr, key, ...) return empty(text) ? '' : prefix.text.suffix endfunction -function! s:get_statusline(winnr, active) +function! airline#get_statusline(winnr, active) let l:mode_color = a:active ? "%#Al2#" : "%#Al2_inactive#" let l:mode_sep_color = a:active ? "%#Al3#" : "%#Al3_inactive#" let l:info_color = a:active ? "%#Al4#" : "%#Al4_inactive#" @@ -137,11 +137,9 @@ function! airline#update_statusline() return endif - for nr in range(1, winnr('$')) - if nr != winnr() && getwinvar(nr, 'airline_active') - call setwinvar(nr, '&statusline', s:get_statusline(nr, 0)) - call setwinvar(nr, 'airline_active', 0) - endif + for nr in filter(range(1, winnr('$')), 'v:val != winnr()') + call setwinvar(nr, 'airline_active', 0) + call setwinvar(nr, '&statusline', airline#get_statusline(nr, 0)) endfor let w:airline_active = 1 @@ -153,7 +151,7 @@ function! airline#update_statusline() endfor call airline#exec_funcrefs(g:airline_statusline_funcrefs, 0) - call setwinvar(winnr(), '&statusline', s:get_statusline(winnr(), 1)) + call setwinvar(winnr(), '&statusline', airline#get_statusline(winnr(), 1)) endfunction function! airline#update_highlight() diff --git a/autoload/airline/extensions/bufferline.vim b/autoload/airline/extensions/bufferline.vim index 852b33c..9a863e1 100644 --- a/autoload/airline/extensions/bufferline.vim +++ b/autoload/airline/extensions/bufferline.vim @@ -1,6 +1,21 @@ -" MIT license. Copyright (c) 2013 Bailey Ling. +" MIT License. Copyright (c) 2013 Bailey Ling. " vim: ts=2 sts=2 sw=2 fdm=indent +function! airline#extensions#bufferline#apply() + " revert to default in non-active splits + for nr in filter(range(1, winnr('$')), 'v:val != winnr()') + if matchstr(getwinvar(nr, '&statusline'), '%{bufferline') != '' + call setwinvar(nr, 'airline_section_c', '%f%m') + call setwinvar(nr, '&statusline', airline#get_statusline(nr, 0)) + endif + endfor + + " check for other plugin overrides first + if !exists('w:airline_section_c') + let w:airline_section_c = '%{bufferline#refresh_status()}'.bufferline#get_status_string() + endif +endfunction + function! airline#extensions#bufferline#init(ext) highlight AlBl_active gui=bold cterm=bold term=bold highlight link AlBl_inactive Al6 @@ -11,6 +26,6 @@ function! airline#extensions#bufferline#init(ext) let g:bufferline_separator = ' ' if g:airline_section_c == '%f%m' - let g:airline_section_c = '%{bufferline#refresh_status()}'.bufferline#get_status_string() + call a:ext.add_statusline_funcref(function('airline#extensions#bufferline#apply')) endif endfunction