diff options
| author | Eli Zaretskii | 2016-07-02 18:03:09 +0300 |
|---|---|---|
| committer | Eli Zaretskii | 2016-07-02 18:03:09 +0300 |
| commit | 38f4b8ea615025e7996754fd72449be91c38d448 (patch) | |
| tree | ed3d8dddcf974568ed6c5b5fd8cdc99485c93b99 | |
| parent | d039fc4ff628ad7f983707609a6d04a96589895b (diff) | |
| download | emacs-38f4b8ea615025e7996754fd72449be91c38d448.tar.gz emacs-38f4b8ea615025e7996754fd72449be91c38d448.zip | |
Clarify the documentation of back-references in replacements
* doc/emacs/search.texi (Regexp Replace): Clarify that \D starts
with \1, not \0.
* lisp/replace.el (query-replace-regexp)
(query-replace-regexp-eval, replace-regexp): Doc fix (Bug#23884)
| -rw-r--r-- | doc/emacs/search.texi | 12 | ||||
| -rw-r--r-- | lisp/replace.el | 17 |
2 files changed, 16 insertions, 13 deletions
diff --git a/doc/emacs/search.texi b/doc/emacs/search.texi index d841934c855..b41214df1ae 100644 --- a/doc/emacs/search.texi +++ b/doc/emacs/search.texi | |||
| @@ -1356,12 +1356,12 @@ Replace every match for @var{regexp} with @var{newstring}. | |||
| 1356 | it can refer to all or part of what is matched by the @var{regexp}. | 1356 | it can refer to all or part of what is matched by the @var{regexp}. |
| 1357 | @samp{\&} in @var{newstring} stands for the entire match being | 1357 | @samp{\&} in @var{newstring} stands for the entire match being |
| 1358 | replaced. @samp{\@var{d}} in @var{newstring}, where @var{d} is a | 1358 | replaced. @samp{\@var{d}} in @var{newstring}, where @var{d} is a |
| 1359 | digit, stands for whatever matched the @var{d}th parenthesized | 1359 | digit starting from 1, stands for whatever matched the @var{d}th |
| 1360 | grouping in @var{regexp}. (This is called a ``back reference''.) | 1360 | parenthesized grouping in @var{regexp}. (This is called a ``back |
| 1361 | @samp{\#} refers to the count of replacements already made in this | 1361 | reference''.) @samp{\#} refers to the count of replacements already |
| 1362 | command, as a decimal number. In the first replacement, @samp{\#} | 1362 | made in this command, as a decimal number. In the first replacement, |
| 1363 | stands for @samp{0}; in the second, for @samp{1}; and so on. For | 1363 | @samp{\#} stands for @samp{0}; in the second, for @samp{1}; and so on. |
| 1364 | example, | 1364 | For example, |
| 1365 | 1365 | ||
| 1366 | @example | 1366 | @example |
| 1367 | M-x replace-regexp @key{RET} c[ad]+r @key{RET} \&-safe @key{RET} | 1367 | M-x replace-regexp @key{RET} c[ad]+r @key{RET} \&-safe @key{RET} |
diff --git a/lisp/replace.el b/lisp/replace.el index fe90062cc8a..eb5e0cfffcb 100644 --- a/lisp/replace.el +++ b/lisp/replace.el | |||
| @@ -391,9 +391,10 @@ replace backward. | |||
| 391 | 391 | ||
| 392 | Fourth and fifth arg START and END specify the region to operate on. | 392 | Fourth and fifth arg START and END specify the region to operate on. |
| 393 | 393 | ||
| 394 | In TO-STRING, `\\&' stands for whatever matched the whole of REGEXP, | 394 | In TO-STRING, `\\&' or `\\0' stands for whatever matched the whole of |
| 395 | and `\\=\\N' (where N is a digit) stands for | 395 | REGEXP, and `\\=\\N' (where N is a digit) stands for whatever matched |
| 396 | whatever what matched the Nth `\\(...\\)' in REGEXP. | 396 | the Nth `\\(...\\)' (1-based) in REGEXP. The `\\(...\\)' groups are |
| 397 | counted from 1. | ||
| 397 | `\\?' lets you edit the replacement text in the minibuffer | 398 | `\\?' lets you edit the replacement text in the minibuffer |
| 398 | at the given position for each replacement. | 399 | at the given position for each replacement. |
| 399 | 400 | ||
| @@ -451,7 +452,9 @@ If the result of TO-EXPR is not a string, it is converted to one using | |||
| 451 | 452 | ||
| 452 | For convenience, when entering TO-EXPR interactively, you can use `\\&' or | 453 | For convenience, when entering TO-EXPR interactively, you can use `\\&' or |
| 453 | `\\0' to stand for whatever matched the whole of REGEXP, and `\\N' (where | 454 | `\\0' to stand for whatever matched the whole of REGEXP, and `\\N' (where |
| 454 | N is a digit) to stand for whatever matched the Nth `\\(...\\)' in REGEXP. | 455 | N is a digit) to stand for whatever matched the Nth `\\(...\\)' (1-based) |
| 456 | in REGEXP. | ||
| 457 | |||
| 455 | Use `\\#&' or `\\#N' if you want a number instead of a string. | 458 | Use `\\#&' or `\\#N' if you want a number instead of a string. |
| 456 | In interactive use, `\\#' in itself stands for `replace-count'. | 459 | In interactive use, `\\#' in itself stands for `replace-count'. |
| 457 | 460 | ||
| @@ -635,9 +638,9 @@ replace backward. | |||
| 635 | 638 | ||
| 636 | Fourth and fifth arg START and END specify the region to operate on. | 639 | Fourth and fifth arg START and END specify the region to operate on. |
| 637 | 640 | ||
| 638 | In TO-STRING, `\\&' stands for whatever matched the whole of REGEXP, | 641 | In TO-STRING, `\\&' or `\\0' stands for whatever matched the whole of |
| 639 | and `\\=\\N' (where N is a digit) stands for | 642 | REGEXP, and `\\=\\N' (where N is a digit) stands for |
| 640 | whatever what matched the Nth `\\(...\\)' in REGEXP. | 643 | whatever matched the Nth `\\(...\\)' (1-based) in REGEXP. |
| 641 | `\\?' lets you edit the replacement text in the minibuffer | 644 | `\\?' lets you edit the replacement text in the minibuffer |
| 642 | at the given position for each replacement. | 645 | at the given position for each replacement. |
| 643 | 646 | ||