字节编译emacs lisp文件:错误:无法打开加载文件

Håk*_*and 5 emacs elisp dired

我在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")
Run Code Online (Sandbox Code Playgroud)

并运行以下命令:

bash$ emacs -batch -l bytecomp.el -kill
Run Code Online (Sandbox Code Playgroud)

并收到以下错误消息:

In toplevel form:
dired+.el:1114:1:Error: Cannot open load file: dired+
Run Code Online (Sandbox Code Playgroud)

更新

将文件更改bytecomp.el为:

(add-to-list 'load-path "~/emacs/test/bytecompile")
(byte-compile-file "dired+.el")
Run Code Online (Sandbox Code Playgroud)

并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"
Run Code Online (Sandbox Code Playgroud)

Dre*_*rew 2

你需要把dired+.el你的load-path.

dired+.el明确地这样做:

(provide 'dired+)
(require 'dired+) ; Ensure loaded before compile this.
Run Code Online (Sandbox Code Playgroud)

这是一个 Emacs-Lisp 习惯用法,可确保在编译之前加载库。对于 Dired+ 来说这是合适的。

所以这样做:

(add-to-list 'load-path "/your/path/to/dired+/")
Run Code Online (Sandbox Code Playgroud)

这里使用的习惯用法的相关文档是 (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.
Run Code Online (Sandbox Code Playgroud)

  • 将文件从“bytecomp.el”重命名。已经有一个同名的标准 Emacs 库。这可能会让事情有点混乱。 (2认同)