diff options
| author | Vincent Belaïche | 2026-03-29 07:20:56 +0200 |
|---|---|---|
| committer | Vincent Belaïche | 2026-03-29 07:29:17 +0200 |
| commit | 71d7726c2a363085f2aca8b621265e01726463c9 (patch) | |
| tree | ed0ece34f5ef267370bc2e9ba5ed1ce7ed03d010 | |
| parent | a39b6a3d75ef18e95cf4f9dd88d1d33ee44371d9 (diff) | |
| download | emacs-scratch/ert-play-keys.tar.gz emacs-scratch/ert-play-keys.zip | |
New ert-with-display-current-buffer defmacro.scratch/ert-play-keys
* test/lisp/simple-tests.el (undo-test-kill-c-a-then-undo)
(undo-test-point-after-forward-kill):
* test/lisp/erc/erc-scenarios-spelling.el
(erc-scenarios-spelling--auto-correct): Use `ert-with-display-current-buffer'
rather than `pop-to-buffer-same-window'.
* lisp/emacs-lisp/ert.el (ert-with-display-current-buffer): New defmacro.
| -rw-r--r-- | lisp/emacs-lisp/ert.el | 26 | ||||
| -rw-r--r-- | test/lisp/erc/erc-scenarios-spelling.el | 48 | ||||
| -rw-r--r-- | test/lisp/simple-tests.el | 50 |
3 files changed, 69 insertions, 55 deletions
diff --git a/lisp/emacs-lisp/ert.el b/lisp/emacs-lisp/ert.el index 924201e6445..1478188132c 100644 --- a/lisp/emacs-lisp/ert.el +++ b/lisp/emacs-lisp/ert.el | |||
| @@ -3173,9 +3173,9 @@ See `ert-call-with-buffer-renamed' for details." | |||
| 3173 | 3173 | ||
| 3174 | KEYS shall have the same format as in a call to function `kmacro'. | 3174 | KEYS shall have the same format as in a call to function `kmacro'. |
| 3175 | 3175 | ||
| 3176 | A prior call to (pop-to-buffer-same-window (current-buffer)) is | 3176 | This macro should be expanded within the body of |
| 3177 | necessary when the keys KEYS start commands acting on the current | 3177 | `ert-with-display-current-buffer' when the keys KEYS start commands |
| 3178 | buffer." | 3178 | acting on the current buffer." |
| 3179 | `(funcall | 3179 | `(funcall |
| 3180 | (kmacro ,keys))) | 3180 | (kmacro ,keys))) |
| 3181 | 3181 | ||
| @@ -3184,13 +3184,27 @@ buffer." | |||
| 3184 | 3184 | ||
| 3185 | KEYS-STRING shall be a string. | 3185 | KEYS-STRING shall be a string. |
| 3186 | 3186 | ||
| 3187 | A prior call to (pop-to-buffer-same-window (current-buffer)) is | 3187 | This macro should be expanded within the body of |
| 3188 | necessary when the keys sequence resulting from KEYS-STRING start | 3188 | `ert-with-display-current-buffer' when the keys sequence resulting from |
| 3189 | commands acting on the current buffer." | 3189 | KEYS-STRING start commands acting on the current buffer." |
| 3190 | (let ((keys (apply #'vector (mapcar #'identity keys-string)))) | 3190 | (let ((keys (apply #'vector (mapcar #'identity keys-string)))) |
| 3191 | `(funcall | 3191 | `(funcall |
| 3192 | (kmacro ,keys)))) | 3192 | (kmacro ,keys)))) |
| 3193 | 3193 | ||
| 3194 | (defmacro ert-with-display-current-buffer (&rest body) | ||
| 3195 | "Execute BODY after trying to display current buffer in the same window | ||
| 3196 | with `pop-to-buffer-same-window'. | ||
| 3197 | |||
| 3198 | This macro restores the old window if changed by | ||
| 3199 | `pop-to-buffer-same-window' after execution of body. This macro does not | ||
| 3200 | change the list of currently selected buffer." | ||
| 3201 | (let ((old-window (make-symbol "old-window"))) | ||
| 3202 | `(let ((,old-window (selected-window))) | ||
| 3203 | (pop-to-buffer-same-window (current-buffer) t) | ||
| 3204 | (unwind-protect | ||
| 3205 | (progn ,@body) | ||
| 3206 | (select-window ,old-window t))))) | ||
| 3207 | |||
| 3194 | 3208 | ||
| 3195 | ;;; Obsolete | 3209 | ;;; Obsolete |
| 3196 | 3210 | ||
diff --git a/test/lisp/erc/erc-scenarios-spelling.el b/test/lisp/erc/erc-scenarios-spelling.el index 15196e485be..88e64ce7cca 100644 --- a/test/lisp/erc/erc-scenarios-spelling.el +++ b/test/lisp/erc/erc-scenarios-spelling.el | |||
| @@ -67,30 +67,30 @@ | |||
| 67 | (funcall expect 10 "<alice> tester, welcome!") | 67 | (funcall expect 10 "<alice> tester, welcome!") |
| 68 | 68 | ||
| 69 | ;; Insert a command with one misspelled word. | 69 | ;; Insert a command with one misspelled word. |
| 70 | (pop-to-buffer-same-window (current-buffer)) | 70 | (ert-with-display-current-buffer |
| 71 | (ert-play-keys-in-string "\M->/AMSG an/dor /gmsg one fsbot two frob my shoe") | 71 | (ert-play-keys-in-string "\M->/AMSG an/dor /gmsg one fsbot two frob my shoe") |
| 72 | (funcall expect 10 "shoe") | 72 | (funcall expect 10 "shoe") |
| 73 | 73 | ||
| 74 | (let* ((ovs (overlays-in erc-input-marker (point))) | 74 | (let* ((ovs (overlays-in erc-input-marker (point))) |
| 75 | (ov1 (pop ovs)) | 75 | (ov1 (pop ovs)) |
| 76 | (ov2 (pop ovs))) | 76 | (ov2 (pop ovs))) |
| 77 | ;; At this point, flyspell should have done its thing. There | 77 | ;; At this point, flyspell should have done its thing. There |
| 78 | ;; should be two overlays: one on "dor" and the other on | 78 | ;; should be two overlays: one on "dor" and the other on |
| 79 | ;; "frob". The spelling module's modifications should have | 79 | ;; "frob". The spelling module's modifications should have |
| 80 | ;; prevented the two valid slash commands as well as "fsbot" | 80 | ;; prevented the two valid slash commands as well as "fsbot" |
| 81 | ;; from being highlighted. | 81 | ;; from being highlighted. |
| 82 | (should-not ovs) | 82 | (should-not ovs) |
| 83 | (should (flyspell-overlay-p ov1)) | 83 | (should (flyspell-overlay-p ov1)) |
| 84 | (should (equal "dor" (buffer-substring (overlay-start ov1) | 84 | (should (equal "dor" (buffer-substring (overlay-start ov1) |
| 85 | (overlay-end ov1)))) | 85 | (overlay-end ov1)))) |
| 86 | (should (flyspell-overlay-p ov2)) | 86 | (should (flyspell-overlay-p ov2)) |
| 87 | (should (equal "frob" (buffer-substring (overlay-start ov2) | 87 | (should (equal "frob" (buffer-substring (overlay-start ov2) |
| 88 | (overlay-end ov2)))) | 88 | (overlay-end ov2)))) |
| 89 | (goto-char (overlay-start ov2)) | 89 | (goto-char (overlay-start ov2)) |
| 90 | 90 | ||
| 91 | ;; Depending on the machine, this should become something | 91 | ;; Depending on the machine, this should become something |
| 92 | ;; like: "/AMSG an/dor /gmsg one fsbot two Rob my shoe". | 92 | ;; like: "/AMSG an/dor /gmsg one fsbot two Rob my shoe". |
| 93 | (ert-play-keys "M-TAB") | 93 | (ert-play-keys "M-TAB")) |
| 94 | (should (equal (overlays-in erc-input-marker (point-max)) | 94 | (should (equal (overlays-in erc-input-marker (point-max)) |
| 95 | (list ov1))))) | 95 | (list ov1))))) |
| 96 | 96 | ||
diff --git a/test/lisp/simple-tests.el b/test/lisp/simple-tests.el index a10d881b08b..fe034e1edf9 100644 --- a/test/lisp/simple-tests.el +++ b/test/lisp/simple-tests.el | |||
| @@ -731,35 +731,35 @@ See bug#35036." | |||
| 731 | ;; https://lists.gnu.org/r/emacs-devel/2015-11/msg01652.html | 731 | ;; https://lists.gnu.org/r/emacs-devel/2015-11/msg01652.html |
| 732 | (defun undo-test-kill-c-a-then-undo () | 732 | (defun undo-test-kill-c-a-then-undo () |
| 733 | (with-temp-buffer | 733 | (with-temp-buffer |
| 734 | (pop-to-buffer-same-window (current-buffer)) | 734 | (ert-with-display-current-buffer |
| 735 | (setq buffer-undo-list nil) | 735 | (setq buffer-undo-list nil) |
| 736 | (insert "a\nb\nc\n") | 736 | (insert "a\nb\nc\n") |
| 737 | (goto-char (point-max)) | 737 | (goto-char (point-max)) |
| 738 | ;; We use a keyboard macro because it adds undo events in the same | 738 | ;; We use a keyboard macro because it adds undo events in the same |
| 739 | ;; way as if a user were involved. | 739 | ;; way as if a user were involved. |
| 740 | (ert-play-keys [left | 740 | (ert-play-keys [left |
| 741 | ;; Delete "c" | 741 | ;; Delete "c" |
| 742 | backspace | 742 | backspace |
| 743 | left left left | 743 | left left left |
| 744 | ;; Delete "a" | 744 | ;; Delete "a" |
| 745 | backspace | 745 | backspace |
| 746 | ;; C-/ or undo | 746 | ;; C-/ or undo |
| 747 | ?\C-/ | 747 | ?\C-/ |
| 748 | ]) | 748 | ])) |
| 749 | (point))) | 749 | (point))) |
| 750 | 750 | ||
| 751 | (defun undo-test-point-after-forward-kill () | 751 | (defun undo-test-point-after-forward-kill () |
| 752 | (with-temp-buffer | 752 | (with-temp-buffer |
| 753 | (pop-to-buffer-same-window (current-buffer)) | 753 | (ert-with-display-current-buffer |
| 754 | (setq buffer-undo-list nil) | 754 | (setq buffer-undo-list nil) |
| 755 | (insert "kill word forward") | 755 | (insert "kill word forward") |
| 756 | ;; Move to word "word". | 756 | ;; Move to word "word". |
| 757 | (goto-char 6) | 757 | (goto-char 6) |
| 758 | (ert-play-keys [;; kill-word | 758 | (ert-play-keys [;; kill-word |
| 759 | C-delete | 759 | C-delete |
| 760 | ;; undo | 760 | ;; undo |
| 761 | ?\C-/ | 761 | ?\C-/ |
| 762 | ]) | 762 | ])) |
| 763 | (point))) | 763 | (point))) |
| 764 | 764 | ||
| 765 | (ert-deftest undo-point-in-wrong-place () | 765 | (ert-deftest undo-point-in-wrong-place () |