aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDmitry Gutov2020-05-04 02:56:10 +0300
committerDmitry Gutov2020-05-04 02:56:39 +0300
commit4b419083f92dc4b4313ae0d9991b825331c2f651 (patch)
tree6e7c69f95e206439f2c14b5c2de4df06c94ce6af
parent310112fdc7448a9297085333fcd4bf4088e634bf (diff)
downloademacs-4b419083f92dc4b4313ae0d9991b825331c2f651.tar.gz
emacs-4b419083f92dc4b4313ae0d9991b825331c2f651.zip
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.
-rw-r--r--lisp/fileloop.el33
1 files changed, 23 insertions, 10 deletions
diff --git a/lisp/fileloop.el b/lisp/fileloop.el
index 543963feafe..833bb0401cb 100644
--- a/lisp/fileloop.el
+++ b/lisp/fileloop.el
@@ -181,8 +181,7 @@ operating on the next file and nil otherwise."
181 (fileloop-initialize 181 (fileloop-initialize
182 files 182 files
183 (lambda () 183 (lambda ()
184 (let ((case-fold-search 184 (let ((case-fold-search (fileloop--case-fold regexp case-fold)))
185 (if (memq case-fold '(t nil)) case-fold case-fold-search)))
186 (re-search-forward regexp nil t))) 185 (re-search-forward regexp nil t)))
187 (lambda () 186 (lambda ()
188 (unless (eq last-buffer (current-buffer)) 187 (unless (eq last-buffer (current-buffer))
@@ -190,28 +189,42 @@ operating on the next file and nil otherwise."
190 (message "Scanning file %s...found" buffer-file-name)) 189 (message "Scanning file %s...found" buffer-file-name))
191 nil)))) 190 nil))))
192 191
192(defun fileloop--case-fold (regexp case-fold)
193 (let ((value
194 (if (memql case-fold '(nil t))
195 case-fold
196 case-fold-search)))
197 (if (and value search-upper-case)
198 (isearch-no-upper-case-p regexp t)
199 value)))
200
193;;;###autoload 201;;;###autoload
194(defun fileloop-initialize-replace (from to files case-fold &optional delimited) 202(defun fileloop-initialize-replace (from to files case-fold &optional delimited)
195 "Initialize a new round of query&replace on several files. 203 "Initialize a new round of query&replace on several files.
196FROM is a regexp and TO is the replacement to use. 204 FROM is a regexp and TO is the replacement to use.
197FILES describes the file, as in `fileloop-initialize'. 205 FILES describes the files, as in `fileloop-initialize'.
198CASE-FOLD can be t, nil, or `default', the latter one meaning to obey 206 CASE-FOLD can be t, nil, or `default':
199the default setting of `case-fold-search'. 207 if it is nil, matching of FROM is case-sensitive.
200DELIMITED if non-nil means replace only word-delimited matches." 208 if it is t, matching of FROM is case-insensitive, except
209 when `search-upper-case' is non-nil and FROM includes
210 upper-case letters.
211 if it is `default', the function uses the value of
212 `case-fold-search' instead.
213 DELIMITED if non-nil means replace only word-delimited matches."
201 ;; FIXME: Not sure how the delimited-flag interacts with the regexp-flag in 214 ;; FIXME: Not sure how the delimited-flag interacts with the regexp-flag in
202 ;; `perform-replace', so I just try to mimic the old code. 215 ;; `perform-replace', so I just try to mimic the old code.
203 (fileloop-initialize 216 (fileloop-initialize
204 files 217 files
205 (lambda () 218 (lambda ()
206 (let ((case-fold-search 219 (let ((case-fold-search (fileloop--case-fold from case-fold)))
207 (if (memql case-fold '(nil t)) case-fold case-fold-search)))
208 (if (re-search-forward from nil t) 220 (if (re-search-forward from nil t)
209 ;; When we find a match, move back 221 ;; When we find a match, move back
210 ;; to the beginning of it so perform-replace 222 ;; to the beginning of it so perform-replace
211 ;; will see it. 223 ;; will see it.
212 (goto-char (match-beginning 0))))) 224 (goto-char (match-beginning 0)))))
213 (lambda () 225 (lambda ()
214 (perform-replace from to t t delimited nil multi-query-replace-map)))) 226 (let ((case-fold-search (fileloop--case-fold from case-fold)))
227 (perform-replace from to t t delimited nil multi-query-replace-map)))))
215 228
216(provide 'fileloop) 229(provide 'fileloop)
217;;; fileloop.el ends here 230;;; fileloop.el ends here