elisp警告“对自由变量的引用” [英] elisp warning "reference to free variable"

查看:217
本文介绍了elisp警告“对自由变量的引用”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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



我有init.el文件设置emacs-root变量:

  ;;所有emacs相关的东西的根
(defvar emacs-root
(if(或(eq system-type'cygwin)
(eq system-type'gnu / linux)
(eq system-type'linux)
(eq system-type'darwin))
〜/ .emacs.d /z:/。emacs.d /
路径到哪里EMACS配置根是。))

然后在我的init.el我有

  ;;加载插件与el-get 
(需要'el-get-settings)

in el -get-settings.el我正在使用el-get加载包,并将el-get / el-get文件夹附加到加载路径:

  ;;添加到加载路径,如果不存在,安装它
(add-to-list'load-path(concat emacs-rootel-get / el-get))

问题是我在最后一个表达式中的'emacs-root'
上有一个嘴唇警告add-to-list:引用自由变量'emacs-root'



我在这里做错了什么,有没有办法让编译器开心? / p>

此设置工作正常btw - 加载时没有任何问题,只是这个烦人的警告。



Regards,Roman

解决方案

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

 (eval-when-compile(defvar emacs-root) );在$ code> el-get-settings中定义的〜/ .init.el 

el



或者,您可以从 defvar code> init.el to el-get-settings.el



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

 (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 /))
配置根是。)

还要注意,您原来的 defvar emacs-root 在该问题中如果损坏,它将变量 emacs-root 设置为EMACS配置根目录的路径。在Windows上。


I am wandering how to get rid of the elisp warning. my setup is the following:

I have init.el file which sets "emacs-root" variable:

;; 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."))

then in my init.el I have

;; load plugins with el-get
(require 'el-get-settings)

in el-get-settings.el I am loading packages with el-get and appending "el-get/el-get" folder to the load-path:

 ;; 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"))

the problem is that I have a lips warning on 'emacs-root' in last expression for add-to-list : "reference to free variable 'emacs-root'"

what am I doing wrong here and is there any way to make the compiler happy?

this setup works ok btw - I don't have any issues during load time, just this annoying warning.

Regards, Roman

解决方案

When you are compiling the file where you reference the variable emacs-root, the variable must be already defined. The easiest way to avoid the warning is to add

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

in el-get-settings.el before the offending form.

Alternatively, you can move the defvar from init.el to el-get-settings.el.

Note that you can use eval-when-compile in defvar to speed-up loading the compiled file (of course, if you do that, you should not copy the compiled file between platforms):

(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.")

Note also that your original defvar emacs-root in the question if broken, it sets the variable emacs-root to "Path to where EMACS configuration root is." on windows.

这篇关于elisp警告“对自由变量的引用”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆