help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: query-replace-regexp number number+1


From: David Kastrup
Subject: Re: query-replace-regexp number number+1
Date: Wed, 12 Apr 2006 10:47:23 +0200
User-agent: Gnus/5.11 (Gnus v5.11) Emacs/22.0.50 (gnu/linux)

"B. T. Raven" <ecinmn@peoplepc.com> writes:

> "David Kastrup" <dak@gnu.org> wrote in message
> 85lkuc6iho.fsf@lola.goethe.zz">news:85lkuc6iho.fsf@lola.goethe.zz...
>> "rturrado" <rturrado@gmail.com> writes:
>>
>> > I've tried that, but it complains with an "Invalid use of '\' in
>> > replacement text" error. I'm using GNU Emacs 21.3.1 on a SuSE bash.
>> > What's the "developer Emacs" version?
>>
>> It announces itself as 22.0.something and has not yet been released.
>> Some people provide snapshots, though.  No idea whether there is
>> something for SuSE (Mandriva has one).  And one can, of course,
>> compile a copy oneself.
>>
>> > Can I find a tutorial online explaining how to run commands/evaluate
>> > expressions/and so on within a regexp?
>>
>> You could probably do
>>
>> M-: (query-replace-regexp "\\([0-9]+\\)" '(replace-eval-replacement
> format "%d" (1+ (string-to-number (match-string 1))))) RET
>>
>> But it is not exactly kosher.
>
> Is it not kosher because it's not documented or because it accesses
> lisp objects in a non-standard way?

It's accessing internals.

> I don't understand it but it works. How?  Here is the function in
> 21.3:

> But why is format not a function, i.e. (format... and what is
> replace-count (not used here)?  I want do to something similar to what
> rturrado needs: Convert a bunch of lines like:
>
> p.150
>
> into
>
> p.150(125)... and then p.151 into p.151(126) etc.

Your best bet is to use a developer version of Emacs which offers the
\, syntax.  Short of that, do your own Elisp loop around
search-forward-regexp and replace-string.

-- 
David Kastrup, Kriemhildstr. 15, 44793 Bochum


reply via email to

[Prev in Thread] Current Thread [Next in Thread]