2008-12-10

When editing text, I find it quite nice to highlight the current line, that is, the line where the cursor is, gets a different color. This can be easily done with emacs, by putting global-hl-line-mode (more about modes) and the following in your .emacs:

;; highlight the current line; set a custom face, so we can
;; recognize from the normal marking (selection)
(deffacehl-line '((t (:background"Gray")))
"Face to use for `hl-line-face'.":group 'hl-line)
(setq hl-line-face 'hl-line)
(global-hl-line-mode t) ; turn it on for all modes by default

What this does:

first, we define a special font ('face' in emacs-jargon) and we call it hl-line; there is a special format for that, which is discussed in detail in the ELisp Manual;

second, we assign this 'face' to the hl-line-face-variable; this determines the face that will be used for highlighting;

third, we turn the highlighting on for all modes.

That is all. Now, some notes to this:

You can of course experiment with the font/face: you can change the foreground and background colors, make things bold or italic, bigger or smaller, etc. -- personally I like to keep things a bit subtle;