将Emacs宏转换为Elisp [英] Convert Emacs macro into Elisp

查看:93
本文介绍了将Emacs宏转换为Elisp的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法将emacs宏转换成elisp,而不是像 M-x insert-kbd-macro 那样,实际的活动成为elisp语句。



感谢您的帮助。

解决方案

将emacs宏转换为elisp没有什么简单的方法。



更新: Emacs已经有一些工作来启动此路径。请参见此线程作为起点。它仍然是不可能的(2010年6月),但有活动。



我可以想到的第一个原因是处理交互式命令,并将键击转换为正确的函数参数。 / p>

想想以下顺序:



Cx b .em TAB RET



这将开始切换到缓冲区的命令,键入三个字符,使用TAB完成完成它和RET接受。最终结果的相当的lisp(在TAB完成唯一的emacs会话中)是:

 (switch-to-缓冲区.emacs)

考虑到完成,还有与所有类型的扩展( dabbrev hippie-expand 等)。



一个起点可以是 Mx edit-last-kbd-macro 哪个(在我的例子中)显示:

  ;;键盘宏编辑器。按C-c C-c完成;按C-x k RET取消。 
;;原始密钥:C-x b .em< tab> RET

命令:last-kbd-macro
密钥:none

宏:

C-x b ;; switch-to-buffer
.em ;; self-insert-command * 3
< tab> ;; pabbrev-expand-maybe
RET ;; newline-and-indent

哪个至少给你一些功能名称。但是你会看到 RET 被标记为'newline-and-indent 这是不正确的,因为在宏执行时,minibuffer是活跃的,绑定实际上是'minibuffer-complete-and-exit 。类似地, TAB 的正确绑定是'minibuffer-complete


Is there a way to convert an emacs macro into elisp, not like what M-x insert-kbd-macro does, the actual activity becoming elisp statements.

Thanks for your help.

解决方案

Nope, sorry. There is no trivial way to convert an emacs macro into elisp.

Update: There's been some work on Emacs to start down this path. See this thread as a starting point. It's still not possible (June 2010), but there's activity.

The first reason I can think of is dealing with interactive commands and translating keystrokes into proper arguments for functions.

Think of the following sequence:

C-x b .em TAB RET

This begins the command to switch to a buffer, types three characters, uses TAB completion to complete it and RET to accept. The equivalent lisp for the end result (in an emacs session where the TAB completion is unique) is:

(switch-to-buffer ".emacs")

Thinking of completion, there are also interactions with expansion of all types (dabbrev, hippie-expand, etc.).

A starting point can be M-x edit-last-kbd-macro which (in my case) shows this:

;; Keyboard Macro Editor.  Press C-c C-c to finish; press C-x k RET to cancel.
;; Original keys: C-x b .em <tab> RET

Command: last-kbd-macro
Key: none

Macro:

C-x b       ;; switch-to-buffer
.em         ;; self-insert-command * 3
<tab>       ;; pabbrev-expand-maybe
RET         ;; newline-and-indent

Which at least gives you some of the function names. But you'll see that RET is labeled as 'newline-and-indent which is incorrect because at the time of the macro execution, the minibuffer is active and the binding is in fact 'minibuffer-complete-and-exit. Similarly, the proper binding for TAB is 'minibuffer-complete.

这篇关于将Emacs宏转换为Elisp的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆