Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

anzu-query-replace behaviour deviates from query-replace during recursive edits #116

Open
jamesmaguire opened this issue Oct 27, 2020 · 2 comments
Labels
bug a feature isn't working

Comments

@jamesmaguire
Copy link

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.

@syohex
Copy link
Contributor

syohex commented Oct 27, 2020

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))

@jamesmaguire
Copy link
Author

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, then anzu-query-replace works the same as query-replace, however, the anzu modeline indicator is not updated (still says (1/2) instead of updating to (1/3).

@gonewest818 gonewest818 added the bug a feature isn't working label Oct 31, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug a feature isn't working
Development

No branches or pull requests

3 participants