Changing Color Themes Emacs 24 -- order matters
Asked Answered
R

6

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.

Rust answered 28/3, 2012 at 2:7 Comment(1)
emacs 24.0??. M-x display-about-screen or M-x emacs-versionUnwise
H
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.

Hixon answered 28/3, 2012 at 6:46 Comment(6)
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?Rust
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?Hixon
I put in the recommendations here for .Xresources: ethanschoonover.com/solarized. I think that might conflict a little with using emacs color theming.Rust
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.Capriccio
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.Griswold
If you follow my advice below, I did automate it.Velasquez
F
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))
Fania answered 24/3, 2013 at 3:56 Comment(0)
V
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)
Velasquez answered 13/9, 2013 at 22:21 Comment(3)
What's (kb "C-t")? Why that instead of (kbd "C-t")? Sorry, just a typo?Halden
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!Velasquez
To try all themes "(setq my-themes (custom-available-themes))"Ankerite
S
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)))
Snow answered 23/10, 2012 at 14:56 Comment(0)
P
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.

Parenteau answered 28/3, 2012 at 11:27 Comment(1)
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.Capriccio
C
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).

Capriccio answered 28/10, 2013 at 20:26 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.