2015-05-25 16:40 GMT+03:00 Nicola <nvitacolonna@gmail.com>:
> On 2015-05-25 05:12:21 +0000, Nikolay Pavlov said:
>
>> 2015-05-25 1:12 GMT+03:00 Justin M. Keyes <justinkz@gmail.com>:
>>>
>>> On Sun, May 24, 2015 at 5:19 AM, Nicola <nvitacolonna@gmail.com> wrote:
>>>>
>>>> Hi,
>>>> am I right that <C-w><C-o> does not trigger any event? I have a custom
>>>> status line, which does not get updated when I close all other windows.
>>>> For
>>>> now, I have this workaround:
>>>>
>>>> nnoremap <C-w>o <C-w>o:call RefreshStatusLines()<CR>
>>>> nnoremap <C-w><C-w> <C-w>o:call RefreshStatusLines()<CR>
>>>>
>>>> I was wondering whether there is a better way to detect when the user
>>>> makes
>>>> the active window the only visible one.
>>>
>>>
>>> No such event.
>
>
> Ok, I see that there is a WinResized event in `h todo`, so it is something
> that is not implemented yet.
>
>>> But you can force statusline redraw by assigning an
>>> option to itself:
>>>
>>> let &readonly=&readonly
>>>
>>> Although, I just noticed that Vim has a :redrawstatus command.
>
>
> Thanks, both seem to work. I can probably dispose of my RefreshStatusLines()
> then.
>
>>> Is
>>> there any need for the "let &ro=&ro" hack mentioned in ":help
>>> 'statusline'", given the existence of :redrawstatus?
>>
>>
>> It is not needed. Status line redraw is being triggered by closing the
>> window, no redraw is the problem of the custom status line, not Vim.
>> RefreshStatusLines function is thus obviously *not* being used from
>> the &statusline in this case.
>
>
> I'm not sure I'm following you: what is the point of calling a function
> whose
> purpose is to redraw the status line from the status line itself? For
> reference,
> the code I'm using is here:
>
>
> https://github.com/lifepillar/lifepillar-vim-config/blob/master/vimrc#L482
>
> I'm far from being a Vim expert, so I may well be doing things suboptimally.
So your code intentions originate from the same Vim problem. When you
referenced its name I imagined a function which fills status line with
actual contents, which makes sense if you need to put results of
lengthy computations into the status line (though usually this would
touch only some segments and thus does not need a function which
updates the whole status line).
> 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.
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.
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. 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.
4. Updating &statusline may trigger unnecessary redraws. Don't do this
if it is already correct.
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
6. Whichever function updates status lines should take care about
assigning w:plugin_window_id for new windows.
Note about autocommands:
1. There are no autocommands launched for some window manipulations.
2. Any code run inside autocommand without `nested` after pattern will
not trigger your autocommands. `nested` is almost never used, though I
wish it and nore mappings/abbreviations would be the defaults.
>
>> I know this because powerline does *not* use anything, but "switch
>> highlight group" and "display raw text" statusline segments and it
>> still immediately occupies all space after closing the window (== it
>> does not use %= segments, so to occupy all space Vim must recompute
>> status line or it will be displayed using the previous window size).
>
>
> How do you get right-aligned elements in the status line without %=?
What does %= do? It fills status line with spaces (well, some value
from &fillchars really). Powerline does the same, but
a) leaves no chances for &fillchars to intervent and
b) supports any applications that displays colored text and provides
length information.
>
> I have used Airline, but not Powerline, in the past, and it has the same
> problem
> (after <C-w>o the status line is not updated). Isn't Airline's codebase
> derived from
> Powerline?
No, and never was.
>
> 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