Emacs 24 Package System Problems

By Xah Lee. Date:

This page describes some flaws with emacs 24's package system. If you are not familiar what it is, see: Emacs: Install Package with ELPA/MELPA.

does anyone have problems with emacs package system?

recently, installed several packages with it: {rainbow-mode, bookmark+, smex, expand-region}.

But they all have a similar problem related to autoload. For example, let's say rainbow-mode. When opening a CSS file, it's not loaded. You have to manually call it. So, if you want it to activate in CSS, you have to add stuff to your init file. Then, this means the package system does not really automatically manage things. You still have know some elisp, and manually add things to your init file. (we talking about basic activation, not advanced customization)

The issue is more pronounced with modes such as “bookmark+”, smex, “expand-region”. For example, after installing “bookmark+”, restart emacs, then i press Ctrl+x r l to open my bookmark, it gives a error call-interactively: Symbol's value as variable is void: bmkp-current-bookmark-file.

Apparently, the problem is that bookmark+ is not properly initialized. (when calling list-bookmarks, it does automatically load bookmark+, but isn't properly initialized) Here, i've spent some 20 min but haven't succeeded in making it work.

Similar problem with {smex, “expand-region”}. For example, smex requires you to define a key for M-x. So i added (global-set-key (kbd "<apps>") 'smex) in my init. But after starting emacs, i press the apps key, i get: “Symbol's function definition is void: smex”. If i put (require 'smex), restart, i get Debugger entered--Lisp error: (file-error "Cannot open load file" "smex"). Next step is to add the load path, which i haven't tried yet. But that seems to defeat half of goodness of package system.

Any insight on this? For emacs 24, is this the way things are?

Here's answer by José A. Romero L. https://groups.google.com/group/gnu.emacs.help/browse_frm/thread/0e83b11fb5c036a4

Newsgroups: gnu.emacs.help
From: José A. Romero L. 
Date: Mon, 4 Jun 2012 01:58:03 -0700 (PDT)
Local: Mon, Jun 4 2012 4:58 am
Subject: Re: elpa package loading problem?

AFAIK, ELPA relies heavily on correctly declared autoload cookies, especially if you really want to avoid loading whole packages at startup. From my own experience adapting SC to ELPA I know this is not easy to get right from the beginning — you, as a user, may end needing to add the missing autoloads to the xxx-autoloads.el file automatically generated by ELPA (this sucks big time, because your added code is ditched away with every upgrade of the package). ELPA works wonderfully well, but only if the authors of the packages you happen to use did make that extra effort to get things right from the start.

«for emacs 24, is this the way things are?»

Yep, that's just the way it is. I'm afraid you'll have to submit a few bug reports before things start working properly for you.

BTW, for smex I've added this to my .emacs:

(defun jarl/smex ()
  (condition-case description
        (global-set-key (kbd "M-x") 'smex)
        (global-set-key (kbd "M-X") 'smex-major-mode-commands)
        (global-set-key (kbd "C-c C-c M-x") 'execute-extended-command)
    (error (execute-extended-command))))

(global-set-key (kbd "M-x") 'jarl/smex)


Here's example of code to put in your emacs init file to properly setup packages installed from ELPA. Still better than no ELPA.

(add-hook 'css-mode-hook 'rainbow-mode)
(add-to-list 'load-path "~/.emacs.d/elpa/bookmark+-20120516/")
(require 'bookmark+)
(add-to-list 'load-path "~/.emacs.d/elpa/smex-20120301/")
(require 'smex)
(global-set-key (kbd "<apps>") 'smex)   ; make the Menu/Apps key do M-x on Windows. On Linux, use (global-set-key (kbd "<menu>") 'smex)
(global-set-key (kbd "<S-apps>") 'smex-major-mode-commands)

Note: if are using ErgoEmacs, some of these packages are already installed and setup for you. You can still use ELPA to install new versions, but no need to setup.


Got several people telling me i should have (package-initialize) before i do any config with packages installed by the packages system.

This will solve some of the problems discussed on this page, but not all. Also, i've emailed bookmark+ author about the issue. bookmark+ and smex both have new versions that improved the situation with package system.

I think emacs 24's package system still have some rough edges. It also needs better documentation. But the above is probably is a good tip, for now.

Here's some references about this issue:

If you have a question, put $5 at patreon and message me on xah discord.
Or support me by Buy Xah Emacs Tutorial