comparison lisp/window.el @ 1127:68f6865bee47

[xemacs-hg @ 2002-11-28 12:38:16 by michaels] 2002-11-26 Mike Sperber <mike@xemacs.org> * window.el (shrink-window-if-larger-than-buffer): Elide braindead use of `save-window-excursion'.
author michaels
date Thu, 28 Nov 2002 12:38:17 +0000
parents a5954632b187
children 960da99ad52b
comparison
equal deleted inserted replaced
1126:bcb5d65d0d94 1127:68f6865bee47
181 "Execute forms in BODY with WINDOW as the selected window. 181 "Execute forms in BODY with WINDOW as the selected window.
182 The value returned is the value of the last form in BODY." 182 The value returned is the value of the last form in BODY."
183 `(save-selected-window 183 `(save-selected-window
184 (select-window ,window) 184 (select-window ,window)
185 ,@body)) 185 ,@body))
186
187 186
188 (defun count-windows (&optional minibuf) 187 (defun count-windows (&optional minibuf)
189 "Return the number of visible windows. 188 "Return the number of visible windows.
190 This counts the windows in the selected frame and (if the minibuffer is 189 This counts the windows in the selected frame and (if the minibuffer is
191 to be counted) its minibuffer frame (if that's not the same frame). 190 to be counted) its minibuffer frame (if that's not the same frame).
485 or if the window is the only window of its frame." 484 or if the window is the only window of its frame."
486 (interactive) 485 (interactive)
487 (or window (setq window (selected-window))) 486 (or window (setq window (selected-window)))
488 (save-excursion 487 (save-excursion
489 (set-buffer (window-buffer window)) 488 (set-buffer (window-buffer window))
490 (let ((n 0) 489 (let ((test-pos
491 (test-pos
492 (- (point-max) 490 (- (point-max)
493 ;; If buffer ends with a newline, ignore it when counting 491 ;; If buffer ends with a newline, ignore it when counting
494 ;; height unless point is after it. 492 ;; height unless point is after it.
495 (if (and (not (eobp)) 493 (if (and (not (eobp))
496 (eq ?\n (char-after (1- (point-max))))) 494 (eq ?\n (char-after (1- (point-max)))))
508 ;; The whole buffer must be visible. 506 ;; The whole buffer must be visible.
509 (pos-visible-in-window-p (point-min) window) 507 (pos-visible-in-window-p (point-min) window)
510 ;; The frame must not be minibuffer-only. 508 ;; The frame must not be minibuffer-only.
511 (not (eq mini 'only))) 509 (not (eq mini 'only)))
512 (progn 510 (progn
513 (save-window-excursion 511 (goto-char (point-min))
514 (goto-char (point-min)) 512 (while (and (pos-visible-in-window-p test-pos window)
515 (while (and (window-live-p window) 513 (> (window-height window) window-min-height))
516 (pos-visible-in-window-p test-pos window)) 514 (shrink-window 1 nil window))
517 (shrink-window 1 nil window) 515 (if (not (pos-visible-in-window-p test-pos window))
518 (setq n (1+ n)))) 516 (enlarge-window 1 nil window)))))))
519 (if (> n 0)
520 (shrink-window (min (1- n)
521 (- (window-height window)
522 (1+ window-min-height)))
523 nil
524 window)))))))
525 517
526 (defun kill-buffer-and-window () 518 (defun kill-buffer-and-window ()
527 "Kill the current buffer and delete the selected window." 519 "Kill the current buffer and delete the selected window."
528 (interactive) 520 (interactive)
529 (if (yes-or-no-p (format "Kill buffer `%s'? " (buffer-name))) 521 (if (yes-or-no-p (format "Kill buffer `%s'? " (buffer-name)))