1

I've installed some things from ELPA, namely evil and rainbow-delimiters.

In order to have them run whenever emacs loads, I would put something like:

(evil-mode)
(global-rainbow-delimiters-mode)

In my init.el file.

However, because I installed them from ELPA, they're not loaded until after my init.el has been loaded, and so both symbols are undefined.

As far as I understand, this also prevents me from doing something like

(add-hook 'after-init-hook 'global-rainbow-delimiters-mode)

How can I work around this?

Postscript: This problem was actually caused by me not calling (package-initialize) at the start of my init.el, which would have loaded all of the things installed using packages (evilmode and rainbow-delimiters being just two of them) at the correct time

Squidly
  • 2,707
  • 19
  • 43

3 Answers3

3

Your add-hook solution will work.

There, 'global-rainbow-delimiters-mode is just a name, it will be resolved to the function later, when add-hook is called, and the function will exist by that time.

The ELPA documentation does mention this method, although it seems to consider it as a last resort.

Frédéric Hamidi
  • 258,201
  • 41
  • 486
  • 479
  • So it does. This seems peculiar, I thought I'd tried it, and it didn't work. Perhaps I forgot to byte compile my init file last time – Squidly Jul 25 '12 at 09:12
1

AFAIU compiling the init file is not a good idea - but not related so far.

Your hook fails, as it runs after reading the init, but before stuff gets loaded. You need a function to run after load from ELPA.

Try eval-after-load

Andreas Röhler
  • 4,804
  • 14
  • 18
  • Why is compiling my init.el a bad idea? – Squidly Jul 26 '12 at 10:03
  • I've compiled init.el for years. The problem is that if you make changes and forget to compile Emacs will load the old byte-compiled version and you might be confused why it doesn't have your changes. I have added hooks to startup and shut down that ask if I want to compile init.el (if it has changed), so that I never forget to do this. – Ivan Andrus Aug 02 '12 at 07:14
1

You can also initialize your packages early with (package-initialize). This will allow you to not put all that code in one hook.

Nicolas Dudebout
  • 9,172
  • 2
  • 34
  • 43