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

itsjeyd
  • 5,070
  • 2
  • 30
  • 49
sudo
  • 647
  • 2
  • 7
  • 19
  • Does a `C-l` paint the colors properly? – vpit3833 Apr 17 '11 at 22:45
  • @vpit3833 Nope. It scrolls the window down, but nothing changes. – sudo Apr 17 '11 at 23:05
  • Why don't you just use the color-theme mode? – Bozhidar Batsov Apr 18 '11 at 05:11
  • @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. – sudo Apr 18 '11 at 05:27
  • 1
    There are external themes compatible with color-theme as well, like - https://github.com/bbatsov/zenburn-emacs (amongs many others). emacs 24 will have a built in theming capability – Bozhidar Batsov Apr 18 '11 at 05:43

4 Answers4

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.

Thomas
  • 71
  • 1
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.

vpit3833
  • 7,817
  • 2
  • 25
  • 25
  • Actually, I have that already, if you are interested try it out, this is my emacs configuration repos on [bitbucket](https://bitbucket.org/brownstone/emacs_configuration), 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. – sudo Apr 18 '11 at 04:53
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.

sudo
  • 647
  • 2
  • 7
  • 19
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 :)

Jonas Berlin
  • 3,344
  • 1
  • 27
  • 33