From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: Miles Bader Newsgroups: gmane.emacs.devel Subject: Re: Feature request: yank-with-replace Date: Fri, 8 Nov 2002 23:11:03 -0500 Sender: emacs-devel-admin@gnu.org Message-ID: <20021109041103.GA5701@gnu.org> References: <1036789346.1215.107.camel@localhost.localdomain> NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: main.gmane.org 1036821875 25711 80.91.224.249 (9 Nov 2002 06:04:35 GMT) X-Complaints-To: usenet@main.gmane.org NNTP-Posting-Date: Sat, 9 Nov 2002 06:04:35 +0000 (UTC) Cc: emacs-devel@gnu.org Return-path: Original-Received: from quimby.gnus.org ([80.91.224.244]) by main.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 18AOjS-0006gZ-00 for ; Sat, 09 Nov 2002 07:04:34 +0100 Original-Received: from monty-python.gnu.org ([199.232.76.173]) by quimby.gnus.org with esmtp (Exim 3.12 #1 (Debian)) id 18AOtG-00042g-00 for ; Sat, 09 Nov 2002 07:14:42 +0100 Original-Received: from localhost ([127.0.0.1] helo=monty-python.gnu.org) by monty-python.gnu.org with esmtp (Exim 4.10) id 18AOeI-0004NE-00; Sat, 09 Nov 2002 00:59:14 -0500 Original-Received: from list by monty-python.gnu.org with tmda-scanned (Exim 4.10) id 18AMxe-0002Ey-00 for emacs-devel@gnu.org; Fri, 08 Nov 2002 23:11:06 -0500 Original-Received: from mail by monty-python.gnu.org with spam-scanned (Exim 4.10) id 18AMxc-0002Ee-00 for emacs-devel@gnu.org; Fri, 08 Nov 2002 23:11:05 -0500 Original-Received: from fencepost.gnu.org ([199.232.76.164]) by monty-python.gnu.org with esmtp (Exim 4.10) id 18AMxc-0002EW-00 for emacs-devel@gnu.org; Fri, 08 Nov 2002 23:11:04 -0500 Original-Received: from miles by fencepost.gnu.org with local (Exim 4.10) id 18AMxb-0001uK-00; Fri, 08 Nov 2002 23:11:03 -0500 Original-To: Luke Hutchison Content-Disposition: inline In-Reply-To: <1036789346.1215.107.camel@localhost.localdomain> User-Agent: Mutt/1.3.28i Blat: Foop Errors-To: emacs-devel-admin@gnu.org X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.0.11 Precedence: bulk List-Help: List-Post: List-Subscribe: , List-Id: Emacs development discussions. List-Unsubscribe: , List-Archive: Xref: main.gmane.org gmane.emacs.devel:9273 X-Report-Spam: http://spam.gmane.org/gmane.emacs.devel:9273 On Fri, Nov 08, 2002 at 02:02:27PM -0700, Luke Hutchison wrote: > It would be very nice to replace values as a region is being yanked: for > example, you have some code that performs operations on the > x-coordinates of something, and you want to duplicate the code for the > y-coordinates, so you select it, kill it, yank it and then go back and > change all the 'x's to 'y's. > > I propose adding yank-with-replace, which asks you for a search and > replace string before the kill buffer is yanked-from, to take care of > situations like this. yank-with-replace-query-regexp would probably be > useful too, which would yank and then run a query-regexp on the region > that you just yanked. To be honest, this sounds like a sort of clumsy way of accomplishing the task. In many situations where you want to replicate a piece of text with some part of it changed, you can (1) use normal yank to duplicate the text a bunch of times, and then (2) use `query-replace-regexp-eval' to change the variable part. If you really want to replace the variable part with a user-entered string, you can do that do using query-replace-regexp-eval. For instance, take the text: #define FLAG_FOO... and duplicate it a bunch of times. Then do something like: M-x query-replace-regexp-eval RET FOO... RET (format "%s\t0x%x" (read-string "Flag name: ") (lsh 1 replace-count)) RET It will prompt you for each flag name, and then automatically fill in an appropriate bit value for the flag (it will also prompt you if you really want to do the replace each time; in this case it's best to just hit `!' to make it replace them all; hmmm, it'd be nice if there were a `replace-regexp-eval' function that just never asked you). For instance, using the above I just duplicated the pattern line 4 times, did the query-replace-regexp-eval, and typed `a', `b', `c', and `d' for the flag names, and got: #define FLAG_a 0x1 #define FLAG_b 0x2 #define FLAG_c 0x4 #define FLAG_d 0x8 -Miles -- Would you like fries with that?