How can I ask Emacs to automatically use a different color theme (e.g. using the Elisp ColorTheme package) depending on the mode of the buffer?

Some color-themes work great when editing code, but not in Dired+, TERM or shell mode.

Thanks

share|improve this question

It seems that you can't set a separate color themes for different buffers, but you can set it for different frames. You can find instructions for setting per frame color themes here http://www.emacswiki.org/emacs/ColorTheme#toc8.

You can use a load-hook to automatically change the color theme when a mode is loaded, but it'll apply the change to all buffers.

You can change the color theme when a mode loads using a load hook. e.g.

(add-hook 'dired-mode-hook 'color-theme-emacs-nw)

Edit: Here is a function that opens shell in a new frame using a different color theme:

(defun my-shell () 
       (interactive)
         (let ((color-theme-is-global nil))
          (select-frame (make-frame))
          (color-theme-gnome)
                         (shell)))
share|improve this answer
    
Thanks Matti. I guess this could be combined with setting color-theme-is-global to nil (emacswiki.org/emacs/ColorTheme#toc8) so that the color-theme only applies to the new frame. I'll give it a try! – Amelio Vazquez-Reina Jan 3 '11 at 18:39
    
Yes, I meant that the theme is changed in all buffers with in the frame when the hook is loaded, but separate frames can have different themes. I corrected the reply.... – Matti Pastell Jan 3 '11 at 18:50
1  
+1 Nice answer, I came here to suggest mode-hook could switch themes, and then learned about color-theme-is-global, thanks. – ocodo Jan 22 '11 at 20:09

The package load-theme-buffer-local (or color-theme-buffer-local.el if you use pre emacs 24 themes) can set different faces per buffer. Your background stays the same though.

You can mode-hook it like this:
(add-hook 'js2-mode-hook (lambda nil (load-theme-buffer-local 'tango (current-buffer))))

The packages are available on MELPA (M-x install-package RET load-theme-buffer-local), source and readme on github

share|improve this answer

I'm using zenburn colors and

(setq font-lock-maximum-decoration (quote ((dired-mode . nil) (t . t))))

didn't work for me but,

(setq font-lock-maximum-decoration (quote ((dired-mode) (t . t))))

works perfectly with the version of dired+ released on 2011/01/04.

share|improve this answer
    
could you explain what the second line does? – Amelio Vazquez-Reina Jan 15 '11 at 20:07
    
According to the emacswiki on dired+ : You can customize option ‘font-lock-maximum-decoration’ to set the level of fontification you want. And you can do this for particular modes if you like. To turn off max highlighting only for Dired mode, do ‘M-x customize-option font-lock-maximum-decoration’ and insert an entry for ‘dired-mode’ that specifies ‘default’ highlighting for it. (You can set another, catch-all entry for ‘all’ that controls all other modes.) – CBM80 Jan 16 '11 at 1:56
    
@CBM80 Thanks! This works for Monokai as well. – mcandre Mar 28 '13 at 19:51

I've faced the same problem in the past with unreadable dired buffers in terminal. As a workaround, I did M-x customize-option font-lock-maximum-decoration; you can also set the variable directly in your config file, e.g. (setq font-lock-maximum-decoration (quote ((dired-mode . nil) (t . t)))). This uses default decorations for dired, and maximum for everything else (that was the default setting). Do C-h v font-lock-maximum-decoration for details.

This doesn't exactly answer the question -- I don't know if it's possible to use per-buffer or per-mode color themes -- but it might help solve the underlying problem.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.