Mercurial > emacs
comparison lisp/replace.el @ 56245:93e88c0fb51c
(query-replace-read-args): Swallow space after \,SYMBOL.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Thu, 24 Jun 2004 23:33:59 +0000 |
parents | 4e0ea2b75232 |
children | 29d03615f533 |
comparison
equal
deleted
inserted
replaced
56244:8b126cc57f70 | 56245:93e88c0fb51c |
---|---|
107 (cond ((eq char ?\#) | 107 (cond ((eq char ?\#) |
108 (push '(number-to-string replace-count) list)) | 108 (push '(number-to-string replace-count) list)) |
109 ((eq char ?\,) | 109 ((eq char ?\,) |
110 (setq pos (read-from-string to)) | 110 (setq pos (read-from-string to)) |
111 (push `(replace-quote ,(car pos)) list) | 111 (push `(replace-quote ,(car pos)) list) |
112 (setq to (substring to (cdr pos))))) | 112 (let ((end |
113 ;; Swallow a space after a symbol | |
114 ;; if there is a space. | |
115 (if (and (or (symbolp (car pos)) | |
116 ;; Swallow a space after 'foo | |
117 ;; but not after (quote foo). | |
118 (and (eq (car-safe (car pos)) 'quote) | |
119 (= ?\( (aref to-string 0)))) | |
120 (equal " " (substring to-string (cdr pos) | |
121 (1+ (cdr pos))))) | |
122 (1+ (cdr pos)) | |
123 (cdr pos)))) | |
124 (setq to (substring to end))))) | |
113 (string-match "\\(\\`\\|[^\\]\\)\\(\\\\\\\\\\)*\\\\[,#]" to))) | 125 (string-match "\\(\\`\\|[^\\]\\)\\(\\\\\\\\\\)*\\\\[,#]" to))) |
114 (setq to (nreverse (delete "" (cons to list))))) | 126 (setq to (nreverse (delete "" (cons to list))))) |
115 (replace-match-string-symbols to) | 127 (replace-match-string-symbols to) |
116 (setq to (cons 'replace-eval-replacement | 128 (setq to (cons 'replace-eval-replacement |
117 (if (> (length to) 1) | 129 (if (> (length to) 1) |
186 and `\\=\\N' (where N is a digit) stands for | 198 and `\\=\\N' (where N is a digit) stands for |
187 whatever what matched the Nth `\\(...\\)' in REGEXP. | 199 whatever what matched the Nth `\\(...\\)' in REGEXP. |
188 `\\?' lets you edit the replacement text in the minibuffer | 200 `\\?' lets you edit the replacement text in the minibuffer |
189 at the given position for each replacement. | 201 at the given position for each replacement. |
190 | 202 |
191 In interactive calls, the replacement text may contain `\\,' | 203 In interactive calls, the replacement text can contain `\\,' |
192 followed by a Lisp expression used as part of the replacement | 204 followed by a Lisp expression. Each |
193 text. Inside of that expression, `\\&' is a string denoting the | 205 replacement evaluates that expression to compute the replacement |
194 whole match, `\\N' a partial matches, `\\#&' and `\\#N' the | 206 string. Inside of that expression, `\\&' is a string denoting the |
195 respective numeric values from `string-to-number', and `\\#' | 207 whole match as a sting, `\\N' for a partial match, `\\#&' and `\\#N' |
196 itself for `replace-count', the number of replacements occured so | 208 for the whole or a partial match converted to a number with |
197 far. | 209 `string-to-number', and `\\#' itself for the number of replacements |
198 | 210 done so far (starting with zero). |
199 If your Lisp expression is an identifier and the next letter in | 211 |
200 the replacement string would be interpreted as part of it, you | 212 If the replacement expression is a symbol, write a space after it |
201 can wrap it with an expression like `\\,(or \\#)'. Incidentally, | 213 to terminate it. One space there, if any, will be discarded. |
202 for this particular case you may also enter `\\#' in the | |
203 replacement text directly. | |
204 | 214 |
205 When using those Lisp features interactively in the replacement | 215 When using those Lisp features interactively in the replacement |
206 text, TO-STRING is actually made a list instead of a string. | 216 text, TO-STRING is actually made a list instead of a string. |
207 Use \\[repeat-complex-command] after this command for details." | 217 Use \\[repeat-complex-command] after this command for details." |
208 (interactive | 218 (interactive |
214 ;; rather than the values they had this time. | 224 ;; rather than the values they had this time. |
215 (if (and transient-mark-mode mark-active) | 225 (if (and transient-mark-mode mark-active) |
216 (region-beginning)) | 226 (region-beginning)) |
217 (if (and transient-mark-mode mark-active) | 227 (if (and transient-mark-mode mark-active) |
218 (region-end))))) | 228 (region-end))))) |
219 | |
220 (perform-replace regexp to-string t t delimited nil nil start end)) | 229 (perform-replace regexp to-string t t delimited nil nil start end)) |
221 | 230 |
222 (define-key esc-map [?\C-%] 'query-replace-regexp) | 231 (define-key esc-map [?\C-%] 'query-replace-regexp) |
223 | 232 |
224 (defun query-replace-regexp-eval (regexp to-expr &optional delimited start end) | 233 (defun query-replace-regexp-eval (regexp to-expr &optional delimited start end) |