Change Emacs' background color
Asked Answered
D

4

6

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

Dinh answered 17/4, 2011 at 22:40 Comment(5)
Does a C-l paint the colors properly?Batha
@Batha Nope. It scrolls the window down, but nothing changes.Dinh
Why don't you just use the color-theme mode?Pretension
@BozhidarBatsov I've tried all the themes, I hated them all. All I need is a couple of simple and clear themes, that I can switch back and forth on different occasions. So I decided make up my own. Everything works out fine until recently I realize this issue on Linux platform, since I've work on my Mac most of the time.Dinh
There are external themes compatible with color-theme as well, like - github.com/bbatsov/zenburn-emacs (amongs many others). emacs 24 will have a built in theming capabilityPretension
D
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.

Dinh answered 19/4, 2011 at 5:17 Comment(0)
H
6

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.

Hosanna answered 18/4, 2011 at 13:15 Comment(1)
This seems to work fine until I resize the window, after which the colors are broken again (emacs 24.4.1).Anstice
B
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.

Batha answered 18/4, 2011 at 0:10 Comment(1)
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.Dinh
D
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.

Dinh answered 19/4, 2011 at 5:17 Comment(0)
A
0

Emacs uses1) (or does not paint over) the Gtk3.0 theme background in more recent Emacs versions. Changing background using e.g. set-background-color or default-frame-alist only works until I resize the window, after which the Gtk theme background "shines through" again.

I have not yet been able to figure out how to get emacs to always paint over the Gtk theme background, but at least I have found a way how to change the Gtk theme background color, for Emacs only: https://superuser.com/questions/699501/emacs-showing-grey-background-where-there-are-no-characters/937749#937749

So this does not fully solve changing the background color when you switch themes, but at least you can get rid of the black-white contrast you experience when opening new frames.

1) on my machine at least :)

Anstice answered 8/7, 2015 at 9:44 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.