From: David Kastrup <dak@gnu.org>
Subject: Re: replace-regexp question
Date: Wed, 26 Oct 2005 21:52:36 +0200 [thread overview]
Message-ID: <851x28hx8b.fsf@lola.goethe.zz> (raw)
In-Reply-To: 86oe5cm90i.fsf@flame.pc
Giorgos Keramidas <keramida@ceid.upatras.gr> writes:
> David Kastrup <dak@gnu.org> writes:
>>Neon Absentius <absent@sdf.lonestar.org> writes:
>>> Is there a way to use the command replace-regexp to replace a number with
>>> that number increased, say, by 15? I tried
>>>
>>> C-M-% -?[0-9]+ RET (number-to-string (+ (string-to-number "\&") 15)) RET
>>>
>>> but it doesn't work because emacs interprets the second input to be
>>> a string and so it doesn't evaluate it. So I guess the question is
>>> how can we use the result of evaluating a sexp for replacement text?
>>>
>>> Any help and/or pointers to documentation will be greatly
>>> appreciated.
>>
>> The development version of Emacs would offer
>> C-M-% -?[0-9]+ RET \,(+ \#& 15) RET
>
> Oh, heh! Very neat ;)
The example in the Emacs manual is more amusing in my opinion, but
then I am biased.
For computing replacement strings for `\,', the `format' function is
often useful (*note Formatting Strings: (elisp)Formatting Strings.).
For example, to add consecutively numbered strings like `ABC00042' to
columns 73 to 80 (unless they are already occupied), you can use
M-x replace-regexp <RET> ^.\{0,72\}$ <RET>
\,(format "%-72sABC%05d" \& \#) <RET>
--
David Kastrup, Kriemhildstr. 15, 44793 Bochum
next prev parent reply other threads:[~2005-10-26 19:52 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <mailman.12812.1130346970.20277.help-gnu-emacs@gnu.org>
2005-10-26 17:34 ` replace-regexp question David Kastrup
2005-10-26 18:24 ` Giorgos Keramidas
2005-10-26 19:52 ` David Kastrup [this message]
2005-10-27 9:01 ` Harald Hanche-Olsen
2005-10-27 9:32 ` David Kastrup
2005-10-27 11:47 ` Neon Absentius
2005-10-27 14:38 ` Sébastien Kirche
2005-10-27 15:08 ` David Kastrup
2005-10-27 17:24 ` Sébastien Kirche
2005-10-26 17:15 Neon Absentius
-- strict thread matches above, loose matches on Subject: below --
2003-06-02 11:21 Chang Luo
2003-06-02 11:53 ` lawrence mitchell
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
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=851x28hx8b.fsf@lola.goethe.zz \
--to=dak@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.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).