Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing Color Themes Emacs 24 -- order matters

Tags:

emacs

emacs24

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.

like image 460
justingordon Avatar asked Mar 28 '12 02:03

justingordon


People also ask

How do I change the color of my Emacs theme?

You can enable a specific Custom theme in the current Emacs session by typing M-x load-theme . This prompts for a theme name, loads the theme from the theme file, and enables it. If a theme file has been loaded before, you can enable the theme without loading its file by typing M-x enable-theme .

How do I change Emacs to dark theme?

Alt + x load-theme , then press Tab to show a list of available themes. Alternatively, Alt + x customize-themes to set a color theme. M-x customize-themes. Click to see the change immediately.

How do I make an Emacs theme?

You can define a Custom theme using an interface similar to the customization buffer, by typing M-x customize-create-theme . This switches to a buffer named *Custom Theme* . It also offers to insert some common Emacs faces into the theme (a convenience, since Custom themes are often used to customize faces).


6 Answers

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.

like image 157
Bozhidar Batsov Avatar answered Oct 04 '22 22:10

Bozhidar Batsov


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))
like image 22
tungd Avatar answered Oct 04 '22 20:10

tungd


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)
like image 23
sshine Avatar answered Oct 04 '22 20:10

sshine


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)))
like image 26
Maris Orbidans Avatar answered Oct 04 '22 22:10

Maris Orbidans


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.

like image 34
deong Avatar answered Oct 04 '22 20:10

deong


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

like image 35
Drew Avatar answered Oct 04 '22 20:10

Drew