Subject: Re: bug#40940: 27.0.91; project-query-replace-regexp stops too early

From: Dmitry Gutov <[email-masked]>
Date: Sun, 3 May 2020 04:43:26 +0300

On 02.05.2020 09:44, Eli Zaretskii wrote:
> I can update the doc string, yes.  But I don't think it's a good idea
> to divide the coding part between us, though.  So please show the
> code, and I will suggest the doc change.

Here's the comprehensive fix I'd like to see:

diff --git a/lisp/fileloop.el b/lisp/fileloop.el
index 543963feaf..69825fdcae 100644
--- a/lisp/fileloop.el
+++ b/lisp/fileloop.el
@@ -181,8 +181,7 @@ fileloop-initialize-search
      (fileloop-initialize
       files
       (lambda ()
-       (let ((case-fold-search
-              (if (memq case-fold '(t nil)) case-fold case-fold-search)))
+       (let ((case-fold-search (fileloop--case-fold regexp case-fold)))
           (re-search-forward regexp nil t)))
       (lambda ()
         (unless (eq last-buffer (current-buffer))
@@ -190,6 +189,15 @@ fileloop-initialize-search
           (message "Scanning file %s...found" buffer-file-name))
         nil))))

+(defun fileloop--case-fold (regexp case-fold)
+  (let ((value
+         (if (memql case-fold '(nil t))
+             case-fold
+           case-fold-search)))
+    (if (and value search-upper-case)
+        (isearch-no-upper-case-p regexp t)
+      value)))
+
  ;;;###autoload
  (defun fileloop-initialize-replace (from to files case-fold &optional 
delimited)
    "Initialize a new round of query&replace on several files.
@@ -203,15 +211,15 @@ fileloop-initialize-replace
    (fileloop-initialize
     files
     (lambda ()
-     (let ((case-fold-search
-            (if (memql case-fold '(nil t)) case-fold case-fold-search)))
+     (let ((case-fold-search (fileloop--case-fold from case-fold)))
         (if (re-search-forward from nil t)
  	   ;; When we find a match, move back
  	   ;; to the beginning of it so perform-replace
  	   ;; will see it.
  	   (goto-char (match-beginning 0)))))
     (lambda ()
-     (perform-replace from to t t delimited nil multi-query-replace-map))))
+     (let ((case-fold-search (fileloop--case-fold from case-fold)))
+       (perform-replace from to t t delimited nil 
multi-query-replace-map)))))

  (provide 'fileloop)
  ;;; fileloop.el ends here