From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: "Ehud Karni" Newsgroups: gmane.emacs.devel,gmane.emacs.help Subject: Re: New balance-windows Date: Sat, 6 Aug 2005 16:27:06 +0300 Organization: Mivtach-Simon Insurance agencies Message-ID: <200508061327.j76DR6jx032167@beta.mvs.co.il> References: <87pssv3kai.fsf@thalassa.informatimago.com> <1123035204.009217.187300@g14g2000cwa.googlegroups.com> <87fytr3ea2.fsf@thalassa.informatimago.com> <200508061159.j76BxILQ018985@beta.mvs.co.il> 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 1123335025 5804 80.91.229.2 (6 Aug 2005 13:30:25 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Sat, 6 Aug 2005 13:30:25 +0000 (UTC) Cc: help-gnu-emacs@gnu.org, knipknap@gmail.com, spam@mouse-potato.com Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sat Aug 06 15:30:15 2005 Return-path: Original-Received: from lists.gnu.org ([199.232.76.165]) by ciao.gmane.org with esmtp (Exim 4.43) id 1E1OkC-0003iX-TV for ged-emacs-devel@m.gmane.org; Sat, 06 Aug 2005 15:29:45 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1E1On7-0006JW-20 for ged-emacs-devel@m.gmane.org; Sat, 06 Aug 2005 09:32:45 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1E1OlD-0005bJ-NI for emacs-devel@gnu.org; Sat, 06 Aug 2005 09:30:50 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1E1Ol3-0005UI-1u for emacs-devel@gnu.org; Sat, 06 Aug 2005 09:30:37 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1E1Okx-0005Rs-V0; Sat, 06 Aug 2005 09:30:32 -0400 Original-Received: from [193.16.147.12] (helo=unix.mvs.co.il) by monty-python.gnu.org with esmtp (Exim 4.34) id 1E1Ouz-0005px-GK; Sat, 06 Aug 2005 09:40:54 -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 j76DR8Ys000418 for ; Sat, 6 Aug 2005 16:27:08 +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 j76DR7lv032170 for ; Sat, 6 Aug 2005 16:27:07 +0300 Original-Received: (from root@localhost) by beta.mvs.co.il (8.13.4/8.13.4/Submit) id j76DR6jx032167; Sat, 6 Aug 2005 16:27:06 +0300 Original-To: emacs-devel@gnu.org, " Lennart Borgman" In-reply-to: <200508061159.j76BxILQ018985@beta.mvs.co.il> (message from Ehud Karni on Sat, 6 Aug 2005 14:59:18 +0300) X-Mailer: Emacs 21.3.1 rmail (send-msg 1.108) X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:41594 gmane.emacs.help:28477 X-Report-Spam: http://spam.gmane.org/gmane.emacs.help:28477 There was an error on my last post of the new `balance-windows'. Thanks to Lennart Borgman who spotted the small typo that is a big bug. Bellow is the corrected code. Ehud. (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 max rpt (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) (windows nil) ;; list of windows (ix 0) nwin ;; number of windows (pass 1) ;; pass number (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 0) ; number of windows in 1 column (or row) (setq cmjr (car (nth ix windows))) ; column / raw identification (while (= cmjr (car (nth (+ count ix) windows))) ; same (setq count (1+ count))) ; count them (if (= count 1) ; only one window in this column/row (setq ix (1+ ix)) ; skip it ; compute and resize windows (setq size (if (= pass 1) ; on pass 1 the saved edges have not changed (- (nth 2 (nth (1- (+ count ix)) windows)) (nth 1 (nth ix windows))) ;; previous changes may changed the window edges (- (nth far (window-edges (nth 3 (nth (1- (+ count ix)) windows)))) (nth edge (window-edges (nth 3 (nth ix windows))))))) (setq size (/ (+ size count -1) count)) ; average window size (setq max (+ ix count)) ; index of next column/row ;; the resizing loop must be done twice ;; because later change may resize previous window (setq rpt 2) (while (> rpt 0) (setq rpt (1- rpt)) (while (< ix max) (setq w (nth 3 (nth ix windows))) (setq resize (- size (- (nth far (window-edges w)) (nth edge (window-edges w))))) ; don't resize by 1 character (if (or (> resize 1) (< resize -1)) (progn (select-window w) ; window to work on (enlarge-window resize horizontally))) (setq ix (1+ ix))) (setq ix (- max count))) (setq ix max) (setq pass 2))) (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