Emacs basics: Changing the background color

One of the first things you’ll probably want to change about Emacs is the default face. This controls the foreground color, the background color, the font, and other attributes. For example, many graphical environments give Emacs a background of white. 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. Change the attributes and the sample text will reflect your settings. When you are satisfied, select Save for future sessions. Your changes will be saved to ~/.emacs and reloaded the next time you start the editor.


This is a draft for Wicked Cool Emacs, a book that will be published by No Starch Press. (if we manage to get it all together! =)

  • http://yrk.nfshost.com/ Yoni Rabkin

    You have a typo: “…to black [my/by] customizing the default face…”.

  • http://www.cis.rit.edu/ Bob Krzaczek

    Along these lines, some of your readers may find the color-theme package interesting. I’d point out to them that it’s a whole set of faces, rather than just a background or a foreground, that are intended to fit well with each other.* Given how easy it can be to try them out before selecting one, there’s probably not much harm in recommending it to beginners, either.

    I use it, too, with just a few custom faces set on top of it. Who knows how much time it saved me from having to futz around with so many different faces…

    * Well, okay… some of them “fit well together” and really are nicely thought out. Others appear designed by whomever brought “Hot Dog Stand” to Windows 3.1.

  • Alan Davis

    I trust it’ll be ok if I share this. Perhaps someone will fix it. I apologize if it is excess baggage.

    Some time ago, I enquired on the emacs list about having different background colors for each frame. I REALLY need some clues on the desktop, as it is always cluttered with at least 10 windows and frames, and having several tasks going at once, it’s extremely helpful to have these visual clues, of corners of frames here and there on the desktop.

    A tentative solution was proposed by Kai.Grossjohan on that list. It works well enough, I suppose, but it’s always been a little broken. It’s a one off, as he suggested. It works really nicely after the first new frame, which is a clone of the originating frame on startup.

    One fantastic enhancement would be changing to different schemes. Judiciously selected background colors help. I possess not the skill to write the more complicated version.

    Here it is:

    ————-%—————————
    ;;—————————————————————————-
    ;; Cycling frame colors
    ;; Kai.Grossjohann
    ;; Newsgroups: gnu.emacs.help, 5 Aug 2002
    ;;———————————-
    (defun my-next-bg-color (frame)
    (let ((x (assq ‘background-color default-frame-alist)))
    (setq default-frame-alist (delq x default-frame-alist))
    (add-to-list ‘default-frame-alist
    (cons ‘background-color
    (cond ((equal (cdr x) “blue”)
    “black”)
    ((equal (cdr x) “black”)
    “dark blue”)
    ((equal (cdr x) “dark blue”)
    “saddle brown”)
    ((equal (cdr x) “saddle brown”)
    “blue1″)
    ((equal (cdr x) “blue1″)
    “dark olive green”)
    ((equal (cdr x) “dark olive green”)
    “maroon”)
    ((equal (cdr x) “maroon”)
    “blue violet”)
    ((equal (cdr x) “blue violet”)
    “MediumPurple”)
    ((equal (cdr x) “MediumPurple”)
    “RoyalBlue3″)
    ((equal (cdr x) “RoyalBlue3″)
    “DeepSkyBlue4″)
    ((equal (cdr x) “DeepSkyBlue4″)
    “blue”)
    (t “black”))))))

    (add-hook ‘after-make-frame-functions ‘my-next-bg-color)

  • http://uriavalos.com Uriel

    OK, thanx to this post I finally figured out how to make the font change permanent. (You can also just hit shift + mouse button to change the font, but that’s not permanent.) However, I’m still scratching my head over how to change the color. Perhaps some examples? What color names are valid? If you’re doing a book, this is a good idea….
    The color theme package also seems interesting. Will check it out

  • Sardar Faisal

    Thank you very much. For default came after the customize face and then after pressing enter defualt all comes. In that there is an option for default.

  • http://uriavalos.com Uriel

    I tried the color-theme package @Bob@ recommended. When using “doremi-color-themes” to cycle themes, this is probably the best way (as in easiest way) to change emacs colors. You don’t have to fuss with configuration files, look up colors, just a pick a theme you like and “Boom” you’re done. You can go back to what you are doing. The whole thing took me about 5 minutes. Installing the dependencies was the hardest part.

  • Glen

    For making changes i need to press enter on the [value] node. Then to actually see the changes i need to press enter on the [SET for this Session] node. For font family I just saw a box that said default…there was no option to change it. I guess this means I don’t have any console fonts installed?

    @bob thx for the recomendation!

  • Andabata

    Oh… emacs for the masses.
    Thanks for your simple and effective explanation. :)

  • prajakta

    Thanks

    -