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

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

Re: replace-regexp in lisp function


From: David Kastrup
Subject: Re: replace-regexp in lisp function
Date: Mon, 18 Jan 2010 14:01:35 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1.90 (gnu/linux)

Sven Garbade <sfgarbade@googlemail.com> writes:

> Hallo List,
>
> I frequently use the following regular-regexp:
>
> M-x replace-regexp <RET> \(<<\) <RET> \1cn\,(+ (line-number-at-pos) \#)
>
> to replace "<<" with "<<cn=line number". I tried to write a function
>
> ;; add chunk number
> (defun add-chunk-number ()
>   (interactive)
>   (query-replace-regexp "\(<<\)" "\1cn\,(+ (line-number-at-pos) \#)")
>   )
>
> to save typing, but this does not work. What did I wrong?

Lisp string syntax needs additional quoting for regexps, and things like
\, and \# are not supported outside of interactive use.

I recommend that you first give your command interactively, then use C-x
Esc Esc to get at the corresponding Lisp verbiage.

-- 
David Kastrup


reply via email to

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