8

I have some custom theme settings like

(package-initialize)
(load-theme 'leuven t)
(custom-theme-set-faces
   'leuven
   '(Man-overstrike ((t (:foreground "red3" :bold t))) t)
   '(Man-underline ((t (:foreground "green3" :underline t))))
   ;; ... ignored
   '(yas-field-highlight-face ((t (:background "#D4DCD8" :foreground "black" :box (:line-width -1 :color "#838383"))))))

in my init.el of a emacs -q session. It works perfectly in emacs 26.1, but not in emacs 27, that's no matter how many times I evaluate the code, there's no custom face changes. I searched google but I can't find if there's some API changes in emacs 27.

Work Eamcs Version: GNU Emacs 26.1.92 (build 2, x86_64-apple-darwin18.2.0, Carbon Version 158 AppKit 1671.2) of 2019-02-26

Unwork Emacs version: GNU Emacs 27.0.50 (build 1, x86_64-apple-darwin18.2.0, NS appkit-1671.20 Version 10.14.3 (Build 18D109)) of 2019-03-10

Any help will be appreciated.

4
  • 2
    Please update your to describe how it’s not working
    – nega
    Mar 15 '19 at 14:42
  • There is no Emacs 27 - it has not yet been released. Please use emacs-version to obtain and note in your question what Emacs-27 development snapshot/build you see the problem in.
    – Drew
    Mar 15 '19 at 18:01
  • The question is unclear, and so risks being deleted. Please specify just what you mean by it not working. Provide a step-by-step recipe, saying what you do at each step, what you see as the effect, and what you expected to see instead. And please start Emacs using emacs -Q (no init file) for the recipe. Thx.
    – Drew
    Mar 15 '19 at 18:03
  • You might want to submit an Emacs bug report, since you are using a development build: M-x report-emacs-bug. Or you might want to just try a more recent build. The development stream is a work in progress.
    – Drew
    Mar 16 '19 at 1:08
10

Put this line in your init. Theme changes will take effect immediately in Emacs 27.

(setq custom--inhibit-theme-enable nil)

Presumably the automatic theme changing was disabled for a good reason. I haven't looked into the reason, but to set the value temporarily for just 1 statement you could do this.

(let ((custom--inhibit-theme-enable nil))
 (custom-theme-set-faces
  'leuven
  ;; theme settings
  ))

The double dashes -- in the name mean it is a "private" variable. So it is subject to change at any time and may not work forever.

I haven't looked into it too deeply. And there are a few other ways to make the color take effect immediately. But setting this variable to nil is the most straight forward way to get the old behavior back.

2
  • Thank you so much! I have been using the same theme in Emacs for ~7 years, and when it broke in v27 I was so distraught. Your setq fixed it for me!
    – zzelman
    Sep 6 '20 at 21:23
  • The other answer should be accepted. It provides the relevant piece of NEWS that explains the change as well as the official way of fixing the issue. By contrast the variable in this answer has a double -- which means it's a private unexported variable that is brittle to use. Feb 4 at 17:04
6

Another solution would be to add enable-theme to the custom theme settings, such as:

(when (< emacs-major-version 27)
  (package-initialize))
(load-theme 'leuven t)
(custom-theme-set-faces
   'leuven
   '(Man-overstrike ((t (:foreground "red3" :bold t))) t)
   '(Man-underline ((t (:foreground "green3" :underline t))))
   ;; ... ignored
   '(yas-field-highlight-face ((t (:background "#D4DCD8" :foreground "black" :box (:line-width -1 :color "#838383"))))))

(enable-theme 'leuven) ;; ADD THIS LINE

Apparently the NEWS file for Emacs 27.1 mentioned this change:

Just loading a theme's file no longer activates the theme's settings.
Loading a theme with 'M-x load-theme' still activates the theme, as it
did before.  However, loading the theme's file with 'M-x load-file',
or using 'require' or 'load' in a Lisp program, doesn't actually apply
the theme's settings until you either invoke 'M-x enable-theme' or
type 'M-x load-theme'.  (In a Lisp program, calling 'enable-theme' or
invoking 'load-theme' with NO-ENABLE argument omitted or nil has the
same effect of activating a theme whose file has been loaded.)  The
special case of the 'user' theme is an exception: it is frequently
used for ad-hoc customizations, so the settings of that theme are by
default applied immediately.

The variable 'custom--inhibit-theme-enable' controls this behavior;
its default value changed in Emacs 27.1.
1
  • This should be the accepted answer: provides insight in the underlying cause, quotes documentation and doesn't depend on internal variables.
    – memeplex
    Oct 24 at 4:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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