Emacs 24 Package System Initialization Problems

喜欢而已 提交于 2019-11-26 11:44:12
Nicolas Dudebout

The packages that you install with package.el are activated by default after your .emacs is loaded. To be able to use them before the end of your .emacs you need to activate them by using the commands:

(setq package-enable-at-startup nil)
(package-initialize)

It's worth noting why Emacs defers the package initialization:

See C-hig (emacs) Package Installation RET, and in particular:

The reason automatic package loading occurs after loading the init file is that user options only receive their customized values after loading the init file, including user options which affect the packaging system. In some circumstances, you may want to load packages explicitly in your init file (usually because some other code in your init file depends on a package). In that case, your init file should call the function package-initialize. It is up to you to ensure that relevant user options, such as package-load-list (see below), are set up prior to the package-initialize call. You should also set package-enable-at-startup to nil, to avoid loading the packages again after processing the init file. Alternatively, you may choose to completely inhibit package loading at startup, and invoke the command M-x package-initialize to load your packages manually.

So provided you make sure that your init file takes care of any non-default values you want for variables in the package customization group1 before calling package-initialize -- and that you maintain this approach whenever customizing the package library config -- it should be okay to do this.

Alternatively, because after-init-hook runs after the standard package initialization has completed, you could use that to evaluate any init code which depends upon packages. So instead of calling package-initialize directly in init.el, you could instead write:

(add-hook 'after-init-hook 'my-after-init-hook)
(defun my-after-init-hook ()
  ;; do things after package initialization
  )

putting the code requiring the initialized package system within that function.

YMMV.

(n.b. I haven't tested the after-init approach, as I don't really use package.el; but I did confirm the sequence of events in the start-up code, so I believe it will work as described.)

1M-x customize-group RET package RET

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!