0

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

Drew
  • 77,472
  • 10
  • 114
  • 243
user3166083
  • 111
  • 1

1 Answers1

1

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.

IOW:

  • 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.

Drew
  • 77,472
  • 10
  • 114
  • 243