在GNU Emacs中,如何通过模式设置背景颜色? [英] in GNU Emacs, how to set background color by mode?
问题描述
在GNU Emacs中,我看到我可以在不同的模式下为前台类型设置不同的面孔,例如:
In GNU Emacs, I see that I can set different faces for foreground type in different modes, e.g.:
(custom-set-faces
'(message-header-to ((t (:foreground "LightGoldenrod1" :weight bold)))))
如何通过模式设置框架的背景颜色?这样,例如,组织模式背景将采取任何颜色主题定义为,但消息模式背景将是黑色的?
How can I set the background color for the frame by mode? Such that, for e.g., org-mode background would take whatever the color-theme defines it as, but message-mode background would be black?
除此之外,以下内容不起作用:
Something like this, except that the below doesn't work:
(custom-set-faces
'(message-mode-frame ((t (:background "black")))))
推荐答案
这是一个快速的例子,它通过框架来实现 - 即它会影响框架中的每个缓冲区:
Here is a quick example to do it by frame -- i.e. where it will affect every buffer in the frame:
(add-hook 'post-command-hook 'change-my-background-color)
(add-hook 'change-major-mode-hook 'change-my-background-color)
(add-hook 'window-configuration-change-hook 'change-my-background-color)
(defun change-my-background-color ()
(cond
((eq major-mode 'org-mode)
(set-background-color "honeydew"))
((eq major-mode 'text-mode)
(set-background-color "blue"))
(t
(set-background-color "red"))))
而且,这是一个改变缓冲区颜色示例:
And, here is a change the buffer color example:
(defun buffer-background-red ()
(interactive)
(setq buffer-face-mode-face `(:background "red"))
(buffer-face-mode 1))
目前不可能在窗口上执行此操作;但是,这里是一个链接,用于更改关于活动窗口的模式颜色。
To do it on a window basis is not presently possible; however, here is a link to changing the modeline color as to the active window.
https://stackoverflow.com/a/20936397/2112489
这篇关于在GNU Emacs中,如何通过模式设置背景颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!