Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change Emacs' background color

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

like image 321
sudo Avatar asked Apr 17 '11 22:04

sudo


People also ask

How do you make Emacs colorful?

Call customize-themes to set a color theme. emacs M-x customize-themes. Click to see the change immediately. Alternatively, call load-theme , then press Tab ↹ to show a list of available themes.

How do I change to dark mode in Emacs?

Alt + x load-theme , then press Tab to show a list of available themes. Alternatively, Alt + x customize-themes to set a color theme.

How do I make Emacs black?

If you prefer a black background (which can be less tiring during long periods of use), you can change the background to black my customizing the default face. To change the background color and other attributes, use the command M-x customize-face , and specify default as the face to customize.


2 Answers

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.

like image 170
Thomas Avatar answered Sep 22 '22 00:09

Thomas


(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.

like image 24
vpit3833 Avatar answered Sep 18 '22 00:09

vpit3833