[Top][All Lists]

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

Re: String replace with lisp code

From: Tim Landscheidt
Subject: Re: String replace with lisp code
Date: Fri, 22 Jul 2011 00:39:52 +0000
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux)

Andreas Röhler <address@hidden> 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\)
> \,(progn (or count (setq count 1))(setq count (1+
> count))(concat "(" (number-to-string count) ")" \1))

> ;;;;;;;;;;;;

> \,EXPR

> evaluates the expression and the takes the result for replacement.

BTW, the number of previous replacements is available as


reply via email to

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