diff options
| author | Richard M. Stallman | 1994-09-20 04:26:12 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 1994-09-20 04:26:12 +0000 |
| commit | 151270f331b4d9f3581861aecb8ce43685cf6a81 (patch) | |
| tree | d13b5e4bc351dd48c068fbf7f980bdaceb73b177 /lisp/replace.el | |
| parent | 53ea491aa51386be2ce042efcfee47880dcc66f0 (diff) | |
| download | emacs-151270f331b4d9f3581861aecb8ce43685cf6a81.tar.gz emacs-151270f331b4d9f3581861aecb8ce43685cf6a81.zip | |
(query-replace-interactive): New user option.
(query-replace-read-args): Obey that option--fetch from
search-ring or regexp-search-ring. New arg regexp-flag.
(query-replace, query-replace-regexp, replace-string)
(replace-regexp): Pass new arg to query-replace-read-args.
(map-query-replace-regexp): Obey query-replace-interactive.
Diffstat (limited to 'lisp/replace.el')
| -rw-r--r-- | lisp/replace.el | 48 |
1 files changed, 37 insertions, 11 deletions
diff --git a/lisp/replace.el b/lisp/replace.el index 7c6b8ea257d..01bf44155e3 100644 --- a/lisp/replace.el +++ b/lisp/replace.el | |||
| @@ -30,11 +30,17 @@ | |||
| 30 | 30 | ||
| 31 | (defvar query-replace-history nil) | 31 | (defvar query-replace-history nil) |
| 32 | 32 | ||
| 33 | (defun query-replace-read-args (string) | 33 | (defvar query-replace-interactive nil |
| 34 | "Non-nil means `query-replace' uses the last search string. | ||
| 35 | That becomes the \"string to replace\".") | ||
| 36 | |||
| 37 | (defun query-replace-read-args (string regexp-flag) | ||
| 34 | (let (from to) | 38 | (let (from to) |
| 35 | (setq from (read-from-minibuffer (format "%s: " string) | 39 | (if query-replace-interactive |
| 36 | nil nil nil | 40 | (setq from (car (if regexp-flag regexp-search-ring search-ring))) |
| 37 | 'query-replace-history)) | 41 | (setq from (read-from-minibuffer (format "%s: " string) |
| 42 | nil nil nil | ||
| 43 | 'query-replace-history))) | ||
| 38 | (setq to (read-from-minibuffer (format "%s %s with: " string from) | 44 | (setq to (read-from-minibuffer (format "%s %s with: " string from) |
| 39 | nil nil nil | 45 | nil nil nil |
| 40 | 'query-replace-history)) | 46 | 'query-replace-history)) |
| @@ -45,13 +51,17 @@ | |||
| 45 | As each match is found, the user must type a character saying | 51 | As each match is found, the user must type a character saying |
| 46 | what to do with it. For directions, type \\[help-command] at that time. | 52 | what to do with it. For directions, type \\[help-command] at that time. |
| 47 | 53 | ||
| 54 | If `query-replace-interactive' is non-nil, the last incremental search | ||
| 55 | string is used as FROM-STRING--you don't have to specify it with the | ||
| 56 | minibuffer. | ||
| 57 | |||
| 48 | Preserves case in each replacement if `case-replace' and `case-fold-search' | 58 | Preserves case in each replacement if `case-replace' and `case-fold-search' |
| 49 | are non-nil and FROM-STRING has no uppercase letters. | 59 | are non-nil and FROM-STRING has no uppercase letters. |
| 50 | Third arg DELIMITED (prefix arg if interactive), if non-nil, means replace | 60 | Third arg DELIMITED (prefix arg if interactive), if non-nil, means replace |
| 51 | only matches surrounded by word boundaries. | 61 | only matches surrounded by word boundaries. |
| 52 | 62 | ||
| 53 | To customize possible responses, change the \"bindings\" in `query-replace-map'." | 63 | To customize possible responses, change the \"bindings\" in `query-replace-map'." |
| 54 | (interactive (query-replace-read-args "Query replace")) | 64 | (interactive (query-replace-read-args "Query replace" nil)) |
| 55 | (perform-replace from-string to-string t nil arg) | 65 | (perform-replace from-string to-string t nil arg) |
| 56 | (or unread-command-events (message "Done"))) | 66 | (or unread-command-events (message "Done"))) |
| 57 | (define-key esc-map "%" 'query-replace) | 67 | (define-key esc-map "%" 'query-replace) |
| @@ -61,6 +71,10 @@ To customize possible responses, change the \"bindings\" in `query-replace-map'. | |||
| 61 | As each match is found, the user must type a character saying | 71 | As each match is found, the user must type a character saying |
| 62 | what to do with it. For directions, type \\[help-command] at that time. | 72 | what to do with it. For directions, type \\[help-command] at that time. |
| 63 | 73 | ||
| 74 | If `query-replace-interactive' is non-nil, the last incremental search | ||
| 75 | regexp is used as REGEXP--you don't have to specify it with the | ||
| 76 | minibuffer. | ||
| 77 | |||
| 64 | Preserves case in each replacement if `case-replace' and `case-fold-search' | 78 | Preserves case in each replacement if `case-replace' and `case-fold-search' |
| 65 | are non-nil and REGEXP has no uppercase letters. | 79 | are non-nil and REGEXP has no uppercase letters. |
| 66 | Third arg DELIMITED (prefix arg if interactive), if non-nil, means replace | 80 | Third arg DELIMITED (prefix arg if interactive), if non-nil, means replace |
| @@ -68,7 +82,7 @@ only matches surrounded by word boundaries. | |||
| 68 | In TO-STRING, `\\&' stands for whatever matched the whole of REGEXP, | 82 | In TO-STRING, `\\&' stands for whatever matched the whole of REGEXP, |
| 69 | and `\\=\\N' (where N is a digit) stands for | 83 | and `\\=\\N' (where N is a digit) stands for |
| 70 | whatever what matched the Nth `\\(...\\)' in REGEXP." | 84 | whatever what matched the Nth `\\(...\\)' in REGEXP." |
| 71 | (interactive (query-replace-read-args "Query replace regexp")) | 85 | (interactive (query-replace-read-args "Query replace regexp" t)) |
| 72 | (perform-replace regexp to-string t t arg) | 86 | (perform-replace regexp to-string t t arg) |
| 73 | (or unread-command-events (message "Done"))) | 87 | (or unread-command-events (message "Done"))) |
| 74 | 88 | ||
| @@ -81,13 +95,18 @@ wrapping around from the last such string to the first. | |||
| 81 | 95 | ||
| 82 | Non-interactively, TO-STRINGS may be a list of replacement strings. | 96 | Non-interactively, TO-STRINGS may be a list of replacement strings. |
| 83 | 97 | ||
| 98 | If `query-replace-interactive' is non-nil, the last incremental search | ||
| 99 | regexp is used as REGEXP--you don't have to specify it with the minibuffer. | ||
| 100 | |||
| 84 | A prefix argument N says to use each replacement string N times | 101 | A prefix argument N says to use each replacement string N times |
| 85 | before rotating to the next." | 102 | before rotating to the next." |
| 86 | (interactive | 103 | (interactive |
| 87 | (let (from to) | 104 | (let (from to) |
| 88 | (setq from (read-from-minibuffer "Map query replace (regexp): " | 105 | (setq from (if query-replace-interactive |
| 89 | nil nil nil | 106 | (car regexp-search-ring) |
| 90 | 'query-replace-history)) | 107 | (read-from-minibuffer "Map query replace (regexp): " |
| 108 | nil nil nil | ||
| 109 | 'query-replace-history))) | ||
| 91 | (setq to (read-from-minibuffer | 110 | (setq to (read-from-minibuffer |
| 92 | (format "Query replace %s with (space-separated strings): " | 111 | (format "Query replace %s with (space-separated strings): " |
| 93 | from) | 112 | from) |
| @@ -117,12 +136,16 @@ are non-nil and FROM-STRING has no uppercase letters. | |||
| 117 | Third arg DELIMITED (prefix arg if interactive), if non-nil, means replace | 136 | Third arg DELIMITED (prefix arg if interactive), if non-nil, means replace |
| 118 | only matches surrounded by word boundaries. | 137 | only matches surrounded by word boundaries. |
| 119 | 138 | ||
| 139 | If `query-replace-interactive' is non-nil, the last incremental search | ||
| 140 | string is used as FROM-STRING--you don't have to specify it with the | ||
| 141 | minibuffer. | ||
| 142 | |||
| 120 | This function is usually the wrong thing to use in a Lisp program. | 143 | This function is usually the wrong thing to use in a Lisp program. |
| 121 | What you probably want is a loop like this: | 144 | What you probably want is a loop like this: |
| 122 | (while (search-forward FROM-STRING nil t) | 145 | (while (search-forward FROM-STRING nil t) |
| 123 | (replace-match TO-STRING nil t)) | 146 | (replace-match TO-STRING nil t)) |
| 124 | which will run faster and will not set the mark or print anything." | 147 | which will run faster and will not set the mark or print anything." |
| 125 | (interactive (query-replace-read-args "Replace string")) | 148 | (interactive (query-replace-read-args "Replace string" nil)) |
| 126 | (perform-replace from-string to-string nil nil delimited) | 149 | (perform-replace from-string to-string nil nil delimited) |
| 127 | (or unread-command-events (message "Done"))) | 150 | (or unread-command-events (message "Done"))) |
| 128 | 151 | ||
| @@ -136,12 +159,15 @@ In TO-STRING, `\\&' stands for whatever matched the whole of REGEXP, | |||
| 136 | and `\\=\\N' (where N is a digit) stands for | 159 | and `\\=\\N' (where N is a digit) stands for |
| 137 | whatever what matched the Nth `\\(...\\)' in REGEXP. | 160 | whatever what matched the Nth `\\(...\\)' in REGEXP. |
| 138 | 161 | ||
| 162 | If `query-replace-interactive' is non-nil, the last incremental search | ||
| 163 | regexp is used as REGEXP--you don't have to specify it with the minibuffer. | ||
| 164 | |||
| 139 | This function is usually the wrong thing to use in a Lisp program. | 165 | This function is usually the wrong thing to use in a Lisp program. |
| 140 | What you probably want is a loop like this: | 166 | What you probably want is a loop like this: |
| 141 | (while (re-search-forward REGEXP nil t) | 167 | (while (re-search-forward REGEXP nil t) |
| 142 | (replace-match TO-STRING nil nil)) | 168 | (replace-match TO-STRING nil nil)) |
| 143 | which will run faster and will not set the mark or print anything." | 169 | which will run faster and will not set the mark or print anything." |
| 144 | (interactive (query-replace-read-args "Replace regexp")) | 170 | (interactive (query-replace-read-args "Replace regexp" t)) |
| 145 | (perform-replace regexp to-string nil t delimited) | 171 | (perform-replace regexp to-string nil t delimited) |
| 146 | (or unread-command-events (message "Done"))) | 172 | (or unread-command-events (message "Done"))) |
| 147 | 173 | ||