Change Emacs' background color

sudo picture sudo · Apr 18, 2011 · Viewed 12.3k times · Source

I have a function that sets Emacs' color theme to a theme defined by myself. In this function I do:

(set-face-attribute 'default cur-frame :foreground fg-color :background bg-color)

I then set the background color, foreground color, and cursor color for default-frame-alist, initial-frame-alist and special-display-frame-alist.

All of this works fine on my Mac. But when I use this on Linux, it looks fine for all frames that have already been opened, but on newly created frames it looks like this:

background color issue

I do not have this problem with new frames if use the set-background-color / set-foreground-color functions instead of (set-face-attribute 'default ...). But if I do that I have to manually reset the colors for every frame that's already open.

I am using Emacs version 23.3 on both Mac and Ubuntu.

For clarification, this is the theme file I use:

my-color.el

Answer

Thomas picture Thomas · Apr 18, 2011

set-face-attribute sets, as the name suggest, the attributes of a face (i.e., font-related properties), not the attributes of the frame. Use

(add-to-list 'default-frame-alist '(background-color . "lightgray"))

and similar to change frame-related properties.