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

case-folding behavior of anzu-isearch-query-replace #103

Open
gonewest818 opened this issue Mar 20, 2020 · 3 comments
Open

case-folding behavior of anzu-isearch-query-replace #103

gonewest818 opened this issue Mar 20, 2020 · 3 comments
Labels
bug a feature isn't working

Comments

@gonewest818
Copy link
Collaborator

Imagine the user does an isearch-forward and toggles a case sensitive search with M-c. The subsequent anzu-isearch-query-replace should not only search for the prior search string, but it should also use the case-sensitivity specified in the prior search. That's not the case.

Example. The buffer contains

anzu Anzu anzu

Searching for "anzu" will match all three words. Searching for "Anzu" will match just the middle word. Searching for "anzu" with M-c will match the first and last word.

However, after a case-sensitive (M-c) search with the string "anzu", the subsequent anzu-isearch-query-replace will always ask to replace all three words. This is the case that needs to be fixed, because the M-c should be honored in the query-replace.

@gonewest818 gonewest818 added the bug a feature isn't working label Mar 20, 2020
@gonewest818
Copy link
Collaborator Author

hello @syohex, do you have any insights on these case-sensitivity bugs?

@syohex
Copy link
Contributor

syohex commented May 14, 2020

I'm not sure, I never use M-c. However anzu--case-fold-search should be check that whether replace string starts with upper character same as original implementation, I suppose.

diff --git a/anzu.el b/anzu.el
index d51727b..cce7de7 100644
--- a/anzu.el
+++ b/anzu.el
@@ -163,10 +163,12 @@
 (defsubst anzu--construct-position-info (count overflow positions)
   (list :count count :overflow overflow :positions positions))
 
-(defsubst anzu--case-fold-search ()
+(defsubst anzu--case-fold-search (input)
   (if isearch-mode
       isearch-case-fold-search
-    case-fold-search))
+    (when case-fold-search
+      (let ((case-fold-search nil))
+        (not (string-match-p "[A-Z]" input))))))
 
 (defsubst anzu--word-search-p ()
   (and (not (memq anzu--last-command anzu-regexp-search-commands))
@@ -206,7 +208,7 @@
                                  (with-no-warnings
                                    (migemo-forward word bound noerror count)))
                              #'re-search-forward))
-              (case-fold-search (anzu--case-fold-search)))
+              (case-fold-search (anzu--case-fold-search input)))
           (while (and (not finish) (funcall search-func input nil t))
             (push (cons (match-beginning 0) (match-end 0)) positions)
             (cl-incf count)
@@ -399,7 +401,7 @@
                 (step (if backward -1 1))
                 (case-fold-search (if case-sensitive
                                       nil
-                                    (anzu--case-fold-search))))
+                                    (anzu--case-fold-search str))))
             (while (and (not finish) (funcall search-func str replace-end t))
               (cl-incf count)
               (let ((beg (match-beginning 0))

@gonewest818
Copy link
Collaborator Author

Agree. I have a very similar set of diffs sitting in here on my laptop ... but as I recall, making that change caused other cases to be broken, so I never checked in the changes.

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

2 participants