nha
nha

Reputation: 18005

check if the theme is available before loading it

I am using emacs with the prelude configuration. I changed the theme and it works fine, and I added it in the preload directory like so :

;; preload color theme
(setq prelude-theme 'my-theme)

I installed the theme via prelude-require-packages, but not in the preload folder (not sure if it is available that soon). Is there a way to programmatically check if the theme is available, to replace the previous line with something more safe, like :

;; just to get the idea
(when (is-available 'my-theme)
      (setq prelude-theme 'my-theme))

Edit I tried :

;; preload color theme
(when (featurep 'my-theme)
  (setq prelude-theme 'my-theme))

But in this case I get the default theme, not 'my-theme.

Upvotes: 2

Views: 636

Answers (1)

Steve Vinoski
Steve Vinoski

Reputation: 20024

The load-theme function uses locate-file to find theme files. This approach is based that code:

(if (locate-file (concat (symbol-name 'my-theme) "-theme.el")
                 custom-theme-load-path '("" "c"))
    (setq prelude-theme 'my-theme))

You can replace the entire (concat ...) construct with the theme filename string, which for this example would be "my-theme-theme.el".

Upvotes: 3

Related Questions