color theming

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!)

(set-face-foreground 'default "blue")
(set-face-background 'default "green")

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.

(require 'color-theme)
(defun color-theme-djcb-dark ()
"dark color theme created by djcb, Jan. 2009."
(interactive)
(color-theme-install
'(color-theme-djcb-dark
((foreground-color . "#a9eadf")
(background-color . "black")
(background-mode . dark))
(bold ((t (:bold t))))
(bold-italic ((t (:italic t :bold t))))
(default ((t (nil))))

(font-lock-builtin-face ((t (:italic t :foreground "#a96da0"))))
(font-lock-comment-face ((t (:italic t :foreground "#bbbbbb"))))
(font-lock-comment-delimiter-face ((t (:foreground "#666666"))))
(font-lock-constant-face ((t (:bold t :foreground "#197b6e"))))
(font-lock-doc-string-face ((t (:foreground "#3041c4"))))
(font-lock-doc-face ((t (:foreground "gray"))))
(font-lock-reference-face ((t (:foreground "white"))))
(font-lock-function-name-face ((t (:foreground "#356da0"))))
(font-lock-keyword-face ((t (:bold t :foreground "#bcf0f1"))))
(font-lock-preprocessor-face ((t (:foreground "#e3ea94"))))
(font-lock-string-face ((t (:foreground "#ffffff"))))
(font-lock-type-face ((t (:bold t :foreground "#364498"))))
(font-lock-variable-name-face ((t (:foreground "#7685de"))))
(font-lock-warning-face ((t (:bold t :italic nil :underline nil
:foreground "yellow"))))
(hl-line ((t (:background "#112233"))))
(mode-line ((t (:foreground "#ffffff" :background "#333333"))))
(region ((t (:foreground nil :background "#555555"))))
(show-paren-match-face ((t (:bold t :foreground "#ffffff"
:background "#050505")))))))

To activate this theme, simply do M-x color-theme-djcb-dark. One nice side-effect of the color-theme package is the fact that colors work properly when you open new frames (windows).

No comments:

Post a Comment

Followers

Popular Posts