emacs - 没有 INITVALUE 的 defvar

标签 emacs elisp

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/

相关文章:

emacs - 如何将文本移回父级别下方

c - 在 emacs 中突出显示整个 c/cpp 宏定义?

regex - Emacs:用每个匹配提示替换正则表达式

vim - 如何在不同长度的多行末尾附加一个数字序列?

emacs - 将 CSV 导入组织模式属性

Emacs/AUCTeX 前缀参数

regex - emacs:突出平衡表达式(例如 LaTeX 标签)

emacs - 结合两个Emacs缓冲区?

emacs - 如何获取 emacs 中最后关闭的文件列表?

emacs - 如何将带有行号的文件名变成超链接?