emacs font-lock faces for composing email

I use Pine (no, not GMail) as my email client. I set its alternate editor to Emacs so I can use it to write email.

Among other Emacs features, font-locking, ie colored highlighting, has spoiled me. Color in general is a huge usability win. It’s such a difference that when I don’t have font-lock, editing a whole page of flat, white text makes me feel slightly dumb.

Sadly, I didn’t have font-lock for composing emails. So, I poked around and found u-vm-color.el. It was written for VM, an Emacs MUA, so it’s a little heavyweight. Still, it can color quoted text, signatures, and other text just like Pine’s message viewer.

To set it up, download u-vm-color.el, put it somewhere in your load-path (e.g. /usr/share/emacs/site-lisp/), and add this to your ~/.emacs:

(require 'u-vm-color)

; ugly heuristic to font-lock pine emails automatically
(add-hook 'find-file-hooks
  (lambda ()
    (if (equal "pico." (substring (buffer-name (current-buffer)) 0 5))

; these match pine's defaults. see M-x list-colors-display for other options
(set-face-foreground 'u-vm-color-citation-1-face "cyan")
(set-face-foreground 'u-vm-color-citation-2-face "lime green")
(set-face-foreground 'u-vm-color-citation-3-face "blue")
(set-face-foreground 'u-vm-color-citation-4-face "dark slate gray")
(set-face-foreground 'u-vm-color-citation-5-face "dark slate blue")
(set-face-foreground 'u-vm-color-signature-face  "gray30")

Happy font-locked emailing!

4 thoughts on “emacs font-lock faces for composing email

  1. Thanks a lot for this howto, very useful!
    Could give an advice on how to enable automatic long-line truncation in emacs in pine? This doesn’t work by default and I couldn’t figure out how to make it work :(  (btw, vim works “out of the box”).


  2. sure! you want auto-fill-mode. you can turn it on with M-x auto-fill-mode. to turn it on automatically in pine buffers, add (auto-fill-mode) after the (u-vm-color-fontify-buffer) line in the code snippet.

  3. Ryan, thank you, i tried that but it doesn’t really work: what I obtain with this option is a backslash token at the ends of the lines. If I enable “truncate-long-lines”, then I get a single long line with dollar tokens at the right margin of the terminal. I found a work around: M-x set-justification-left, which formats a selected portion of the text or the whole buffer, but that is not very convenient (I would like emacs to do that automatically).

    One last note: when I enable the auto-fill-mode in .emacs file, I get the expected behavior on regular text files (not inside Pine).

    Do you have any idea how to fix that?

    Thanks a lot for your help.

  4. it sounds like your fill-column variable is larger than your emacs’ width. figure out how many columns wide your emacs is, pick a number smaller than that, then do C-u [number] M-x set-fill-column.

    as for auto-fill-mode, you want it inside the lambda, ie inside the close parentheses. the last two lines should look like this:


Leave a Reply

Your email address will not be published.