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

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

Re: String replace with lisp code


From: Andreas Röhler
Subject: Re: String replace with lisp code
Date: Mon, 18 Jul 2011 08:13:55 +0200
User-agent: Mozilla/5.0 (X11; U; Linux i686; de; rv:1.9.2.18) Gecko/20110616 SUSE/3.1.11 Thunderbird/3.1.11

Am 18.07.2011 07:36, schrieb C K Kashyap:
Hi,
During search/replace, how can I use  the evaluation of a lisp expression as
the substitution string?

An example could be ... say I want to replace the occurrence of a certain
word with the word prefixed with its occurrence count -

For example -  If I'd like to replace the occurrence of sea in  -
She sells sea shells on the sea shore
with
She sells (1)sea shells on the (2)sea shore.

Or perhaps a more frequent use case of adding line number to each line

(while I was typing this, I got the idea of using the keyboard macro to
achieve this .... is there a better way though?)

Regards,
Kashyap


M-x query-replace-regexp,
\(sea\)
RET
\,(progn (or count (setq count 1))(setq count (1+ count))(concat "(" (number-to-string count) ")" \1))
RET

;;;;;;;;;;;;

\,EXPR

evaluates the expression and the takes the result for replacement.


Andreas

--
https://launchpad.net/python-mode
https://launchpad.net/s-x-emacs-werkstatt/




reply via email to

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