1
0
mirror of https://git.savannah.gnu.org/git/emacs.git synced 2024-12-29 11:02:01 +00:00

* lisp/window.el (internal--before-save-selected-window)

(internal--after-save-selected-window): New functions extracted from
save-selected-window.  Make sure we return the `alist' we construct.
(save-selected-window): Use them.
* lisp/textmodes/tex-mode.el (tex-recenter-output-buffer):
Use with-selected-window.
This commit is contained in:
Stefan Monnier 2012-10-07 11:54:30 -04:00
parent 13af0d109f
commit 662a9d0e1c
3 changed files with 40 additions and 27 deletions

View File

@ -1,5 +1,13 @@
2012-10-07 Stefan Monnier <monnier@iro.umontreal.ca>
* window.el (internal--before-save-selected-window)
(internal--after-save-selected-window): New functions extracted from
save-selected-window. Make sure we return the `alist' we construct.
(save-selected-window): Use them.
* textmodes/tex-mode.el (tex-recenter-output-buffer):
Use with-selected-window.
* emacs-lisp/autoload.el (make-autoload): Add `cl-defmacro' to the
forms that define macros (bug#12593).

View File

@ -2565,8 +2565,7 @@ line LINE of the window, or centered if LINE is nil."
(if (null tex-shell)
(message "No TeX output buffer")
(setq window (display-buffer tex-shell))
(save-selected-window
(select-window window)
(with-selected-window window
(bury-buffer tex-shell)
(goto-char (point-max))
(recenter (if linenum

View File

@ -28,6 +28,35 @@
;;; Code:
(defun internal--before-save-selected-window ()
(cons (selected-window)
;; We save and restore all frames' selected windows, because
;; `select-window' can change the frame-selected-window of
;; whatever frame that window is in. Each text terminal's
;; top-frame is preserved by putting it last in the list.
(apply #'append
(mapcar (lambda (terminal)
(let ((frames (frames-on-display-list terminal))
(top-frame (tty-top-frame terminal))
alist)
(if top-frame
(setq frames
(cons top-frame
(delq top-frame frames))))
(dolist (f frames)
(push (cons f (frame-selected-window f))
alist))
alist))
(terminal-list)))))
(defun internal--after-save-selected-window (state)
(dolist (elt (cdr state))
(and (frame-live-p (car elt))
(window-live-p (cdr elt))
(set-frame-selected-window (car elt) (cdr elt) 'norecord)))
(when (window-live-p (car state))
(select-window (car state) 'norecord)))
(defmacro save-selected-window (&rest body)
"Execute BODY, then select the previously selected window.
The value returned is the value of the last form in BODY.
@ -44,34 +73,11 @@ its normal operation could make a different buffer current. The
order of recently selected windows and the buffer list ordering
are not altered by this macro (unless they are altered in BODY)."
(declare (indent 0) (debug t))
`(let ((save-selected-window-window (selected-window))
;; We save and restore all frames' selected windows, because
;; `select-window' can change the frame-selected-window of
;; whatever frame that window is in. Each text terminal's
;; top-frame is preserved by putting it last in the list.
(save-selected-window-alist
(apply 'append
(mapcar (lambda (terminal)
(let ((frames (frames-on-display-list terminal))
(top-frame (tty-top-frame terminal))
alist)
(if top-frame
(setq frames
(cons top-frame
(delq top-frame frames))))
(dolist (f frames)
(push (cons f (frame-selected-window f))
alist))))
(terminal-list)))))
`(let ((save-selected-window--state (internal--before-save-selected-window)))
(save-current-buffer
(unwind-protect
(progn ,@body)
(dolist (elt save-selected-window-alist)
(and (frame-live-p (car elt))
(window-live-p (cdr elt))
(set-frame-selected-window (car elt) (cdr elt) 'norecord)))
(when (window-live-p save-selected-window-window)
(select-window save-selected-window-window 'norecord))))))
(internal--after-save-selected-window save-selected-window--state)))))
(defvar temp-buffer-window-setup-hook nil
"Normal hook run by `with-temp-buffer-window' before buffer display.