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: Sven Garbade
Subject: Re: replace-regexp in lisp function
Date: Mon, 18 Jan 2010 15:06:39 +0100

Hi,

many thanks. C-x Esc Esc gave me:

  (query-replace-regexp "\\(<<\\)"
                        (quote (replace-eval-replacement concat "\\1cn" 
(replace-quote (+
(line-number-at-pos) replace-count)) ",")) nil
                        (if (and transient-mark-mode mark-active) 
(region-beginning))
                        (if (and transient-mark-mode mark-active) (region-end)))

which works inside my function. Looks quite complicate for me...

Are there any recommended documents / books for an elisp newbie?

Thanks, Sven




2010/1/18 David Kastrup <address@hidden>:
> Sven Garbade <address@hidden> 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]