On Wed, 27 Sep 2006 at 10:07am, Charles E Campbell Jr wrote: > Bram Moolenaar wrote: > > >Charles Campbell wrote: > > > > > > > >>Just a suggestion -- I'd appreciate a WinClose event. BufWinLeave would > >>almost do, but if two or more windows are open on the same buffer, then > >>no event. WinLeave fires whenever one changes windows, which isn't > >>what I want, either. Unless I'm misunderstanding the help for these two > >>events. > >> > >> > > > >What would this event be used for? > > > >The WinResized event has also been suggested. It could be used to > >update the Window layout. It will also be triggered when a window is > >closed, since another window will get bigger then. Would it be > >sufficient to only have a WinResized event? Would these events also be > >triggered when closing the last window of a tab page? > > > > > > > As an example: I have debugging output in a left hand window (Decho.vim > produces this sort of output); > when I hit <f9> on a function name, a vertically split window shows up > on the right and tags to the > named function. However, if that window already exists, I just want to > re-use it, not split and create another > one. To do that correctly, I need that window, when it is actually > closed, to perform some cleanup (ie. make a change > in a script variable). I want to allow other vertical windows, so there > isn't necessarily a fixed number of vertically > split panes. Actually, the script also allows <s-f9> to create a left > hand source window: [leftsource|debugging|rightsource]. > > The leftsource and right source windows may well be open to the same > source file. Consequently the various buffer > closing events aren't adequate. BufWinLeave almost does the trick, but > there's that "not when a buffer is still visible > in another window" caveat associated with it. That's what I've been > using, but it really isn't adequate. > > A WinResized might easily occur when that window wasn't closed, too. > > Regards, > Chip Campbell
FYI, the last I needed this event, I wrote a function to do this. It is part of genutils.vim as NotifyWinClose(). Here is the implementation (written as a generalization), it is kind of heuristic (see CheckWindowClose). I will be happy to see a WinClose event though. let s:notifyWindow = {} function! genutils#AddNotifyWindowClose(windowTitle, functionName) let bufName = a:windowTitle let s:notifyWindow[bufName] = a:functionName "let g:notifyWindow = s:notifyWindow " Debug. " Start listening to events. aug NotifyWindowClose au! au WinEnter * :call genutils#CheckWindowClose() au BufEnter * :call genutils#CheckWindowClose() aug END endfunction function! genutils#RemoveNotifyWindowClose(windowTitle) let bufName = a:windowTitle if has_key(s:notifyWindow, bufName) call remove(s:notifyWindow, bufName) if len(s:notifyWindow) == 0 "unlet g:notifyWindow " Debug. aug NotifyWindowClose au! aug END endif endif endfunction function! genutils#CheckWindowClose() if !exists('s:notifyWindow') return endif " Now iterate over all the registered window titles and see which one's are " closed. for nextWin in keys(s:notifyWindow) if bufwinnr(s:FindBufferForName(nextWin)) == -1 let funcName = s:notifyWindow[nextWin] " Remove this entry as these are going to be processed. The caller can add " them back if needed. unlet s:notifyWindow[nextWin] "call input("cmd: " . cmd) call call(funcName, [nextWin]) endif endfor endfunction Here is a test case that shows how to use it: function! NotifyWindowCloseF(title) call input(a:title . " closed") endfunction function! RunNotifyWindowCloseTest() call input("Creating three windows, 'ABC', 'XYZ' and 'b':") split ABC split X Y Z split b redraw call genutils#AddNotifyWindowClose("ABC", "NotifyWindowCloseF") call genutils#AddNotifyWindowClose("X Y Z", "NotifyWindowCloseF") call input("notifyWindow: " . string(s:notifyWindow)) au NotifyWindowClose WinEnter call input("Added notifications for 'ABC' and 'XYZ'\n". \ "Now closing the windows, you should see ONLY two notifications:") quit quit quit endfunction -- Thanks, Hari __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com