2009-03-04

There are people who think it's a waste of time to spend time customizing the colors in emacs. They are probably right; I haven't seen evidence that the some color scheme makes you more productive (which is the purpose of life, of course). Red on orange may not be the best though. Nevertheless, I like to customize emacs' colors. I like darkness with shades of blue - please do your own psycho-analysis.

Anyway, to change the colors that emacs uses, you can do something like (yuk!)

This sets the foreground color of the text recognized as default to blue, and the background to green; some other properties (such as 'underline') are available as well. Emacs 'knows' what text is supposed to be a 'warning', a 'variable' or a 'comment', and applies the color configured for it. Now, if you see some text that has some unexpected color, and you wonder why that is, move the cursor there, and call M-x describe-face. With that information, you can then configure the looks (note: if you don't see any colors you might be either (color-)blind, have a monochrome monitor, or forgot to specify (global-font-lock-mode t) in your .emacs)

You can also use set-face-foreground et al interactively; it lets you scroll to a long list of named colors, and alternatively you can use an HTML-style "#RRGGBB" hexadecimal red-green-blue color description. For example, "#000000" is black, "#ffffff" is white, and all colors of the form "#XYXYXY" (the RGB components are equal) give you various shades of gray: "#151515" is a rather dark gray, while "#e5e5e5" is rather light. For the full rainbow, a program like The Gimp can give you the hex-representation.

Using this knowledge, we can define all the colors, make comments gray, warnings red and so on. However, some people have already done much of the work for you, and prepared a wide range of color themes -- get the color-theme-el package. After installing, you can select interesting color-themes like M-x color-theme-subtle-hacker or M-x color-theme-blippblopp. Meanwhile, color-theme-select gives you an overview of all available color theme.

Of course, we're not happy with any of those, and prefer our very own theme. See below for an example of how to create your own color theme. When you're totally happy with the theme, you could even submit it to the color-theme people, and it might end up in a future version of the package.

23 comments:

I only do basic customizations but noticed it's way faster than via .emacs and as a bonus, it allows remote X emacs to keep the same look - and since I am still running emacs 19 on some VMS box - color theme is not really an option...

I'm running Emacs 23 in daemon mode. I'd like to use two different color themes depending on whether I run "emacsclient -t" (terminal frame) or "emacsclient -c -n" (X windows frame). If I weren't using daemon/emacsclient, it would be trivial to change the theme based upon the window-system value. Don't know how to do it though since .emacs evaluates window-system when "emacs --daemon" is run

> I haven't seen evidence that the some color> scheme makes you more productive

Are you familiar with Zenburn? It's a low contrast theme originally created for Vim but it spread like fire. For me personally it was a life saver, I had headaches every single day... hard not to if you're spending 16 hours a day in front of the screen.

Anyway, you can the color-theme for Emacs and a bunch of other apps on it's home page http://slinky.imukuppi.org/zenburnpage/

Pierre's elisp code works, but if you have a terminal emacsclient open at the same time you have an X-windows emacsclient open, you always get the same color theme in both frames. That is, do emacsclient -c -n to open an X-windows frame. You get a frame with the gnome2 color theme. Then do emacsclient -t. You get a terminal frame with the tty-dark theme. However... the X-windows theme jumps to the tty-dark theme also.

I'm running emacs 23, using emacs --daemon to start the server. Is there any way around this?

Hmm - guess I mixed up my test case...I think this version should work betterin mixed case:(note: I set gnome2 coz it makes my eyes bleed on console, so testing is obvious when it's not working... feel free to use another one...)

Interesting discussion. I'm working on the same problem. The solution postedby Pierre works fine, thanks a million! I only added a small change. I setcolor-theme-is-cumulative to nil as well so the themes that areloaded later don't contain remnants of a theme loaded earlier. Also, I putthe color-theme-related options outside the function so you can also changethe theme in a frame at some point without applying that change to all otherframes.

I was trying to use the above so as to not have my X-client theme interfere with the default theme.

Problem with the above is that if I invoke emacsclient -c ; though the theme gets applied correctly (color-theme-comidia) it also applies it to any running non-x client sessions.Any way I can make sure it leaves the current terminal session theme alone and apply any themes mentioned above only for any X clients?

After I've set up my colors the way I like them, how do I then save the color theme itself? That is, how do I export and save the color theme file, or at least get the color theme source into a buffer so I can then save it.

I think you should really update the post to rip out the Gimp line and mention the list-colors-display function. AFAIK it has been around for a long time and must be available to pretty much everyone. Of course it also gives you the hex representation.

Anyway, I landed here while searching for the name of the face (color?) used for the window separators, still searching.