emacs - 字节编译时警告: the function 'whitespace-mode' might not be defined at runtime

标签 emacs elisp

如果我将以下内容放入 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/

相关文章:

emacs - 如何使 .emacs 文件具有幂等性?

emacs - 如何在 Emacs 中以编程方式查找键绑定(bind)来自哪个映射

shell - 如何使 emacs-org 导出以适合宽度的模式打开 pdf?

gnome 终端控制键上的 emacs

emacs - 在 GNU Emacs 24 上重做+.el

emacs - 当 emacs 锁定时

Emacs 将备用文件扩展映射到 .ini 语法突出显示

Emacs 函数创建新终端

emacs 口齿不清 : how to add to link/hyperlink to another file just like that in *H e l p*

emacs - emacs elisp 中的简单 tcp 客户端示例?