In my vim configuration I have a function like
function! StatuslineTrailingSpace()
if !exists('b:statusline_trailing_space_warning')
let b:statusline_trailing_space_warning = &modifiable ? search('\s\+$', 'nw') != 0 ? ' %#warningmsg#[\s]%*' : '' : ''
endif
return b:statusline_trailing_space_warning
endfunction
and then somewhere later the line
set statusline+=%{StatuslineTrailingSpace()}
But instead of a colored [\s] tag in the statusline I see the full %#warningmsg#[\s]%* string.
Trying to use %! instead of %{} as proposed in this answer does not seem to work as my vim gives the error
line 70:
E539: Illegal character <!>: statusline+=%!StatuslineTrailingSpace()
How can I get the colored statusline working?