Tuesday, May 26, 2015

Re: Does trigger any event?

2015-05-26 12:04 GMT+03:00 Nicola <nvitacolonna@gmail.com>:
> On 2015-05-26 04:59:00 +0000, Nikolay Pavlov said:
>
>> 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.
>
>
> Ok, I'm having some difficulty with this. Currently I have something like
> this in my .vimrc:
>
> func! WinNrFromID(window_id)
> return filter(range(1, winnr('$')), 'getwinvar(v:val, "custom_window_id")
> == ' . a:window_id)[0]
> endf
>
> func! BuildStatusLine(window_id)
> let nr = WinNrFromID(window_id)
> " Build the status line
> endf
>
> let g:window_id = 0 " Global unique id
>
> func! SetupLocalStatusLine()
> let g:window_id +=1
> let w:custom_window_id = g:window_id
> exec 'setlocal statusline=%!BuildStatusLine(' . w:custom_window_id . ')'
> endf
>
> set statusline=%!SetupLocalStatusLine()
>
> Problems:
>
> 1) How do I detect whether a window is the active one (I want different
> status lines
> for active and inactive windows)? I cannot use winnr() inside
> BuildStatusLine()
> or in the context of %!.

Why do you think so? Inside %{…%} winnr() will report window number
for the current status line. But inside %! it will report current
window number:

> Note that the "%!" expression is evaluated in the context of the
> current window and buffer, while %{} items are evaluated in the
> context of the window that the statusline belongs to.

(from :h 'statusline').

>
> 2) When I open several windows and then I close them with <c-w>o, I get an
> out of bounds
> error in WinNrFromID(). Why? Is the function being called for closing/closed
> windows?
>
>
> 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