views:

49

answers:

1

I use the builtin f3/f4 bindings in emacs a lot to record and repeat macros, and find it to be a very powerful and useful feature, especially when combined with search. However, I noticed recently that whenever I do a query-replace (M-S-5 by default) that recording my macro stops! Is there a way to prevent this? I know that query-replace is interactive but if I enter 'y' 3 times to do 3 replaces, I figure the macro should just do the same.

No problem I figure, when recording my macro I'll do C-u 3 M-S-5 so it'll do the replacement exactly 3 times since I know that's good enough for what I'm doing. But apparently query-replace ignores C-u! Usually macro use and C-u use are seamless for me. Is there a way I can make them work with query-replace?

+3  A: 

With my Emacs (23.2) and no user init file (emacs -q), I find that query-replace works just fine. This is my test

I typed in:

1 2 3 4 5
1 2 3 4 5
1 2 3 4 5
1 2 3 4 5
1 2 3 4 5
1 2 3 4 5
1 2 3 4 5
1 2 3 4 5

I moved the cursor to the top of that text block

<f3> M-S-5 3 RET tj RET y y y q <f4>

which left me with:

1 2 tj 4 5
1 2 tj 4 5
1 2 tj 4 5
1 2 3 4 5
1 2 3 4 5
1 2 3 4 5
1 2 3 4 5
1 2 3 4 5

Pressing <f4> again left me with:

1 2 tj 4 5
1 2 tj 4 5
1 2 tj 4 5
1 2 3 4 5
1 2 tj 4 5
1 2 tj 4 5
1 2 tj 4 5
1 2 3 4 5

Works as expected. I'd recommend trying with emacs -q to ensure you don't have any customizations that affect the behavior.

Trey Jackson
I was hitting Ctrl-G out of habit to exit the query-replace, but it ends the macro recording as well for some reason.
Joseph Garvin
although I'd still be curious to know how to get it to work with C-u ;)
Joseph Garvin
@JosephGarvin `C-g` interrupts the current command, which in your case was recording the keyboard macro. See http://www.gnu.org/software/emacs/manual/html_node/emacs/Quitting.html
Trey Jackson
Yes, but the 'most current' command was query-replace. I'd expect C-g to pop off the top-most command if during the execution of one command (macro recording) a second one starts (query-replace).
Joseph Garvin