all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: "Andreas Röhler" <andreas.roehler@easy-emacs.de>
To: help-gnu-emacs@gnu.org
Subject: Re: String replace with lisp code
Date: Mon, 18 Jul 2011 08:13:55 +0200	[thread overview]
Message-ID: <4E23CF23.4050908@easy-emacs.de> (raw)
In-Reply-To: <CAGdT1gpvyig=M7Q--B0PqiA=gihHMmBH6_6EtrijENN13nKe1g@mail.gmail.com>

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	other threads:[~2011-07-18  6:13 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-07-18  5:36 String replace with lisp code C K Kashyap
2011-07-18  6:13 ` Andreas Röhler [this message]
2011-07-18  8:07   ` C K Kashyap
2011-07-22  0:39   ` Tim Landscheidt
2011-07-18  6:14 ` Teemu Likonen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4E23CF23.4050908@easy-emacs.de \
    --to=andreas.roehler@easy-emacs.de \
    --cc=help-gnu-emacs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.