Emacs 24: Loading a package installed via ELPA

Solution 1:

I installed cmake-mode with the marmalade-repo, and took a look at cmake-mode-autoloads.el. It appears that the author made a conscious decision not include everything needed for the setup within the autoloads file. However, the instructions on lines 25 to 30 of cmake-mode.el are correct, which you cited in your question. If you use lines 25 to 30 and set the path correctly, then you do NOT need an extra line of code such as (add-to-list 'load-path "~/.emacs.d/elpa/cmake-mode-20110824/").

Obviously, you would not want to use /dir/with/cmake-mode -- you want to use ~/.emacs.d/elpa/cmake-mode-20110824 without a forwardslash at the ending.

(setq load-path (cons (expand-file-name "~/.emacs.d/elpa/cmake-mode-20110824") load-path))
(require 'cmake-mode)
(setq auto-mode-alist
      (append '(("CMakeLists\\.txt\\'" . cmake-mode)
                ("\\.cmake\\'" . cmake-mode))
              auto-mode-alist))

You may need to delete the c-make-mode... directory and try reinstalling if the code above does not work (using your own path).

Solution 2:

Given the wiki's nature as half code repository, half aide-memoire for Emacs hackers, you understandably overlooked this point:

it could 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:

This is what I do; one of the first files loaded by my custom init script (the creation of which, from all I can gather, is the pons asinorum of serious Emacs use1) does

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

and from there I simply (require) what ELPA packages I need. This also has the benefit of allowing finer control over the behavior of ELPA-installed packages; if, for example, I want to disable a given package for the moment but not uninstall it entirely, it's a simple matter of commenting out the relevant (require) call, where the default behavior would require moving the package out of my ELPA directory entirely.

(1. Despite almost overwhelming temptation, I manfully refused to name my custom init script lightsaber.el.)

Solution 3:

You can just do all your initialization after packages load using after-init-hook. From EmacsWiki:

;; init.el
(add-hook 'after-init-hook (lambda () (load "<real init file>")))