# HG changeset patch # User Karl Heuer # Date 896737783 0 # Node ID 874f007a7d9c23641c8570e913f601752f17bf54 # Parent c119045b2019232bedf218b95841a6b2afa9dcfb (shrink-window-if-larger-than-buffer): Switch to the specified window and its buffer at the outset. (count-windows): Doc fix. diff -r c119045b2019 -r 874f007a7d9c lisp/window.el --- a/lisp/window.el Mon Jun 01 21:47:36 1998 +0000 +++ b/lisp/window.el Mon Jun 01 21:49:43 1998 +0000 @@ -88,7 +88,9 @@ (defun count-windows (&optional minibuf) "Returns the number of visible windows. -Optional arg MINIBUF non-nil means count the minibuffer +This counts the windows in the selected frame and (if the minibuffer is +to be counted) its minibuffer frame (if that's not the same frame). +The optional arg MINIBUF non-nil means count the minibuffer even if it is inactive." (let ((count 0)) (walk-windows (function (lambda (w) @@ -241,33 +243,32 @@ or if the window is not the full width of the frame, or if the window is the only window of its frame." (interactive) - (or window (setq window (selected-window))) - (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 (window-frame window))) - (mini (cdr (assq 'minibuffer params))) - (edges (window-edges (selected-window))) - text-height) - (if (and (< 1 (save-selected-window - (select-window window) - (count-windows))) - (= (window-width window) (frame-width (window-frame window))) - (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))))) - (save-selected-window - (select-window window) - (let (result height) - (save-excursion - (set-buffer (window-buffer window)) - (goto-char (point-min)) + (save-selected-window + (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)