diff --git a/autoload/airline/builder.vim b/autoload/airline/builder.vim index 65a1f699..18d81e49 100644 --- a/autoload/airline/builder.vim +++ b/autoload/airline/builder.vim @@ -40,12 +40,28 @@ function! s:prototype.build() let i = 0 let length = len(self._sections) let split = 0 + let is_empty = 0 + let prev_group = '' while i < length let section = self._sections[i] let group = section[0] let contents = section[1] + let pgroup = prev_group let prev_group = s:get_prev_group(self._sections, i) + if is_empty + let prev_group = pgroup + endif + let is_empty = s:section_is_empty(self, contents) + + if is_empty + " need to fix highlighting groups, since we + " have skipped a section, we actually need + " the previous previous group and so the + " seperator goes from the previous previous group + " to the current group + let pgroup = group + endif if group == '' let line .= contents @@ -57,12 +73,16 @@ function! s:prototype.build() if prev_group == '' let line .= '%#'.group.'#' elseif split - let line .= s:get_transitioned_seperator(self, prev_group, group, side) + if !is_empty + let line .= s:get_transitioned_seperator(self, prev_group, group, side) + endif let split = 0 else - let line .= s:get_seperator(self, prev_group, group, side) + if !is_empty + let line .= s:get_seperator(self, prev_group, group, side) + endif endif - let line .= s:get_accented_line(self, group, contents) + let line .= is_empty ? '' : s:get_accented_line(self, group, contents) endif let i = i + 1 @@ -121,6 +141,43 @@ function! s:get_accented_line(self, group, contents) return line endfunction +function! s:section_is_empty(self, content) + let start=1 + + " do not check for inactive windows + if a:self._context.active == 0 + return 0 + endif + + " only check, if airline#skip_empty_sections == 1 + if get(g:, 'airline_skip_empty_sections', 0) == 0 + return 0 + endif + " assume accents sections to be never empty + " (avoides, that on startup the mode message becomes empty) + if match(a:content, '%#__accent_[^#]*#.*__restore__#') > -1 + return 0 + endif + let list=matchlist(a:content, '%{\zs.\{-}\ze}', 1, start) + if empty(list) + return 0 " no function in statusline text + endif + while len(list) > 0 + let expr = list[0] + try + " catch all exceptions, just in case + if !empty(eval(expr)) + return 0 + endif + catch + return 0 + endtry + let start += 1 + let list=matchlist(a:content, '%{\zs.\{-}\ze}', 1, start) + endw + return 1 +endfunction + function! airline#builder#new(context) let builder = copy(s:prototype) let builder._context = a:context diff --git a/autoload/airline/extensions/whitespace.vim b/autoload/airline/extensions/whitespace.vim index 41949929..7e13d472 100644 --- a/autoload/airline/extensions/whitespace.vim +++ b/autoload/airline/extensions/whitespace.vim @@ -136,6 +136,13 @@ function! airline#extensions#whitespace#init(...) unlet! b:airline_whitespace_check augroup airline_whitespace autocmd! - autocmd CursorHold,BufWritePost * unlet! b:airline_whitespace_check + autocmd CursorHold,BufWritePost * call ws_refresh() augroup END endfunction + +function! s:ws_refresh() + unlet! b:airline_whitespace_check + if get(g:, 'airline_skip_empty_sections', 0) + exe ':AirlineRefresh' + endif +endfunction diff --git a/doc/airline.txt b/doc/airline.txt index 40bb2fc0..0053504c 100644 --- a/doc/airline.txt +++ b/doc/airline.txt @@ -140,6 +140,10 @@ values): * disable the Airline customization for selective windows (this is a window-local variable so you can disable it for only some windows) > let w:airline_disabled = 1 + +* Do not draw separators for empty sections (only for the active window) + > + let g:airline_skip_empty_sections = 1 < ==============================================================================