7

I want to understand why an expression of the form

(load-theme 'my-kewl-theme t)

fails1 when run as the last expression in my init (~/.emacs) file, but works fine if I evaluate it as soon as soon as Emacs' startup is done.

How can I troubleshoot/debug this conundrum?

The only clue I have is that right before (load-theme 'my-kewl-theme t) is evaluated at the end of the loading of ~/.emacs, the variable custom-theme-load-path has the value

(custom-theme-load-directory t)

whereas after Emacs starts, it has the value

("/path/to/my-kewl-theme/" custom-theme-load-directory t)

I don't know what accounts for this difference. (This variable is not referred to at all by ~/.emacs, at least explicitly.) The variable custom-theme-load-directory has the value ~/.emacs.d throughout.


1error: Unable to find theme file for `my-kewl-theme`

1
  • Without bothering to understand, you could set the variable to include the element "/path/to/my-kewl-theme/" as its first element, in your init file before invoking the load-theme. You can alternatively try to find the code that (already) adds that path to the value, and evaluate that code before loading the theme.
    – Drew
    Commented Oct 25, 2015 at 3:24

2 Answers 2

7

From the emacs manual regarding packages:

By default, Emacs also automatically loads all installed packages in subsequent Emacs sessions. This happens at startup, after processing the init file.

So if your theme relies on some package initialisation you can put your call in after-init-hook. For example

(add-hook 'after-init-hook 
   (lambda ()
     (load-theme 'my-kewl-theme t)))

Alternatively, enable the theme by customising custom-enabled-themes, instead of using load-theme in your init file.

1
  • It turns out that with after-init-hook I did not get the same results as with manual evaluation, so instead I ended up adding the hook to window-setup-hook (which is triggered after after-init-hook), but basically the same idea. Thanks!
    – kjo
    Commented Oct 25, 2015 at 18:58
10

I believe it is standard practice for themes installed as packages to add their own paths to custom-theme-load-path as an autoload. A call to package-initialize will execute all of your package autoloads (among other things), and if there isn't an explicit call in your init file, it is called implicitly at the end of initialization.

I recommend putting a (package-initialize) towards the beginning of your init file, right after you configure package.el itself (adding repositories, etc.) and before you do anything with any packages not built-in to Emacs itself.

Not the answer you're looking for? Browse other questions tagged or ask your own question.