From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: storm@cua.dk (Kim F. Storm) Newsgroups: gmane.emacs.devel,gmane.emacs.help Subject: Re: balance-windows again Date: Thu, 29 Sep 2005 14:34:44 +0200 Message-ID: References: <4328B58E.6010103@student.lu.se> <432A6DC2.30606@student.lu.se> <432ABE47.1010909@student.lu.se> NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: sea.gmane.org 1127998488 3899 80.91.229.2 (29 Sep 2005 12:54:48 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Thu, 29 Sep 2005 12:54:48 +0000 (UTC) Cc: help-gnu-emacs@gnu.org, Emacs Devel Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Thu Sep 29 14:54:43 2005 Return-path: Original-Received: from lists.gnu.org ([199.232.76.165]) by ciao.gmane.org with esmtp (Exim 4.43) id 1EKxuK-0005j3-CM for ged-emacs-devel@m.gmane.org; Thu, 29 Sep 2005 14:53:04 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1EKxuJ-0006Pi-Id for ged-emacs-devel@m.gmane.org; Thu, 29 Sep 2005 08:53:03 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1EKxeI-0007cv-9j for emacs-devel@gnu.org; Thu, 29 Sep 2005 08:36:31 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1EKxeD-0007a4-Ba for emacs-devel@gnu.org; Thu, 29 Sep 2005 08:36:28 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1EKxeC-0007YB-MX; Thu, 29 Sep 2005 08:36:24 -0400 Original-Received: from [195.41.46.235] (helo=pfepa.post.tele.dk) by monty-python.gnu.org with esmtp (Exim 4.34) id 1EKxcw-0002ji-Ao; Thu, 29 Sep 2005 08:35:06 -0400 Original-Received: from kfs-l.imdomain.dk.cua.dk (unknown [80.165.4.124]) by pfepa.post.tele.dk (Postfix) with SMTP id 7757547FF2D; Thu, 29 Sep 2005 14:34:51 +0200 (CEST) Original-To: Lennart Borgman In-Reply-To: (Kim F. Storm's message of "Wed, 28 Sep 2005 00:57:06 +0200") User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.0.50 (gnu/linux) 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:43352 gmane.emacs.help:29809 Archived-At: storm@cua.dk (Kim F. Storm) writes: > The following patch adds a window-split-tree function which returns a simple > tree presentation of the window split. You can use window-edges on the > elements of the tree to get the dimensions (and build your representation). I think exposing the "container windows" as my previous patch did was a really bad idea. Instead, I prefer to explicitly include the window-edges of those windows. Below is a different patch which implements this. The new window-split-tree function doesn't return the format Lennart requested, but it is trivial to convert it to his proposed format: (defun balance-window-split (&optional frame) (balance-window-split-1 (car (window-split-tree frame)))) (defun balance-window-split-1 (split) (if (windowp split) split (let ((dir (car split)) (edges (car (cdr split))) (childs (cdr (cdr split)))) (list (cons 'dir (if dir 'ver 'hor)) (cons 'b (nth 3 edges)) (cons 'r (nth 2 edges)) (cons 't (nth 1 edges)) (cons 'l (nth 0 edges)) (cons 'childs (mapcar #'balance-window-split-1 childs)))))) Here's the revised patch: Index: window.c =================================================================== RCS file: /cvsroot/emacs/emacs/src/window.c,v retrieving revision 1.516 diff -c -r1.516 window.c *** window.c 18 Sep 2005 16:28:53 -0000 1.516 --- window.c 29 Sep 2005 12:31:57 -0000 *************** *** 6225,6230 **** --- 6226,6310 ---- return unbind_to (count, val); } + + + /*********************************************************************** + Window Split Tree + ***********************************************************************/ + + static Lisp_Object + window_split_tree (w) + struct window *w; + { + Lisp_Object tail = Qnil; + Lisp_Object result = Qnil; + + while (w) + { + Lisp_Object wn; + + XSETWINDOW (wn, w); + if (!NILP (w->hchild)) + wn = Fcons (Qnil, Fcons (Fwindow_edges (wn), + window_split_tree (XWINDOW (w->hchild)))); + else if (!NILP (w->vchild)) + wn = Fcons (Qt, Fcons (Fwindow_edges (wn), + window_split_tree (XWINDOW (w->vchild)))); + + if (NILP (result)) + { + result = tail = Fcons (wn, Qnil); + } + else + { + XSETCDR (tail, Fcons (wn, Qnil)); + tail = XCDR (tail); + } + + w = NILP (w->next) ? 0 : XWINDOW (w->next); + } + + return result; + } + + + + DEFUN ("window-split-tree", Fwindow_split_tree, Swindow_split_tree, + 0, 1, 0, + doc: /* Return the window split tree for frame FRAME. + + The return value is a list of the form (ROOT MINI), where ROOT + represents the window split tree of the frame's root window, and MINI + is the frame's minibuffer window. + + If the root window is not split, ROOT is the root window itself. + Otherwise, ROOT is a list (DIR EDGES W1 W2 ...) where DIR is nil for a + horisontal split, and t for a vertical split, EDGES gives the combined + size and position of the subwindows in the split, and the rest of the + elements are the subwindows in the split. Each of the subwindows may + again be a window or a list representing a window split, and so on. + EDGES is a list \(LEFT TOP RIGHT BOTTOM) as returned by `window-edges'. + + If FRAME is nil or omitted, return information on the currently + selected frame. */) + (frame) + Lisp_Object frame; + { + Lisp_Object alist; + FRAME_PTR f; + + if (NILP (frame)) + frame = selected_frame; + + CHECK_FRAME (frame); + f = XFRAME (frame); + + if (!FRAME_LIVE_P (f)) + return Qnil; + + return window_split_tree (XWINDOW (FRAME_ROOT_WINDOW (f))); + } + /*********************************************************************** Marginal Areas *************** *** 7031,7036 **** --- 7111,7117 ---- defsubr (&Sset_window_configuration); defsubr (&Scurrent_window_configuration); defsubr (&Ssave_window_excursion); + defsubr (&Swindow_split_tree); defsubr (&Sset_window_margins); defsubr (&Swindow_margins); defsubr (&Sset_window_fringes); -- Kim F. Storm http://www.cua.dk