From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: "Drew Adams" Newsgroups: gmane.emacs.devel Subject: FW: fit-frame.el Date: Sun, 9 Mar 2008 20:44:12 -0800 Message-ID: <004301c88269$637220e0$0600a8c0@us.oracle.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="----=_NextPart_000_0044_01C88226.554EE0E0" X-Trace: ger.gmane.org 1205124357 5801 80.91.229.12 (10 Mar 2008 04:45:57 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 10 Mar 2008 04:45:57 +0000 (UTC) To: "Emacs-Devel" Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Mon Mar 10 05:46:25 2008 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1JYZu3-0003TN-DY for ged-emacs-devel@m.gmane.org; Mon, 10 Mar 2008 05:46:24 +0100 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1JYZtV-0002SU-0k for ged-emacs-devel@m.gmane.org; Mon, 10 Mar 2008 00:45:49 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1JYZtM-0002Q9-NX for emacs-devel@gnu.org; Mon, 10 Mar 2008 00:45:40 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1JYZtK-0002Oc-Ba for emacs-devel@gnu.org; Mon, 10 Mar 2008 00:45:39 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1JYZtJ-0002OH-Uo for emacs-devel@gnu.org; Mon, 10 Mar 2008 00:45:38 -0400 Original-Received: from agminet01.oracle.com ([141.146.126.228]) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1JYZtJ-0003ZS-EM for emacs-devel@gnu.org; Mon, 10 Mar 2008 00:45:38 -0400 Original-Received: from rgmgw1.us.oracle.com (rgmgw1.us.oracle.com [138.1.186.110]) by agminet01.oracle.com (Switch-3.2.4/Switch-3.1.7) with ESMTP id m2A4jXvU019015 for ; Sun, 9 Mar 2008 23:45:33 -0500 Original-Received: from acsmt351.oracle.com (acsmt351.oracle.com [141.146.40.151]) by rgmgw1.us.oracle.com (Switch-3.2.4/Switch-3.2.4) with ESMTP id m2A4jWRs021227 for ; Sun, 9 Mar 2008 22:45:32 -0600 Original-Received: from inet-141-146-46-1.oracle.com by acsmt351.oracle.com with ESMTP id 3605851121205124307; Sun, 09 Mar 2008 21:45:07 -0700 Original-Received: from dradamslap1 (/141.144.112.116) by bhmail.oracle.com (Oracle Beehive Gateway v4.0) with ESMTP ; Sun, 09 Mar 2008 21:45:06 -0700 X-Mailer: Microsoft Office Outlook 11 Thread-Index: Achsz/BQt5/CzlI+R+qM4eZY9bV13wVmVxOA X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.3198 X-Brightmail-Tracker: AAAAAQAAAAI= X-Brightmail-Tracker: AAAAAQAAAAI= X-Whitelist: TRUE X-Whitelist: TRUE X-detected-kernel: by monty-python.gnu.org: Linux 2.4-2.6 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:91999 Archived-At: This is a multi-part message in MIME format. ------=_NextPart_000_0044_01C88226.554EE0E0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Resending for review. ---- > From: Richard Stallman Sent: Tuesday, January 15, 2008 6:42 PM > Would people please read the file fit-frame.el > that was sent by Drew Adams on Dec 30, and comment on it? ---- > From: Drew Adams Sent: Sunday, December 30, 2007 7:02 PM > Attached is library `fit-frame.el', for possible inclusion in Emacs. > > Command `fit-frame' fits a frame to its buffer(s). See the > doc string, in particular, for the use of a prefix arg. A > common use is to fit a one-window frame to its buffer. > > Users can set minimum and maximum width and height limits. > Within those limits, the width of a one-window frame that has > been fit accommodates all of the buffer lines without > wrapping, and the height accommodates all of the buffer lines. > > Please give it a try. Let me know, especially, how well it > works on different platforms and with different kinds of > buffers. I've tried to take into account the menu-bar, > minibuffer, and tool-bar, and I've tried to compensate for > long header lines in some buffers, such as Dired. > > Wrt the last point: header lines can be wrapped in some modes > - see option `fit-frame-skip-header-lines-alist'. In these > cases, a header line is ignored, in order not to let its > exceptional length skew the width measurement. Example: Dired > with `dired-details' hiding details - the frame is only as > wide as the longest file-name length, not the directory name > in the header line. > > Note too that if a buffer contains faces larger than the > default for the frame, or characters that are extra-wide, > then fitting is not perfect. For example, TAB characters in > Info menus can in some cases cause a menu line to wrap, and > likewise for the slightly larger characters of raised buttons > in Customize. This is because the computed size is based only > on the frame's default character size. ------=_NextPart_000_0044_01C88226.554EE0E0 Content-Type: application/octet-stream; name="fit-frame-2007-12-30.el" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="fit-frame-2007-12-30.el" ;;; fit-frame.el --- Resize a frame. In particular, fit a frame to its = buffers.=0A= ;;=0A= ;; Filename: fit-frame.el=0A= ;; Description: Resize a frame. In particular, fit a frame to its = buffers.=0A= ;; Author: Drew Adams=0A= ;; Maintainer: Drew Adams=0A= ;; Copyright (C) 2000-2007, Drew Adams, all rights reserved.=0A= ;; Created: Thu Dec 7 09:32:12 2000=0A= ;; Version: 22.0=0A= ;; Last-Updated: Sun Dec 30 18:43:49 2007 (-28800 Pacific Standard Time)=0A= ;; By: dradams=0A= ;; Update #: 1159=0A= ;; Keywords: convenience, frame, window=0A= ;; Compatibility: GNU Emacs 22.x=0A= ;;=0A= ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;=0A= ;;=0A= ;;; Commentary:=0A= ;;=0A= ;; Resize a frame. In particular, fit a frame to its buffers.=0A= ;;=0A= ;; Commands and user options (variables) are provided here to resize=0A= ;; (shrink-wrap) a frame to fit its displayed buffers, its selected=0A= ;; buffer, or the `fill-column' width.=0A= ;;=0A= ;; The command to fit a frame is `fit-frame'. The main user options=0A= ;; for this command are `fit-frame-inhibit-fitting-flag' and=0A= ;; `fit-frame-max-*[-percent]'. You can use a prefix argument to=0A= ;; control the behavior of command `fit-frame'.=0A= ;;=0A= ;; Put this in your initialization file (`~/.emacs'):=0A= ;;=0A= ;; (require 'fit-frame)=0A= ;; (add-hook 'after-make-frame-functions 'fit-frame)=0A= ;;=0A= ;; The second line here causes newly created frames to be fitted to=0A= ;; their buffer.=0A= ;;=0A= ;; Command `fit-frame' does *not* take the following into account,=0A= ;; when determining the proper frame size:=0A= ;;=0A= ;; - font sizes, other than the default frame font=0A= ;; - characters, such as TAB, that have special widths=0A= ;;=0A= ;; Suggested key bindings:=0A= ;;=0A= ;; (global-set-key [(control ?x) (control ?_)] 'fit-frame)=0A= ;; (global-set-key [vertical-line down-mouse-1]=0A= ;; 'fit-frame-or-mouse-drag-vertical-line)=0A= ;;=0A= ;; Customize the menu-bar. Uncomment this to try it out.=0A= ;;=0A= ;; (defvar menu-bar-frames-menu (make-sparse-keymap "Frames"))=0A= ;; (define-key global-map [menu-bar frames]=0A= ;; (cons "Frames" menu-bar-frames-menu)))=0A= ;; (define-key menu-bar-frames-menu [fit-frame]=0A= ;; '("Fit This Frame" . fit-frame))=0A= ;;=0A= ;; TO DO:=0A= ;;=0A= ;; Emacs needs a command similar to `fit-frame' for windows, that is,=0A= ;; a command that will fit the existing windows of a frame to their=0A= ;; buffers, as well as possible. That could be then be used in=0A= ;; combination with `fit-frame'.=0A= ;;=0A= ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;=0A= ;;=0A= ;; This program is free software; you can redistribute it and/or modify=0A= ;; it under the terms of the GNU General Public License as published by=0A= ;; the Free Software Foundation; either version 3, or (at your option)=0A= ;; any later version.=0A= =0A= ;; This program is distributed in the hope that it will be useful,=0A= ;; but WITHOUT ANY WARRANTY; without even the implied warranty of=0A= ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the=0A= ;; GNU General Public License for more details.=0A= =0A= ;; You should have received a copy of the GNU General Public License=0A= ;; along with this program; see the file COPYING. If not, write to=0A= ;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth=0A= ;; Floor, Boston, MA 02110-1301, USA.=0A= ;;=0A= ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;=0A= =0C=0A= ;;; User options ---------------------------------------------------=0A= =0A= ;;;###autoload=0A= (defgroup fit-frame nil=0A= "Resize a frame to fit its buffers."=0A= :group 'frames :group 'convenience)=0A= =0A= ;;;###autoload=0A= (defcustom fit-frame-inhibit-fitting-flag nil=0A= "*Non-nil means command `fit-frame' does nothing.=0A= You can bind this to non-`nil' to temporarily inhibit frame fitting:=0A= (let ((fit-frame-inhibit-fitting-flag t))...)"=0A= :type 'boolean :group 'fit-frame)=0A= =0A= ;;;###autoload=0A= (defcustom fit-frame-min-width 20=0A= "*Minimum width, in characters, that `fit-frame' gives to a frame.=0A= The actual minimum is at least the greater of this and = `window-min-width'."=0A= :type 'integer :group 'fit-frame)=0A= =0A= ;;;###autoload=0A= (defcustom fit-frame-max-width nil=0A= "*Maximum width, in characters, that `fit-frame' gives to a frame.=0A= If nil, then the function `fit-frame-max-width' is used instead."=0A= :type '(choice (const :tag "Use `fit-frame-max-width-percent' instead" = nil)=0A= integer)=0A= :group 'fit-frame)=0A= =0A= ;;;###autoload=0A= (defcustom fit-frame-max-width-percent 94=0A= "*Maximum percent of display width that `fit-frame' gives to a frame'.=0A= See function `fit-frame-max-width'.=0A= Not used unless `fit-frame-max-width' is nil."=0A= :type 'integer :group 'fit-frame)=0A= =0A= ;;;###autoload=0A= (defcustom fit-frame-min-height window-min-height=0A= "*Minimum height, in lines, that `fit-frame' gives to a frame.=0A= The actual minimum is at least the greater of this and = `window-min-height'."=0A= :type 'integer :group 'fit-frame)=0A= =0A= ;;;###autoload=0A= (defcustom fit-frame-max-height nil=0A= "*Maximum height, in lines, that `fit-frame' gives to a frame.=0A= If nil, then the function `fit-frame-max-height' is used instead."=0A= :type '(choice (const :tag "Use `fit-frame-max-height-percent' = instead" nil)=0A= integer)=0A= :group 'fit-frame)=0A= =0A= ;;;###autoload=0A= (defcustom fit-frame-max-height-percent 82=0A= "*Maximum percent of display height that `fit-frame' gives to a frame.=0A= See function `fit-frame-max-height'.=0A= Not used unless `fit-frame-max-height' is nil."=0A= :type 'integer :group 'fit-frame)=0A= =0A= ;;;###autoload=0A= (defcustom fit-frame-empty-width (or (cdr (assq 'width = default-frame-alist)) 80)=0A= "*Width, in characters, that `fit-frame' gives to an empty frame."=0A= :type 'integer :group 'fit-frame)=0A= =0A= ;;;###autoload=0A= (defcustom fit-frame-empty-height (or (cdr (assq 'height = default-frame-alist)) 35)=0A= "*Height, in lines, that `fit-frame' gives to an empty frame."=0A= :type 'integer :group 'fit-frame)=0A= =0A= ;;;###autoload=0A= (defcustom fit-frame-empty-special-display-width 80=0A= "*Width, in chars, that `fit-frame' gives to an empty special-display = frame.=0A= If this is nil, it is ignored."=0A= :type 'integer :group 'fit-frame)=0A= =0A= ;;;###autoload=0A= (defcustom fit-frame-empty-special-display-height 9=0A= "*Height, in lines, that `fit-frame' gives to an empty special-display = frame.=0A= If this is nil, it is ignored."=0A= :type 'integer :group 'fit-frame)=0A= =0A= ;;;###autoload=0A= (defcustom fit-frame-fill-column-margin 7=0A= "*Difference between `fill-column' and frame width after fitting a = frame.=0A= Used when `fit-frame' fits a frame, if the prefix arg is negative.=0A= Depending on the average word length of the language used in the=0A= selected window, you might want different values for this. For this=0A= reason, writers of some modes might want to make this buffer-local."=0A= :type 'integer :group 'fit-frame)=0A= =0A= ;;;###autoload=0A= (defcustom fit-frame-skip-header-lines-alist=0A= '((Info-mode . 1) (dired-mode . 2) (compilation-mode . 2))=0A= "*Alist of major-modes and header lines to ignore.=0A= =0A= When `fit-frame' calculates the width of the current buffer, it can=0A= first skip some lines at the buffer beginning, ignoring their=0A= widths. For example, Info, Dired, and compilation buffers sometimes=0A= have a long header line at the top. You can use this alist to tell=0A= `fit-frame' to ignore the width of these header lines.=0A= =0A= Each item in the alist is of form (MODE . LINES).=0A= MODE is a major-mode name.=0A= LINES is the number of lines to skip at the beginning of the buffer."=0A= :type '(repeat (cons :format "%v" (symbol :tag "Major Mode")=0A= (integer :tag "Header Lines to Ignore")))=0A= :group 'fit-frame)=0A= =0C=0A= ;;; Commands ---------------------------------------------------=0A= =0A= ;;;###autoload=0A= (defun fit-frame (&optional frame width height all-windows-p)=0A= "Resize FRAME to fit its buffer(s).=0A= Does nothing if `fit-frame-inhibit-fitting-flag' is non-nil.=0A= =0A= FRAME defaults to the current (i.e. selected) frame.=0A= =0A= If non-nil, WIDTH and HEIGHT specify the frame width and height. To=0A= define them interactively, use a non-negative prefix arg (e.g. `C-9').=0A= =0A= To set the width to `fill-column' + `fit-frame-fill-column-margin',=0A= use a negative prefix arg (e.g. `M--').=0A= =0A= To fit the frame to all of its displayed buffers, use no prefix arg.=0A= To fit it to just the current buffer, use a plain prefix arg (`C-u').=0A= =0A= Fitting a non-empty buffer means resizing the frame to the smallest=0A= size such that the following are both true:=0A= =0A= * The width is at least `fit-frame-min-width' and `window-min-width'.=0A= The width is at most `fit-frame-max-width(-percent)' and the=0A= longest line length.=0A= =0A= * The height is at least `fit-frame-min-height' and=0A= `window-min-height'. The height is at most=0A= `fit-frame-max-height(-percent)' and the number of lines.=0A= =0A= You can thus use those user variables to control the maximum and=0A= minimum frame sizes. The `*-percent' options let you specify the=0A= maximum as a percentage of your display size.=0A= =0A= See also option `fit-frame-skip-header-lines-alist'.=0A= =0A= The following user options control how an empty frame is fit.=0A= An empty frame is a one-window frame displaying an empty buffer.=0A= =0A= * `fit-frame-empty-width', `fit-frame-empty-height' (normal buffer)=0A= * `fit-frame-empty-special-display-width',=0A= `fit-frame-empty-special-display-height' (special-display buffer)"=0A= (interactive=0A= (let ((option (prefix-numeric-value current-prefix-arg)))=0A= (list nil=0A= ;; Plain `C-u' means WIDTH, HEIGHT, and ALL-WINDOWS-P are all = nil.=0A= ;; Non-negative prefix arg means prompt user for WIDTH and = HEIGHT.=0A= ;; Negative prefix arg means use=0A= ;; `fill-column' + `fit-frame-fill-column-margin'=0A= ;; for WIDTH, and use current frame height for HEIGHT.=0A= (and current-prefix-arg (atom current-prefix-arg)=0A= (if (natnump option)=0A= (floor (if (fboundp 'read-number)=0A= (read-number "New width: ")=0A= (string-to-number (read-string "New width: = "))))=0A= (+ fill-column fit-frame-fill-column-margin)))=0A= (and current-prefix-arg (atom current-prefix-arg)=0A= (if (natnump option)=0A= (floor (if (fboundp 'read-number)=0A= (read-number "New height: ")=0A= (string-to-number (read-string "New height: = "))))=0A= (frame-height)))=0A= (atom current-prefix-arg))))=0A= (setq frame (or frame (selected-frame)))=0A= (unless fit-frame-inhibit-fitting-flag=0A= (let (extra-lines computed-max-frame-size empty-buf-p specbuf-p)=0A= (save-window-excursion=0A= (select-frame frame)=0A= (setq empty-buf-p (and (=3D (point-min) (point-max))=0A= (one-window-p (selected-window)))=0A= specbuf-p (and empty-buf-p=0A= (special-display-p (buffer-name = (window-buffer))))))=0A= ;; `extra-lines' for minimum frame height. `set-frame-size' = includes the=0A= ;; tool-bar and the minibuffer. For Emacs without a toolkit, the = one-line=0A= ;; menu-bar is also included - add 1 line for that. Add 1 line = for the=0A= ;; minibuffer, unless it is standalone. Perhaps we should also = take into=0A= ;; account a possible horizontal scroll bar, but we don't do that.=0A= (let* ((fparams (frame-parameters frame)))=0A= (setq extra-lines (+ 2 ; Minimum is 1 for empty + 1 = extra.=0A= (or (cdr (assq 'tool-bar-lines fparams)) = 0))) ; Tool bar.=0A= (when (and (cdr (assq 'minibuffer fparams)) ; Frame has a = minibuffer, but=0A= (save-window-excursion (select-frame frame) ; it's = not standalone.=0A= (not (one-window-p nil = 'selected-frame))))=0A= (setq extra-lines (1+ extra-lines))))=0A= (when (and (not (eq system-type 'windows-nt)) (not (featurep = 'x-toolkit)))=0A= (setq extra-lines (1+ extra-lines)))=0A= (unless (or empty-buf-p (and width height))=0A= (setq computed-max-frame-size (fit-frame-max-frame-size frame = all-windows-p)))=0A= (set-frame-size=0A= ;; Frame=0A= frame=0A= ;; Columns=0A= (or width=0A= (and empty-buf-p (if specbuf-p=0A= fit-frame-empty-special-display-width=0A= fit-frame-empty-width))=0A= (max fit-frame-min-width window-min-width=0A= (min (or fit-frame-max-width (fit-frame-max-width frame))=0A= (1+ (car computed-max-frame-size)))))=0A= ;; Rows=0A= (or height=0A= (and empty-buf-p (if specbuf-p=0A= fit-frame-empty-special-display-height=0A= fit-frame-empty-height))=0A= (max fit-frame-min-height window-min-height=0A= (min (or fit-frame-max-height (fit-frame-max-height = frame))=0A= (+ (cdr computed-max-frame-size) extra-lines))))))))=0A= =0A= ;;;###autoload=0A= (defun fit-frame-or-mouse-drag-vertical-line (start-event)=0A= "If only window in frame, `fit-frame'; else = `mouse-drag-vertical-line'."=0A= (interactive "e")=0A= (if (one-window-p t) (fit-frame) (mouse-drag-vertical-line = start-event)))=0A= =0C=0A= ;;; Non-Interactive Functions -------------------------------------------=0A= =0A= (defun fit-frame-max-width (&optional frame)=0A= "Returns the max width, in chars, for `fit-frame' to use for a new = frame.=0A= If option `fit-frame-max-width' is non-nil, then this is not used.=0A= =0A= The value is relative to your display size and FRAME's character=0A= size, and depends on the value of `fit-frame-max-width-percent':=0A= =0A= (/ (* fit-frame-max-width-percent (x-display-pixel-width))=0A= (* 100 (frame-char-width FRAME)))"=0A= (setq frame (or frame (selected-frame)))=0A= (/ (* fit-frame-max-width-percent=0A= (if (fboundp 'winmgr-display-available-pixel-bounds) ; For = MacIntosh.=0A= (nth 2 (winmgr-display-available-pixel-bounds))=0A= (x-display-pixel-width)))=0A= (* 100 (frame-char-width frame))))=0A= =0A= (defun fit-frame-max-height (&optional frame)=0A= "Returns the max height, in lines, for `fit-frame' to use for a new = frame.=0A= If option `fit-frame-max-height' is non-nil, then this is not used.=0A= =0A= The value is relative to your display size and FRAME's character=0A= size, and depends on the value of `fit-frame-max-height-percent':=0A= =0A= (/ (* fit-frame-max-height-percent (x-display-pixel-height))=0A= (* 100 (frame-char-height FRAME)))"=0A= (setq frame (or frame (selected-frame)))=0A= (/ (* fit-frame-max-height-percent=0A= (if (fboundp 'winmgr-display-available-pixel-bounds) ; For = MacIntosh.=0A= (nth 3 (winmgr-display-available-pixel-bounds))=0A= (x-display-pixel-height)))=0A= (* 100 (frame-char-height frame)=0A= ;; When fitting a thumbnail frame, we don't want the height to = use the=0A= ;; whole display height. So, we apply a fudge factor:=0A= ;; `fit-frame-thumbnail-factor'. We could also use it in=0A= ;; `fit-frame-max-width', in addition to `fit-frame-max-height',=0A= ;; but we don't need to.=0A= (fit-frame-thumbnail-factor frame))))=0A= =0A= (defun fit-frame-max-frame-size (frame all-windows-p)=0A= "Return maximum size of frame FRAME as a cons: (MAX-WIDTH . = MAX-HEIGHT).=0A= If ALL-WINDOWS-P is non-nil, then consider all buffers shown in FRAME.=0A= Otherwise, consider only the selected buffer."=0A= (save-window-excursion=0A= (select-frame frame)=0A= (if (not all-windows-p)=0A= (fit-frame-max-window-size (selected-window))=0A= (let* ((wins ())=0A= (marked-wins ()) ; Windows whose size was already = considered.=0A= (max-width 0)=0A= (max-height 0))=0A= (walk-windows (lambda (w) (push w wins)) 'no-mini 'this-frame)=0A= (setq wins (sort wins (lambda (w1 w2) ; Top to bottom, left to = right.=0A= (let ((edges1 (window-edges w1))=0A= (edges2 (window-edges w2)))=0A= (or (< (cadr edges1) (cadr edges2)) ; = top=0A= (and (=3D (cadr edges1) (cadr = edges2))=0A= (<=3D (car edges1) (car = edges2)))))))) ; left=0A= ;; Iterate over all windows in frame.=0A= ;; For each, check all windows in the same row, and all in the = same column.=0A= ;; When checking those in the same row:=0A= ;; 1. Increase MAX-HEIGHT to the max buffer height of the row = windows.=0A= ;; 2. Increase MAX-WIDTH to the sum of the buffer widths of = the row windows.=0A= ;; When checking those in the same column:=0A= ;; 1. Increase MAX-WIDTH to the max buffer width of the column = windows.=0A= ;; 2. Increase MAX-HEIGHT to the sum of the buffer heights of = the col windows.=0A= ;; After examining a window in the frame, exclude it from = further examination=0A= ;; by adding it to MARKED-WINS.=0A= (dolist (win wins)=0A= (unless (memq win marked-wins)=0A= (let* ((win-edges (window-edges win))=0A= (win-top (cadr win-edges))=0A= (win-left (car win-edges)))=0A= ;; Add widths of buffers in the same row. Max the heights = of the buffers.=0A= (dolist (row-win (fit-frame-same-row-windows wins win = marked-wins))=0A= ;; Add ROW-WIN to exclusion list for subsequent = iterations.=0A= (setq marked-wins (cons row-win marked-wins))=0A= (let* ((win-size (fit-frame-max-window-size row-win))=0A= (max-win-width (car win-size))=0A= (max-win-height (cdr win-size)))=0A= (unless (> (cadr (window-edges row-win)) win-top) ; = Use only first.=0A= (setq max-width (+ max-width max-win-width)))=0A= (setq max-height (max max-height max-win-height))))=0A= ;; Add heights of buffers in the same column. Max the = buffer widths.=0A= (dolist (col-win (fit-frame-same-column-windows wins win = marked-wins))=0A= ;; Add COL-WIN to exclusion list for subsequent = iterations.=0A= (setq marked-wins (cons col-win marked-wins))=0A= (let* ((win-size (fit-frame-max-window-size col-win))=0A= (max-win-width (car win-size))=0A= (max-win-height (cdr win-size)))=0A= (unless (> (car (window-edges col-win)) win-left) ; = Use only first.=0A= (setq max-height (+ max-height max-win-height)))=0A= (setq max-width (max max-width max-win-width)))))))=0A= (cons max-width max-height)))))=0A= =0A= (defun fit-frame-same-row-windows (wins window exclude)=0A= "Returns the windows in WINS that are in the same row as window WINDOW.=0A= This the list of windows in WINS whose top edge is above the bottom=0A= edge of WINDOW.=0A= Windows that are in list EXCLUDE are excluded from the result."=0A= (let ((ref-bottom (cadddr (window-edges window)))=0A= (row-wins ()))=0A= (dolist (win wins)=0A= (when (and (not (memq win exclude)) (< (cadr (window-edges win)) = ref-bottom))=0A= (push win row-wins)))=0A= row-wins))=0A= =0A= (defun fit-frame-same-column-windows (wins window exclude)=0A= "Returns the windows in WINS that are in the same column as window = WINDOW.=0A= This the list of windows in WINS whose left edge is to the left of the=0A= right edge of WINDOW.=0A= Windows that are in list EXCLUDE are excluded from the result."=0A= (let ((ref-right (caddr (window-edges window)))=0A= (col-wins ()))=0A= (dolist (win wins)=0A= (when (and (not (memq win exclude)) (< (car (window-edges win)) = ref-right))=0A= (push win col-wins)))=0A= col-wins))=0A= =0A= (defun fit-frame-max-window-size (window)=0A= "Maximum size that would be needed to display the buffer in WINDOW.=0A= Returned as a cons: (MAX-WIDTH . MAX-HEIGHT), where:=0A= MAX-WIDTH is the maximum width, in characters.=0A= MAX-HEIGHT is the maximum height, in lines."=0A= (select-window window)=0A= (let ((hdr-lines (cdr (assq major-mode = fit-frame-skip-header-lines-alist)))=0A= (hdr-widths ())=0A= (max-win-width 0)=0A= (max-win-height 0))=0A= (save-excursion=0A= (set-buffer (window-buffer))=0A= (goto-char (point-min))=0A= ;; Don't count header lines for width calculation.=0A= (while (and hdr-lines (> hdr-lines 0))=0A= (end-of-line)=0A= (setq hdr-widths (cons (current-column) hdr-widths)=0A= hdr-lines (1- hdr-lines))=0A= (forward-line)=0A= (setq max-win-height (1+ max-win-height)))=0A= ;; Calculate maximum line width and number of lines.=0A= (while (not (eobp))=0A= (end-of-line)=0A= (setq max-win-width (max (current-column) max-win-width))=0A= (forward-line 1)=0A= (setq max-win-height (1+ max-win-height))))=0A= ;; Add height for any wrap-around header lines.=0A= (while hdr-widths=0A= (when (> (car hdr-widths) max-win-width)=0A= (if (zerop max-win-width)=0A= (setq max-win-height (1+ max-win-height))=0A= (let ((nb-wraps (/ (car hdr-widths) max-win-width))=0A= (remainder (% (car hdr-widths) max-win-width)))=0A= (unless (zerop remainder) (setq nb-wraps (1+ nb-wraps)))=0A= (setq max-win-height (+ max-win-height nb-wraps)))))=0A= (setq hdr-widths (cdr hdr-widths)))=0A= (cons max-win-width max-win-height)))=0A= =0A= (defun fit-frame-thumbnail-factor (frame)=0A= "Shrink factor for thumbnail frames. See `thumb-frm.el'.=0A= FRAME is the frame to apply factor to."=0A= (let ((char-height (frame-char-height frame)))=0A= (if (and (fboundp 'thumbnail-frame-p) ; Defined in `thumb-frm.el'=0A= (thumbnail-frame-p frame))=0A= ;; Need integer result for `set-frame-size'. 1+ because of = integer round-off.=0A= (1+ (/ (+ char-height frame-thumbnail-font-difference) = char-height))=0A= 1)))=0A= =0A= ;;;;;;;;;;=0A= =0A= (provide 'fit-frame)=0A= =0A= ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;=0A= ;;; fit-frame.el ends here=0A= ------=_NextPart_000_0044_01C88226.554EE0E0--