【发布时间】:2014-06-11 22:24:32
【问题描述】:
我在 Emacs 中使用 elpa 安装了一些包,但是在启动 Emacs 时它们是如何加载的?
【问题讨论】:
我在 Emacs 中使用 elpa 安装了一些包,但是在启动 Emacs 时它们是如何加载的?
【问题讨论】:
package-install 是package.el 的一部分——您可以使用describe-function 查看。来自package.el 文档:
;; At activation time we will set up the load-path and the info path,
;; and we will load the package's autoloads. If a package's
;; dependencies are not available, we will not activate that package.
所以每个包里都有一个文件
NAME-autoloads.el
这个文件是在启动时加载的。
整个包都包含在package-user-dir下:
(setq package-user-dir "~/.emacs.d/site-lisp/package-install")
(require 'package)
每个包还包含NAME-pkg.el 以及包版本和描述。例如这里是与tabbar 包相关的文件:
package-install # that's my package-user-dir
└── tabbar-2.0.1 # each package dir is in the separate dir
├── tabbar-autoloads.el # this file is loaded at start up
├── tabbar.el # the package itself. In this case it is just a single file
└── tabbar-pkg.el # information about the package for package managment
引用手册:39.1.1 Summary: Sequence of Actions at Startup:
15。如果 package-enable-at-startup 不为 nil,它会调用函数 package-initialize 来激活任何已安装的可选 Emacs Lisp 包。
package-initialize 然后调用package-activate 进而调用package-activate-1 以加载NAME-autoload.el 结束:
(load (expand-file-name (concat name "-autoloads") pkg-dir) nil t)
【讨论】: