开发者

Cant apply color theme to one frame in Emacs?

My .emacs file is here. I want the theme 开发者_如何学Cto change when I am in shell-mode. But what happens is that the theme gets applied to all the windows. I set the variable color-theme-is-global to nil, but the problem still persists.

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

These are the corresponding lines in my .emacs file. What should I do to make it work?


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜