Adding this line at the very end of the .emacs file, that loads a default theme coming with the Emacs package,

(load-theme 'tsdh-dark)

the (main) screen looks like

enter image description here

Note the black-on-dark text, the barely visible mini-buffer, and other syntax highlighted languages (C++, Perl...) have all a lot of dark-on-dark text.

Now, if, instead, I do the command manually, right after .emacs was executed (ie first command),

M-x load-theme → tsdh-dark

the highlighting is normal,

enter image description here

in all languages.

Why is it that running as the last lisp instruction in .emacs the rendering is wrong, while loading the theme manually just after works?

And how can I fix that?

(I realized that the command might do more than just the (load-theme) lisp instruction... this question is also to fix the problem in a clean way)

3 Answers 3


Do you use Emacs in the client/server configuration? My guess is that for some reason Emacs is redefining faces after loading the theme. I can't find any reference but I think Emacs finishes setting up some of the faces when it makes the frame, at least for client frames, which is after it has loaded the init file (but, of course, before you can call load-theme interactively). The way I had found to delay face settings until everything was well defined was to call a function that applies the settings from after-make-frame-functions:

(load-theme 'tsdh-dark t)

(defun load-tsdh-dark-theme (_frame)
  (enable-theme 'tsdh-dark))

(add-hook 'after-make-frame-functions #'load-tsdh-dark-theme)

Even simpler, try loading the theme with (load-theme 'tsdh-dark t) (notice the additional t). From C-h f load-theme RET:

This function is normally called through Customize when setting ‘custom-enabled-themes’. If used directly in your init file, it should be called with a non-nil NO-CONFIRM argument, or after ‘custom-safe-themes’ has been loaded.

I can't reproduce your issue on Emacs 27, so I'm guessing...

  • Hi, no it's not a client/server config. Currently Emacs 25 (Ubuntu 18.04). Will upgrade soon, maybe the problem will disappear. Unfortunately adding the code above to the .emacs file doesn't improve the rendering. Maybe there is a way to postpone (timer) the execution of load-theme?
    – Déjà vu
    Jan 23, 2021 at 14:43
  • I don't think a timer is the right solution here. Did you try the hook with non-nil NO-CONFIRM in the load-theme form (as in the updated code block)? Jan 23, 2021 at 15:02
  • Just did, no change :(
    – Déjà vu
    Jan 23, 2021 at 15:06
  • I don't really know how to fix it then, but I've got a couple more ideas that you might try if no one more knowledgeable answers. First, try (customize-set-variable 'custom-enabled-themes '(tsdh-dark)) after (load-theme 'tsdh-dark t). If that doesn't work, I've simplified the hook, give it a try. Jan 23, 2021 at 15:22
  • @e2-e4 That's the dirtiest theme setting I've ever seen :-) Did you try with customize-set-variable? I'm curious about it.. Jan 23, 2021 at 16:33

Try: (custom-set-variables '(custom-enabled-themes (quote (tsdh-dark))))


Ok, it seems by delaying the execution (200ms), I can get it to work correctly.

Adding this to the bottom of ~/.emacs

(run-at-time "0.2" nil (lambda nil (load-theme (quote tsdh-dark) nil nil)))

Your Answer

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

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