From: Stefan Monnier <monnier@iro.umontreal.ca>
Cc: knipknap@jabber.org, help-gnu-emacs@gnu.org, rms@gnu.org,
emacs-devel@gnu.org
Subject: Re: New balance-windows
Date: Tue, 09 Aug 2005 20:05:47 -0400 [thread overview]
Message-ID: <m1u0hy8xsr.fsf-monnier+emacs@gnu.org> (raw)
In-Reply-To: <200508080927.j789R6Ss007055@beta.mvs.co.il> (Ehud Karni's message of "Mon, 8 Aug 2005 12:27:06 +0300")
> After `balance-windows' After my new function
> +-------+-------+-------+ +-------+-------+-------+
> | 9 | | | | | | |
> | | | 19 | | 15 | | 20 |
> +-------+ | | | | | |
> | | 29 | | +-------+ 30 | |
> | 19 | +-------+ | | +-------+
> | | | | | 15 | | |
> | | | | | | | |
> +----+--+-------+ 19 | +----+--+-------+ 20 |
> | | | | | | | | | |
> | 19 | | | | | 14 | | | |
> | | | +-------+ | | | +-------+
> | | | 32 | | +----+--+ 31 | |
> +----+--+ | | | | | |
> | | | 22 | | 15 | | 20 |
> | 12 | | | | | | |
> | | | | | | | |
> +-------+-------+-------+ +-------+-------+-------+
For what it's worth, here is another alternative I wrote a few years ago.
Note how it iterates to try and get to a fix point without using the
`preserve-before' argument (which didn't exist at that point).
Stefan
(defun balance-windows-area ()
"Make all visible windows use the same area (approximately)."
(interactive)
(save-selected-window
(let* ((change t)
(resizecount 0)
(wins (window-list nil 'nomini))
(count (length wins))
minresize next (carry 0))
;; Resizing a window changes the size of surrounding windows
;; in complex ways, so it's difficult to set the sizes in a single pass.
;; Instead, we just go through all the windows several times
;; until nothing needs to be CHANGEd.
(while (and change (> count 1))
(setq change nil count (1- count))
(dolist (win wins)
;; We always have to check liveness because enlarging/shrinking
;; always risks deleting windows (although we are very careful
;; to avoid most such cases).
(when (and (window-live-p win) (not (window-fixed-size-p win)))
(select-window win)
(setq next nil)
(while (progn (setq next (next-window next))
(window-fixed-size-p next)))
(let ((diff (- (* (window-height) (window-width))
(* (window-height next) (window-width next)))))
(if (< (car (window-edges)) (car (window-edges next)))
;; The windows are side-by-side
(unless (zerop (setq diff (/ diff (window-height) 2)))
;; Change things more smoothly.
(if (or (> diff 1) (< diff -1)) (setq diff (/ diff 2)))
(shrink-window diff)
(setq change t))
(setq diff (/ diff (window-width) 2))
;; Change things more smoothly.
(if (or (> diff 1) (< diff -1)) (setq diff (/ diff 2)))
(cond
((= diff 0))
;; Try to shrink to balance out with a smaller next window.
;; Enlarging risks killing a window, but if the next-window
;; is adjacent, then it should be safe.
((or (and (> diff 0) (window-safely-shrinkable-p))
(and (< diff 0)
(= (car (window-edges))
(car (window-edges next)))
(not (eq next (frame-first-window)))))
(shrink-window diff)
(setq change t))
;; Resizing is also safe if all windows are big enough.
((> (setq minresize
(- (apply 'min (mapcar 'window-height wins))
window-min-height))
0)
(shrink-window
(if (> diff 0)
(min diff minresize) (max diff (- minresize))))
(setq change t))
;; Let's try yet something else
((and (< diff 0) (window-safely-shrinkable-p next))
(select-window next)
(shrink-window (- diff))
(setq change t)))))))))))
next prev parent reply other threads:[~2005-08-10 0:05 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-08-03 0:47 Making the width of three windows equal Samuel
2005-08-03 1:01 ` Pascal Bourguignon
2005-08-03 2:13 ` Samuel
2005-08-03 3:11 ` Pascal Bourguignon
2005-08-06 11:59 ` New balance-windows (Was Re: Making the width of three windows equal) Ehud Karni
2005-08-06 13:27 ` New balance-windows Ehud Karni
[not found] ` <mailman.2758.1123335041.20277.help-gnu-emacs@gnu.org>
2005-08-06 16:42 ` Pascal Bourguignon
2005-08-07 17:15 ` New balance-windows (Was Re: Making the width of three windows equal) Richard M. Stallman
2005-08-08 9:27 ` Ehud Karni
2005-08-09 0:27 ` Richard M. Stallman
2005-08-10 0:05 ` Stefan Monnier [this message]
2005-08-10 1:48 ` New balance-windows Stefan Monnier
[not found] ` <mailman.3158.1123633927.20277.help-gnu-emacs@gnu.org>
2005-08-21 0:33 ` David Combs
[not found] ` <mailman.2979.1123493766.20277.help-gnu-emacs@gnu.org>
2005-08-08 17:55 ` Pascal Bourguignon
[not found] ` <mailman.2888.1123436059.20277.help-gnu-emacs@gnu.org>
2005-08-07 18:31 ` Pascal Bourguignon
[not found] ` <mailman.2754.1123329756.20277.help-gnu-emacs@gnu.org>
2005-08-06 16:39 ` Pascal Bourguignon
2005-08-06 16:58 ` Lennart Borgman
[not found] ` <mailman.2773.1123347813.20277.help-gnu-emacs@gnu.org>
2005-08-06 20:45 ` Pascal Bourguignon
2005-08-06 21:14 ` Lennart Borgman
[not found] ` <mailman.2796.1123363907.20277.help-gnu-emacs@gnu.org>
2005-08-07 18:23 ` Pascal Bourguignon
2005-08-07 18:59 ` Lennart Borgman
[not found] ` <mailman.2899.1123441421.20277.help-gnu-emacs@gnu.org>
2005-08-07 20:42 ` Pascal Bourguignon
2005-08-06 21:05 ` Ehud Karni
2005-08-07 2:17 ` Lennart Borgman
2005-08-08 9:36 ` Ehud Karni
2005-08-08 9:47 ` Lennart Borgman
[not found] ` <mailman.2988.1123495783.20277.help-gnu-emacs@gnu.org>
2005-08-08 10:18 ` David Kastrup
2005-08-08 11:18 ` Ehud Karni
2005-08-08 12:05 ` Lennart Borgman
[not found] ` <mailman.3002.1123500982.20277.help-gnu-emacs@gnu.org>
2005-08-08 18:11 ` Pascal Bourguignon
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=m1u0hy8xsr.fsf-monnier+emacs@gnu.org \
--to=monnier@iro.umontreal.ca \
--cc=emacs-devel@gnu.org \
--cc=help-gnu-emacs@gnu.org \
--cc=knipknap@jabber.org \
--cc=rms@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).