[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Feature request: yank-with-replace

From: Miles Bader
Subject: Re: Feature request: yank-with-replace
Date: Fri, 8 Nov 2002 23:11:03 -0500
User-agent: Mutt/1.3.28i

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

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

  #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

Would you like fries with that?

reply via email to

[Prev in Thread] Current Thread [Next in Thread]