On 2015-05-26 09:04:39 +0000, Nicola said:

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

On a second thought, that's not true: I can use winnr() to get the current window.
So, the real problem is:

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?

All works as expected (including <C-w><C-o>!) if I open windows with :new, :vnew, etc...
But when I split a window, say with <C-w><C-s>, SetupLocalStatusLine()
is not called, which means that somehow the current &l:statusline is re-used. The rest
is just a consequence of that. I have no idea how to fix this.

I have also noticed that when I split a window, BuildStatusLine() is called three times, while I'd expect it to be called twice (once per split window). Is that expected behaviour?

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 [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to