Книга: Learning GNU Emacs, 3rd Edition

11.7.1 Byte-Compiling Lisp Files

11.7.1 Byte-Compiling Lisp Files

After you have created your Lisp directory, you can make loading and running your Lisp files more efficient by byte-compiling them, or translating their code into byte code, a more compact, machine-readable form. Byte-compiling the Lisp file filename.el creates the byte code file filename.elc. Byte code files are typically 40 to 75 percent of the size of their non-byte-compiled counterparts.

Although byte-compiled files are more efficient, they are not strictly necessary. The load-library command, when given the argument filename, first looks for a file called <filename>.elc. If that doesn't exist, it tries <filename>.el, that is, the non-byte-compiled version. If that doesn't exist, it finally tries just <filename>. Thus, you can byte-compile your .emacs file, which may result in faster startup if your .emacs is large.

You can byte-compile a single function in a buffer of Lisp code by placing your cursor anywhere in the function and typing M-x compile-defun. You can byte-compile an entire file of Lisp by invoking M-x byte-compile-file Enter and supplying the filename. If you omit the .el suffix, Emacs appends it and asks for confirmation. If you have changed the file but have not saved it, Emacs offers to save it first.

Then you will see an entertaining little display in the minibuffer as the byte-compiler does its work: the names of functions being compiled flash by. The byte-compiler creates a file with the same name as the original Lisp file but with c appended; thus, <filename>.el becomes <filename>.elc, and .emacs becomes .emacs.elc.

Finally, if you develop a directory with several Lisp files, and you make changes to some of them, you can use the byte-recompile-directory command to recompile only those Lisp files that have been changed since being byte-compiled (analogously to the Unix make utility). Just type M-x byte-recompile-directory Enter and supply the name of the Lisp directory or just press Enter for the default, which is the current directory.

Оглавление книги

Оглавление статьи/книги

Генерация: 1.157. Запросов К БД/Cache: 3 / 1
поделиться
Вверх Вниз