diff options
| author | Richard M. Stallman | 1992-07-24 08:17:31 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 1992-07-24 08:17:31 +0000 |
| commit | 770970cbad7bc867d747ad04b5d620d223ca6f40 (patch) | |
| tree | 65a356b0125f8e7cbabbc07fabd0e733b9771b5a /lisp/replace.el | |
| parent | 15c65264fae0a306ac53cef41af7b1879051ce17 (diff) | |
| download | emacs-770970cbad7bc867d747ad04b5d620d223ca6f40.tar.gz emacs-770970cbad7bc867d747ad04b5d620d223ca6f40.zip | |
*** empty log message ***
Diffstat (limited to 'lisp/replace.el')
| -rw-r--r-- | lisp/replace.el | 32 |
1 files changed, 27 insertions, 5 deletions
diff --git a/lisp/replace.el b/lisp/replace.el index 01dbeb5558a..24a4818051f 100644 --- a/lisp/replace.el +++ b/lisp/replace.el | |||
| @@ -23,6 +23,18 @@ | |||
| 23 | (defconst case-replace t "\ | 23 | (defconst case-replace t "\ |
| 24 | *Non-nil means query-replace should preserve case in replacements.") | 24 | *Non-nil means query-replace should preserve case in replacements.") |
| 25 | 25 | ||
| 26 | (defvar query-replace-history nil) | ||
| 27 | |||
| 28 | (defun query-replace-read-args (string) | ||
| 29 | (let (from to) | ||
| 30 | (setq from (read-from-minibuffer (format "%s: " string) | ||
| 31 | nil nil nil | ||
| 32 | 'query-replace-history)) | ||
| 33 | (setq to (read-from-minibuffer (format "%s %s with: " string from) | ||
| 34 | nil nil nil | ||
| 35 | 'query-replace-history)) | ||
| 36 | (list from to current-prefix-arg))) | ||
| 37 | |||
| 26 | (defun query-replace (from-string to-string &optional arg) | 38 | (defun query-replace (from-string to-string &optional arg) |
| 27 | "Replace some occurrences of FROM-STRING with TO-STRING. | 39 | "Replace some occurrences of FROM-STRING with TO-STRING. |
| 28 | As each match is found, the user must type a character saying | 40 | As each match is found, the user must type a character saying |
| @@ -32,7 +44,7 @@ Preserves case in each replacement if case-replace and case-fold-search | |||
| 32 | are non-nil and FROM-STRING has no uppercase letters. | 44 | are non-nil and FROM-STRING has no uppercase letters. |
| 33 | Third arg DELIMITED (prefix arg if interactive) non-nil means replace | 45 | Third arg DELIMITED (prefix arg if interactive) non-nil means replace |
| 34 | only matches surrounded by word boundaries." | 46 | only matches surrounded by word boundaries." |
| 35 | (interactive "sQuery replace: \nsQuery replace %s with: \nP") | 47 | (interactive (query-replace-read-args "Query replace")) |
| 36 | (perform-replace from-string to-string t nil arg) | 48 | (perform-replace from-string to-string t nil arg) |
| 37 | (message "Done")) | 49 | (message "Done")) |
| 38 | (define-key esc-map "%" 'query-replace) | 50 | (define-key esc-map "%" 'query-replace) |
| @@ -48,7 +60,7 @@ Third arg DELIMITED (prefix arg if interactive) non-nil means replace | |||
| 48 | only matches surrounded by word boundaries. | 60 | only matches surrounded by word boundaries. |
| 49 | In TO-STRING, \\& means insert what matched REGEXP, | 61 | In TO-STRING, \\& means insert what matched REGEXP, |
| 50 | and \\=\\<n> means insert what matched <n>th \\(...\\) in REGEXP." | 62 | and \\=\\<n> means insert what matched <n>th \\(...\\) in REGEXP." |
| 51 | (interactive "sQuery replace regexp: \nsQuery replace regexp %s with: \nP") | 63 | (interactive (query-replace-read-args "Query replace regexp")) |
| 52 | (perform-replace regexp to-string t t arg) | 64 | (perform-replace regexp to-string t t arg) |
| 53 | (message "Done")) | 65 | (message "Done")) |
| 54 | 66 | ||
| @@ -63,7 +75,17 @@ Non-interactively, TO-STRINGS may be a list of replacement strings. | |||
| 63 | 75 | ||
| 64 | A prefix argument N says to use each replacement string N times | 76 | A prefix argument N says to use each replacement string N times |
| 65 | before rotating to the next." | 77 | before rotating to the next." |
| 66 | (interactive "sMap query replace (regexp): \nsQuery replace %s with (space-separated strings): \nP") | 78 | (interactive |
| 79 | (let (from to) | ||
| 80 | (setq from (read-from-minibuffer "Map query replace (regexp): " | ||
| 81 | nil nil nil | ||
| 82 | 'query-replace-history)) | ||
| 83 | (setq to (read-from-minibuffer | ||
| 84 | (format "Query replace %s with (space-separated strings): " | ||
| 85 | from) | ||
| 86 | nil nil nil | ||
| 87 | 'query-replace-history)) | ||
| 88 | (list from to current-prefix-arg))) | ||
| 67 | (let (replacements) | 89 | (let (replacements) |
| 68 | (if (listp to-strings) | 90 | (if (listp to-strings) |
| 69 | (setq replacements to-strings) | 91 | (setq replacements to-strings) |
| @@ -92,7 +114,7 @@ What you probably want is a loop like this: | |||
| 92 | (while (search-forward OLD-STRING nil t) | 114 | (while (search-forward OLD-STRING nil t) |
| 93 | (replace-match REPLACEMENT nil t)) | 115 | (replace-match REPLACEMENT nil t)) |
| 94 | which will run faster and will not set the mark or print anything." | 116 | which will run faster and will not set the mark or print anything." |
| 95 | (interactive "sReplace string: \nsReplace string %s with: \nP") | 117 | (interactive (query-replace-read-args "Replace string")) |
| 96 | (perform-replace from-string to-string nil nil delimited) | 118 | (perform-replace from-string to-string nil nil delimited) |
| 97 | (message "Done")) | 119 | (message "Done")) |
| 98 | 120 | ||
| @@ -110,7 +132,7 @@ What you probably want is a loop like this: | |||
| 110 | (while (re-search-forward REGEXP nil t) | 132 | (while (re-search-forward REGEXP nil t) |
| 111 | (replace-match REPLACEMENT nil nil)) | 133 | (replace-match REPLACEMENT nil nil)) |
| 112 | which will run faster and will not set the mark or print anything." | 134 | which will run faster and will not set the mark or print anything." |
| 113 | (interactive "sReplace regexp: \nsReplace regexp %s with: \nP") | 135 | (interactive (query-replace-read-args "Replace regexp")) |
| 114 | (perform-replace regexp to-string nil t delimited) | 136 | (perform-replace regexp to-string nil t delimited) |
| 115 | (message "Done")) | 137 | (message "Done")) |
| 116 | 138 | ||