whitespace: support multiline statusline for warnings

Add a new airline_section_warning2 that displays whitespace warnings on
a second statusline line when Vim supports the statuslineopt option
(Vim 9.2.0083+) and g:airline_multiline is set. The second line only
appears when there are actual whitespace issues, avoiding an empty
second line when the buffer is clean.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
This commit is contained in:
Christian Brabandt
2026-04-12 08:15:15 +00:00
co-authored by Claude Opus 4.6
parent 7fe264257e
commit ee44d57525
7 changed files with 77 additions and 16 deletions
+35 -10
View File
@@ -11,10 +11,11 @@ let s:section_truncate_width = get(g:, 'airline#extensions#default#section_trunc
\ 'z': 45,
\ 'warning': 80,
\ 'error': 80,
\ 'warning2': 80,
\ })
let s:layout = get(g:, 'airline#extensions#default#layout', [
\ [ 'a', 'b', 'c' ],
\ [ 'x', 'y', 'z', 'warning', 'error' ]
\ [ 'x', 'y', 'z', 'warning', 'error', 'warning2' ]
\ ])
function! s:get_section(winnr, key, ...)
@@ -32,9 +33,24 @@ function! s:get_section(winnr, key, ...)
return empty(text) ? '' : prefix.text.suffix
endfunction
function! s:eval_section_empty(content)
let exprlist = []
call substitute(a:content, '%{\([^}]*\)}', '\=add(exprlist, submatch(1))', 'g')
for expr in exprlist
try
if !empty(eval(expr))
return 0
endif
catch
return 0
endtry
endfor
return 1
endfunction
function! s:build_sections(builder, context, keys)
for key in a:keys
if (key == 'warning' || key == 'error') && !a:context.active
if (key == 'warning' || key == 'error' || key == 'warning2') && !a:context.active
continue
endif
call s:add_section(a:builder, a:context, key)
@@ -49,21 +65,30 @@ if s:section_use_groups && (v:version >= 704 || (v:version >= 703 && has('patch8
\ (v:version == 704 && !has("patch1511"))
" 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)))
if ((a:key == 'error' || a:key == 'warning' || a:key == 'warning2')
\ && empty(s:get_section(a:context.winnr, a:key)))
return
endif
if condition
call a:builder.add_raw('%(')
endif
call a:builder.add_section('airline_'.a:key, s:get_section(a:context.winnr, a:key))
if condition
call a:builder.add_raw('%)')
if a:key == 'warning2' && airline#util#has_multiline()
let section = s:get_section(a:context.winnr, a:key)
if !s:eval_section_empty(section)
call a:builder.add_raw('%@%#airline_warning#'.section)
endif
else
if condition
call a:builder.add_raw('%(')
endif
call a:builder.add_section('airline_'.a:key, s:get_section(a:context.winnr, a:key))
if condition
call a:builder.add_raw('%)')
endif
endif
endfunction
else
" older version don't like the use of %(%)
function! s:add_section(builder, context, key)
if ((a:key == 'error' || a:key == 'warning') && empty(s:get_section(a:context.winnr, a:key)))
if ((a:key == 'error' || a:key == 'warning')
\ && empty(s:get_section(a:context.winnr, a:key)))
return
endif
if a:key == 'warning'