Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!husc6!mit-eddie!YALE.ARPA!ram-ashwin From: ram-ashwin@YALE.ARPA (Ashwin Ram) Newsgroups: comp.emacs Subject: walk-windows Message-ID: <8711161522.AA06021@ELI.CS.YALE.EDU> Date: Mon, 16-Nov-87 10:22:24 EST Article-I.D.: ELI.8711161522.AA06021 Posted: Mon Nov 16 10:22:24 1987 Date-Received: Wed, 18-Nov-87 02:49:51 EST Sender: daemon@eddie.MIT.EDU Lines: 54 Here's a nice abstraction that lets you do things like count-windows and balance-windows pretty easily. The function walk-windows applies its argument, a procedure of one argument, to every visible window. Now it's trivial to define count-windows (pass down a lambda that increments a count), Mike's balance-windows (pass down a lambda that does an enlarge-window on each window). Etc. etc... -- Ashwin Ram -- ARPA: Ram-Ashwin@cs.yale.edu UUCP: {decvax,linus,seismo}!yale!Ram-Ashwin BITNET: Ram@yalecs ----------------------------------- cut ----------------------------------- ;; walk-windows and friends. ;; Ashwin Ram, 11/12/87. (defun walk-windows (proc &optional no-mini) "Applies PROC to each visible window. Optional arg NO-MINI non-nil means don't apply PROC to the minibuffer even if it is active." (let ((start (selected-window)) (current (next-window (selected-window) no-mini))) (while (not (eq current start)) (funcall proc current) (setq current (next-window current no-mini))))) (defun count-windows (&optional no-mini) "Returns the number of visible windows. Optional arg NO-MINI non-nil means don't count the minibuffer even if it is active." (let ((count 1)) (walk-windows (function (lambda (w) (ignore w) (setq count (+ count 1)))) no-mini) count)) (defun balance-windows () "Makes all visible windows the same size." (interactive) (let ((start (selected-window)) (size (/ (screen-height) (count-windows)))) (walk-windows (function (lambda (w) (select-window w) (enlarge-window (- size (window-height))))) 'no-mini) (select-window start))) ----------------------------------- cut ----------------------------------- P.S. enlarge-window really should take a window as its argument, rather than making you have to select the window first. When called interactively, that argument should default to the current window.