Werden wir Helden für einen Tag

Home | About | Archive

Advent of emacs #10: How I do theming in emacs

Posted on Dec 10, 2022 by Chung-hong Chan

As I said yesterday, this is a break for me. I just want to quickly show you what theme I am using and also the technique to quickly to switch to another theme.


The theme I am currently using is tron-legacy-theme by Ian Pan et al. I actually don’t like the movie, I dig the sound track by Daft Punk. This theme obviously is not an official product from Disney but somehow I like the color theme. Previously, I used kaolin-dark by Ogden Webb et al. and doom-themes by the Doom Emacs team.

Switching theme.

Regardless of what research says about dark mode, I use dark, high contrast themes for programming, writing, and reading. However, sometimes I still need to quickly switch to something which doesn’t have a dark background, e.g. for presentation.

My favourite light theme is solo-jazz by Carl Steib et al. But changing theme within an emacs session is kind of tricky. Let me explain.

Suppose I am using tron-legacy and I want to quickly switch to solo-jazz. There is a command called load-theme. So the obvious choice would be M-x load-theme and then select the theme I want to use now: solo-jazz. And actually, it’s kind of working, except when you do something non-trivial such as find-file (C-x C-f). Some residual settings from tron-legacy are still there.

The reason for it is that emacs allows us to have more than one theme simultaneous running. One can look at the variable custom-enabled-themes (note the plural). One would see that it is a list of symbols like (solo-jazz tron-legacy). I would say it is not what a modern user would expected (we expect a software to have just one theme).

In the end, I have something like this in my configuration

(use-package all-the-icons)
(use-package tron-legacy-theme
  (setq tron-legacy-theme-vivid-cursor t)
  (load-theme 'tron-legacy t))

(use-package solo-jazz-theme) ; Don't activate
(set-face-attribute 'default nil :family master-font-family :height 140)

(defvar dark-mode t "Whether or not dark mode is enabled")

(defun toggle-dark-mode ()
  "Toggle dark mode"
  (if dark-mode
		(disable-theme 'tron-legacy)
		(load-theme 'solo-jazz t)
		(setq dark-mode nil)
	  (disable-theme 'solo-jazz)
	  (load-theme 'tron-legacy t)
	  (setq dark-mode t)	

And I toggle between dark and light mode with the custom command toggle-dark-mode.

Powered by Jekyll and profdr theme