diff --git a/lisp/replace.el b/lisp/replace.el index b0689b93e06..5ef16b9df68 100644 --- a/lisp/replace.el +++ b/lisp/replace.el @@ -2781,8 +2781,8 @@ to a regexp that is actually used for the search.") (isearch-clean-overlays)) ;; A macro because we push STACK, i.e. a local var in `perform-replace'. -(defmacro replace--push-stack (replaced search-str next-replace stack) - (declare (indent 0) (debug (form form form gv-place))) +(defmacro replace--push-stack (replaced search-str next-replace next-replacement match-again stack) + (declare (indent 0) (debug (form form form form form gv-place))) `(push (list (point) ,replaced ;; If the replacement has already happened, all we need is the ;; current match start and end. We could get this with a trivial @@ -2797,7 +2797,7 @@ to a regexp that is actually used for the search.") (list (match-beginning 0) (match-end 0) (current-buffer)) (match-data)) - ,search-str ,next-replace) + ,search-str ,next-replace ,next-replacement ,match-again) ,stack)) (defun replace--region-filter (bounds) @@ -3149,7 +3149,9 @@ characters." real-match-data (replace-match-data nil real-match-data - (nth 2 elt)))) + (nth 2 elt)) + next-replacement (nth 5 elt) + match-again (nth 6 elt))) (message "No previous match") (ding 'no-terminate) (sit-for 1))) @@ -3258,7 +3260,8 @@ characters." (replace--push-stack replaced search-string-replaced - next-replacement-replaced stack))) + next-replacement-replaced next-replacement match-again + stack))) ((or (eq def 'automatic) (eq def 'automatic-all)) (or replaced (setq noedit @@ -3372,7 +3375,8 @@ characters." (replace--push-stack replaced search-string-replaced - next-replacement-replaced stack)) + next-replacement-replaced next-replacement match-again + stack)) (setq next-replacement-replaced nil search-string-replaced nil last-was-act-and-show nil)))))) diff --git a/test/lisp/replace-tests.el b/test/lisp/replace-tests.el index d8f2060c5f1..fc93e614898 100644 --- a/test/lisp/replace-tests.el +++ b/test/lisp/replace-tests.el @@ -437,6 +437,9 @@ Each element has the format: ("abab" "C-M-% b* RET 1 RET !" "1a1a1") ;; Test case from commit 5632eb272c7 ("a a a " "C-M-% \\ba SPC RET c RET !" "ccc") ; not "ca c" + ;; Backup ('^') with calculated replacement ('\,') (bug#79811) + ("abc" "C-M-% \\([abc]\\) RET [\\1,\\#] RET y n ^ y y" "[a,0][b,1][c,2]") + ("abc" "C-M-% \\([abc]\\) RET [\\,\\1,\\#] RET y n ^ y y" "[a,0][b,1][c,2]") )) (defun query-replace--run-tests (tests)