From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Tim Landscheidt Newsgroups: gmane.emacs.help Subject: Re: How can I enter query-replace in GNU Emacs using a repeatable function based on values in the line currently at point. - Super User Date: Mon, 21 Jun 2010 15:00:19 +0000 Organization: Message-ID: References: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: dough.gmane.org 1277132469 16733 80.91.229.12 (21 Jun 2010 15:01:09 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Mon, 21 Jun 2010 15:01:09 +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 Jun 21 17:01:06 2010 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1OQiUk-000714-1h for geh-help-gnu-emacs@m.gmane.org; Mon, 21 Jun 2010 17:01:06 +0200 Original-Received: from localhost ([127.0.0.1]:43260 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OQiUj-0005mD-Hk for geh-help-gnu-emacs@m.gmane.org; Mon, 21 Jun 2010 11:01:05 -0400 Original-Received: from [140.186.70.92] (port=56546 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OQiUK-0005k0-69 for help-gnu-emacs@gnu.org; Mon, 21 Jun 2010 11:00:41 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OQiUE-0003eU-Mh for help-gnu-emacs@gnu.org; Mon, 21 Jun 2010 11:00:40 -0400 Original-Received: from lo.gmane.org ([80.91.229.12]:46118) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OQiUE-0003eA-7f for help-gnu-emacs@gnu.org; Mon, 21 Jun 2010 11:00:34 -0400 Original-Received: from list by lo.gmane.org with local (Exim 4.69) (envelope-from ) id 1OQiUB-0006f6-Dr for help-gnu-emacs@gnu.org; Mon, 21 Jun 2010 17:00:31 +0200 Original-Received: from e177123166.adsl.alicedsl.de ([85.177.123.166]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Mon, 21 Jun 2010 17:00:31 +0200 Original-Received: from tim by e177123166.adsl.alicedsl.de with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Mon, 21 Jun 2010 17:00:31 +0200 X-Injected-Via-Gmane: http://gmane.org/ Mail-Followup-To: help-gnu-emacs@gnu.org Original-Lines: 53 Original-X-Complaints-To: usenet@dough.gmane.org X-Gmane-NNTP-Posting-Host: e177123166.adsl.alicedsl.de Mail-Copies-To: never User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:tSKh4glqvVoyffyiws9MxtyYYuw= X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:73942 Archived-At: Tim Visher wrote: > I'd like to take the following data and query-replace occurences of > each word identifier with the corresponding numeric identifier using > some sort of repeatable function. > -1 ACT/CNS > -2 AG NFC > -3 AID > -4 BBG > -5 BIA > -6 BLM > -7 BOC > -8 BPD > -9 CCC > -10 CDC > -11 Census > In other words, with point at > -1 ACT/CNS > ^ > I'd like to be able to hit a key and launch into the following command > query-replace RET ACT/CNS RET -1 RET > [...] >From my experience, the easiest way to do that is to copy the lines to a temporary buffer, hack up a small lisplet: | (dolist (line '(("-1" "ACT/CNS") | ("-2" "AG NFC") | ("-3" "AID") | ("-4" "BBG") | ("-5" "BIA") | ("-6" "BLM") | ("-7" "BOC") | ("-8" "BPD") | ("-9" "CCC") | ("-10" "CDC") | ("-11" "Census"))) | (query-replace (car line) (cdr line) nil (point-min) (point-max))) and then evaluate that in the original buffer with M-x :. While it is possible to create a proper "one-key command" as you intended, chances are that it is very cumbersome and that you will have to change it soon afterwards when your requirements shift just a little bit. Directly programming in Emacs Lisp is much easier and more flexible. Tim