From 20d77c3220a6fa02c811e9373cb6c832b4fde4d5 Mon Sep 17 00:00:00 2001 From: Jeff Pitman Date: Tue, 28 Dec 2021 09:40:20 +0100 Subject: [PATCH] builder: bugs in is_empty_section The current way to parse the statusline content and decide whether a section is empty, has some flaws: That is for the following reasons: - accents are considered to be empty (which they really shouldn't) - manually parsing the expressions using a `:while ... matchlist() ... endwhile` loop is slow and fragile - grouping items such as %( %) are not considered So replace the logic by using `substitute('pat', '\=add()', '')` to capture all single expression groups into a list and then looping over those to decide whether the section is empty. fixes #2411 --- autoload/airline/builder.vim | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/autoload/airline/builder.vim b/autoload/airline/builder.vim index adc680b7..6c2a494c 100644 --- a/autoload/airline/builder.vim +++ b/autoload/airline/builder.vim @@ -198,20 +198,22 @@ function! s:section_is_empty(self, content) if get(w:, 'airline_skip_empty_sections', -1) == 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 + if empty(a:content) return 1 endif - let list=matchlist(a:content, '%{\zs.\{-}\ze}', 1, start) - if empty(list) - return 0 " no function in statusline text + + let stripped = substitute(a:content, + \ '\(%{.*}\|%#__accent_[^#]*#\|%#__restore__#\|%( \| %)\)', '', 'g') + + if !empty(stripped) + return 0 " There is content in the statusline endif - while len(list) > 0 - let expr = list[0] + + let exprlist = [] + call substitute(a:content, '%{\([^}]*\)}', '\=add(exprlist, submatch(1))', 'g') + + for expr in exprlist try " catch all exceptions, just in case if !empty(eval(expr)) @@ -220,9 +222,7 @@ function! s:section_is_empty(self, content) catch return 0 endtry - let start += 1 - let list=matchlist(a:content, '%{\zs.\{-}\ze}', 1, start) - endw + endfor return 1 endfunction