anzu
anzu copied to clipboard
anzu-query-replace behaviour deviates from query-replace during recursive edits
Apologies, but I don't have the time (or probably the expertise) to look into the cause of this, but I noticed that during recursive editing the anzu version of query-replace does not update the matches.
To reproduce, open a blank buffer and enter:
a
b
a
b
Move the point to the beginning of the buffer and use M-x query-replace to replace a with x. Before accepting the changes, type C-r to enter a recursive edit. Move to the end of the file and add a newline with another a like so:
a
b
a
b
a
Now exit recursive edit (C-M-c). The new a is also highlighted. You can change all a's with 3x y or !, resulting in:
x
b
x
b
x
Performing the same operations with anzu-query-replace results in only the first two a's being replaced:
x
b
x
b
a
I'm not sure if this is something that's technically difficult to solve, or just overlooked as it's probably not commonly come across. I hope the later, but either way I thought it would be helpful to open an issue.
I'm not sure that does the following patch fix this issue ?
diff --git a/anzu.el b/anzu.el
index d51727b..5455fb5 100644
--- a/anzu.el
+++ b/anzu.el
@@ -799,6 +799,11 @@
anzu--replaced-markers (reverse anzu--replaced-markers)
clear-overlay t)
(let ((case-fold-search (and case-fold-search (not at-cursor))))
+ (unless use-region
+ (when (= beg (point))
+ (setq beg nil))
+ (when (or (and backward (= end (point-min))) (= end (point-max)))
+ (setq end nil)))
(if use-regexp
(apply #'perform-replace (anzu--construct-perform-replace-arguments
from to delimited beg end backward query))
The patch doesn't seem to address the issue on my system. From a bit of extra testing, here is some more information:
- If the recursive edit is at the end of the buffer (as was my original issue), the issue remains with or without the patch.
- If the recursive edit is not at the end of the buffer (say open a newline at line 2 and add another
a, thenanzu-query-replaceworks the same asquery-replace, however, the anzu modeline indicator is not updated (still says(1/2)instead of updating to(1/3).