Black schrieb:
> Hi all,
>
> I try to customise my SL to have a style depending section on the
> state of the buffer which it is attached.
> set statusline=%1*\ %f\ %2*%=\ %3*\ %{&modified?'✖':'✔'}\ %4*\ <%
> {&encoding}:%{&fileformat}>\ %5*\ %r%y\ %6*\ %cc,%lL/%LL\ %3p%%
>
> I tried the following code, the return of the unfortunate condition is
> not interpreted.
> set statusline=%1*\ %f\ %2*%=\ %{&modified?'%7*\ ✖':'%8*\ ✔'}\ %4*\ <%
> {&encoding}:%{&fileformat}>\ %5*\ %r%y\ %6*\ %cc,%lL/%LL\ %3p%%
yes, the result of the conditional operator is not re-evaluated, so
you get %7* and %8* inserted literally.
> I then tried this code. It works well when I have a buffer, beyond all
> my SL are identical to the SL of my current buffer.
> function! StatusLine(e)
> if (a:e)
> return '%1* %f %2*%= %7* ✖ %4* <%{&encoding}:%{&fileformat}>
> %5* %r%y %6* %cc,%lL/%LL %3p%%'
> else
> return '%1* %f %2*%= %8* ✔ %4* <%{&encoding}:%{&fileformat}>
> %5* %r%y %6* %cc,%lL/%LL %3p%%'
> endif
> endfunction
>
> set statusline=%!StatusLine(&modified)
It seems you are not allowed to pass any arguments to you StatusLine()
function inside the 'statusline' option. But even if you define
StatusLine() someway like
function! StatusLine()
if &l:modified
return '%1* %f %2*%= %7* ✖ %4* <%{&encoding}:%{&fileformat}>%5* %r%y
%6* %cc,%lL/%LL %3p%%'
else
return '%1* %f %2*%= %8* ✔ %4* <%{&encoding}:%{&fileformat}>%5* %r%y
%6* %cc,%lL/%LL %3p%%'
endif
endfunction
set statusline=%!StatusLine()
this would probably not work, because &l:modified is evaluated in the
context of the current buffer.
You can circumvent those problems by always using both highlight groups.
You just have to make sure you return an empty string if the highlight
group should not be used for the current modified state:
set statusline=%1*\ %f\ %2*%=\ %7*%{&modified?'✖':''}%8*%{&modified?'':'✔'}\
%4*\ <%{&encoding}:%{&fileformat}>\ %5*\ %r%y\ %6*\ %cc,%lL/%LL\ %3p%%
Regards,
Jürgen
--
Sometimes I think the surest sign that intelligent life exists elsewhere
in the universe is that none of it has tried to contact us. (Calvin)
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php