Question

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.

Was it helpful?

Solution

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.

OTHER TIPS

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))

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)

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)))

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.

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top