Mercurial > emacs
changeset 23748:19e23f0e3cd3
(window-buffer-height): New function, split from
shrink-window-if-larger-than-buffer.
(shrink-window-if-larger-than-buffer): Use window-buffer-height.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Sun, 22 Nov 1998 17:26:33 +0000 |
parents | fb3963445995 |
children | ea095fa15fb9 |
files | lisp/window.el |
diffstat | 1 files changed, 32 insertions(+), 35 deletions(-) [+] |
line wrap: on
line diff
--- a/lisp/window.el Sun Nov 22 17:26:16 1998 +0000 +++ b/lisp/window.el Sun Nov 22 17:26:33 1998 +0000 @@ -237,6 +237,23 @@ (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 @@ (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."