* String replace with lisp code
@ 2011-07-18 5:36 C K Kashyap
2011-07-18 6:13 ` Andreas Röhler
2011-07-18 6:14 ` Teemu Likonen
0 siblings, 2 replies; 5+ messages in thread
From: C K Kashyap @ 2011-07-18 5:36 UTC (permalink / raw)
To: help-gnu-emacs
[-- Attachment #1: Type: text/plain, Size: 604 bytes --]
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
[-- Attachment #2: Type: text/html, Size: 788 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: String replace with lisp code
2011-07-18 5:36 String replace with lisp code C K Kashyap
@ 2011-07-18 6:13 ` Andreas Röhler
2011-07-18 8:07 ` C K Kashyap
2011-07-22 0:39 ` Tim Landscheidt
2011-07-18 6:14 ` Teemu Likonen
1 sibling, 2 replies; 5+ messages in thread
From: Andreas Röhler @ 2011-07-18 6:13 UTC (permalink / raw)
To: help-gnu-emacs
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/
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: String replace with lisp code
2011-07-18 5:36 String replace with lisp code C K Kashyap
2011-07-18 6:13 ` Andreas Röhler
@ 2011-07-18 6:14 ` Teemu Likonen
1 sibling, 0 replies; 5+ messages in thread
From: Teemu Likonen @ 2011-07-18 6:14 UTC (permalink / raw)
To: C. K. Kashyap; +Cc: help-gnu-emacs
* 2011-07-18T11:06:53+05:30 * C. K. Kashyap wrote:
> During search/replace, how can I use the evaluation of a lisp
> expression as the substitution string?
Let's read this part of the reference manual:
C-h r m Regexp Replace RET
> (while I was typing this, I got the idea of using the keyboard macro
> to achieve this .... is there a better way though?)
I think this is a good option.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: String replace with lisp code
2011-07-18 6:13 ` Andreas Röhler
@ 2011-07-18 8:07 ` C K Kashyap
2011-07-22 0:39 ` Tim Landscheidt
1 sibling, 0 replies; 5+ messages in thread
From: C K Kashyap @ 2011-07-18 8:07 UTC (permalink / raw)
To: Andreas Röhler; +Cc: help-gnu-emacs
[-- Attachment #1: Type: text/plain, Size: 508 bytes --]
>
>
> 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/python-mode>
> https://launchpad.net/s-x-**emacs-werkstatt/<https://launchpad.net/s-x-emacs-werkstatt/>
>
>
>
Thank you very much Teemu and Andreas!
Regards,
Kashyap
[-- Attachment #2: Type: text/html, Size: 920 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: String replace with lisp code
2011-07-18 6:13 ` Andreas Röhler
2011-07-18 8:07 ` C K Kashyap
@ 2011-07-22 0:39 ` Tim Landscheidt
1 sibling, 0 replies; 5+ messages in thread
From: Tim Landscheidt @ 2011-07-22 0:39 UTC (permalink / raw)
To: help-gnu-emacs
Andreas Röhler <andreas.roehler@easy-emacs.de> wrote:
>> 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?)
> 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.
BTW, the number of previous replacements is available as
"\#".
Tim
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2011-07-22 0:39 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-07-18 5:36 String replace with lisp code C K Kashyap
2011-07-18 6:13 ` Andreas Röhler
2011-07-18 8:07 ` C K Kashyap
2011-07-22 0:39 ` Tim Landscheidt
2011-07-18 6:14 ` Teemu Likonen
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).