Monday, May 25, 2015

Re: Does trigger any event?

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?

> 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).
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?

> 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.

> 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?

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.

No comments: