问题描述
如何重命名elisp宏?为了更准确,我想让 defun 与 cl-defun 的同义词。
我不在乎时间或内存开销。
How can I rename elisp macro? To be more accurate, I want make defun to be synonym to cl-defun.I do not care about time or memory overhead.
推荐答案
摘要
我不认为你可以这样做 - 至少不容易。
Summary
I don't think you can do that - at least not easily.
由于 cl-defun 展开为 defun ,当您使用 defun 时,您将获得无限的宏展开循环,如果您执行明显的(defalias'defun'cl-defun)。
Since cl-defun expands to defun, you will get an infinite macroexpand loop when using defun if you do the obvious (defalias 'defun 'cl-defun).
所以你需要做的是
-
保存原始的 defun :(fset'defun-original(symbol-function'defun))。
在 cl-macs.el 中复制 cl-defun 的定义,替换 defun with defun-original 。
copy the definition of cl-defun in cl-macs.el, replacing defun with defun-original.
替换 defalias :(defalias ), cl-defun 'defun'cl-defun)。
replace defun with cl-defun using defalias: (defalias 'defun 'cl-defun).
现在,至少,如果事情走了酸,你ca使用恢复原始行为(fset'defun(symbol-function'defun-original))。
Now, at least, if things go sour, you can restore the original behavior with (fset 'defun (symbol-function 'defun-original)).
但是,我觉得你真的不希望这样做。
However, I think you don't really want to do that.
如果要使用Common Lisp,请 。试图假装你可以把Elisp变成CL,只会让你感到悲伤。 15年前,我试图去那条路,那里没有乐趣。现在应该更容易,至少有词汇约束,但我仍然不认为这是值得的努力。
If you want to use a Common Lisp, use it. Trying to pretend that you can turn Elisp into CL will cause you nothing but grief. I tried to travel that road 15 years ago - there is no fun there. It should be easier now, at least there is lexical binding, but I still don't think it is worth the effort.
如果你想扩展 Emacs ,然后使用 cl-defun 更没有意义:您的扩展将对其他人无用,您甚至无法要求帮助,因为很少有人会因为这样一个微小的收获而在这样一个基本的功能上进行如此彻底的改变。
If you want to extend Emacs, then using cl-defun makes even less sense: your extensions will be useless for others and you won't even be able to ask for help because few people will bother with such a radical change in such a basic functionality for such a tiny gain.
这篇关于Elisp重命名宏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!