Frage

I am using Gnu Emacs 24.3 on Ubuntu 12.04. I downloaded dired+.el from here: http://www.emacswiki.org/emacs/dired%2b.el . I then tried to byte-compile this file in Emacs. I made a file bytecomp.el :

(byte-compile-file "dired+.el")

and run the following command:

bash$ emacs -batch -l bytecomp.el -kill

and got the following error message:

In toplevel form:
dired+.el:1114:1:Error: Cannot open load file: dired+

Update

Changing the file bytecomp.el to:

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

and running emacs -batch -l bytecomp.el -kill from the same directory ( ~/emacs/test/bytecompile ) gives another error message:

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"
War es hilfreich?

Lösung

You need to put dired+.el in your load-path.

dired+.el explicitly does this:

(provide 'dired+)
(require 'dired+) ; Ensure loaded before compile this.

This is an Emacs-Lisp idiom that ensures that the library is loaded before compiling it. For Dired+ this is appropriate.

So do this:

(add-to-list 'load-path "/your/path/to/dired+/")

The relevant doc for the idiom used here is (elisp) Named Features. Here is a bit of it:

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.

Andere Tipps

You do not need a file to compile dired+.el. Just invoke the byte compiler directly from the command line:

$ emacs -Q --batch -L . -f batch-byte-compile dired+.el

Before invoking this command, remove your bytecomp.el file, or at least rename it to something else, e.g. my-byte-compilation.el.

Your bytecomp.el file shadows the built-in Emacs library bytecomp.el, which defines byte-compile-file and a couple of other byte compilation functions, including the above batch-byte-compile.

When calling byte-compile-file, Emacs tries to load the implementing library bytecomp.el to have the function definition available. However, since you named your file bytecomp.el, and placed the containing directory in front of load-path, Emacs actually tries to load your file again.

This in turn leads to another call to byte-compile-file, which again triggers a load of bytecomp.el. Hence the recursive load error, you saw.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top