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: B. T. Raven
Subject: Re: query-replace-regexp number number+1
Date: Wed, 12 Apr 2006 05:46:40 GMT

"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? I don't understand it but it works. How?
Here is the function in 21.3:

(defun replace-eval-replacement (expression replace-count)
  (let ((replacement (eval expression)))
    (if (stringp replacement)
        replacement  ;; string
      (prin1-to-string replacement t)))) ;; number

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.

Thanks,

Ed.



reply via email to

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