首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >elisp警告“引用空闲变量”

elisp警告“引用空闲变量”
EN

Stack Overflow用户
提问于 2014-04-06 18:38:47
回答 1查看 5.2K关注 0票数 8

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

我有设置“emacs”变量的init.el文件:

代码语言:javascript
复制
;; 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里

代码语言:javascript
复制
;; load plugins with el-get
(require 'el-get-settings)

在el-get -setings.el中,我用el加载包,并将"el-get/el-get“文件夹添加到加载路径中:

代码语言:javascript
复制
 ;; 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'”。

我在这里做错了什么,有什么办法让编译器高兴吗?

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

你好,罗曼

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-04-06 19:36:40

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

代码语言:javascript
复制
(eval-when-compile (defvar emacs-root)) ; defined in ~/.init.el

在冒犯表单之前的el-get-settings.el中。

或者,您可以将defvarinit.el移动到el-get-settings.el

请注意,您可以在eval-when-compile中使用defvar加速加载编译的文件(当然,如果这样做,您不应该在平台之间复制编译的文件):

代码语言:javascript
复制
(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."

票数 8
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/22898244

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档