字节编译emacs lisp文件:错误:无法打开加载文件
我在Ubuntu 12.04上使用Gnu Emacs 24.3。 我从这里下载了字节编译emacs lisp文件:错误:无法打开加载文件,emacs,elisp,dired,Emacs,Elisp,Dired,我在Ubuntu 12.04上使用Gnu Emacs 24.3。 我从这里下载了dired+.el:。然后我尝试在Emacs中对这个文件进行字节编译。我制作了一个文件字节码.el: (byte-compile-file "dired+.el") 并运行以下命令: bash$ emacs -batch -l bytecomp.el -kill 并收到以下错误消息: In toplevel form: dired+.el:1114:1:Error: Cannot open load file:
dired+.el
:。然后我尝试在Emacs中对这个文件进行字节编译。我制作了一个文件字节码.el
:
(byte-compile-file "dired+.el")
并运行以下命令:
bash$ emacs -batch -l bytecomp.el -kill
并收到以下错误消息:
In toplevel form:
dired+.el:1114:1:Error: Cannot open load file: dired+
Recursive load: "/home/fcihh/emacs/test/bytecompile/bytecomp.el", "/home/fcihh/emacs/test/bytecompile/bytecomp.el", "/home/fcihh/emacs/test/bytecompile/bytecomp.el", "/home/fcihh/emacs/test/bytecompile/bytecomp.el", "/home/fcihh/emacs/test/bytecompile/bytecomp.el"
更新
将文件字节码.el
更改为:
(add-to-list 'load-path "~/emacs/test/bytecompile")
(byte-compile-file "dired+.el")
从同一目录(~/emacs/test/bytecompile
)运行emacs-batch-l bytecomp.el-kill
)会显示另一条错误消息:
In toplevel form:
dired+.el:1114:1:Error: Cannot open load file: dired+
Recursive load: "/home/fcihh/emacs/test/bytecompile/bytecomp.el", "/home/fcihh/emacs/test/bytecompile/bytecomp.el", "/home/fcihh/emacs/test/bytecompile/bytecomp.el", "/home/fcihh/emacs/test/bytecompile/bytecomp.el", "/home/fcihh/emacs/test/bytecompile/bytecomp.el"
您需要将
dired+.el
放入加载路径中
dired+.el
明确地执行以下操作:
(provide 'dired+)
(require 'dired+) ; Ensure loaded before compile this.
这是一种Emacs Lisp习惯用法,可确保在编译库之前加载库。对于Dired+来说,这是合适的
这样做:
(add-to-list 'load-path "/your/path/to/dired+/")
这里使用的习惯用法的相关文档是(elisp)命名功能
。这里有一点:
Although top-level calls to `require' are evaluated during byte
compilation, `provide' calls are not. Therefore, you can ensure that a
file of definitions is loaded before it is byte-compiled by including a
`provide' followed by a `require' for the same feature, as in the
following example.
(provide 'my-feature) ; Ignored by byte compiler,
; evaluated by `load'.
(require 'my-feature) ; Evaluated by byte compiler.
The compiler ignores the `provide', then processes the `require' by
loading the file in question. Loading the file does execute the
`provide' call, so the subsequent `require' call does nothing when the
file is loaded.
编译dired+.el
不需要文件。只需从命令行直接调用字节编译器:
$ emacs -Q --batch -L . -f batch-byte-compile dired+.el
在调用此命令之前,删除字节编译.el
文件,或者至少将其重命名为其他文件,例如我的字节编译.el
您的bytecomp.el
文件隐藏了内置的Emacs库bytecomp.el
,它定义了字节编译文件
和一些其他字节编译函数,包括上面的批量字节编译
调用字节编译文件
时,Emacs尝试加载实现库字节编译.el
,以使函数定义可用。但是,由于您将文件命名为bytecomp.el
,并将包含的目录放在加载路径的前面,因此Emacs实际上会再次尝试加载您的文件
这反过来又导致另一个对字节编译文件的调用,该调用再次触发字节编译文件的加载。因此,您看到了递归加载错误。谢谢,我做到了。。但是现在我在文件bytecomp.el
上遇到了另一个关于“递归加载”的错误。我不知道为什么要把它弄得很复杂,但是请尝试在-l bytecomp.el
之前添加-l dired+.el
。(或者只需打开Emacs,加载dired+.el
,然后M-x字节编译文件dired+.el
。或者使用L
,然后在dired+.el
上的dired中加载dired+.el
)重点是编译它之前需要加载dired+.el
。我想从bash
脚本自动化字节编译。这就是我这么做的原因:)从bytecomp.el
重命名文件。已经有一个具有该名称的标准Emacs库。这可能有点让人困惑。如果只执行emacs-batch-l dired+.el--eval(字节编译文件)/your/path/to/dired+.el”)
,会发生什么情况?是dired+.el
目录中的~/emacs/test/bytecomile
?如果没有,它的目录是否在您的加载路径中?@Drew Yes它在同一个目录中..谢谢您提供的信息。。我试试这个。