tags:

views:

106

answers:

2

This is my emacs file http://pastie.org/1003551. I want the theme to change when I am in shell-mode. But what happens is that the theme gets applied on all the windows. I set the variable color-theme-is-global to nil, but still the same problem is persisting.

(add-hook 'shell-mode-hook 'color-theme-monokai-terminal)
(set-variable 'color-theme-is-global nil)

These are lines 81 and 83 in my .emacs file. What should I do to make it work?

+1  A: 

I usually start Emacs as a daemon and then open frames as needed. I use different color themes for X frames and terminal frames like so:

(require 'color-theme)
(color-theme-initialize)

(defun apply-color-theme (frame)
  "Apply color theme to a frame based on whether its a 'real'
   window or a console window."
  (select-frame frame)
  (if (window-system frame)
      (color-theme-tango)
    (color-theme-tango-black)))

(setq color-theme-is-global nil)
(add-hook 'after-make-frame-functions 'apply-color-theme)

You can replace the (if window-system ...) part with your check for shell-script-mode and the color-theme-X parts with your favorite themes.

There is one downside to this: if you don't start Emacs as a deamon, the customization will only kick in after you create a second frame, the first one that pops up will have the standard theme.

mmmasterluke
The problem with this is that, I can't check the mode of the frame upon its creation. I could have made a frame earlier and now am opening shell-mode on it.
prtksxna
+1  A: 

I think your terminology is off: in emacs-speak frame means what people normally mean by window in a graphical environment. (That is, the thing that has the close, minimize and maximize buttons and a titlebar, etc, is the "frame".) Whereas the things that show up when you do a C-x 3 (split-window) are called windows, and when you do something like M-x shell-mode you get a new buffer, which may or may not be in a new window.

Color themes are always frame-global (as far as I know, and it's certainly what the documentation suggests) the variable color-theme-is-global determines whether a single theme propagates across frames.

I'm thinking that the closest thing to what you want is something like (completely untested, probably broken):

(defun shell-mode-in-new-frame ()
    (interactive)
    (select-frame (make-frame))
    (color-theme-monokai-terminal)
    (shell-mode))

Although this does create a new frame, which isn't what you want.

quodlibetor
My terminology was incorrect. I have edited it now. So there is no way a window can a different theme than the rest of the windows?
prtksxna
I've never tried, but I would imagine that it would be fairly difficult, and possibly impossible. There are a lot of variables that you need to set, and you'd need to set all of them buffer-local. And some of them are probably in the C sources and not buffer-localizeable. But I'm just guessing there. In my experience though most modes provide enough mode-specific faces. (Try M-x list-faces-display with shell-mode active, and look for the comint-* faces, which are [I'm pretty sure] what shell mode uses.)
quodlibetor
I guess it is pretty difficult. Thanks for making me ask the right question though. The way you are suggesting, I would be able to partly change the shell-mode buffer, but not completely.
prtksxna
Yes, exactly. It's conceptually possible that every important face (which I didn't say before but "face" is emacs' way of saying "text-color") *can* be made buffer-local, in which case it's just a matter of doing something like (add-hook 'shell-mode-hook (lambda () (setq (make-local-variable background-color) "new-color") (setq (make-local-variable "something else") "new-color"))) for every face you care about. Which, you know, is tedious but possible. Maybe try doing that for one or two faces that you care about at a time, setting them to the values in the color theme that you want?
quodlibetor