mirror of
git://git.sv.gnu.org/emacs.git
synced 2025-12-05 22:20:24 -08:00
Fix query-replace-regexp for using '^' with calculated replacement '\,'
* lisp/replace.el (replace--push-stack): Add new args
'next-replacement' and 'match-again' and push them to the stack.
(perform-replace): Restore the previous already calculated values
of 'next-replacement' and 'match-again' from the stack for the
'backup' ('^') key (bug#79811).
* test/lisp/replace-tests.el (query-replace-tests): Add tests.
This commit is contained in:
parent
b852555401
commit
33d813c63b
2 changed files with 13 additions and 6 deletions
|
|
@ -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))))))
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue