13

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?

Notes:

  • 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"
wonea
  • 1,877
Chen Levy
  • 1,685

4 Answers4

3

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

Aaron Miller
  • 10,087
2

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

lawlist
  • 1,427
1

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>")))
Poulsbo
  • 111
0

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

Dmytro
  • 101