From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: David Kastrup Newsgroups: gmane.emacs.help Subject: Re: replace-regexp question Date: Wed, 26 Oct 2005 21:52:36 +0200 Organization: Organization?!? Message-ID: <851x28hx8b.fsf@lola.goethe.zz> References: <85d5lsji7g.fsf@lola.goethe.zz> <86oe5cm90i.fsf@flame.pc> NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: sea.gmane.org 1130356544 21222 80.91.229.2 (26 Oct 2005 19:55:44 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Wed, 26 Oct 2005 19:55:44 +0000 (UTC) Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Wed Oct 26 21:55:44 2005 Return-path: Original-Received: from lists.gnu.org ([199.232.76.165]) by ciao.gmane.org with esmtp (Exim 4.43) id 1EUrN0-000849-8P for geh-help-gnu-emacs@m.gmane.org; Wed, 26 Oct 2005 21:55:34 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1EUrMz-0006z6-Nl for geh-help-gnu-emacs@m.gmane.org; Wed, 26 Oct 2005 15:55:33 -0400 Original-Path: shelby.stanford.edu!newsfeed.stanford.edu!news.tele.dk!news.tele.dk!small.news.tele.dk!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsfeed.arcor.de!news.arcor.de!not-for-mail Original-Newsgroups: gnu.emacs.help X-Face: 2FEFf>]>q>2iw=B6, xrUubRI>pR&Ml9=ao@P@i)L:\urd*t9M~y1^:+Y]'C0~{mAl`oQuAl \!3KEIp?*w`|bL5qr,H)LFO6Q=qx~iH4DN; i"; /yuIsqbLLCh/!U#X[S~(5eZ41to5f%E@'ELIi$t^ Vc\LWP@J5p^rst0+('>Er0=^1{]M9!p?&:\z]|;&=NP3AhB!B_bi^]Pfkw User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.0.50 (gnu/linux) Cancel-Lock: sha1:NCtQk1Ej+R878nQdAS1fmJyqnSc= Original-Lines: 35 Original-NNTP-Posting-Date: 26 Oct 2005 21:52:36 MEST Original-NNTP-Posting-Host: f5adba14.newsread4.arcor-online.net Original-X-Trace: DXC=[:; kR_cIEP6JeejX5MOK` List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:30591 Archived-At: Giorgos Keramidas writes: > David Kastrup writes: >>Neon Absentius 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 ^.\{0,72\}$ \,(format "%-72sABC%05d" \& \#) -- David Kastrup, Kriemhildstr. 15, 44793 Bochum