Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have just installed the cmake-mode package in Emacs 24 using:

M-x package-install cmake-mode

I can see the package at: ~/.emacs.d/elpa/cmake-mode-20110824, and I can load it using the instruction at Commentary: section of ~/.emacs.d/elpa/cmake-mode-20110824/cmake-mode.el:

;; Add this code to your .emacs file to use the mode:
;;  (setq load-path (cons (expand-file-name "/dir/with/cmake-mode") load-path))
;;  (require 'cmake-mode)
;;  (setq auto-mode-alist
;;        (append '(("CMakeLists\\.txt\\'" . cmake-mode)
;;                  ("\\.cmake\\'" . cmake-mode))
;;                auto-mode-alist))

However this contradicts the usage instruction on ELPA's EmacsWiki page:

... packages are initialized AFTER the init.el is loaded. This means you should NOT put package specific initialization into your init.el ...

I tend to agree with this instruction because adding to my ~/.gnu-emacs file a line such as:

(add-to-list 'load-path "~/.emacs.d/elpa/cmake-mode-20110824/")

is ugly, and will break if and when I will upgrade the package. However without this line I am unable to use cmake-mode.

Am I missing something here?


  • I did nothing strange with package-enable-at-startup and its' value is t.
  • I am using prelude.
  • user-emacs-directory value is "~/.emacs.d/" (Thanks @lawlist for the suggestion)
  • package-user-dir value is "~/.emacs.d/elpa"
share|improve this question
Is it possible you have altered the locations of the default-directory or the user-emacs-directory, such that the elpa directory is not being loaded? package-install creates an elpa directory and the autoloads file that is created during the installation is based on that location. – lawlist Aug 13 '13 at 17:10
Your last line of code in your question suggests that you moved the package out of the elpa directory -- i.e., ~/.emacs.d/cmake-mode-20110824/ is not where the autoloads file expects it to be. – lawlist Aug 13 '13 at 17:16
@lawlist: You are very observant. I made a mistake in the question. It is now fixed (the question) to the correct value of ~/.emacs.d/elpa/cmake-mode-20110824/. The problem remains. – Chen Levy Aug 14 '13 at 16:29
up vote 2 down vote accepted

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))

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

share|improve this answer
Sure, but unless I'm missing something, if you later update cmake-mode via ELPA, then either the directory gets renamed to something not in your init file, or the newer version ends up in a directory that's not in your load path; in the latter case, you either don't see the update, or you get undue weirdness because you're manually loading one version and (package-initialize) is loading another. Am I wrong? I mean, I haven't used ELPA much and have yet to update any packages with it, so I could be wrong. And, sure, it's not a major concern in any case, but why not avoid it entirely? – Aaron Miller Aug 20 '13 at 7:15
You are correct. However, the packages don't just update themselves without you knowing about it -- if and when you update, then that would be the time to do your housekeeping. I frequently invest a substantial amount of time modifying the source files of various packages, and I wouldn't necessarily want them updated after having spent all that time getting them just right. Emacs is far from what one might consider "maintenance free". – lawlist Aug 20 '13 at 15:26
An excellent point. – Aaron Miller Aug 20 '13 at 15:27

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)

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.)

share|improve this answer
Just a reminder to check on user-emacs-directory if changed as ELPA packages reside in there by default. I keep my stuff in Dropbox and I was surprised to see no effect from the above commands in my batch script until I setq it. – mlt Jul 29 '14 at 22:33

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>")))
share|improve this answer

I've had similar problem when I started to use ELPA. In my case I have had several local packages as those were not present in ELPA.

And thus I had altered load-path. For some reason load-path is not properly updated by package.el. To solve the problem I had to put (setq load-path (cons "~/.emacs.d" load-path)) after the call to package-initialize

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .