Function: ert-with-buffer-selected
ert-with-buffer-selected is a macro defined in ert.el.gz.
Signature
(ert-with-buffer-selected BUFFER-OR-NAME &body BODY)
Documentation
Display a buffer in a temporary selected window and run BODY.
If BUFFER-OR-NAME is nil, the current buffer is used.
The buffer is made the current buffer, and the temporary window
becomes the selected-window, before BODY is evaluated. The
modification hooks before-change-functions and
after-change-functions are not inhibited during the evaluation
of BODY, which makes it easier to use execute-kbd-macro to
simulate user interaction. The window configuration is restored
before returning, even if BODY exits nonlocally. The return
value is the last form in BODY.
Probably introduced at or before Emacs version 31.1.
Source Code
;; Defined in /usr/src/emacs/lisp/emacs-lisp/ert.el.gz
(cl-defmacro ert-with-buffer-selected (buffer-or-name &body body)
"Display a buffer in a temporary selected window and run BODY.
If BUFFER-OR-NAME is nil, the current buffer is used.
The buffer is made the current buffer, and the temporary window
becomes the `selected-window', before BODY is evaluated. The
modification hooks `before-change-functions' and
`after-change-functions' are not inhibited during the evaluation
of BODY, which makes it easier to use `execute-kbd-macro' to
simulate user interaction. The window configuration is restored
before returning, even if BODY exits nonlocally. The return
value is the last form in BODY."
(declare (debug (form body)) (indent 1))
`(save-window-excursion
(with-current-buffer (or ,buffer-or-name (current-buffer))
(with-selected-window (display-buffer (current-buffer))
,@body))))