将先前定义的宏添加到 Emacs 中的宏环中
我一直在使用 kmacro 命令(例如 kmacro-name-last-macro
)来保存键盘宏。问题是,在我保存宏并将其添加到我的 .emacs 文件中后,我遇到了错误,并希望使用 kmacro-step-edit-macro
编辑宏。如果我命名的宏不再位于宏环中(默认 kmacro-ring-max
为 8),我将无法在该宏上使用任何编辑或宏环命令。在得知 name-last-kbd-macro
会保存更容易编辑的符号形式后,我后悔使用 kmacro-name-last-macro
并想知道这是为什么新的默认值。
有没有办法将先前定义的宏添加到宏环中,以便我可以使用 kmacro-step-edit-macro
对其进行编辑?
I've been using kmacro commands such as kmacro-name-last-macro
to save keyboard macros. The problem is that after I have saved a macro and even added it to my .emacs file, I come across an error and want to edit the macro using kmacro-step-edit-macro
. If my named macro is no longer in the macro ring (the default kmacro-ring-max
is 8) I can't use any of the editing or macro ring commands on that macro. After learning that name-last-kbd-macro
will save the symbol form which is easier to edit, I regret using kmacro-name-last-macro
and wonder why it is the new default.
Is there are way to add a previously defined macro to the macro ring so I can edit it with kmacro-step-edit-macro
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,有一种方法可以将先前定义的宏添加到宏环中,以便您可以使用 kmacro-step-edit-macro 对其进行编辑:
假设您已使用
name-last-kbd-macro< 命名了键盘宏 tata /code>,并为 tata 完成了
insert-kbd-macro
。例如:您可以将此宏定义存储到 .emacs 中以供以后使用。在新的 emacs 会话中,您可以使用以下 lisp 代码将宏放回到 kmacro-ring 中:
之后,您可以对其执行
kmacro-step-edit-macro
。如果您使用
kmacro-name-last-macro
命名宏,而不是name-last-kbd-macro
,则调用insert-kbd-macro< /code> 将为您的宏插入不同的定义,使用 lambda 函数而不是向量或字符串(以便能够存储当前计数器),例如:
在本例中,
kmacro-step-edit-宏
会引发错误,因为这不是向量或字符串。要解决此问题,您可以:将 lambda 函数转换为经典向量宏定义(例如上面 tata 的顶部定义)。通常总是可以进行这种转换。
或者定义一个调用您的 lambda 函数宏的宏,例如:
(fset 'foo [?\Mx ?t ?a ?t ?a return])
然后您可以放置此 foo如前所述,宏进入 kmacro 环。但在这种情况下,您可能会在宏执行结束时产生一些副作用。Yes, there is a way to add a previously defined macro to the macro ring so you can edit it with kmacro-step-edit-macro :
Imagine you have named a keyboard macro tata using
name-last-kbd-macro
, and done ainsert-kbd-macro
for tata. For example :You can store this macro definition into your .emacs for later use. On a new emacs session, you can use the following lisp code to put back your macro into your kmacro-ring :
After that, you can do a
kmacro-step-edit-macro
on it.If you have named your macro using
kmacro-name-last-macro
instead ofname-last-kbd-macro
, the call toinsert-kbd-macro
will insert a different definition for your macro, using a lambda function instead of a vector or a string (to be able to store the current counter), for example :In this case,
kmacro-step-edit-macro
raises an error as this is not a vector or a string. To solve this problem you can :either transform your lambda function to a classic vector macro definition (like, for example, the top definition of tata above). It is normally always possible to do this kind of transformation.
or define a macro that calls your lambda function macro, for example :
(fset 'foo [?\M-x ?t ?a ?t ?a return])
And then you can place this foo macro into the kmacro ring as said before. But in this case, you could have some side-effects at the end of the macro execution.