我在Ubuntu 12.04上使用Gnu Emacs 24.3。
我从这里下载了dired+.el
:http://www.emacswiki.org/emacs/dired%2b.el。然后我尝试在Emacs中对此文件进行字节编译。我创建了一个文件bytecomp.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+
将文件bytecomp.el
更改为:
(add-to-list 'load-path "~/emacs/test/bytecompile")
(byte-compile-file "dired+.el")
并从同一目录(emacs -batch -l bytecomp.el -kill
)运行~/emacs/test/bytecompile
会显示另一条错误消息:
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"
答案 0 :(得分:2)
您需要将dired+.el
放入load-path
。
dired+.el
明确这样做:
(provide 'dired+)
(require 'dired+) ; Ensure loaded before compile this.
这是一个Emacs-Lisp习惯用法,可以确保在编译之前加载库。对于Dired +,这是合适的。
这样做:
(add-to-list 'load-path "/your/path/to/dired+/")
这里使用的习语的相关文档是(elisp)Named Features
。这里有一点:
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.
答案 1 :(得分:2)
您不需要文件来编译dired+.el
。只需从命令行直接调用字节编译器:
$ emacs -Q --batch -L . -f batch-byte-compile dired+.el
在调用此命令之前,删除您的bytecomp.el
文件,或者至少将其重命名为其他内容,例如: my-byte-compilation.el
。
您的bytecomp.el
文件会影响内置的Emacs库bytecomp.el
,该库定义byte-compile-file
以及其他一些字节编译功能,包括上面的batch-byte-compile
。
调用byte-compile-file
时,Emacs会尝试加载实现库bytecomp.el
以使函数定义可用。但是,由于您将文件命名为bytecomp.el
,并将包含目录放在load-path
前面,因此Emacs实际上会尝试再次加载您的文件。
这反过来会导致另一次调用byte-compile-file
,再次触发bytecomp.el
的加载。因此,您看到了递归加载错误。