unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Miles Bader <miles@gnu.org>
Cc: emacs-devel@gnu.org
Subject: Re: Feature request: yank-with-replace
Date: Fri, 8 Nov 2002 23:11:03 -0500	[thread overview]
Message-ID: <20021109041103.GA5701@gnu.org> (raw)
In-Reply-To: <1036789346.1215.107.camel@localhost.localdomain>

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?

  reply	other threads:[~2002-11-09  4:11 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-11-08 21:02 Feature request: yank-with-replace Luke Hutchison
2002-11-09  4:11 ` Miles Bader [this message]
2002-11-10 18:07 ` Richard Stallman

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

  List information: https://www.gnu.org/software/emacs/

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

  git send-email \
    --in-reply-to=20021109041103.GA5701@gnu.org \
    --to=miles@gnu.org \
    --cc=emacs-devel@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 public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).