4

For some reason, I need to manually update the custom-theme-load-path list after every update of a theme like smart-mode-line or leuven-theme. Looking for a solution, I came across this SO post. Here is the solution from that post (with slight modification):

;; Ensure that the custom-theme-load-path has all the theme paths added
;; Source: https://stackoverflow.com/a/15381087/1219634
(require 'dash)
  (require 's)
  (-each
      (-map
       (lambda (item)
         (format (concat elpa-dir "/%s") item))
       (-filter
        (lambda (item)
          (or (s-contains? "theme" item)
              (s-contains? "smart-mode-line" item)))
        (directory-files elpa-dir)))
    (lambda (item)
      (add-to-list 'custom-theme-load-path item)))

The above snippet works great and it updates custom-theme-load-path. The catch is that every time I load a theme using load-theme, the custom-theme-load-path resets to the value set by Customize. I have verified this behavior by putting (message "%s" custom-theme-load-path) before and after the call to (load-theme ..).

How can I permanently set the value of custom-theme-load-path so that load-theme cannot reset its value?

Here is a workaround I use to avoid this issue (but I'd like to understand why this is happening):

  • I have wrapped the above snippet in a function called update-custom-theme-load-path.
  • I call that function right before I call (load-theme 'leuven t)
4
  • To clarify: custom-theme-load-path is set in Customize. When you update (via package.el) either leuven or smart-mode-line, those packages are no longer on custom-theme-load-path? Oct 13, 2014 at 13:46
  • @JonathanLeech-Pepin Yes, those paths don't get auto updated even when I install through package.el. I used to manually update the path till I found the above snippet. Oct 13, 2014 at 13:48
  • Do you have a call to package-initialize in your init-file? And/or could you test running package-initialize after updating the theme, but before loading it? Oct 13, 2014 at 13:54
  • I do have (package-initialize). I call it before requiring any of the themes. I also tried C-x C-e on that just now with the themes updated; but that did not update custom-theme-load-path. I load this before requiring any theme/package. Oct 13, 2014 at 14:01

1 Answer 1

7

The Short Answer

You should not customize the custom-theme-load-path variable in the Customize interface.
So call M-x customize-variable RET custom-theme-load-path and ask to erase customizations (and save changes).

If you want to configure a custom theme directory beyond that which packages automatically add, customize the custom-theme-directory variable instead. That is exactly what this variable is for.


The Long Answer

Any customizations made through the Customize interface are reapplied whenever a theme changes. That’s due to 2 reasons:

  1. Themes are not just about faces, they’re about variables too.
  2. And the user customizations should always supersede the customizations applied by themes.

Thus, whenever a new theme is applied, the user customizations must be reapplied on top of it. Since your customization contains the custom-theme-load-path variable, themes are unable to add themselves to it.

That’s probably why the custom-theme-directory variable was created. This one is safe to customize, because it’s only yours (themes won’t touch it).

12
  • 1
    I am under that assumption that custom-theme-directory can contain just one directory. Isn't that true? Oct 13, 2014 at 14:56
  • I didn't need to set the custom-theme-directory. But I simply erased the customization of custom-theme-load-path and now the value set to this list in my init.el stick! Thanks! Oct 13, 2014 at 15:02
  • 1
    @kaushalmodi Yes, the custom-theme-directory variable is only needed if you want a directory beyond the automatically added ones AND you want to use the customize interface.
    – Malabarba
    Oct 13, 2014 at 15:04
  • It's almost as though package.el needs to have it's own package-theme-directory that it can add files to, so that installations don't worry about customize overwriting them. Oct 13, 2014 at 15:04
  • 1
    custom-theme-directory being one directory is still useful because themes are just individual files. Not so good for version control, but symlinks fix that.
    – Vamsi
    Oct 13, 2014 at 15:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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