我在徘徊如何摆脱过分警告。我的设置如下:
我有设置“ emacs-root”变量的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."))
Run Code Online (Sandbox Code Playgroud)
然后在我的init.el中
;; load plugins with el-get
(require 'el-get-settings)
Run Code Online (Sandbox Code Playgroud)
在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"))
Run Code Online (Sandbox Code Playgroud)
问题是我对添加到列表的最后一个表达式中的'emacs-root'发出警告:“引用自由变量'emacs-root'”
我在这里做错了什么,有什么办法可以使编译器满意?
顺便说一句,这个设置可以正常工作-在加载期间,我没有任何问题,只是这个烦人的警告。
问候,罗马
在编译引用变量的文件时,emacs-root必须已经定义了变量。避免警告的最简单方法是添加
(eval-when-compile (defvar emacs-root)) ; defined in ~/.init.el
Run Code Online (Sandbox Code Playgroud)
在el-get-settings.el违规表格之前。
或者,您可以defvar将从init.el移至el-get-settings.el。
请注意,您可以使用eval-when-compilein 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.")
Run Code Online (Sandbox Code Playgroud)
还需要注意的是你原来defvar emacs-root的问题,如果坏了,它把变量emacs-root到"Path to where EMACS configuration root is."Windows上。
| 归档时间: |
|
| 查看次数: |
2936 次 |
| 最近记录: |