mutt inside emacs

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:

(autoload 'post-mode "post" "mode for e-mail" t)
(add-to-list 'auto-mode-alist
'("\\.*mutt-*\\|.article\\|\\.followup"
. post-mode))

This will automatically load post-mode when editing a message from mutt (and for some other programs). You might also want to set up some other things when editing mails, using a hook:
(add-hook 'post-mode-hook 
(lambda()
(auto-fill-mode t)
(setq fill-column 72) ; rfc 1855 for usenet messages
(require 'footnote-mode)
(footmode-mode t)
(require 'boxquote)))

Obviously, you need to install the boxquote and footnode modes, if you want to use those.

Final note: this same setup works nicely for the slrn news reader as well; just use the set editor_command= in your .slrnrc.

No comments:

Post a Comment

Followers

Popular Posts