all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: David Kastrup <dak@gnu.org>
Subject: Re: query-replace-regexp number number+1
Date: Wed, 12 Apr 2006 10:47:23 +0200	[thread overview]
Message-ID: <85bqv75gf8.fsf@lola.goethe.zz> (raw)
In-Reply-To: 4v0%f.3588$sq5.3185@newsread2.news.atl.earthlink.net

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

> "David Kastrup" <dak@gnu.org> wrote in message
> 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

  parent reply	other threads:[~2006-04-12  8:47 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-04-11 16:04 query-replace-regexp number number+1 rturrado
2006-04-11 16:14 ` David Kastrup
2006-04-11 18:36   ` rturrado
2006-04-11 19:05     ` David Kastrup
2006-04-12  5:46       ` B. T. Raven
2006-04-12  8:22         ` Thien-Thi Nguyen
2006-04-12  8:47         ` David Kastrup [this message]
2006-04-12 16:12       ` rturrado
2006-04-12 14:52     ` Giorgos Keramidas

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=85bqv75gf8.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.
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.