diff options
| author | Richard M. Stallman | 2003-02-24 16:45:47 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 2003-02-24 16:45:47 +0000 |
| commit | 10784bace46bcbd0cf78d26a87626d063982cb81 (patch) | |
| tree | d57d4597c063662b99b40a6f337aff82498536de /lisp/replace.el | |
| parent | d25ab73f88b7b1f6a7a95b887b3cfc3fb0acc3ec (diff) | |
| download | emacs-10784bace46bcbd0cf78d26a87626d063982cb81.tar.gz emacs-10784bace46bcbd0cf78d26a87626d063982cb81.zip | |
(query-replace-read-args): Return just 3 values.
(query-replace, query-replace-regexp)
(query-replace-regexp-eval, map-query-replace-regexp)
(replace-string, replace-regexp): Read the start and end args
separately so that the expressions are recorded in command-history.
Diffstat (limited to 'lisp/replace.el')
| -rw-r--r-- | lisp/replace.el | 68 |
1 files changed, 51 insertions, 17 deletions
diff --git a/lisp/replace.el b/lisp/replace.el index 14bbb6fb9ad..5fc68fa9408 100644 --- a/lisp/replace.el +++ b/lisp/replace.el | |||
| @@ -87,9 +87,7 @@ strings or patterns." | |||
| 87 | (setq to (read-from-minibuffer (format "%s %s with: " string from) | 87 | (setq to (read-from-minibuffer (format "%s %s with: " string from) |
| 88 | nil nil nil | 88 | nil nil nil |
| 89 | query-replace-to-history-variable from t)) | 89 | query-replace-to-history-variable from t)) |
| 90 | (if (and transient-mark-mode mark-active) | 90 | (list from to current-prefix-arg))) |
| 91 | (list from to current-prefix-arg (region-beginning) (region-end)) | ||
| 92 | (list from to current-prefix-arg nil nil)))) | ||
| 93 | 91 | ||
| 94 | (defun query-replace (from-string to-string &optional delimited start end) | 92 | (defun query-replace (from-string to-string &optional delimited start end) |
| 95 | "Replace some occurrences of FROM-STRING with TO-STRING. | 93 | "Replace some occurrences of FROM-STRING with TO-STRING. |
| @@ -116,7 +114,16 @@ only matches surrounded by word boundaries. | |||
| 116 | Fourth and fifth arg START and END specify the region to operate on. | 114 | Fourth and fifth arg START and END specify the region to operate on. |
| 117 | 115 | ||
| 118 | To customize possible responses, change the \"bindings\" in `query-replace-map'." | 116 | To customize possible responses, change the \"bindings\" in `query-replace-map'." |
| 119 | (interactive (query-replace-read-args "Query replace" nil)) | 117 | (interactive (let ((common |
| 118 | (query-replace-read-args "Query replace" nil))) | ||
| 119 | (list (nth 0 common) (nth 1 common) (nth 2 common) | ||
| 120 | ;; These are done separately here | ||
| 121 | ;; so that command-history will record these expressions | ||
| 122 | ;; rather than the values they had this time. | ||
| 123 | (if (and transient-mark-mode mark-active) | ||
| 124 | (region-beginning)) | ||
| 125 | (if (and transient-mark-mode mark-active) | ||
| 126 | (region-end))))) | ||
| 120 | (perform-replace from-string to-string t nil delimited nil nil start end)) | 127 | (perform-replace from-string to-string t nil delimited nil nil start end)) |
| 121 | 128 | ||
| 122 | (define-key esc-map "%" 'query-replace) | 129 | (define-key esc-map "%" 'query-replace) |
| @@ -148,7 +155,18 @@ Fourth and fifth arg START and END specify the region to operate on. | |||
| 148 | In TO-STRING, `\\&' stands for whatever matched the whole of REGEXP, | 155 | In TO-STRING, `\\&' stands for whatever matched the whole of REGEXP, |
| 149 | and `\\=\\N' (where N is a digit) stands for | 156 | and `\\=\\N' (where N is a digit) stands for |
| 150 | whatever what matched the Nth `\\(...\\)' in REGEXP." | 157 | whatever what matched the Nth `\\(...\\)' in REGEXP." |
| 151 | (interactive (query-replace-read-args "Query replace regexp" t)) | 158 | (interactive |
| 159 | (let ((common | ||
| 160 | (query-replace-read-args "Query replace regexp" t))) | ||
| 161 | (list (nth 0 common) (nth 1 common) (nth 2 common) | ||
| 162 | ;; These are done separately here | ||
| 163 | ;; so that command-history will record these expressions | ||
| 164 | ;; rather than the values they had this time. | ||
| 165 | (if (and transient-mark-mode mark-active) | ||
| 166 | (region-beginning)) | ||
| 167 | (if (and transient-mark-mode mark-active) | ||
| 168 | (region-end))))) | ||
| 169 | |||
| 152 | (perform-replace regexp to-string t t delimited nil nil start end)) | 170 | (perform-replace regexp to-string t t delimited nil nil start end)) |
| 153 | (define-key esc-map [?\C-%] 'query-replace-regexp) | 171 | (define-key esc-map [?\C-%] 'query-replace-regexp) |
| 154 | 172 | ||
| @@ -181,10 +199,7 @@ Third arg DELIMITED (prefix arg if interactive), if non-nil, means replace | |||
| 181 | only matches that are surrounded by word boundaries. | 199 | only matches that are surrounded by word boundaries. |
| 182 | Fourth and fifth arg START and END specify the region to operate on." | 200 | Fourth and fifth arg START and END specify the region to operate on." |
| 183 | (interactive | 201 | (interactive |
| 184 | (let (from to start end) | 202 | (let (from to) |
| 185 | (when (and transient-mark-mode mark-active) | ||
| 186 | (setq start (region-beginning) | ||
| 187 | end (region-end))) | ||
| 188 | (if query-replace-interactive | 203 | (if query-replace-interactive |
| 189 | (setq from (car regexp-search-ring)) | 204 | (setq from (car regexp-search-ring)) |
| 190 | (setq from (read-from-minibuffer "Query replace regexp: " | 205 | (setq from (read-from-minibuffer "Query replace regexp: " |
| @@ -197,7 +212,11 @@ Fourth and fifth arg START and END specify the region to operate on." | |||
| 197 | ;; We make TO a list because replace-match-string-symbols requires one, | 212 | ;; We make TO a list because replace-match-string-symbols requires one, |
| 198 | ;; and the user might enter a single token. | 213 | ;; and the user might enter a single token. |
| 199 | (replace-match-string-symbols to) | 214 | (replace-match-string-symbols to) |
| 200 | (list from (car to) current-prefix-arg start end))) | 215 | (list from (car to) current-prefix-arg |
| 216 | (if (and transient-mark-mode mark-active) | ||
| 217 | (region-beginning)) | ||
| 218 | (if (and transient-mark-mode mark-active) | ||
| 219 | (region-end))))) | ||
| 201 | (perform-replace regexp (cons 'replace-eval-replacement to-expr) | 220 | (perform-replace regexp (cons 'replace-eval-replacement to-expr) |
| 202 | t t delimited nil nil start end)) | 221 | t t delimited nil nil start end)) |
| 203 | 222 | ||
| @@ -222,10 +241,7 @@ A prefix argument N says to use each replacement string N times | |||
| 222 | before rotating to the next. | 241 | before rotating to the next. |
| 223 | Fourth and fifth arg START and END specify the region to operate on." | 242 | Fourth and fifth arg START and END specify the region to operate on." |
| 224 | (interactive | 243 | (interactive |
| 225 | (let (from to start end) | 244 | (let (from to) |
| 226 | (when (and transient-mark-mode mark-active) | ||
| 227 | (setq start (region-beginning) | ||
| 228 | end (region-end))) | ||
| 229 | (setq from (if query-replace-interactive | 245 | (setq from (if query-replace-interactive |
| 230 | (car regexp-search-ring) | 246 | (car regexp-search-ring) |
| 231 | (read-from-minibuffer "Map query replace (regexp): " | 247 | (read-from-minibuffer "Map query replace (regexp): " |
| @@ -236,7 +252,11 @@ Fourth and fifth arg START and END specify the region to operate on." | |||
| 236 | from) | 252 | from) |
| 237 | nil nil nil | 253 | nil nil nil |
| 238 | 'query-replace-history from t)) | 254 | 'query-replace-history from t)) |
| 239 | (list from to start end current-prefix-arg))) | 255 | (list from to current-prefix-arg |
| 256 | (if (and transient-mark-mode mark-active) | ||
| 257 | (region-beginning)) | ||
| 258 | (if (and transient-mark-mode mark-active) | ||
| 259 | (region-end))))) | ||
| 240 | (let (replacements) | 260 | (let (replacements) |
| 241 | (if (listp to-strings) | 261 | (if (listp to-strings) |
| 242 | (setq replacements to-strings) | 262 | (setq replacements to-strings) |
| @@ -277,7 +297,14 @@ What you probably want is a loop like this: | |||
| 277 | which will run faster and will not set the mark or print anything. | 297 | which will run faster and will not set the mark or print anything. |
| 278 | \(You may need a more complex loop if FROM-STRING can match the null string | 298 | \(You may need a more complex loop if FROM-STRING can match the null string |
| 279 | and TO-STRING is also null.)" | 299 | and TO-STRING is also null.)" |
| 280 | (interactive (query-replace-read-args "Replace string" nil)) | 300 | (interactive |
| 301 | (let ((common | ||
| 302 | (query-replace-read-args "Replace string" nil))) | ||
| 303 | (list (nth 0 common) (nth 1 common) (nth 2 common) | ||
| 304 | (if (and transient-mark-mode mark-active) | ||
| 305 | (region-beginning)) | ||
| 306 | (if (and transient-mark-mode mark-active) | ||
| 307 | (region-end))))) | ||
| 281 | (perform-replace from-string to-string nil nil delimited nil nil start end)) | 308 | (perform-replace from-string to-string nil nil delimited nil nil start end)) |
| 282 | 309 | ||
| 283 | (defun replace-regexp (regexp to-string &optional delimited start end) | 310 | (defun replace-regexp (regexp to-string &optional delimited start end) |
| @@ -304,7 +331,14 @@ What you probably want is a loop like this: | |||
| 304 | (while (re-search-forward REGEXP nil t) | 331 | (while (re-search-forward REGEXP nil t) |
| 305 | (replace-match TO-STRING nil nil)) | 332 | (replace-match TO-STRING nil nil)) |
| 306 | which will run faster and will not set the mark or print anything." | 333 | which will run faster and will not set the mark or print anything." |
| 307 | (interactive (query-replace-read-args "Replace regexp" t)) | 334 | (interactive |
| 335 | (let ((common | ||
| 336 | (query-replace-read-args "Replace regexp" t))) | ||
| 337 | (list (nth 0 common) (nth 1 common) (nth 2 common) | ||
| 338 | (if (and transient-mark-mode mark-active) | ||
| 339 | (region-beginning)) | ||
| 340 | (if (and transient-mark-mode mark-active) | ||
| 341 | (region-end))))) | ||
| 308 | (perform-replace regexp to-string nil t delimited nil nil start end)) | 342 | (perform-replace regexp to-string nil t delimited nil nil start end)) |
| 309 | 343 | ||
| 310 | 344 | ||