From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: "Ehud Karni" Newsgroups: gmane.emacs.help,gmane.emacs.devel Subject: Re: New balance-windows Date: Sun, 7 Aug 2005 00:05:54 +0300 Organization: Mivtach-Simon Insurance agencies Message-ID: <200508062105.j76L5sj4006926@beta.mvs.co.il> References: <87pssv3kai.fsf@thalassa.informatimago.com> <1123035204.009217.187300@g14g2000cwa.googlegroups.com> <87fytr3ea2.fsf@thalassa.informatimago.com> <87vf2juij1.fsf@thalassa.informatimago.com> Reply-To: ehud@unix.mvs.co.il NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-8-i Content-Transfer-Encoding: 7bit X-Trace: sea.gmane.org 1123363805 5785 80.91.229.2 (6 Aug 2005 21:30:05 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Sat, 6 Aug 2005 21:30:05 +0000 (UTC) Cc: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Sat Aug 06 23:29:54 2005 Return-path: Original-Received: from lists.gnu.org ([199.232.76.165]) by ciao.gmane.org with esmtp (Exim 4.43) id 1E1WEA-00017P-NA for geh-help-gnu-emacs@m.gmane.org; Sat, 06 Aug 2005 23:29:11 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1E1WGc-0003ii-JU for geh-help-gnu-emacs@m.gmane.org; Sat, 06 Aug 2005 17:31:42 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1E1WG4-0003ch-19 for help-gnu-emacs@gnu.org; Sat, 06 Aug 2005 17:31:09 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1E1WFr-0003Wx-9O for help-gnu-emacs@gnu.org; Sat, 06 Aug 2005 17:30:55 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1E1WFq-0003P4-It; Sat, 06 Aug 2005 17:30:54 -0400 Original-Received: from [193.16.147.12] (helo=unix.mvs.co.il) by monty-python.gnu.org with esmtp (Exim 4.34) id 1E1W50-0007Ak-Fz; Sat, 06 Aug 2005 17:19:43 -0400 Original-Received: from beta.mvs.co.il (beta [10.253.0.3]) by unix.mvs.co.il (8.13.0/8.13.0) with ESMTP id j76L5ti0010030 for ; Sun, 7 Aug 2005 00:05:55 +0300 Original-Received: from beta.mvs.co.il (localhost [127.0.0.1]) by beta.mvs.co.il (8.13.4/8.13.4) with ESMTP id j76L5t4c006929 for ; Sun, 7 Aug 2005 00:05:55 +0300 Original-Received: (from root@localhost) by beta.mvs.co.il (8.13.4/8.13.4/Submit) id j76L5sj4006926; Sun, 7 Aug 2005 00:05:54 +0300 Original-To: spam@mouse-potato.com, emacs-devel@gnu.org In-reply-to: <87vf2juij1.fsf@thalassa.informatimago.com> (message from Pascal Bourguignon on Sat, 06 Aug 2005 18:39:14 +0200) X-Mailer: Emacs 21.3.1 rmail (send-msg 1.108) X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:28499 gmane.emacs.devel:41626 X-Report-Spam: http://spam.gmane.org/gmane.emacs.help:28499 On Sat, 06 Aug 2005 18:39:14 +0200, Pascal Bourguignon wrote: > > "Ehud Karni" writes: > > > Following the recent discussion of `balance-windows' on help-gnu-emacs > > I looked into it and wrote a replacement (new) function based on > > somewhat different logic to achieve the balancing. > I think it is good as it can get until Emacs resizing is changed. In Emacs 22.0.50 a 3rd argument was add to enlarge window: Optional third arg PRESERVE-BEFORE, if non-nil, means do not change the size of the siblings above or to the left of the selected window. Only siblings to the right or below are changed. I tried using this argument but I found a problem (bug ?). When you have a configuration like: +----------+----------+ + lw1 + rw1 + +----------+ + + lw2 +----------+ +----------+ rw2 + + lw3 + + +----------+----------+ + fw6 + +----------+----------+ You can move the border between windows lw3/rw2 and fw6 with enlarge-window command in lw3/rw2. i.e. the command (enlarge-window 5 nil t) in lw3/rw2 does nothing. Because the preserving is regarding only windows to the left and above the current window (and there is no other way to specify the size of a window) the "enlarging/shrinking" must be done from top to bottom or left to right (which my function does). Below is my latest version (using PRESERVE-BEFORE - available only in 22.0) which is failing in such situation. NOTE. This discussion really should be done in emacs-devel@gnu.org list and not in help-gnu-emacs@gnu.org. Ehud. The lines with "^ ;; (" are for debugging, just drop the ";;" and you'll see animation of the resizing with messages in the echo area. (defun balance-windows (&optional horizontally) "Make all visible windows on the current frame the same size (approximately). If optional prefix arg is not given, \"same size\" is same height. When prefix arg is given, \"same size\" is same width." (interactive "P") (let* (count size w cmjr resize (edge (if horizontally 0 1)) ;; Minor field to sort by 0=LEFT, 1=TOP (mjr (- 1 edge)) ;; Major field to sort (far (+ 2 edge)) ;; far edge (right/bottom) - for current size (windows nil) ;; list of windows (ix 0) nwin ;; number of windows (curw (selected-window)) ;; selected window (to return to) ) ;; Build and sort list of all windows on frame (save-window-excursion (walk-windows (function (lambda (w) (let ((ltrb (window-edges w))) (setq windows (cons (list (nth mjr ltrb) (nth edge ltrb) (nth far ltrb) w) windows))))) 'nomini) (setq windows (sort windows (lambda (e1 e2) (if (< (nth 0 e1) (nth 0 e2)) t (if (= (nth 0 e1) (nth 0 e2)) (if (< (nth 1 e1) (nth 1 e2)) t))))))) (setq nwin (length windows)) ;; add 1 extra entry (for while check) (setq windows (append windows '((-1 -1 -1 nil)))) (while (< ix nwin) ; walk on all (sorted) windows (setq count ix) ; count the windows in 1 column (or row) (setq cmjr (car (nth ix windows))) ; column / raw identification (while (= cmjr (car (nth ix windows))) ; same column / row (setq ix (1+ ix))) ; next window (setq count (- ix count)) (if (/= count 1) ; do only if more than one window in this column/row (let ((gix (- ix count))) (setq size (- (nth far (window-edges (nth 3 (nth (1- ix) windows)))) (nth edge (window-edges (nth 3 (nth (- ix count) windows)))))) (setq size (/ (+ size count -1) count)) ; average window size ;; (message "Size=%d" size) (while (< gix ix) (setq w (nth 3 (nth gix windows))) (setq resize (- size (- (nth far (window-edges w)) (nth edge (window-edges w))))) ;; (message "Window=%s resize=%d" w resize) ; don't resize by 1 character/line (if (or (> resize 1) (< resize -1)) (progn ;; (sit-for 2) (select-window w) ; window to work on (enlarge-window resize horizontally 'preserve) ;; (sit-for 2) )) (setq gix (1+ gix)))))) ;; (message "") (select-window curw))) -- Ehud Karni Tel: +972-3-7966-561 /"\ Mivtach - Simon Fax: +972-3-7966-667 \ / ASCII Ribbon Campaign Insurance agencies (USA) voice mail and X Against HTML Mail http://www.mvs.co.il FAX: 1-815-5509341 / \ GnuPG: 98EA398D Better Safe Than Sorry