From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: =?ISO-8859-1?Q?Andreas_R=F6hler?= Newsgroups: gmane.emacs.help Subject: Re: String replace with lisp code Date: Mon, 18 Jul 2011 08:13:55 +0200 Message-ID: <4E23CF23.4050908@easy-emacs.de> References: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Trace: dough.gmane.org 1310969876 16758 80.91.229.12 (18 Jul 2011 06:17:56 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Mon, 18 Jul 2011 06:17:56 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Mon Jul 18 08:17:52 2011 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([140.186.70.17]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1Qih9M-0000xm-7o for geh-help-gnu-emacs@m.gmane.org; Mon, 18 Jul 2011 08:17:52 +0200 Original-Received: from localhost ([::1]:39982 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Qih9L-0004sv-89 for geh-help-gnu-emacs@m.gmane.org; Mon, 18 Jul 2011 02:17:51 -0400 Original-Received: from eggs.gnu.org ([140.186.70.92]:46104) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Qih5h-0004SQ-CV for help-gnu-emacs@gnu.org; Mon, 18 Jul 2011 02:14:09 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Qih5a-0001PD-V2 for help-gnu-emacs@gnu.org; Mon, 18 Jul 2011 02:14:05 -0400 Original-Received: from moutng.kundenserver.de ([212.227.17.9]:61553) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Qih5a-0001Or-CS for help-gnu-emacs@gnu.org; Mon, 18 Jul 2011 02:13:58 -0400 Original-Received: from [192.168.178.27] (brln-4db9dfc7.pool.mediaWays.net [77.185.223.199]) by mrelayeu.kundenserver.de (node=mreu4) with ESMTP (Nemesis) id 0LknrN-1RIZfd2Gt3-00aiZx; Mon, 18 Jul 2011 08:13:56 +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 In-Reply-To: X-Provags-ID: V02:K0:wO5mf6TT4Kd0KWzLcGFJqtOwmUPweZOzSRLuqxnpFyH WXB0AdksmzP/CqSF9vxXAn4Ni6hJU/UHRjkWE/iicDQUyUcMct mj4K3vFpeqHbtKGn6p/kCDecI/S03jMGLRCafRk7w3Z4vd/Q5b nYYzwdMrVIygFzB2MjfWTWjUM9gZ2BicKuiPYw1BsQEeLWXYGU rfn7EEANrbRt1Tswl/lQ6N5DmhvDjY/WN+yCUTqCrk= X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 212.227.17.9 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:81642 Archived-At: 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/