I have an init file for Emacs located at /home/username/.emacs.d/init.el and it has the command (set-background-color "honeydew").

However, when I open Emacs the color has obviously not changed from black. How can I make the file load on startup?

It does work if I run M-x set-background-color but it isn't persistent.

  • do you happen to also have a .emacs file in your HOME path? – shoshin Jan 28 at 5:10
  • @GrantShangreaux Could you please tell me how I can check? I have only used Linux for about 1 week. – Adam G Jan 28 at 5:11
  • cd will take you to your home directory, then ls -a will show you the contents of the directory, including hidden files. – shoshin Jan 28 at 5:12
  • How do you start Emacs? – Gilles Jan 30 at 9:52

set-background-color is an interactive compiled Lisp function in `frame.el'.

(set-background-color COLOR-NAME)

Set the background color of the selected frame to COLOR-NAME. When called interactively, prompt for the name of the color to use. To get the frame's current background color, use `frame-parameters'.

I'm going to guess that you're starting Emacs with emacs --daemon, in which case an init file containing (set-background-color "honeydew") is setting the background of a frame you'll never see.

And even if that's not the case, your setting wouldn't be repeated in other frames (e.g. C-x52), so you want to take care of that issue regardless.

(defun my-set-background-color (&optional frame)
  "Set custom background color."
  (with-selected-frame (or frame (selected-frame))
    (set-background-color "honeydew2")))

;; Run later, for client frames...
(add-hook 'after-make-frame-functions 'my-set-background-color)
;; ...and now, for the initial frame.

I've set honeydew2 here because I honestly can't tell the difference between honeydew and white on my monitor. (That may or may not be a contributing factor for you too?)

Edit: All of that said... an initial terminal frame may still be a problem, and you can both deal with that and replace everything I've written above with just:

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

set-background-color does work in your init file! It's just that the setting is overridden later in Emacs's startup process, which goes (in part) something like this:

  • load site init files
  • load user init file
  • load packages
  • set up frame parameters

To set up window frame attributes and have them actually persist, you need to set up variables (customization options) that are used in that last step when Emacs configures the UI.

To customize frame settings such as width, height, background color, set the default-frame-alist variable (see the chapter "Frames and Graphical Displays" in the Emacs manual, under the section "Frame Parameters"). Or you can customize it through the menus: Options -> Customize Emacs -> Specific Option -> Initial Frame Alist.

If you need more complex control of the window attributes and how they're created, you'll have to create a custom function and add it to window-setup-hook.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.