覆盖emacs lisp函数的首选方法? [英] Preferred method of overriding an emacs lisp function?
问题描述
我已经重写并独立地测试了由Emacs 24捆绑的Emacs函数之一调用的内部函数的行为。在我的 init.el
- 我的函数的行为覆盖捆绑的功能?
我已经遵循各种线程的建议
vs fset
等等,我很困惑。
@iainH通过描述您要完成的目标
,您可以更快地获得有用的答案,那么你到目前为止。我要求代码
尝试帮助你做你想做的,而不必覆盖任何东西。
我还是不明白你为什么不t只是使用 defun
?我怀疑
可能发生的情况是您在init文件中使用 defun
,但原来的
函数尚未加载(请参阅autoload )。有一段时间后,您会执行
的某些事情,导致原始定义的文件被加载,并且
自定义函数被原来的覆盖。
如果是这个问题,你有三个选择(假设你要
从telnet.el覆盖 telnet-initial-filter
):
-
在定义自己的版本之前自己加载文件。
(require'telnet)
(defun telnet-initial-filter(proc string)
...)
-
直接Emacs仅在文件加载
eval-after-load 机制。(eval-after-loadtelnet
/ pre>
'(defun telnet-initial-filter(proc string)
...))
-
使用建议。
<其中2个是最好的。 1也可以,但你必须加载一个文件,你可以
从来没有在会话中使用。 3是最差的任何涉及 defadvice
的内容应作为最后的手段选择。
I have rewritten and stand-alone tested the behaviour of an inner function invoked by one of the Emacs functions bundled with Emacs 24. What is the preferred way of incorporating - e.g. in my init.el
- my function's behaviour overriding the bundled function?
I have followed various threads of advice
vs fset
etc. and am confused.
@iainH You tend to get to a useful answer faster by describing what goal you're trying to accomplish, then what you have so far. I asked for code to try to help you do what you want to do without having to overwrite anything.
I still don't understand why you don't just use defun
though? I suspect
what may happen is you use defun
in your init file, but the original
function isn't loaded yet (see autoload). Some time later, you do
something to cause the file with the original definition to be loaded and your
custom function is overwritten by the original.
If this is the problem, you have three options (let's say you want to
overwrite telnet-initial-filter
from "telnet.el"):
Load the file yourself before you define your own version.
(require 'telnet) (defun telnet-initial-filter (proc string) ...)
Direct Emacs to load your function only after the file loads with the eval-after-load mechanism.
(eval-after-load "telnet" '(defun telnet-initial-filter (proc string) ...))
Use advice.
Of these, 2 is best. 1 is also okay, but you have to load a file you may
never use in a session. 3 is the worst. Anything involving defadvice
should be left as a last resort option.
这篇关于覆盖emacs lisp函数的首选方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!