From: Juri Linkov <juri@jurta.org>
Cc: emacs-devel@gnu.org
Subject: Re: Search/Replace manual changes.
Date: Thu, 24 Jun 2004 19:07:47 +0300 [thread overview]
Message-ID: <87zn6tq77m.fsf@mail.jurta.org> (raw)
In-Reply-To: <x5d63pnk8x.fsf@lola.goethe.zz> (David Kastrup's message of "24 Jun 2004 15:44:30 +0200")
David Kastrup <dak@gnu.org> writes:
> @example
> -M-x query-replace @key{RET} x @key{RET} @@TEMP@@ @key{RET}
> -M-x query-replace @key{RET} y @key{RET} x @key{RET}
> -M-x query-replace @key{RET} @@TEMP@@ @key{RET} y @key{RET}
> +M-x replace-string @key{RET} x @key{RET} @@TEMP@@ @key{RET}
> +M-< M-x replace-string @key{RET} y @key{RET} x @key{RET}
> +M-< M-x replace-string @key{RET} @@TEMP@@ @key{RET} y @key{RET}
> @end example
I think this example should be removed from the Emacs manual completely.
Using three commands to exchange words is too clumsy. When reading
the Emacs manual the users will mis-spend their time at understanding
and remembering this example not knowing that a better method to do this
is shown in the next chapter.
If an example for `replace-string' is absolutely necessary we could
write a better example. If not necessary, no example is still better
than a bad example.
> + You can also use arbitrary Lisp expressions evaluated at replacement
> +time by placing @samp{\,} before them in the replacement string. Inside
> +of those expressions, the symbols @samp{\&} and @samp{\@var{d}} refer to
> +match and submatch strings like described above (a submatch not matching
> +anything will be @samp{nil}), and @samp{\&#} and @samp{\@var{d}#} to
This looks like a typo: this should be @samp{\#&} and @samp{\#@var{d}}.
> +those strings converted to numbers. @samp{\#} is short for
> +@samp{replace-count}, the number of already completed replacements.
> +This particular shorthand can also be used outside of @samp{\,}.
> +
> + Repeating our example to exchange @samp{x} and @samp{y}, we can thus
> +do it also this way:
> +
> +@example
> +M-x replace-regexp @key{RET} \(x\)\|y @key{RET}
> +\,(if \1 "y" "x") @key{RET}
> +@end example
> +
> + Another feature you can use in the replacement string of Regexp
> +commands is @samp{\?}. In that case you will be allowed to edit the
> +replacement string at the given position before the replacement gets
> +performed. Lisp style replacements have already been done before
> +@samp{\?} is executed. For example,
> +
> +@example
> +M-x replace-regexp @key{RET} \footnote@{ @key{RET}
> +\&\\label@{fn:\#\?@} @key{RET}
> +@end example
> +
> +@noindent
> +will add labels starting with @samp{\label@{fn:0@}} to occurences of
> +@samp{\footnote@{}, but letting you edit each replacement before
> +performing it. If you want labels starting at 1, use @samp{\,(1+ \#)}
> +instead of @samp{\#}.
> +
> +As another example, to add consecutively numbered strings like
> +@samp{ABC00042} to column 73 to~80 (unless they are already occupied),
> +you can use
> +
> +@example
> +M-x replace-regexp @key{RET} ^.\@{0,72\@}$ @key{RET}
> +\,(format "%-72sABC%05d" \& \#) @key{RET}
> +@end example
Do we really need this ancient punched card 80-column filling example?
Perhaps there are enough examples already. The previous example with
adding labels shows most features: \&, \# and \?. It have no \,
but \, could be added to the same example as well, e.g.:
M-x replace-regexp @key{RET} \footnote@{ @key{RET}
\&\\label@{fn:\,(format "%05d" (1+ \#))\?@} @key{RET}
--
Juri Linkov
http://www.jurta.org/emacs/
next prev parent reply other threads:[~2004-06-24 16:07 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-06-24 13:44 Search/Replace manual changes David Kastrup
2004-06-24 16:07 ` Juri Linkov [this message]
2004-06-24 22:00 ` David Kastrup
2004-06-25 0:18 ` Juri Linkov
2004-06-25 7:28 ` David Kastrup
2004-06-25 23:56 ` Richard Stallman
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87zn6tq77m.fsf@mail.jurta.org \
--to=juri@jurta.org \
--cc=emacs-devel@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.