diff options
| author | Richard M. Stallman | 1996-12-18 23:36:24 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 1996-12-18 23:36:24 +0000 |
| commit | ae4eb03ccbef490ff286f86867a643af3dafaf41 (patch) | |
| tree | a078dfb8fa1c381a913a6163267873bc04b3f17c /lisp/replace.el | |
| parent | 56256c2a0c7c52a4543ca4f6c4758c2fa8288631 (diff) | |
| download | emacs-ae4eb03ccbef490ff286f86867a643af3dafaf41.tar.gz emacs-ae4eb03ccbef490ff286f86867a643af3dafaf41.zip | |
(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.el | 20 |
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." | |||
| 529 | (next-rotate-count 0) | 529 | (next-rotate-count 0) |
| 530 | (replace-count 0) | 530 | (replace-count 0) |
| 531 | (lastrepl nil) ;Position after last match considered. | 531 | (lastrepl nil) ;Position after last match considered. |
| 532 | (match-again t) | ||
| 532 | (message | 533 | (message |
| 533 | (if query-flag | 534 | (if query-flag |
| 534 | (substitute-command-keys | 535 | (substitute-command-keys |
| @@ -555,7 +556,7 @@ which will run faster and probably do exactly what you want." | |||
| 555 | (if (or (eq lastrepl (point)) | 556 | (if (or (eq lastrepl (point)) |
| 556 | (and regexp-flag | 557 | (and regexp-flag |
| 557 | (eq lastrepl (match-beginning 0)) | 558 | (eq lastrepl (match-beginning 0)) |
| 558 | (eq lastrepl (match-end 0)))) | 559 | (not match-again))) |
| 559 | (if (eobp) | 560 | (if (eobp) |
| 560 | nil | 561 | nil |
| 561 | ;; Don't replace the null string | 562 | ;; Don't replace the null string |
| @@ -564,6 +565,14 @@ which will run faster and probably do exactly what you want." | |||
| 564 | (funcall search-function search-string nil t)) | 565 | (funcall search-function search-string nil t)) |
| 565 | t)) | 566 | t)) |
| 566 | 567 | ||
| 568 | ;; Save the data associated with the real match. | ||
| 569 | ;; For speed, use only integers and reuse the list used last time. | ||
| 570 | (setq real-match-data (match-data t real-match-data)) | ||
| 571 | |||
| 572 | ;; Before we make the replacement, decide whether the search string | ||
| 573 | ;; can match again just after this match. | ||
| 574 | (if regexp-flag | ||
| 575 | (setq match-again (looking-at search-string))) | ||
| 567 | ;; If time for a change, advance to next replacement string. | 576 | ;; If time for a change, advance to next replacement string. |
| 568 | (if (and (listp replacements) | 577 | (if (and (listp replacements) |
| 569 | (= next-rotate-count replace-count)) | 578 | (= next-rotate-count replace-count)) |
| @@ -574,11 +583,11 @@ which will run faster and probably do exactly what you want." | |||
| 574 | (setq replacement-index (% (1+ replacement-index) (length replacements))))) | 583 | (setq replacement-index (% (1+ replacement-index) (length replacements))))) |
| 575 | (if (not query-flag) | 584 | (if (not query-flag) |
| 576 | (progn | 585 | (progn |
| 586 | (store-match-data real-match-data) | ||
| 577 | (replace-match next-replacement nocasify literal) | 587 | (replace-match next-replacement nocasify literal) |
| 578 | (setq replace-count (1+ replace-count))) | 588 | (setq replace-count (1+ replace-count))) |
| 579 | (undo-boundary) | 589 | (undo-boundary) |
| 580 | (let (done replaced key def) | 590 | (let (done replaced key def) |
| 581 | (setq real-match-data (match-data)) | ||
| 582 | ;; Loop reading commands until one of them sets done, | 591 | ;; Loop reading commands until one of them sets done, |
| 583 | ;; which means it has finished handling this occurrence. | 592 | ;; which means it has finished handling this occurrence. |
| 584 | (while (not done) | 593 | (while (not done) |
| @@ -650,7 +659,12 @@ which will run faster and probably do exactly what you want." | |||
| 650 | ((eq def 'edit) | 659 | ((eq def 'edit) |
| 651 | (store-match-data | 660 | (store-match-data |
| 652 | (prog1 (match-data) | 661 | (prog1 (match-data) |
| 653 | (save-excursion (recursive-edit))))) | 662 | (save-excursion (recursive-edit)))) |
| 663 | ;; Before we make the replacement, | ||
| 664 | ;; decide whether the search string | ||
| 665 | ;; can match again just after this match. | ||
| 666 | (if regexp-flag | ||
| 667 | (setq match-again (looking-at search-string)))) | ||
| 654 | ((eq def 'delete-and-edit) | 668 | ((eq def 'delete-and-edit) |
| 655 | (delete-region (match-beginning 0) (match-end 0)) | 669 | (delete-region (match-beginning 0) (match-end 0)) |
| 656 | (store-match-data | 670 | (store-match-data |