emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

emacs-27 4b41908: Honor search-upper-case


From: Dmitry Gutov
Subject: emacs-27 4b41908: Honor search-upper-case
Date: Sun, 3 May 2020 19:57:01 -0400 (EDT)

branch: emacs-27
commit 4b419083f92dc4b4313ae0d9991b825331c2f651
Author: Dmitry Gutov <address@hidden>
Commit: Dmitry Gutov <address@hidden>

    Honor search-upper-case
    
    * lisp/fileloop.el (fileloop--case-fold):
    Extract from existing code.  Honor search-upper-case (bug#40940).
    (fileloop-initialize-replace, fileloop-initialize-search): Use it.
    Update the docstring.
---
 lisp/fileloop.el | 33 +++++++++++++++++++++++----------
 1 file changed, 23 insertions(+), 10 deletions(-)

diff --git a/lisp/fileloop.el b/lisp/fileloop.el
index 543963f..833bb04 100644
--- a/lisp/fileloop.el
+++ b/lisp/fileloop.el
@@ -181,8 +181,7 @@ operating on the next file and nil otherwise."
     (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,28 +189,42 @@ operating on the next file and nil otherwise."
          (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.
-FROM is a regexp and TO is the replacement to use.
-FILES describes the file, as in `fileloop-initialize'.
-CASE-FOLD can be t, nil, or `default', the latter one meaning to obey
-the default setting of `case-fold-search'.
-DELIMITED if non-nil means replace only word-delimited matches."
+  FROM is a regexp and TO is the replacement to use.
+  FILES describes the files, as in `fileloop-initialize'.
+  CASE-FOLD can be t, nil, or `default':
+    if it is nil, matching of FROM is case-sensitive.
+    if it is t, matching of FROM is case-insensitive, except
+       when `search-upper-case' is non-nil and FROM includes
+       upper-case letters.
+    if it is `default', the function uses the value of
+       `case-fold-search' instead.
+  DELIMITED if non-nil means replace only word-delimited matches."
   ;; FIXME: Not sure how the delimited-flag interacts with the regexp-flag in
   ;; `perform-replace', so I just try to mimic the old code.
   (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



reply via email to

[Prev in Thread] Current Thread [Next in Thread]