Mercurial > emacs
comparison lisp/replace.el @ 16725:cdc897a9054f
(perform-replace): Undo previous change.
Instead, use the new match-data features to avoid consing.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Wed, 18 Dec 1996 23:36:24 +0000 |
parents | 490b479ce48a |
children | bbe21b1c17a7 |
comparison
equal
deleted
inserted
replaced
16724:4b1fb372a4fe | 16725:cdc897a9054f |
---|---|
527 (keep-going t) | 527 (keep-going t) |
528 (stack nil) | 528 (stack nil) |
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 |
535 "Query replacing %s with %s: (\\<query-replace-map>\\[help] for help) ")))) | 536 "Query replacing %s with %s: (\\<query-replace-map>\\[help] for help) ")))) |
536 (if (stringp replacements) | 537 (if (stringp replacements) |
553 ;; the previous match, but it did not match there | 554 ;; the previous match, but it did not match there |
554 ;; before the replacement was done, ignore the match. | 555 ;; before the replacement was done, ignore the match. |
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 |
562 ;; right after end of previous replacement. | 563 ;; right after end of previous replacement. |
563 (forward-char 1) | 564 (forward-char 1) |
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)) |
570 (progn | 579 (progn |
571 (setq next-rotate-count | 580 (setq next-rotate-count |
572 (+ next-rotate-count repeat-count)) | 581 (+ next-rotate-count repeat-count)) |
573 (setq next-replacement (nth replacement-index replacements)) | 582 (setq next-replacement (nth replacement-index replacements)) |
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) |
585 (store-match-data real-match-data) | 594 (store-match-data real-match-data) |
586 (replace-highlight (match-beginning 0) (match-end 0)) | 595 (replace-highlight (match-beginning 0) (match-end 0)) |
648 ((eq def 'recenter) | 657 ((eq def 'recenter) |
649 (recenter nil)) | 658 (recenter nil)) |
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 |
657 (prog1 (match-data) | 671 (prog1 (match-data) |
658 (save-excursion (recursive-edit)))) | 672 (save-excursion (recursive-edit)))) |