From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: martin rudalics Newsgroups: gmane.emacs.bugs Subject: bug#1488: 23.0.60; dired-pop-to-buffer: use fit-window-to-buffer Date: Sat, 06 Dec 2008 20:25:00 +0100 Message-ID: <493AD18C.6070002@gmx.at> References: <87fxl446mr.fsf@escher.local.home> <493939C0.7010507@gmx.at> <87bpvqttvr.fsf@escher.local.home> <493966D2.5050108@gmx.at> <877i6etrjp.fsf@escher.local.home> Reply-To: martin rudalics , 1488@emacsbugs.donarmstrong.com NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------060004000107090304000808" X-Trace: ger.gmane.org 1228593038 21429 80.91.229.12 (6 Dec 2008 19:50:38 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sat, 6 Dec 2008 19:50:38 +0000 (UTC) Cc: 1488@emacsbugs.donarmstrong.com To: Stephen Berman Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Sat Dec 06 20:51:42 2008 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1L93Bk-0005D5-AU for geb-bug-gnu-emacs@m.gmane.org; Sat, 06 Dec 2008 20:51:40 +0100 Original-Received: from localhost ([127.0.0.1]:58389 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1L93AZ-0001Md-Le for geb-bug-gnu-emacs@m.gmane.org; Sat, 06 Dec 2008 14:50:27 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1L93AR-0001JL-CD for bug-gnu-emacs@gnu.org; Sat, 06 Dec 2008 14:50:19 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1L93AP-0001I7-HR for bug-gnu-emacs@gnu.org; Sat, 06 Dec 2008 14:50:18 -0500 Original-Received: from [199.232.76.173] (port=53810 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1L93AP-0001Hx-9I for bug-gnu-emacs@gnu.org; Sat, 06 Dec 2008 14:50:17 -0500 Original-Received: from rzlab.ucr.edu ([138.23.92.77]:37277) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1L93AO-00044D-Hp for bug-gnu-emacs@gnu.org; Sat, 06 Dec 2008 14:50:17 -0500 Original-Received: from rzlab.ucr.edu (rzlab.ucr.edu [127.0.0.1]) by rzlab.ucr.edu (8.13.8/8.13.8/Debian-3) with ESMTP id mB6JoD7H007843; Sat, 6 Dec 2008 11:50:14 -0800 Original-Received: (from debbugs@localhost) by rzlab.ucr.edu (8.13.8/8.13.8/Submit) id mB6JZ3SY003450; Sat, 6 Dec 2008 11:35:03 -0800 X-Loop: don@donarmstrong.com Resent-From: martin rudalics Resent-To: bug-submit-list@donarmstrong.com Resent-CC: Emacs Bugs Resent-Date: Sat, 06 Dec 2008 19:35:03 +0000 Resent-Message-ID: Resent-Sender: don@donarmstrong.com X-Emacs-PR-Message: report 1488 X-Emacs-PR-Package: emacs X-Emacs-PR-Keywords: Original-Received: via spool by 1488-submit@emacsbugs.donarmstrong.com id=B1488.12285917142053 (code B ref 1488); Sat, 06 Dec 2008 19:35:03 +0000 Original-Received: (at 1488) by emacsbugs.donarmstrong.com; 6 Dec 2008 19:28:34 +0000 Original-Received: from mail.gmx.net (mail.gmx.net [213.165.64.20]) by rzlab.ucr.edu (8.13.8/8.13.8/Debian-3) with SMTP id mB6JST1d002046 for <1488@emacsbugs.donarmstrong.com>; Sat, 6 Dec 2008 11:28:30 -0800 Original-Received: (qmail invoked by alias); 06 Dec 2008 19:28:23 -0000 Original-Received: from 62-47-55-164.adsl.highway.telekom.at (EHLO [62.47.55.164]) [62.47.55.164] by mail.gmx.net (mp069) with SMTP; 06 Dec 2008 20:28:23 +0100 X-Authenticated: #14592706 X-Provags-ID: V01U2FsdGVkX1+NSMIGYsON1KxVijubEbifxTU5pmGEtDakGnw9/e vo3pkg1xdDquuD User-Agent: Thunderbird 2.0.0.16 (Windows/20080708) In-Reply-To: <877i6etrjp.fsf@escher.local.home> X-Y-GMX-Trusted: 0 X-FuHaFi: 0.82,0.48 X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6 (newer, 3) Resent-Date: Sat, 06 Dec 2008 14:50:18 -0500 X-BeenThere: bug-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:23013 Archived-At: This is a multi-part message in MIME format. --------------060004000107090304000808 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Stephen, `fit-window-to-buffer' had more bugs than I thought. I rewrote it completely but you would have to use it for a couple of days to know whether it DTRT. Patch attached. martin --------------060004000107090304000808 Content-Type: text/plain; name="window.el.diff" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="window.el.diff" *** window.el.~1.169.~ 2008-11-27 11:14:14.671875000 +0100 --- window.el 2008-12-06 20:20:34.390625000 +0100 *************** *** 1296,1379 **** "Adjust height of WINDOW to display its buffer's contents exactly. WINDOW defaults to the selected window. Optional argument MAX-HEIGHT specifies the maximum height of the ! window and defaults to the height of WINDOW's frame. Optional argument MIN-HEIGHT specifies the minimum height of the window and defaults to `window-min-height'. Both, MAX-HEIGHT and MIN-HEIGHT are specified in lines and include the mode line and header line, if any. Always return nil." (interactive) ! ! (when (null window) ! (setq window (selected-window))) ! (when (null max-height) ! (setq max-height (frame-height (window-frame window)))) ! ! (let* ((buf ! ;; Buffer that is displayed in WINDOW ! (window-buffer window)) ! (window-height ! ;; The current height of WINDOW ! (window-height window)) ! (desired-height ! ;; The height necessary to show the buffer displayed by WINDOW ! ;; (`count-screen-lines' always works on the current buffer). ! (with-current-buffer buf ! (+ (count-screen-lines) ! ;; If the buffer is empty, (count-screen-lines) is ! ;; zero. But, even in that case, we need one text line ! ;; for cursor. ! (if (= (point-min) (point-max)) ! 1 0) ! ;; For non-minibuffers, count the mode-line, if any ! (if (and (not (window-minibuffer-p window)) ! mode-line-format) ! 1 0) ! ;; Count the header-line, if any ! (if header-line-format 1 0)))) ! (delta ! ;; Calculate how much the window height has to change to show ! ;; desired-height lines, constrained by MIN-HEIGHT and MAX-HEIGHT. ! (- (max (min desired-height max-height) ! (or min-height window-min-height)) ! window-height))) ! ! ;; Don't try to redisplay with the cursor at the end ! ;; on its own line--that would force a scroll and spoil things. ! (when (with-current-buffer buf ! (and (eobp) (bolp) (not (bobp)))) ! (set-window-point window (1- (window-point window)))) ! ! (save-selected-window ! (select-window window 'norecord) ! ! ;; Adjust WINDOW to the nominally correct size (which may actually ! ;; be slightly off because of variable height text, etc). ! (unless (zerop delta) ! (enlarge-window delta)) ! ! ;; Check if the last line is surely fully visible. If not, ! ;; enlarge the window. ! (let ((end (with-current-buffer buf ! (save-excursion ! (goto-char (point-max)) ! (when (and (bolp) (not (bobp))) ! ;; Don't include final newline ! (backward-char 1)) ! (when truncate-lines ! ;; If line-wrapping is turned off, test the ! ;; beginning of the last line for visibility ! ;; instead of the end, as the end of the line ! ;; could be invisible by virtue of extending past ! ;; the edge of the window. ! (forward-line 0)) ! (point))))) ! (set-window-vscroll window 0) ! (while (and (< desired-height max-height) ! (= desired-height (window-height window)) ! (not (pos-visible-in-window-p end window))) ! (enlarge-window 1) ! (setq desired-height (1+ desired-height))))))) (defun window-safely-shrinkable-p (&optional window) "Return t if WINDOW can be shrunk without shrinking other windows. --- 1296,1383 ---- "Adjust height of WINDOW to display its buffer's contents exactly. WINDOW defaults to the selected window. Optional argument MAX-HEIGHT specifies the maximum height of the ! window and defaults to the maximum permissible height of a window ! on WINDOW's frame. Optional argument MIN-HEIGHT specifies the minimum height of the window and defaults to `window-min-height'. Both, MAX-HEIGHT and MIN-HEIGHT are specified in lines and include the mode line and header line, if any. Always return nil." (interactive) ! ;; Do all the work in WINDOW and its buffer and restore the selected ! ;; window and the current buffer when we're done. ! (save-excursion ! (with-selected-window (or window (selected-window)) ! (set-buffer (window-buffer)) ! (let* ((desired-height ! ;; The height necessary to show all of WINDOW's buffer. ! ;; For an empty buffer (count-screen-lines) returns zero. ! ;; Even in that case we need one line for the cursor. ! (+ (max (count-screen-lines) 1) ! ;; For non-minibuffers count the mode-line, if any. ! (if (and (not (window-minibuffer-p)) mode-line-format) 1 0) ! ;; Count the header-line, if any. ! (if header-line-format 1 0))) ! ;; MIN-HEIGHT must not be less than 1 and defaults to ! ;; `window-min-height'. ! (min-height (max (or min-height window-min-height) 1)) ! (max-window-height ! ;; Maximum height of any window on this frame. ! (min (window-height (frame-root-window)) (frame-height))) ! ;; MAX-HEIGHT must not be larger than max-window-height and ! ;; also defaults to that value. ! (max-height ! (min (or max-height max-window-height) max-window-height)) ! (delta ! ;; How much the window height has to change to show ! ;; desired-height lines, constrained by MIN-HEIGHT and ! ;; MAX-HEIGHT. ! (- (min max-height (max desired-height min-height)) ! (window-height))) ! ;; Avoid deleting this window if it becomes too small. As ! ;; a side-effect, this may keep some other windows as well. ! ! ;; Note: The following was removed by Jan on 2007-07-09 but ! ;; it seems needed to (1) avoid deleting the window we want ! ;; to shrink, and (2) as a consequence of (1) have ! ;; (window-height WINDOW) return the buffer displayed by ! ;; WINDOW which seems like a bug in delete_all_subwindows ! ;; which uses decode_any_window (so it doesn't care wether ! ;; WINDOW is live). ! (window-min-height 1)) ! ;; Don't try to redisplay with the cursor at the end on its own ! ;; line--that would force a scroll and spoil things. ! (when (and (eobp) (bolp) (not (bobp))) ! (set-window-point window (1- (window-point)))) ! ;; Use condition-case to handle any fixed-size windows and other ! ;; pitfalls nearby. ! (condition-case nil ! ;; Adjust WINDOW's height to the nominally correct one ! ;; (which may actually be slightly off because of variable ! ;; height text, etc). ! (unless (zerop delta) ! (enlarge-window delta) ! ;; Check if the last line is surely fully visible. If ! ;; not, enlarge the window. ! (let ((end (save-excursion ! (goto-char (point-max)) ! (when (and (bolp) (not (bobp))) ! ;; Don't include final newline ! (backward-char 1)) ! (when truncate-lines ! ;; If line-wrapping is turned off, test the ! ;; beginning of the last line for ! ;; visibility instead of the end, as the ! ;; end of the line could be invisible by ! ;; virtue of extending past the edge of the ! ;; window. ! (forward-line 0)) ! (point)))) ! (set-window-vscroll window 0) ! (while (and (< (window-height) max-height) ! (not (pos-visible-in-window-p end))) ! (enlarge-window 1)))) ! (error nil)))))) (defun window-safely-shrinkable-p (&optional window) "Return t if WINDOW can be shrunk without shrinking other windows. --------------060004000107090304000808--