emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Add function to rotate/transpose all windows


From: martin rudalics
Subject: Re: Add function to rotate/transpose all windows
Date: Mon, 18 Nov 2024 09:55:09 +0100
User-agent: Mozilla Thunderbird

> I can't quite get it to work, imagine this scinario:
>
> +-----+------+
> | A   |__B___|
> |     |  C   |
> +-----+------+
>
> What the above split does is that is splits A, with refer B, and these
> windows aren't really siblings.  So if I do pass the refer of A and B,
> it should be from A's parent, but then when I pass B with refer (cons C
> (B and C's parent)), won't it bug out since B's parent is being set twice?

I tell you what I'm doing here: Let's call P the original parent of A
and Q that of B and C.  The first split is a "first child" below split
with A as window to split and a cons of B and P as REFER.  The second
split is a "next sibling" left split with B as window to split and a
cons of C and Q as REFER.  Both splits are done with combination limit
set to t.

So 'split-window-internal' will not use the current parent of A in the
first split (which is nil anyway) but make a new parent which it sets to
P (since that is passed as second argument of REFER).

In the second split it will not use the current parent of A and B (which
is the already resurrected P) but again make a new parent which it sets
to Q (since that is passed as second argument of REFER).

So the parent of B is indeed set twice: When B is resurrected it is set
to P.  When C is resurrected it is set to Q and Q's parent is set to P.

'split-window-internal' makes a new parent window (which it resurrects
in the cases above immediately) when 'window-combination-limit' is
non-nil.  Setting that value up is done in window-rotate.el in the
following excerpt where 'window' is the window to split (first A and
then B in our case):

            (let* ((prev (window-alist-prev window))
                   (limit (window-alist-combination-limit parent))
                   ;; Set 'window-combination-limit' to make sure
                   ;; that a new parent is created when WINDOW's
                   ;; previous sibling and WINDOW do not have the
                   ;; same parent.
                   (window-combination-limit
                    (or limit
                        (not prev)
                        (not (eq (window-alist-parent prev)
                                 (window-alist-parent window)))))

Here 'prev' is the original previous sibling of 'window' and 'parent'
its original parent (P in the first split and Q in the second).  I set
'window-combination-limit' to t in the following cases:

- 'parent' already has its combination limit set in which case I have to
  preserve it

- 'window' has no previous sibling

- the original parent of 'prev' is not the original parent of 'window'.

In our example, neither A in the first split nor B in the second split
have a previous sibling so I set 'window-combination-limit' to t in both
cases.

BTW if you bind 'window-combination-limit' to t don't forget to reset
it's effect for the parent window via

(set-window-combination-limit parent limit)

right after the split.  Otherwise the parent window cannot be recombined
later on although that would be principally possible.

martin



reply via email to

[Prev in Thread] Current Thread [Next in Thread]