Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!husc6!bloom-beacon!gatech!hubcap!beede From: beede@hubcap.UUCP (Mike Beede) Newsgroups: comp.emacs Subject: Re: How many windows? Message-ID: <641@hubcap.UUCP> Date: Tue, 10-Nov-87 09:29:34 EST Article-I.D.: hubcap.641 Posted: Tue Nov 10 09:29:34 1987 Date-Received: Thu, 12-Nov-87 20:06:33 EST References: <231@usl-pc.UUCP> Organization: Clemson University, Clemson, SC Lines: 50 in article <231@usl-pc.UUCP>, jpdres10@usl-pc.UUCP (Green Eric Lee) says: > > Is there any way to find out how many windows are on the screen in a > Elisp program (GNU Emacs version 18.??). I have a program that I want > to automatically split the screen into two windows, ONLY two windows, > that is, if we already have two windows on the screen, we DON'T want > to split into THREE windows. Since there is probably a more elegant (or maybe even built-in) way to do this, I post this code for comment/correction/flaming . . . (defun num-windows nil "Return number of open windows" (save-window-excursion (num-w) )) (defune num-w nil "Don't call this!" (cond ((one-window-p) 1) (t (delete-window) (1+ (num-w))) )) Another way to approach this would be to step through the windows until arriving back at the start. And while I'm at it, this is to balance the height of open windows, since I needed it for my program, where I didn't want more than n open windows-- all the same size (roughly): (defun balance-windows nil "Make windows' heights balanced" (let ((size (/ (screen-height) (num-windows)) (n (num-windows)) (i 1)) (while (<= i n) (if (< (window-height) size) (enlarge-window (- size (window-height))) (if (> (window-height) size) (shrink-window (- (window-height) size)) ) ) (setq i (1+ i)) (other-window 1) ) )) -- Mike Beede Computer Science Dept. UUCP: . . . !hubcap!beede Clemson University INET: beede@hubcap.clemson.edu Clemson SC 29634-1906 YOUR DIME: (803)656-{2845,3444}