summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKarl Heuer <kwzh@gnu.org>1998-06-01 21:49:43 +0000
committerKarl Heuer <kwzh@gnu.org>1998-06-01 21:49:43 +0000
commitb70b2dd2c0fbd821a749740db5b672efa4d91816 (patch)
treebb9397f02071842f324d86e1e980abaa5331a55c
parent5f7493ac6950f30813753002286c45f097cc8ff8 (diff)
downloademacs-b70b2dd2c0fbd821a749740db5b672efa4d91816.tar.gz
(shrink-window-if-larger-than-buffer):
Switch to the specified window and its buffer at the outset. (count-windows): Doc fix.
-rw-r--r--lisp/window.el57
1 files changed, 29 insertions, 28 deletions
diff --git a/lisp/window.el b/lisp/window.el
index 433ba731ea1..1f272364e6c 100644
--- a/lisp/window.el
+++ b/lisp/window.el
@@ -88,7 +88,9 @@ Anything else means restrict to the selected frame."
(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 some of the window's contents are scrolled out of view,
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)