我在徘徊如何摆脱私密的警告。我的设置如下:
我有设置“emacs”变量的init.el文件:
;; 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 -setings.el中,我用el加载包,并将"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'”。
我在这里做错了什么,有什么办法让编译器高兴吗?
这个设置工作正常,顺便说一句-我在加载时没有任何问题,只是这个恼人的警告。
你好,罗曼
发布于 2014-04-06 19:36:40
在编译引用变量emacs-root的文件时,必须已经定义了变量。避免警告的最简单方法是添加
(eval-when-compile (defvar emacs-root)) ; defined in ~/.init.el在冒犯表单之前的el-get-settings.el中。
或者,您可以将defvar从init.el移动到el-get-settings.el。
请注意,您可以在eval-when-compile中使用defvar加速加载编译的文件(当然,如果这样做,您不应该在平台之间复制编译的文件):
(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被破坏,它会在windows上将变量emacs-root设置为"Path to where EMACS configuration root is."。
https://stackoverflow.com/questions/22898244
复制相似问题