Function: ert-with-buffer-selected

ert-with-buffer-selected is a macro defined in ert-x.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.

Source Code

;; Defined in /usr/src/emacs/lisp/emacs-lisp/ert-x.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))))