23

In emacs 24, the order that color themes are applied seems to matter. This is obvious if you do M-x color-theme-select. The order that you ic

Does anybody have any insight into this issue?

I'd like to be able to switch between the following color themes without restarting:

  1. solarized-light
  2. solarized-dark
  3. zenburn
  4. railscasts

I guess I need the equivalent of a css-reset for emacs. One other tip that is invaluable is that if you use evil, then you need this line or else your cursor stays black, which is horrible for the dark themes:

(setq evil-default-cursor t) 

This is a related issue: Switching between color themes in Emacs ( < v.24). I am using Emacs 24.0. I'm posting this question because I'm looking for workaround for pre 24.1, or maybe advice if 24.1 is stable enough.

Community
  • 1
  • 1
justingordon
  • 12,553
  • 12
  • 72
  • 116

6 Answers6

18

It seem to me that even on Emacs 24 you're still using the old (and unmaintained) color-theme package. Emacs 24 has a built-in color theming infrastructure (and themes like zenburn and solarized have been ported to it) that I'd suggest you use instead. Have a look here for details on deftheme and friends.

То answer your particular question about color-theme - themes usually do not define every face that a previous theme might have tweaked and that causes your problems. Moving to the default theme between themes might probably be considered similar to a css reset.

Bozhidar Batsov
  • 55,802
  • 13
  • 100
  • 117
  • 1
    How do I move to the default theme between switches? Thanks so much! If I'm using elpa, should I make sure that I don't install color-theme? BTW, I love zenburn, but I'd like to also have railscasts colors for when i want a little more contrast during the day. Any, any opinions on customized .Xresources that comes with solarized? – justingordon Mar 28 '12 at 09:29
  • 3
    I guess you've installed a theme that depended on `color-theme` - there are many of those on Marmalade. In Emacs 24 - `M-x disable-theme` (though I'm not sure the problem you've describe will be present there). I haven't used `color-theme` in a while so I cannot help you about it. I personally do not customize `.Xresources` (for color themes) at all. Why do you want to do so? – Bozhidar Batsov Mar 28 '12 at 10:22
  • I put in the recommendations here for .Xresources: http://ethanschoonover.com/solarized. I think that might conflict a little with using emacs color theming. – justingordon Mar 29 '12 at 08:36
  • Color theme has a few advantages compared with the custom-them feature of Emacs: (1) Switching color themes is very fast. Switching custom themes is very slow, and is accompanied by flashing as the preceding theme(s) are disabled and the next theme is enabled. The difference is greatly exacerbated if you have several frame. (2) You cannot undo a custom theme, to restore a previous non-theme (but perhaps customized) appearance. You can only "disable" a custom theme relative to another theme. – Drew Oct 28 '13 at 20:19
  • This answer is wrong,, or not completely right. I'm using `load-theme` and when I use zenburn and solarized (which need to be installed from MELPA/Marmalade) I get the exact problems described by the OP. `disable-theme` seems to be a good solution, but It would be nice to automate it. – Mike Vella Feb 28 '14 at 11:18
  • If you follow my [advice below](http://stackoverflow.com/a/18796138/235908), I did automate it. – sshine Oct 13 '15 at 13:24
12

To automatically disable current theme before load the new one, you can also use advice:

(defadvice load-theme 
  (before theme-dont-propagate activate)
  (mapcar #'disable-theme custom-enabled-themes))
tungd
  • 14,467
  • 5
  • 41
  • 45
8

Inserting the code below in your .emacs/init.el, I bound C-t to cycle through a fixed list of themes in the specified order. This is compatible with Emacs 24.

;;;;; Theme ;;;;;
;; Cycle through this set of themes
(setq my-themes '(solarized-light solarized-dark zenburn railscast))

(setq my-cur-theme nil)
(defun cycle-my-theme ()
  "Cycle through a list of themes, my-themes"
  (interactive)
  (when my-cur-theme
    (disable-theme my-cur-theme)
    (setq my-themes (append my-themes (list my-cur-theme))))
  (setq my-cur-theme (pop my-themes))
  (load-theme my-cur-theme t))

;; Switch to the first theme in the list above
(cycle-my-theme)

;; Bind this to C-t
(global-set-key (kbd "C-t") 'cycle-my-theme)
sshine
  • 15,635
  • 1
  • 41
  • 66
  • What's (kb "C-t")? Why that instead of (kbd "C-t")? Sorry, just a typo? – ericx Jan 31 '15 at 01:48
  • It was not a typo, but in this case, you could just as well have used (kbd "C-t"). The reason I have a 'kb' macro is because of another piece of code for doing multiple keybindings at once: `(dolist (pair '(("C-k" kill-whole-line) ("C-z" undo) ...)) ((global-set-key (kb (car pair)) (cadr pair)))`. If I used 'kbd' rather than my own 'kb' macro: `(defun kb (k) (read-kbd-macro k))`, it'd complain about 'kbd' being a macro and not a function. Or something like that. Stupid little work-around. I've fixed 'kb' into 'kbd' in the code above, so thanks! – sshine Feb 02 '15 at 23:48
  • 1
    To try all themes "(setq my-themes (custom-available-themes))" – Talespin_Kit Aug 20 '20 at 02:56
5

I wrote a function that disables current theme before emacs switches to new one.

You can paste following snippet into you'r init.el and use M-x l0ad-theme.

https://github.com/maruks/.emacs.d

    ;; color themes
(add-to-list 'custom-theme-load-path "~/.emacs.d/themes")

(setq current-t43m3 nil)

(defun enab-theme (theme) 
  (if current-t43m3 (disable-theme current-t43m3))
  (setq current-t43m3 theme) 
  (load-theme theme t)) 

(defun disab-current-theme () 
  (if current-t43m3 (disable-theme current-t43m3))
  (setq current-t43m3 nil))

(global-set-key (kbd "C-c ltwo") '(lambda () (interactive) (enab-theme 'wombat)))

(global-set-key (kbd "C-c ltze") '(lambda () (interactive) (enab-theme 'zenburn)))

(global-set-key (kbd "C-c ltsd") '(lambda () (interactive) (enab-theme 'solarized-dark)))

(global-set-key (kbd "C-c ltsl") '(lambda () (interactive) (enab-theme 'solarized-light)))

(global-set-key (kbd "C-c ltne") '(lambda () (interactive) (enab-theme 'tomorrow-night-eighties)))

(global-set-key (kbd "C-c ltni") '(lambda () (interactive) (enab-theme 'tomorrow-night)))

(global-set-key (kbd "C-c ltnb") '(lambda () (interactive) (enab-theme 'tomorrow-night-bright)))

(global-set-key (kbd "C-c ltto") '(lambda () (interactive) (enab-theme 'tomorrow)))

(global-set-key (kbd "C-c ltta") '(lambda () (interactive) (enab-theme 'tango)))

(global-set-key (kbd "C-c ltdb") '(lambda () (interactive) (enab-theme 'deeper-blue)))

(global-set-key (kbd "C-c ltdi") '(lambda () (interactive) (enab-theme 'dichromacy)))

(global-set-key (kbd "C-c dct") '(lambda () (interactive) (disab-current-theme)))

(defun l0ad-theme (name) 
  (interactive
   (list
    (intern (completing-read "Load custom theme: "
                 (mapcar 'symbol-name (custom-available-themes))))))
  (enab-theme name))

(setq d3fault-theme (getenv "EMACS_DEFAULT_THEME"))

(when d3fault-theme
  (enab-theme (intern d3fault-theme)))
j0k
  • 22,600
  • 28
  • 79
  • 90
Maris Orbidans
  • 163
  • 2
  • 4
4

As others said, switch to the Emacs 24 version of themes. Once you're using that, you can "undo" a theme with disable-theme. Just give it the same argument that you passed to load-theme and you should get back to a blank slate. Then just load the new theme.

deong
  • 3,820
  • 21
  • 18
  • No, you ***cannot*** *undo a custom theme*. AND you can, for the most part, undo a *color* theme, restoring a previous, non-themed appearance. "Disabling" a custom theme is only relative to another theme. – Drew Oct 28 '13 at 20:21
3

You can cycle among custom or color themes using either of these libraries:

  • Do Re Mi, commands doremi-custom-themes+ and doremi-color-themes+. You need doremi-cmd.el for this.

  • Icicles, multi-commands icicle-custom-theme and icicle-color-theme.

With the Icicles commands you can also narrow the set of themes to cycle among, and you can sort it in various ways (i.e., change the cycle order).

Drew
  • 29,895
  • 7
  • 74
  • 104