diff options
| author | Jim Blandy | 1992-06-30 13:54:21 +0000 |
|---|---|---|
| committer | Jim Blandy | 1992-06-30 13:54:21 +0000 |
| commit | e5d77022e8429ca757746ed5d7cf9e2420703e8e (patch) | |
| tree | 2e273d216c8f9e34d5e29547f8e7e7c6c5d32049 /lisp/replace.el | |
| parent | 53b0a6f88893036a42db2abcfbc257b68906956e (diff) | |
| download | emacs-e5d77022e8429ca757746ed5d7cf9e2420703e8e.tar.gz emacs-e5d77022e8429ca757746ed5d7cf9e2420703e8e.zip | |
*** empty log message ***
Diffstat (limited to 'lisp/replace.el')
| -rw-r--r-- | lisp/replace.el | 28 |
1 files changed, 12 insertions, 16 deletions
diff --git a/lisp/replace.el b/lisp/replace.el index 6f8601dfd8f..3dc23295218 100644 --- a/lisp/replace.el +++ b/lisp/replace.el | |||
| @@ -1,12 +1,12 @@ | |||
| 1 | ;;; replace.el --- replace commands for Emacs. | 1 | ;;; replace.el --- replace commands for Emacs. |
| 2 | 2 | ||
| 3 | ;; Copyright (C) 1985-1991 Free Software Foundation, Inc. | 3 | ;; Copyright (C) 1985, 86, 87, 88, 89, 90, 91, 92 Free Software Foundation, Inc. |
| 4 | 4 | ||
| 5 | ;; This file is part of GNU Emacs. | 5 | ;; This file is part of GNU Emacs. |
| 6 | 6 | ||
| 7 | ;; GNU Emacs is free software; you can redistribute it and/or modify | 7 | ;; GNU Emacs is free software; you can redistribute it and/or modify |
| 8 | ;; it under the terms of the GNU General Public License as published by | 8 | ;; it under the terms of the GNU General Public License as published by |
| 9 | ;; the Free Software Foundation; either version 1, or (at your option) | 9 | ;; the Free Software Foundation; either version 2, or (at your option) |
| 10 | ;; any later version. | 10 | ;; any later version. |
| 11 | 11 | ||
| 12 | ;; GNU Emacs is distributed in the hope that it will be useful, | 12 | ;; GNU Emacs is distributed in the hope that it will be useful, |
| @@ -19,11 +19,9 @@ | |||
| 19 | ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. | 19 | ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. |
| 20 | 20 | ||
| 21 | 21 | ||
| 22 | ;;;###autoload | ||
| 23 | (defconst case-replace t "\ | 22 | (defconst case-replace t "\ |
| 24 | *Non-nil means query-replace should preserve case in replacements.") | 23 | *Non-nil means query-replace should preserve case in replacements.") |
| 25 | 24 | ||
| 26 | ;;;###autoload | ||
| 27 | (defun query-replace (from-string to-string &optional arg) | 25 | (defun query-replace (from-string to-string &optional arg) |
| 28 | "Replace some occurrences of FROM-STRING with TO-STRING. | 26 | "Replace some occurrences of FROM-STRING with TO-STRING. |
| 29 | As each match is found, the user must type a character saying | 27 | As each match is found, the user must type a character saying |
| @@ -36,10 +34,8 @@ only matches surrounded by word boundaries." | |||
| 36 | (interactive "sQuery replace: \nsQuery replace %s with: \nP") | 34 | (interactive "sQuery replace: \nsQuery replace %s with: \nP") |
| 37 | (perform-replace from-string to-string t nil arg) | 35 | (perform-replace from-string to-string t nil arg) |
| 38 | (message "Done")) | 36 | (message "Done")) |
| 39 | ;;;###autoload | ||
| 40 | (define-key esc-map "%" 'query-replace) | 37 | (define-key esc-map "%" 'query-replace) |
| 41 | 38 | ||
| 42 | ;;;###autoload | ||
| 43 | (defun query-replace-regexp (regexp to-string &optional arg) | 39 | (defun query-replace-regexp (regexp to-string &optional arg) |
| 44 | "Replace some things after point matching REGEXP with TO-STRING. | 40 | "Replace some things after point matching REGEXP with TO-STRING. |
| 45 | As each match is found, the user must type a character saying | 41 | As each match is found, the user must type a character saying |
| @@ -55,7 +51,6 @@ and \\=\\<n> means insert what matched <n>th \\(...\\) in REGEXP." | |||
| 55 | (perform-replace regexp to-string t t arg) | 51 | (perform-replace regexp to-string t t arg) |
| 56 | (message "Done")) | 52 | (message "Done")) |
| 57 | 53 | ||
| 58 | ;;;###autoload | ||
| 59 | (defun map-query-replace-regexp (regexp to-strings &optional arg) | 54 | (defun map-query-replace-regexp (regexp to-strings &optional arg) |
| 60 | "Replace some matches for REGEXP with various strings, in rotation. | 55 | "Replace some matches for REGEXP with various strings, in rotation. |
| 61 | The second argument TO-STRINGS contains the replacement strings, separated | 56 | The second argument TO-STRINGS contains the replacement strings, separated |
| @@ -84,7 +79,6 @@ before rotating to the next." | |||
| 84 | (perform-replace regexp replacements t t nil arg)) | 79 | (perform-replace regexp replacements t t nil arg)) |
| 85 | (message "Done")) | 80 | (message "Done")) |
| 86 | 81 | ||
| 87 | ;;;###autoload | ||
| 88 | (defun replace-string (from-string to-string &optional delimited) | 82 | (defun replace-string (from-string to-string &optional delimited) |
| 89 | "Replace occurrences of FROM-STRING with TO-STRING. | 83 | "Replace occurrences of FROM-STRING with TO-STRING. |
| 90 | Preserve case in each match if `case-replace' and `case-fold-search' | 84 | Preserve case in each match if `case-replace' and `case-fold-search' |
| @@ -101,7 +95,6 @@ which will run faster and will not set the mark or print anything." | |||
| 101 | (perform-replace from-string to-string nil nil delimited) | 95 | (perform-replace from-string to-string nil nil delimited) |
| 102 | (message "Done")) | 96 | (message "Done")) |
| 103 | 97 | ||
| 104 | ;;;###autoload | ||
| 105 | (defun replace-regexp (regexp to-string &optional delimited) | 98 | (defun replace-regexp (regexp to-string &optional delimited) |
| 106 | "Replace things after point matching REGEXP with TO-STRING. | 99 | "Replace things after point matching REGEXP with TO-STRING. |
| 107 | Preserve case in each match if case-replace and case-fold-search | 100 | Preserve case in each match if case-replace and case-fold-search |
| @@ -348,7 +341,6 @@ C-l to clear the screen, redisplay, and offer same replacement again, | |||
| 348 | ^ to move point back to previous match." | 341 | ^ to move point back to previous match." |
| 349 | "Help message while in query-replace") | 342 | "Help message while in query-replace") |
| 350 | 343 | ||
| 351 | ;;;###autoload | ||
| 352 | (defun perform-replace (from-string replacements | 344 | (defun perform-replace (from-string replacements |
| 353 | query-flag regexp-flag delimited-flag | 345 | query-flag regexp-flag delimited-flag |
| 354 | &optional repeat-count) | 346 | &optional repeat-count) |
| @@ -364,6 +356,7 @@ which will run faster and do exactly what you probably want." | |||
| 364 | (literal (not regexp-flag)) | 356 | (literal (not regexp-flag)) |
| 365 | (search-function (if regexp-flag 're-search-forward 'search-forward)) | 357 | (search-function (if regexp-flag 're-search-forward 'search-forward)) |
| 366 | (search-string from-string) | 358 | (search-string from-string) |
| 359 | (real-match-data nil) ; the match data for the current match | ||
| 367 | (next-replacement nil) | 360 | (next-replacement nil) |
| 368 | (replacement-index 0) | 361 | (replacement-index 0) |
| 369 | (keep-going t) | 362 | (keep-going t) |
| @@ -400,6 +393,10 @@ which will run faster and do exactly what you probably want." | |||
| 400 | (forward-char 1) | 393 | (forward-char 1) |
| 401 | (funcall search-function search-string nil t)) | 394 | (funcall search-function search-string nil t)) |
| 402 | t)) | 395 | t)) |
| 396 | |||
| 397 | ;; Save the data associated with the real match. | ||
| 398 | (setq real-match-data (match-data)) | ||
| 399 | |||
| 403 | ;; Before we make the replacement, decide whether the search string | 400 | ;; Before we make the replacement, decide whether the search string |
| 404 | ;; can match again just after this match. | 401 | ;; can match again just after this match. |
| 405 | (if regexp-flag | 402 | (if regexp-flag |
| @@ -414,15 +411,13 @@ which will run faster and do exactly what you probably want." | |||
| 414 | (setq replacement-index (% (1+ replacement-index) (length replacements))))) | 411 | (setq replacement-index (% (1+ replacement-index) (length replacements))))) |
| 415 | (if (not query-flag) | 412 | (if (not query-flag) |
| 416 | (progn | 413 | (progn |
| 414 | (store-match-data real-match-data) | ||
| 417 | (replace-match next-replacement nocasify literal) | 415 | (replace-match next-replacement nocasify literal) |
| 418 | (setq replace-count (1+ replace-count))) | 416 | (setq replace-count (1+ replace-count))) |
| 419 | (undo-boundary) | 417 | (undo-boundary) |
| 420 | (let (done replaced) | 418 | (let (done replaced) |
| 421 | (while (not done) | 419 | (while (not done) |
| 422 | ;; Preserve the match data. Process filters and sentinels | 420 | (let ((help-form |
| 423 | ;; could run inside read-char.. | ||
| 424 | (let ((data (match-data)) | ||
| 425 | (help-form | ||
| 426 | '(concat "Query replacing " | 421 | '(concat "Query replacing " |
| 427 | (if regexp-flag "regexp " "") | 422 | (if regexp-flag "regexp " "") |
| 428 | from-string " with " next-replacement ".\n\n" | 423 | from-string " with " next-replacement ".\n\n" |
| @@ -432,8 +427,9 @@ which will run faster and do exactly what you probably want." | |||
| 432 | (message "Query replacing %s with %s: " from-string next-replacement) | 427 | (message "Query replacing %s with %s: " from-string next-replacement) |
| 433 | (setq char (read-event)) | 428 | (setq char (read-event)) |
| 434 | (if (and (numberp char) (= char ??)) | 429 | (if (and (numberp char) (= char ??)) |
| 435 | (setq unread-command-char help-char char help-char))) | 430 | (setq unread-command-char help-char char help-char)))) |
| 436 | (store-match-data data)) | 431 | ;; Restore the match data while we process the command. |
| 432 | (store-match-data real-match-data) | ||
| 437 | (cond ((or (= char ?\e) | 433 | (cond ((or (= char ?\e) |
| 438 | (= char ?q)) | 434 | (= char ?q)) |
| 439 | (setq keep-going nil) | 435 | (setq keep-going nil) |