gpt4 book ai didi

emacs - elisp 警告 "reference to free variable"

转载 作者:行者123 更新时间:2023-12-04 19:06:42 24 4
gpt4 key购买 nike

我在徘徊如何摆脱elisp警告。
我的设置如下:

我有 init.el 文件,它设置了“emacs-root”变量:

;; root of all emacs-related stuff
(defvar emacs-root
(if (or (eq system-type 'cygwin)
(eq system-type 'gnu/linux)
(eq system-type 'linux)
(eq system-type 'darwin))
"~/.emacs.d/" "z:/.emacs.d/"
"Path to where EMACS configuration root is."))

然后在我的 init.el 我有
;; load plugins with el-get
(require 'el-get-settings)

在 el-get-settings.el 中,我正在使用 el-get 加载包并将“el-get/el-get”文件夹附加到加载路径:
 ;; add el-get to the load path, and install it if it doesn't exist
(add-to-list 'load-path (concat emacs-root "el-get/el-get"))

问题是我在“emacs-root”上有一个嘴唇警告
在添加到列表的最后一个表达式中:“对自由变量‘emacs-root’的引用”

我在这里做错了什么,有什么方法可以让编译器满意?

顺便说一句,此设置可以正常工作 - 我在加载期间没有任何问题,只是这个烦人的警告。

问候, 罗马

最佳答案

当您编译引用变量 emacs-root 的文件时,变量必须已经定义。
避免警告的最简单方法是添加

(eval-when-compile (defvar emacs-root)) ; defined in ~/.init.el

el-get-settings.el在违规表格之前。

或者,您可以移动 defvar来自 init.elel-get-settings.el .

请注意,您可以使用 eval-when-compiledefvar加速加载编译文件(当然,如果你这样做,你不应该在平台之间复制编译文件):
(defvar emacs-root
(eval-when-compile
(if (or (eq system-type 'cygwin)
(eq system-type 'gnu/linux)
(eq system-type 'linux)
(eq system-type 'darwin))
"~/.emacs.d/"
"z:/.emacs.d/"))
"Path to where EMACS configuration root is.")

另请注意您原来的 defvar emacs-root在问题中,如果损坏,则设置变量 emacs-root"Path to where EMACS configuration root is."在 window 上。

关于emacs - elisp 警告 "reference to free variable",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22898244/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com