Previous: Milkypostman’s Emacs Lisp Package Archive—MELPA, Up: Emacs Lisp Package Manager and Archives [Index]
Whenever Emacs starts up, it automatically calls the function
‘package-initialize’ to load installed packages. This is done after
loading the init file and before running ‘after-init-hook’. Automatic
package loading is disabled if the user option
package-enable-at-startup
is nil.
This means you should NOT put package specific initialization into
your init.el
except in a few ways:
auto-mode-alist
changes can be made in a way that does not require
the package to be loaded before they are setup:
(add-to-list 'auto-mode-alist '("\\.gradle" . groovy-mode))
(add-hook 'groovy-mode-hook (lambda () (setq tab-width 4)))
(global-set-key (kbd "C-'") 'shell-switcher-switch-buffer)
eval-after-load
It might be easier just to move package-initialize
to another point
during startup so you can (require)
ELPA packages; this takes care
of a lot of the described issues:
;; basic initialization, (require) non-ELPA packages, etc. (setq package-enable-at-startup nil) (package-initialize) ;; (require) your ELPA packages, configure them as normal
Starting in emacs 24.4, with-eval-after-load
is simpler than
eval-after-load
:
(with-eval-after-load 'abcd-mode (setq-default abcd-basic-offset 7) ; setting some option (add-to-list 'abcd-globals-list "console") ; appending to a list option (add-hook 'abcd-mode-hook 'prepare-some-abcd-soup) ; things to do for abcd mode buffers (define-key abcd-mode-map (kbd "C-c C-c") 'play-some-abcd-song) ; add some key binding for abcd mode )