2015-05-26 0:54 GMT+03:00 Nicola <nvitacolonna@gmail.com>:
> On 2015-05-25 19:31:48 +0000, Nikolay Pavlov said:
>
>>> call setwinvar(nr, '&statusline', '%!BuildStatusLine(' . winwidth(nr) .
>>> ',' . winbufnr(nr) . ',' . (nr == winnr()) . ')')
>>
>>
>> 1. winwidth(nr) can be called inside BuildStatusLine. Same for other
>> arguments. Just provide it with `nr`: this is a curse of `%!` that
>> your code *is not* executed in the current window context, so you need
>> external facilities for providing window number.
>
>
> Ok, thanks, I've fixed that. In fact, I have added those parameters
> because winnr() did not give me the correct result inside BuildStatusLine().
>
>> 2. In place of window number it is better to mark windows with a
>> window id (e.g. w:plugin_window_id: per-window unique variable).
>> Window number is then obtained by using something like
>> `filter(range(1, winnr('$')), 'getwinvar(v:val, "plugin_window_id")
>> =window_id')[0]`. Reasoning: when you rotate windows (:h window-moving)
>> you do not get any events AFAIR, but window number changes.
>
>
> This is an interesting idea, but how do I generate unique id's?
Vim is single threaded. Just use a global integer variable which is
incremented after each time it was assigned.
>
>> 3. In place of using *any* events at all update &statusline in a
>> status line function. It is the only thing which will *definitely* be
>> called.
>
>
> This is what I do already, if I understand correctly: let
> &statusline=%!BuildStatusLine(nr).
No. You need to do this assignment from BuildStatusLine().
> So, I can get rid of the autocmd definitions that trigger a refresh, because
> Vim already
> takes care of that. Good. But I still need an autocmd to set the value of
> &statusline to
> my function each time a new window is opened, do I?
No.
>
>> Setting &statusline from statusline function causes no errors,
>> except that the intro screen may disappear:
>>
>> https://github.com/powerline/powerline/blob/2fa7c3cfc8023a927e44975514b7da4d5ac6e57e/powerline/vim.py#L212-L223.
>
>
> This is not the case for me. I see the intro screen when I start Vim.
Check out the list of conditions. They are *very* specific. They will
only hit you if you modify your code according to my suggestions.
>
>> 4. Updating &statusline may trigger unnecessary redraws. Don't do this
>> if it is already correct.
>
>
> Ok.
>
>> 5. In place of updating &statusline in a statusline function always,
>> do this only if `BuildNewStatusLine()` function is called. At the
>> start set &g:statusline (note: ***global* option**) to
>> %!BuildNewStatusLine(). :h global-local
>
>
> I think I don't understand this point. Would you mind to elaborate?
Default value from &l:statusline is &g:statusline (actually,
pseudo-value "no value set, fall back to &g:statusline"). If you set
&g:statusline to `%!BuildNewStatusLine()` and run
`RefreshStatusLines()` inside then this function will be run only when
new window appears because `RefreshStatusLines()` will set
&l:statusline which will be used then and which will only call
BuildStatusLine, but not BuildNewStatusLine.
>
>
> Nicola
>
>
> --
> --
> 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
>
> --- You received this message because you are subscribed to the Google
> Groups "vim_use" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to vim_use+unsubscribe@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
--
--
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
---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
No comments:
Post a Comment