It is kind of similar to this question How do I automatically load a mode for a specific set of file extensions?

So I am in a situation where, when I want to write in TeX, I want to use 'whiteboard' theme. Whereas whenever I want to program in C++ or python, I want to use "afternoon" theme.

I kind of expect my init file to look like

(if [file extention is tex] (load-theme 'whiteboard t) (load-theme 'afternoon t))

Is this right?

I am using Emacs 26.3

  • You may be interested in investigating how to make a theme buffer-local and apply that theme to the file-visiting-buffer, rather than applying a new theme globally ....
    – lawlist
    May 16 '20 at 4:45
  • 4
    Does this answer your question? Different themes in different modes
    – phils
    May 16 '20 at 4:50

A theme is global, but you can cause a given theme to be used when you visit a file with a given major mode: You can use the mode hook of a mode you're interested in to start using the theme you want for that mode.

auto-mode-alist associates file types (extensions) with major modes, and each major mode has a mode hook. So you can associate file types with themes by using mode hooks to turn on given themes.


  • file extension => specific major mode
  • major mode's hook => specific theme

The theme you change to because of a mode hook will then be used everywhere (all buffers, all modes), until you visit a file with a different mode, whose mode hook says to use a different theme. That behavior might not be what you want. But it's one possibility to consider.

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.