summaryrefslogtreecommitdiff
path: root/lisp/replace.el
diff options
context:
space:
mode:
authorRichard M. Stallman <rms@gnu.org>2005-12-27 04:31:21 +0000
committerRichard M. Stallman <rms@gnu.org>2005-12-27 04:31:21 +0000
commitc0b457636e9a18775121223d04bbea36cf14454d (patch)
tree61ffc7f6f36447fdefb2439053514a3413c7e2d0 /lisp/replace.el
parentd6f0f3e06926125ab9570ee66e49da7c788dbbd1 (diff)
downloademacs-c0b457636e9a18775121223d04bbea36cf14454d.tar.gz
(perform-replace): Calculate match-again
before skipping read-only matches.
Diffstat (limited to 'lisp/replace.el')
-rw-r--r--lisp/replace.el43
1 files changed, 22 insertions, 21 deletions
diff --git a/lisp/replace.el b/lisp/replace.el
index 8229eda85a4..46f672a8d1a 100644
--- a/lisp/replace.el
+++ b/lisp/replace.el
@@ -1474,32 +1474,33 @@ make, or the user didn't cancel the call."
;; For speed, use only integers and
;; reuse the list used last time.
(replace-match-data t real-match-data)))))
+
+ ;; Record whether the match is nonempty, to avoid an infinite loop
+ ;; repeatedly matching the same empty string.
+ (setq nonempty-match
+ (/= (nth 0 real-match-data) (nth 1 real-match-data)))
+
+ ;; If the match is empty, record that the next one can't be
+ ;; adjacent.
+
+ ;; Otherwise, if matching a regular expression, do the next
+ ;; match now, since the replacement for this match may
+ ;; affect whether the next match is adjacent to this one.
+ ;; If that match is empty, don't use it.
+ (setq match-again
+ (and nonempty-match
+ (or (not regexp-flag)
+ (and (looking-at search-string)
+ (let ((match (match-data)))
+ (and (/= (nth 0 match) (nth 1 match))
+ match))))))
+
;; Optionally ignore matches that have a read-only property.
(unless (and query-replace-skip-read-only
(text-property-not-all
- (match-beginning 0) (match-end 0)
+ (nth 0 real-match-data) (nth 1 real-match-data)
'read-only nil))
- ;; Record whether the match is nonempty, to avoid an infinite loop
- ;; repeatedly matching the same empty string.
- (setq nonempty-match
- (/= (nth 0 real-match-data) (nth 1 real-match-data)))
-
- ;; If the match is empty, record that the next one can't be
- ;; adjacent.
-
- ;; Otherwise, if matching a regular expression, do the next
- ;; match now, since the replacement for this match may
- ;; affect whether the next match is adjacent to this one.
- ;; If that match is empty, don't use it.
- (setq match-again
- (and nonempty-match
- (or (not regexp-flag)
- (and (looking-at search-string)
- (let ((match (match-data)))
- (and (/= (nth 0 match) (nth 1 match))
- match))))))
-
;; Calculate the replacement string, if necessary.
(when replacements
(set-match-data real-match-data)