Change Emacs' background color

12,620

Solution 1

It seems that it's better to use

(custom-set-faces
  '(default ... )
  '(region ... )
  ....
)

style to set faces, this way it will not have that problem.

Solution 2

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.

Solution 3

(if (eq system-type 'darwin)
    ;; mac os x settings
  (if (eq system-type 'gnu/linux)
    (setq default-frame-alist '((background-color . "black")
                                (foreground-color . "gray")))))

something like this should help you maintain settings per OS.

Share:
12,620
sudo
Author by

sudo

Updated on June 05, 2022

Comments

  • sudo
    sudo almost 2 years

    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

  • sudo
    sudo about 13 years
    Actually, I have that already, if you are interested try it out, this is my emacs configuration repos on bitbucket, it's in the file called my-color.el. The issue is that if I use set-face-attributes for 'default, new frames will be messed up, even if I set default-frame-alist. Without it, they would be fine, but I'll have to manually set every other opened frames one by one. Though generally there won't be that many frames, I still would like to make the change with one command.
  • Jonas Berlin
    Jonas Berlin almost 9 years
    This seems to work fine until I resize the window, after which the colors are broken again (emacs 24.4.1).