I'm trying to create a status line and get the color scheme correctly. I have the function
function GetDiagnosticErrorCount()
local errorCount = #vim.diagnostic.get(0, { severity = vim.diagnostic.severity.ERROR })
if (errorCount > 0) then
return ' ' .. errorCount .. ''
end
return ''
end
and would like it to have a colorscheme. My current solution today is to add colorscheme before in the definition of the statusline.
%#StatusLineError#%{luaeval('GetDiagnosticErrorCount()')}%
However, this becomes bad because I don't want the space before the error count to get the highlight, and I don't want the space to be there unless it's needed. The ideal solution would be to be able to add the colorscheme directly in the returned string:
function GetDiagnosticErrorCount()
local errorCount = #vim.diagnostic.get(0, { severity = vim.diagnostic.severity.ERROR })
if (errorCount > 0) then
return ' %#StatusLineError#% ' .. errorCount .. '%'
end
return ''
end
But this doesn't work.
%{%
as in:help statusline
to re-evaluate the result as a statusline string? (If that works, feel free to self-answer.)