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.
This commit is contained in:
parent
310112fdc7
commit
4b419083f9
1 changed files with 23 additions and 10 deletions
|
@ -181,8 +181,7 @@ operating on the next file and nil otherwise."
|
||||||
(fileloop-initialize
|
(fileloop-initialize
|
||||||
files
|
files
|
||||||
(lambda ()
|
(lambda ()
|
||||||
(let ((case-fold-search
|
(let ((case-fold-search (fileloop--case-fold regexp case-fold)))
|
||||||
(if (memq case-fold '(t nil)) case-fold case-fold-search)))
|
|
||||||
(re-search-forward regexp nil t)))
|
(re-search-forward regexp nil t)))
|
||||||
(lambda ()
|
(lambda ()
|
||||||
(unless (eq last-buffer (current-buffer))
|
(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))
|
(message "Scanning file %s...found" buffer-file-name))
|
||||||
nil))))
|
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
|
;;;###autoload
|
||||||
(defun fileloop-initialize-replace (from to files case-fold &optional delimited)
|
(defun fileloop-initialize-replace (from to files case-fold &optional delimited)
|
||||||
"Initialize a new round of query&replace on several files.
|
"Initialize a new round of query&replace on several files.
|
||||||
FROM is a regexp and TO is the replacement to use.
|
FROM is a regexp and TO is the replacement to use.
|
||||||
FILES describes the file, as in `fileloop-initialize'.
|
FILES describes the files, as in `fileloop-initialize'.
|
||||||
CASE-FOLD can be t, nil, or `default', the latter one meaning to obey
|
CASE-FOLD can be t, nil, or `default':
|
||||||
the default setting of `case-fold-search'.
|
if it is nil, matching of FROM is case-sensitive.
|
||||||
DELIMITED if non-nil means replace only word-delimited matches."
|
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
|
;; FIXME: Not sure how the delimited-flag interacts with the regexp-flag in
|
||||||
;; `perform-replace', so I just try to mimic the old code.
|
;; `perform-replace', so I just try to mimic the old code.
|
||||||
(fileloop-initialize
|
(fileloop-initialize
|
||||||
files
|
files
|
||||||
(lambda ()
|
(lambda ()
|
||||||
(let ((case-fold-search
|
(let ((case-fold-search (fileloop--case-fold from case-fold)))
|
||||||
(if (memql case-fold '(nil t)) case-fold case-fold-search)))
|
|
||||||
(if (re-search-forward from nil t)
|
(if (re-search-forward from nil t)
|
||||||
;; When we find a match, move back
|
;; When we find a match, move back
|
||||||
;; to the beginning of it so perform-replace
|
;; to the beginning of it so perform-replace
|
||||||
;; will see it.
|
;; will see it.
|
||||||
(goto-char (match-beginning 0)))))
|
(goto-char (match-beginning 0)))))
|
||||||
(lambda ()
|
(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)
|
(provide 'fileloop)
|
||||||
;;; fileloop.el ends here
|
;;; fileloop.el ends here
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue