diff options
| author | Tino Calancha | 2017-08-08 10:25:27 +0900 |
|---|---|---|
| committer | Tino Calancha | 2017-08-08 10:25:27 +0900 |
| commit | 919ac3ae1635bf2b99eb1f3efc7476826359e92a (patch) | |
| tree | 0b2b85d5bce21bad1d83ff18dc33b5143a097fb0 /test | |
| parent | bec5b602597b8b6f596067167f3b3fe0e6eff285 (diff) | |
| download | emacs-919ac3ae1635bf2b99eb1f3efc7476826359e92a.tar.gz emacs-919ac3ae1635bf2b99eb1f3efc7476826359e92a.zip | |
query-replace: Undo replacements performed with 'comma
During a `query-replace', the char ',' replaces the character
at point and doesn't move point; right after, the char 'u'
must undo such replacement (Bug#27268).
* lisp/replace.el (replace--push-stack):
New macro extracted from `perform-replace'.
(perform-replace): Use it.
* test/lisp/replace-tests.el (query-replace--undo): Add test.
Diffstat (limited to 'test')
| -rw-r--r-- | test/lisp/replace-tests.el | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/test/lisp/replace-tests.el b/test/lisp/replace-tests.el index adef5a3f3dc..a8bc5407f42 100644 --- a/test/lisp/replace-tests.el +++ b/test/lisp/replace-tests.el | |||
| @@ -358,4 +358,26 @@ Each element has the format: | |||
| 358 | (dotimes (i (length replace-occur-tests)) | 358 | (dotimes (i (length replace-occur-tests)) |
| 359 | (replace-occur-test-create i)) | 359 | (replace-occur-test-create i)) |
| 360 | 360 | ||
| 361 | (defun replace-tests--query-replace-undo (&optional comma) | ||
| 362 | (with-temp-buffer | ||
| 363 | (insert "111") | ||
| 364 | (goto-char 1) | ||
| 365 | (let ((count 0)) | ||
| 366 | ;; Don't wait for user input. | ||
| 367 | (cl-letf (((symbol-function 'read-event) | ||
| 368 | (lambda (&rest args) | ||
| 369 | (cl-incf count) | ||
| 370 | (let ((val (pcase count | ||
| 371 | ('2 (if comma ?, ?\s)) ; replace and: ',' no move; '\s' go next | ||
| 372 | ('3 ?u) ; undo | ||
| 373 | ('4 ?q) ; exit | ||
| 374 | (_ ?\s)))) ; replace current and go next | ||
| 375 | val)))) | ||
| 376 | (perform-replace "1" "2" t nil nil))) | ||
| 377 | (buffer-string))) | ||
| 378 | |||
| 379 | (ert-deftest query-replace--undo () | ||
| 380 | (should (string= "211" (replace-tests--query-replace-undo))) | ||
| 381 | (should (string= "211" (replace-tests--query-replace-undo 'comma)))) | ||
| 382 | |||
| 361 | ;;; replace-tests.el ends here | 383 | ;;; replace-tests.el ends here |