From: martin rudalics <rudalics@gmx.at>
To: Stephen Berman <stephen.berman@gmx.net>
Cc: 1488@emacsbugs.donarmstrong.com
Subject: bug#1488: 23.0.60; dired-pop-to-buffer: use fit-window-to-buffer
Date: Sat, 06 Dec 2008 20:25:00 +0100 [thread overview]
Message-ID: <493AD18C.6070002@gmx.at> (raw)
In-Reply-To: <877i6etrjp.fsf@escher.local.home>
[-- Attachment #1: Type: text/plain, Size: 188 bytes --]
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
[-- Attachment #2: window.el.diff --]
[-- Type: text/plain, Size: 7566 bytes --]
*** 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.
next prev parent reply other threads:[~2008-12-06 19:25 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <4940E3E8.8050501@gmx.at>
2008-12-04 9:44 ` bug#1488: 23.0.60; dired-pop-to-buffer: use fit-window-to-buffer Stephen Berman
2008-12-04 17:23 ` Drew Adams
2008-12-04 17:58 ` martin rudalics
2008-12-04 18:33 ` martin rudalics
2008-12-05 14:25 ` martin rudalics
2008-12-05 17:27 ` Stephen Berman
2008-12-05 17:37 ` martin rudalics
2008-12-05 18:17 ` Stephen Berman
2008-12-06 19:25 ` martin rudalics [this message]
2008-12-09 20:15 ` Stephen Berman
2008-12-11 17:29 ` martin rudalics
2008-12-11 10:05 ` bug#1488: marked as done (23.0.60; dired-pop-to-buffer: use fit-window-to-buffer) Emacs bug Tracking System
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=493AD18C.6070002@gmx.at \
--to=rudalics@gmx.at \
--cc=1488@emacsbugs.donarmstrong.com \
--cc=stephen.berman@gmx.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.