Reputation: 6368
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")))))
Upvotes: 3
Views: 3343
Reputation: 1330
"Entire frame, i.e. entire background of message-mode"
this phrase make me think author mixed up frame and window in Emacs. Each frame can contains several windows. While *-mode can refer to each buffer, i.e. window. So if you want to set background color by mode for each buffer with it (but not for frame) then better use mode hooks like here
Upvotes: -1
Reputation: 13447
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
Upvotes: 4