anzu
anzu copied to clipboard
case-folding behavior of `anzu-isearch-query-replace`
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.
hello @syohex, do you have any insights on these case-sensitivity bugs?
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))
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.