# HG changeset patch # User Richard M. Stallman # Date 911755593 0 # Node ID 19e23f0e3cd326e08a769564c6c4857f0e20ea61 # Parent fb39634459958a9f37248c9a73c4e6bfbde8cddf (window-buffer-height): New function, split from shrink-window-if-larger-than-buffer. (shrink-window-if-larger-than-buffer): Use window-buffer-height. diff -r fb3963445995 -r 19e23f0e3cd3 lisp/window.el --- 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."