comparison lisp/window.el @ 442:abe6d1db359e r21-2-36

Import from CVS: tag r21-2-36
author cvs
date Mon, 13 Aug 2007 11:35:02 +0200
parents 8de8e3f6228a
children 576fb035e263
comparison
equal deleted inserted replaced
441:72a7cfa4a488 442:abe6d1db359e
118 "Return t if WINDOW (a minibuffer window) is now active." 118 "Return t if WINDOW (a minibuffer window) is now active."
119 (eq window (active-minibuffer-window))) 119 (eq window (active-minibuffer-window)))
120 120
121 (defmacro save-selected-window (&rest body) 121 (defmacro save-selected-window (&rest body)
122 "Execute BODY, then select the window that was selected before BODY." 122 "Execute BODY, then select the window that was selected before BODY."
123 (list 'let 123 `(let ((save-selected-window-window (selected-window)))
124 '((save-selected-window-window (selected-window))) 124 (unwind-protect
125 (list 'unwind-protect 125 (progn ,@body)
126 (cons 'progn body) 126 (when (window-live-p save-selected-window-window)
127 (list 'and ; XEmacs 127 (select-window save-selected-window-window)))))
128 (list 'window-live-p 'save-selected-window-window) 128
129 (list 'select-window 'save-selected-window-window))))) 129 (defmacro with-selected-window (window &rest body)
130 "Execute forms in BODY with WINDOW as the selected window.
131 The value returned is the value of the last form in BODY."
132 `(save-selected-window
133 (select-window ,window)
134 ,@body))
135
130 136
131 (defun count-windows (&optional minibuf) 137 (defun count-windows (&optional minibuf)
132 "Return the number of visible windows. 138 "Return the number of visible windows.
133 Optional arg MINIBUF non-nil means count the minibuffer 139 Optional arg MINIBUF non-nil means count the minibuffer
134 even if it is inactive." 140 even if it is inactive."
284 ;; If buffer ends with a newline, ignore it when counting 290 ;; If buffer ends with a newline, ignore it when counting
285 ;; height unless point is after it. 291 ;; height unless point is after it.
286 (if (and (not (eobp)) 292 (if (and (not (eobp))
287 (eq ?\n (char-after (1- (point-max))))) 293 (eq ?\n (char-after (1- (point-max)))))
288 1 0))) 294 1 0)))
289 (mini (frame-property (window-frame window) 'minibuffer)) 295 (mini (frame-property (window-frame window) 'minibuffer)))
290 (edges (window-pixel-edges (selected-window))))
291 (if (and (< 1 (let ((frame (selected-frame))) 296 (if (and (< 1 (let ((frame (selected-frame)))
292 (select-frame (window-frame window)) 297 (select-frame (window-frame window))
293 (unwind-protect 298 (unwind-protect
294 (count-windows) 299 (count-windows)
295 (select-frame frame)))) 300 (select-frame frame))))
296 ;; check to make sure that the window is the full width 301 ;; check to make sure that the window is the full width
297 ;; of the frame 302 ;; of the frame
298 (window-leftmost-p window) 303 (window-leftmost-p window)
299 (window-rightmost-p window) 304 (window-rightmost-p window)
300 (zerop (nth 0 edges))
301 ;; The whole buffer must be visible. 305 ;; The whole buffer must be visible.
302 (pos-visible-in-window-p (point-min) window) 306 (pos-visible-in-window-p (point-min) window)
303 ;; The frame must not be minibuffer-only. 307 ;; The frame must not be minibuffer-only.
304 (not (eq mini 'only))) 308 (not (eq mini 'only)))
305 (progn 309 (progn
349 (walk-windows (lambda (win) 353 (walk-windows (lambda (win)
350 (push win wins)) 354 (push win wins))
351 minibuf all-frames device) 355 minibuf all-frames device)
352 wins)) 356 wins))
353 357
354
355 ;;; window.el ends here 358 ;;; window.el ends here