summaryrefslogtreecommitdiff
path: root/lisp/window.el
diff options
context:
space:
mode:
authorRichard M. Stallman <rms@gnu.org>1998-11-22 17:26:33 +0000
committerRichard M. Stallman <rms@gnu.org>1998-11-22 17:26:33 +0000
commit3b134005bb34dfd1c0dd01f1d0cbaa5688fd4fbc (patch)
tree9fa1e43edb72a73b03f2610acff31384c47589e7 /lisp/window.el
parent48ce3c223194833596a0d50cc8122d979d61d073 (diff)
downloademacs-3b134005bb34dfd1c0dd01f1d0cbaa5688fd4fbc.tar.gz
(window-buffer-height): New function, split from
shrink-window-if-larger-than-buffer. (shrink-window-if-larger-than-buffer): Use window-buffer-height.
Diffstat (limited to 'lisp/window.el')
-rw-r--r--lisp/window.el67
1 files changed, 32 insertions, 35 deletions
diff --git a/lisp/window.el b/lisp/window.el
index c18dcc41acc..cd043e0d47e 100644
--- a/lisp/window.el
+++ b/lisp/window.el
@@ -237,6 +237,23 @@ to the window's right, if any. No arg means split equally."
(interactive "p")
(shrink-window arg t))
+(defun window-buffer-height (window)
+ "Return the height (in screen lines) of the buffer that WINDOW is displaying."
+ (save-excursion
+ (set-buffer (window-buffer window))
+ (goto-char (point-min))
+ (let ((ignore-final-newline
+ ;; If buffer ends with a newline, ignore it when counting height
+ ;; unless point is after it.
+ (and (not (eobp)) (eq ?\n (char-after (1- (point-max)))))))
+ (+ 1 (nth 2 (compute-motion (point-min)
+ '(0 . 0)
+ (- (point-max) (if ignore-final-newline 1 0))
+ (cons 0 100000000)
+ (window-width window)
+ nil
+ window))))))
+
(defun shrink-window-if-larger-than-buffer (&optional window)
"Shrink the WINDOW to be as small as possible to display its contents.
Do not shrink to less than `window-min-height' lines.
@@ -249,41 +266,21 @@ or if the window is the only window of its frame."
(if window
(select-window window)
(setq window (selected-window)))
- (save-excursion
- (set-buffer (window-buffer window))
- (goto-char (point-min))
- (let* ((ignore-final-newline
- ;; If buffer ends with a newline, ignore it when counting height
- ;; unless point is after it.
- (and (not (eobp))
- (eq ?\n (char-after (1- (point-max))))))
- (params (frame-parameters))
- (mini (cdr (assq 'minibuffer params)))
- (edges (window-edges))
- text-height)
- (if (and (< 1 (count-windows))
- (= (window-width) (frame-width))
- (pos-visible-in-window-p (point-min) window)
- (not (eq mini 'only))
- (or (not mini)
- (< (nth 3 edges)
- (nth 1 (window-edges mini)))
- (> (nth 1 edges)
- (cdr (assq 'menu-bar-lines params)))))
- (let (result height)
- (setq result
- (compute-motion (point-min) '(0 . 0)
- (- (point-max)
- (if ignore-final-newline 1 0))
- (cons 0 (window-height))
- (window-width) nil
- window))
- ;; Get number of screen lines that the text needs.
- (setq text-height (+ 1 (nth 2 result)))
- ;; Shrink down to that, or as far as we can go.
- (if (> (window-height) (1+ text-height))
- (shrink-window (- (window-height)
- (max (1+ text-height) window-min-height))))))))))
+ (let* ((params (frame-parameters))
+ (mini (cdr (assq 'minibuffer params)))
+ (edges (window-edges)))
+ (if (and (< 1 (count-windows))
+ (= (window-width) (frame-width))
+ (pos-visible-in-window-p (point-min) window)
+ (not (eq mini 'only))
+ (or (not mini)
+ (< (nth 3 edges) (nth 1 (window-edges mini)))
+ (> (nth 1 edges) (cdr (assq 'menu-bar-lines params)))))
+ (let ((text-height (window-buffer-height window))
+ (window-height (window-height)))
+ (when (> window-height (1+ text-height))
+ (shrink-window
+ (- window-height (max (1+ text-height) window-min-height)))))))))
(defun kill-buffer-and-window ()
"Kill the current buffer and delete the selected window."