如果我将以下内容放入 foo.el
中:
(defun whitespace-redraw ()
(eval-when-compile (require 'whitespace nil t))
(when (require 'whitespace nil t)
(if whitespace-mode
(whitespace-mode 0))
(whitespace-mode 1)))
然后字节编译它:
emacs -Q --batch --eval '(byte-compile-file "foo.el")'
我收到以下警告:
In end of data:
foo.el:7:1:Warning: the function `whitespace-mode' might not be defined at
runtime.
Wrote foo.elc
当然,whitespace-mode
可以在运行时未定义,但除非成功加载空白,否则永远不应该执行它。如果加载空白,则将定义 whitespace-mode
。
此警告是 emacs 编译器限制的结果还是我做错了什么?
最佳答案
我在这里添加了我在上面作为评论发表的回复,仅供记录。
编译器所说的是该函数是在编译时定义的,但当您运行代码时它可能不存在(它告诉您在运行代码时必须事先需要它)。因此,仅当您只需要在该包中定义的宏时,eval-when-compile
可能是一个好习惯。如果您还需要函数和/或变量,您应该只 require
包,而不是在 eval-when-compile
下,但始终如此。
关于emacs - 字节编译时警告: the function 'whitespace-mode' might not be defined at runtime,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8902609/