2009-01-14

There are some emacs-native programs for e-mail, such as gnus, vm and a couple of others. I never really got into them for some reason; I found them rather hard to set up and a bit counter-intuitive. Maybe I should give them another try, but for the last decade, I've been using the mutt console e-mail client - even with graphical alternatives like Evolution and Thunderbird available.

mutt is not perfect -- you cannot read older e-mails when composing a new one (without starting a new instance) and the macro language is a joke compared to elisp. Still, because it's totally keyboard-driven, I'm really efficient with mutt. Side note: if you need quick searching capability which can be integrated with mutt, see my mu search tool.

Mutt does not have a built-in editor -- instead, it relies on an external program. Obviously, I use emacs for that. Now, I don't want to start a new emacs for each new message that I write; instead I make use of the emacs server functionality. Practically, we can start an emacs server by adding to .emacs:

(server-start)

Now, we can open files in the existing emacs by calling emacsclient instead of emacs; and tell mutt to use that editor. Put in your .muttrc:

set editor="emacsclient +8 %s -a emacs"

This opens new messages in an existing emacs, and put the cursor on line 8 (after the mail headers). If no emacs is running yet, a new one will be started, due to the '-a'-argument.

This solution will work nicely, but requires you to start mutt in a console, and start emacs in a separate window. I prefer, however, to run everything inside emacs. This can easily be done - please look at the 'running console programs inside emacs'-entry again, to create a short-cut.

Now, when editing e-mail messages, it's nice to use one the special modes for that; they provide some interesting 'syntax highlighting' to your mail. You can use mail-mode, or my favorite, post-mode. To automatically use it, download and install it, and add some code to your .emacs:

12 comments:

20y.hu: When speaking about "emacs --deamon" it would be a good idea to mention that it is only available in the development version of Emacs. So the answer to your "why not" question might be that the feature doesn't exist in any released Emacs version.

I didn't know about these handy modes, thanks. A note: footnote is misspelled in the second code listing (footmode-mode t) and the long link at the end (footnode mode). Might I suggest another great mode, flyspell-mode? ;) (Sarcasm unintended)

I'm trying to run mutt within emacs. I've tried using both ansi-term and multi-term. mutt loads fine, but whenever I press a key to perform any action, the cursor jumps to the end of the line, which emacs then centres in the frame, so that I can only see the right half of mutt. This only seems to happen with mutt, not any other terminal application. I don't suppose you have any idea what might cause this or how to fix it?