On Fri, 7 Apr 2006 at 2:44pm, Yakov Lerner wrote: > On 4/7/06, Eric Arnold <[EMAIL PROTECTED]> wrote: > > > > Is there a way to get full information about all the windows, i.e. whether a > > window is against the left/right/top/bottom side, or to the right of another > > window, etc.etc.? > > I'd do it like this. I'd write 4 functions, GetWinOnRight, GetWinOnLeft, > GetWinAbove, GetWinBelow. Each function accepts window number, or > '.' for current window, and returns window number or -1. > > Here's how I'd write GetWinOnRight: we try to do "wincmd l". If window > number does not change, we return -1 (we're in rightmost window). If > window number changed, we return its winnr(). > > function! GetWinOnRight(winnum) " untested > let save_winnr = winnr() > if winnum != '.' > exe winnum."wincmd w" > endif > if winnr() != winnum > return -1 > endif > silent! "wincmd l" > if winnr() == winnum > result = -1 > else > result = winnr() > endif > "restore window > exe save_winnr."wincmd w" > return result > endfu > > Other 3 functions are similar, only use "wincmd h", "wincmd j", and > "wincmd k". Applying those functions iteratively, you can discover > full relation of windows in relation to each other. >
My genutils.vim plugin has a few functions that use almost the same scheme to determine a few facts about windows. They are tested and avoid side effects by modifying 'eventignore'. You might want to take a look at the IsOnlyVerticalWindow() and IsOnlyHorizontalWindow() functions. You can easily extend those functions using the other primitives such as MarkActiveWindow() and RestoreActiveWindow(). If you want, I can include any new functions you come up with, back in the genutils.vim so other scripts can share. -- Thanks, Hari __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com
