如何在我的Emacs初始化文件中生成键盘宏?

3
我经常定义一个特定的键盘宏,所以我想如果每次加载Emacs时它可以自动可用就会很方便。我该怎么做?

1
编写相应的elisp函数。 - Reactormonk
2个回答

5

手册中的保存键盘宏部分怎么样?

C-x C-k n
    Give a command name (for the duration of the Emacs session) to the most recently defined keyboard macro (kmacro-name-last-macro).
C-x C-k b
    Bind the most recently defined keyboard macro to a key sequence (for the duration of the session) (kmacro-bind-to-key).
M-x insert-kbd-macro
    Insert in the buffer a keyboard macro's definition, as Lisp code.

是的,我已经完成了。但我想在重新启动emacs后仍然保留宏。 - zinking
4
insert-kbd-macro 的作用是:“保存键盘宏,访问一个 Lisp 代码文件(例如你的 ~/.emacs),使用该命令,然后保存该文件。” - user725091
所提到的手册部分专门讲解了如何将录制的宏保存到您的 init 文件中。 - event_jr
1
使用 global-set-key 将您的命名宏绑定到一个按键上。 - event_jr

0
这在很大程度上是接受答案的重复,但我强烈推荐阅读这篇Mastering Emacs文章
如果你知道适当格式的按键序列,你可以直接使用defaliaskmacro -- 例如,要执行C-c a a,只需将以下内容放入你的初始化文件中:
 (defalias 'start-org-agenda
    (kmacro "C-c a a") "Start the org-mode agenda for the current day.")

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接