From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Pascal Bourguignon Newsgroups: gmane.emacs.help Subject: Re: Making the width of three windows equal Date: Wed, 03 Aug 2005 05:11:49 +0200 Organization: [posted via Easynet Spain] Message-ID: <87fytr3ea2.fsf@thalassa.informatimago.com> References: <87pssv3kai.fsf@thalassa.informatimago.com> <1123035204.009217.187300@g14g2000cwa.googlegroups.com> NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: sea.gmane.org 1123038841 22882 80.91.229.2 (3 Aug 2005 03:14:01 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Wed, 3 Aug 2005 03:14:01 +0000 (UTC) Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Wed Aug 03 05:13:58 2005 Return-path: Original-Received: from lists.gnu.org ([199.232.76.165]) by ciao.gmane.org with esmtp (Exim 4.43) id 1E09gH-0003YR-Ci for geh-help-gnu-emacs@m.gmane.org; Wed, 03 Aug 2005 05:12:34 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1E09j0-0002QJ-0b for geh-help-gnu-emacs@m.gmane.org; Tue, 02 Aug 2005 23:15:22 -0400 Original-Path: shelby.stanford.edu!newsfeed.stanford.edu!news.tele.dk!news.tele.dk!small.news.tele.dk!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!feed.news.tiscali.de!easynet-quince!easynet.net!easynet-post2!not-for-mail Original-Newsgroups: gnu.emacs.help User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.0.50 (gnu/linux) Cancel-Lock: sha1:6APbRlnPh3ZefrRRTQJXiceQF2k= Original-Lines: 104 Original-NNTP-Posting-Host: 62.93.174.79 Original-X-Trace: DXC=`6YGUg;UmQFP3VbBd4DjF1d]Q Original-Xref: shelby.stanford.edu gnu.emacs.help:132859 Original-To: help-gnu-emacs@gnu.org 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:28373 X-Report-Spam: http://spam.gmane.org/gmane.emacs.help:28373 "Samuel" writes: > Pascal Bourguignon wrote: >> > When opening multiple (three) vertically split windows by pressing C-x 3 >> > twice, one of the windows takes up 50% of the screen width and the other >> > two 25% each. I am looking for an equivalent to what C-x + does for >> > horizontally split windows, that is, making each of them take up 33% of >> > the terminal width. Is there a shortcut to do this? >> >> Since balance-windows doesn't work vertically (or is it >> horizontally?), your best bet is to fetch its sources and to edit them >> to implement horizontal (or is it vertical?) window balancing. > > Thanks, Pascal. > (I had a look at the balance-windows source now, but geesh, this > language is just out of my range.) Well, even if you don't understand anything to lisp, it's quite easy to substitute width for height, left for bottom and right for top, isn't it? (defun horizontal-offset () "Number of columns taken by the fringe and vertical scroll bar" ;; TODO: Implement in function of the effective fringe and vertical scroll bar. 5) (defun balance-windows-vertically () "Make all visible windows the same width (approximately)." (interactive) (let ((count -1) levels newsizes level-size (last-window (previous-window (frame-first-window (selected-frame)))) ;; Don't count the columns that are past the lowest main window. total) ;; Rightmost edge of last window determines what size we have to work with. (setq total (+ (window-width last-window) (horizontal-offset) (nth 0 (window-edges last-window)))) ;; Find all the different hpos's at which windows start, ;; then count them. But ignore levels that differ by only 1. (let (lefts (prev-left -2)) (walk-windows (function (lambda (w) (setq lefts (cons (nth 0 (window-edges w)) lefts)))) 'nomini) (setq lefts (sort lefts '<)) (while lefts (if (> (car lefts) (1+ prev-left)) (setq prev-left (car lefts) count (1+ count))) (setq levels (cons (cons (car lefts) count) levels)) (setq lefts (cdr lefts))) (setq count (1+ count))) ;; Subdivide the frame into desired number of vertical levels. (setq level-size (/ total count)) (message "levels=%S" levels) (message "level-size=%S" level-size) (save-selected-window ;; Set up NEWSIZES to map windows to their desired sizes. ;; If a window ends at the rightmost level, don't include ;; it in NEWSIZES. Those windows get the right sizes ;; by adjusting the ones above them. (walk-windows (function (lambda (w) (let ((newleft (cdr (assq (nth 0 (window-edges w)) levels))) (newright (cdr (assq (+ (window-width w) (horizontal-offset) (nth 0 (window-edges w))) levels)))) (message "newleft=%S newright=%S" newleft newright) (if newright (setq newsizes (cons (cons w (* level-size (- newright newleft))) newsizes)))))) 'nomini) (message "newsizes=%S" newsizes) ;; Make walk-windows start with the leftmost window. (select-window (previous-window (frame-first-window (selected-frame)))) (let (done (count 0)) ;; Give each window its precomputed size, or at least try. ;; Keep trying until they all get the intended sizes, ;; but not more than 3 times (to prevent infinite loop). (while (and (not done) (< count 3)) (setq done t) (setq count (1+ count)) (walk-windows (function (lambda (w) (select-window w) (let ((newsize (cdr (assq w newsizes)))) (when newsize (enlarge-window (- newsize (horizontal-offset) (window-width)) t t) (unless (= (window-width) (- newsize (horizontal-offset))) (setq done nil)))))) 'nomini)))))) -- __Pascal Bourguignon__ http://www.informatimago.com/ Cats meow out of angst "Thumbs! If only we had thumbs! We could break so much!"