Warning Tips - GNU Emacs Lisp Reference Manual 中的第一个提示:
Try to avoid compiler warnings about undefined free variables, by adding dummy defvar definitions for these variables, like this: (defvar foo) Such a definition has no effect except to tell the compiler not to warn about uses of the variable foo in this file.
在什么情况下,有人不希望任何效果,但又想禁用有关自由变量的警告?每当我收到有关未定义自由变量的警告时,总是会出现这样的情况:要么我忘记输入 (defvar foo initvalue docstring)
,要么我拼错了局部变量名称。
最佳答案
您的问题是为什么/何时抑制此类警告。答案是:在以下任一情况下:
该变量在其他地方定义,并且您知道定义它的库将在代码实际尝试使用该变量之前加载。
您想要声明该变量是一个“特殊”变量,也就是说,它是动态绑定(bind)的,而不是词法绑定(bind)的。
关于emacs - 没有 INITVALUE 的 defvar,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19081523/