summaryrefslogtreecommitdiff
path: root/lisp/replace.el
diff options
context:
space:
mode:
authorRichard M. Stallman <rms@gnu.org>1996-12-18 23:36:24 +0000
committerRichard M. Stallman <rms@gnu.org>1996-12-18 23:36:24 +0000
commit33cdc837a258140270e8eea6773fca63e1e41b9a (patch)
tree7701e9243f782315eca9ad7e6812d7cd2bc11288 /lisp/replace.el
parent480e0d05670912d3ea879a58c598dd1023ef3cf5 (diff)
downloademacs-33cdc837a258140270e8eea6773fca63e1e41b9a.tar.gz
(perform-replace): Undo previous change.
Instead, use the new match-data features to avoid consing.
Diffstat (limited to 'lisp/replace.el')
-rw-r--r--lisp/replace.el20
1 files changed, 17 insertions, 3 deletions
diff --git a/lisp/replace.el b/lisp/replace.el
index 75369d1de09..205c8508090 100644
--- a/lisp/replace.el
+++ b/lisp/replace.el
@@ -529,6 +529,7 @@ which will run faster and probably do exactly what you want."
(next-rotate-count 0)
(replace-count 0)
(lastrepl nil) ;Position after last match considered.
+ (match-again t)
(message
(if query-flag
(substitute-command-keys
@@ -555,7 +556,7 @@ which will run faster and probably do exactly what you want."
(if (or (eq lastrepl (point))
(and regexp-flag
(eq lastrepl (match-beginning 0))
- (eq lastrepl (match-end 0))))
+ (not match-again)))
(if (eobp)
nil
;; Don't replace the null string
@@ -564,6 +565,14 @@ which will run faster and probably do exactly what you want."
(funcall search-function search-string nil t))
t))
+ ;; Save the data associated with the real match.
+ ;; For speed, use only integers and reuse the list used last time.
+ (setq real-match-data (match-data t real-match-data))
+
+ ;; Before we make the replacement, decide whether the search string
+ ;; can match again just after this match.
+ (if regexp-flag
+ (setq match-again (looking-at search-string)))
;; If time for a change, advance to next replacement string.
(if (and (listp replacements)
(= next-rotate-count replace-count))
@@ -574,11 +583,11 @@ which will run faster and probably do exactly what you want."
(setq replacement-index (% (1+ replacement-index) (length replacements)))))
(if (not query-flag)
(progn
+ (store-match-data real-match-data)
(replace-match next-replacement nocasify literal)
(setq replace-count (1+ replace-count)))
(undo-boundary)
(let (done replaced key def)
- (setq real-match-data (match-data))
;; Loop reading commands until one of them sets done,
;; which means it has finished handling this occurrence.
(while (not done)
@@ -650,7 +659,12 @@ which will run faster and probably do exactly what you want."
((eq def 'edit)
(store-match-data
(prog1 (match-data)
- (save-excursion (recursive-edit)))))
+ (save-excursion (recursive-edit))))
+ ;; Before we make the replacement,
+ ;; decide whether the search string
+ ;; can match again just after this match.
+ (if regexp-flag
+ (setq match-again (looking-at search-string))))
((eq def 'delete-and-edit)
(delete-region (match-beginning 0) (match-end 0))
(store-match-data