emacs - 字节编译 emacs lisp 文件 : Error: Cannot open load file

标签 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")

并运行以下命令:
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"

最佳答案

您需要输入 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.

关于emacs - 字节编译 emacs lisp 文件 : Error: Cannot open load file,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20526714/

相关文章:

emacs - 如何在 Emacs 中 [tar 和] 压缩标记的文件

emacs - 组织议程跳过功能不起作用

Emacs——放置/删除覆盖的运行时间增加了每次运行

sorting - 在 Windows 7 上的 Emacs 24.3.1 中,如何首先在 dired 中对目录进行分组?

emacs - 防止 Emacs 在按回车键时删除尾随空格

emacs - Emacs 中的代码完成键绑定(bind)

emacs - Emacs Dired重命名许多文件

emacs - clojure swank 服务器打开公共(public)端口?

emacs - 在动态/按上下文自动插入之间切换

emacs - elisp:对当前文件调用命令