简体   繁体   English

查询替换emacs中的宏?

[英]query-replace for macros in emacs?

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. 我在emacs中使用内置的f3 / f4绑定来记录和重复宏,并发现它是一个非常强大和有用的功能,特别是当与搜索结合使用时。 However, I noticed recently that whenever I do a query-replace (MS-5 by default) that recording my macro stops! 但是,我最近注意到每当我进行查询替换(默认情况下为MS-5)时,录制我的宏停止! 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. 我知道查询替换是交互式的,但如果我输入'y'3次做3次替换,我认为宏应该做同样的事情。

No problem I figure, when recording my macro I'll do Cu 3 MS-5 so it'll do the replacement exactly 3 times since I know that's good enough for what I'm doing. 没问题我想,在录制我的宏时,我会做Cu 3 MS-5所以它会做3次更换,因为我知道这对我正在做的事情已经足够好了。 But apparently query-replace ignores Cu! 但显然查询替换忽略了Cu! Usually macro use and Cu use are seamless for me. 通常宏使用和Cu使用对我来说是无缝的。 Is there a way I can make them work with query-replace? 有没有办法让它们可以使用查询替换?

With my Emacs (23.2) and no user init file ( emacs -q ), I find that query-replace works just fine. 使用我的Emacs(23.2)和没有用户初始化文件( emacs -q ),我发现query-replace工作正常。 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: 再次按<f4>键让我:

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. 我建议尝试使用emacs -q以确保您没有任何影响该行为的自定义项。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM