Compose Mail with Emacs

exmh can integrate with the gnuclient application that lets you load your mail draft into emacs from exmh. Simply set your editor preference to

 emacsclient &

or

 gnuclient &

If you can send an email from these interfaces, preface the command with "give-away"

 give-away emacsclient
 give-away gnuclient

There are probably multiple ways to do this. If so, add 'em here.

This is how *I* compose mail with Emacs. This is a conglomeration of code and ideas that I got from Leo Zelevisnky <leo@cs.umass.edu>. I don't claim to fully understand it; but it works for me.

      give-away /PATH/TO/MY/CODE/HERE/mh-gnu
      #!/bin/sh
      #
      # From Leo Zelevinsky <leo@cs.umass.edu>
      #

      if test "$mhannotate"
      then
        /usr/local/bin/gnudoit -q "(my-mh-edit-draft \"$1\" \"$mhfolder\" $mhmessages \"$mhannotate\")"
      else
        /usr/local/bin/gnuclient -q $*
      fi
      ;;
      ;; From Leo Zelevinsky <leo@cs.umass.edu>
      ;;
      (defun my-mh-edit-draft (fname sf-folder sf-msg af)
        (server-edit-files-quickly (list (cons 1 . (fname))))
        (end-of-line)
        (let ((rgexp (concat mh-user-path "\\(.*\\)")))
          (string-match rgexp sf-folder)
          (setq mh-sent-from-folder (concat "+" (match-string 1 sf-folder)))
          (setq mh-sent-from-msg sf-msg)
          (setq mh-annotate-field af)
          (setq mh-annotate-char "*")))
      ;;
      ;; End of stuff from Leo Z.
      ;;

As I said, it isn't the prettiest and I don't fully understand it - but it works for me.

- Bill Benedetto <bbenedetto@goodyear.com>


Ben Escoto's web page on Exmh/(X)Emacs Integration can be found here http://www.stanford.edu/~bescoto/ExmhEmacs/


My setup at the elisp level is (see ftp://ftp.kanga.nu/pub/users/claw/dot/xemacs):

  ; -*- Mode: Emacs-Lisp -*-
  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  ;;; Make Emacs go into mh-letter mode when editing messages
  (pushnew '("/Mail/Drafts/" . mh-letter-mode) auto-mode-alist)
  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  ;;; Add some shortcuts to mh-letter mode so I can send messages,
  ;;; PGP encrypt, etc, with a few keystrokes
  (add-hook 'mh-letter-mode-hook
          #'(lambda ()
               (local-set-key "\C-c\C-t" 'my-save-and-stop)
              (local-set-key "\C-c\C-y" 'my-quote)
              (local-set-key "\C-c\C-s" 'my-signature)
              (my-quote)
              (my-signature)
              )
          )
  (add-hook 'mh-letter-mode-hook
          (setq flyspell-generic-check-word-p 'mail-mode-flyspell-verify))
  (add-hook 'mh-letter-mode-hook 'flyspell-mode)
  ;;; Here are the functions that get bound
  (defun my-signature ()
    (interactive)
    (goto-char (point-max))
    (mh-insert-signature))
  (defun my-quote ()
    (interactive)
    (goto-char (point-max))
    (set-mark (point-max))
    (insert-file-contents "~/Mail/@")
    (goto-char (point-max))
    (exchange-point-and-mark)
    (sc-cite-original))
  (defun my-save-and-stop ()
    (interactive)
    (mh-send-letter)
    (delete-frame))
  ; Ripped off the font-lock stuff from mail-mode.  Would be nice if
  ; it handled different quote levels.
  (defvar mail-font-lock-keywords
    (eval-when-compile
      (let* ((cite-chars "[>|}]")
             (cite-prefix "[A-Za-z]")
             (cite-suffix (concat cite-prefix "0-9_.@-`'\"")))
        (list '("^\\(To\\|Newsgroups\\):" . font-lock-function-name-face)
              '("^\\(B?CC\\|Reply-to\\):" . font-lock-keyword-face)
              '("^\\(Subject:\\)[ \t]*\\(.+\\)?"
                (1 font-lock-comment-face) (2 font-lock-type-face nil t))
              ;; Use EVAL to delay in case `mail-header-separator' gets changed.
              '(eval .
                   (let ((separator (if (zerop (length mail-header-separator))
                                        " \\`\\' "
                                      (regexp-quote mail-header-separator))))
                     (cons (concat "^" separator "$") 'font-lock-warning-face)))
              ;; Use MATCH-ANCHORED to effectively anchor the regexp left side.
              `(,cite-chars
                (,(concat "\\=[ \t]*"
                          "\\(\\([" cite-prefix "]+[" cite-suffix "]*\\)?"
                          "\\(" cite-chars "[ \t]*\\)\\)+"
                          "\\(.*\\)")
                 (beginning-of-line) (end-of-line)
                 (2 font-lock-constant-face nil t)
                 (4 font-lock-comment-face nil t)))
              '("^\\(X-[A-Za-z0-9-]+\\|In-reply-to\\):.*"
                . font-lock-string-face))))
    "Additional expressions to highlight in Mail mode.")
  (put 'mh-letter-mode 'font-lock-defaults '(mail-font-lock-keywords t))
  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  ; This makes the mh-e features available, and is not specific to
  ; Exmh.
  (load-library "mh-e")
  ; This last part is for supercite.  It does not need to be specifically
  ; tailored to Exmh, but here is my configuration:
  (autoload 'sc-cite-original     "supercite" "Supercite 3.1" t)
  (setq sc-nested-citation-p t)
  (setq sc-reference-tag-string "")
  (setq sc-citation-delimiter ">")
  (setq sc-citation-leader "")
  (setq sc-nuke-mail-headers 'all)
  (setq sc-mail-warn-if-non-rfc822-p nil)
  (setq sc-citation-leader "")
  (setq sc-confirm-always-p nil)
  (defun my-sc-header ()
    (insert sc-reference-tag-string
  ;;    (sc-hdr "\"" (sc-mail-field "sc-attribution") "\" == ")
  ;;    (sc-hdr ""   (sc-mail-field "sc-author") " ")
  ;;    "\n" sc-reference-tag-string
  ;;    sc-reference-tag-string
      (sc-hdr "On " (sc-mail-field "date") " ")
      "\n"
      (sc-hdr ""   (sc-mail-field "sc-author") "")
      (or (sc-hdr " <" (sc-mail-field "sc-from-address") ">" t)
        (sc-hdr " <" (sc-mail-field "sc-reply-address") ">"  t)
      )
      " wrote:\n"
    )
  (setq sc-rewrite-header-list '((my-sc-header)))
  (setq sc-preferred-header-style 0)
  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  ; From Daniel Quinlan, quinlan@pleiades.cs.bucknell.edu and
  ;      Ethan Bradford, ethanb@u.washington.edu
  (defun ispell-message ()
    (interactive)
    "Check the spelling of a current mail message or news post.
     Don't check spelling of message headers or included messages."
    (let (start
        (cite-regexp                    ;Prefix of inserted text
         (concat "In article <\\|\\("
                 (if (featurep 'sc)
                     sc-cite-regexp
                   (regexp-quote mail-yank-prefix))
                 "\\)"))
        )
      (save-excursion
        (save-restriction
        (widen)
        ;; Make sure buffer ends with a newline.
        (goto-char (- (point-max) 1))
        (if (not (looking-at "$"))
            (progn
              (goto-char (point-max))
              (insert "\n")))
        (goto-char (point-min))
        (re-search-forward
         (concat "^" (regexp-quote mail-header-separator) "\n"))
        (while (not (eobp))
          (setq start (point))
          (re-search-forward
           (concat "^\\(" cite-regexp "\\)") nil 'end)
          (beginning-of-line)
          (save-excursion (ispell-region (- start 1) (point)))
          ;; save excursion and starting from start-1 are to get around
          ;; bugs in ispell-region
          (while (looking-at cite-regexp)
            (next-line 1)))))))
  ; Bindings that let you send or read mail using MH
  ;(global-set-key "\C-xm"  'mh-smail)
  ;(global-set-key "\C-x4m" 'mh-smail-other-window)
  ;(global-set-key "\C-cr"  'mh-rmail)
  ;; Customization of MH behavior.
  (setq mh-delete-yanked-msg-window t)
  (setq mh-yank-from-start-of-msg 'body)
  (setq mh-summary-height 11)
  ; Use lines like the following if your version of MH
  ; is in a special place.
  ;(setq mh-progs "/usr/dist/pkgs/mh/bin.svr4/")
  ;(setq mh-lib "/usr/dist/pkgs/mh/lib.svr4/")
  (load-file "~/.xemacs/e-mh-alias.el")

My Exmh setup can be found at: ftp://ftp.kanga.nu/pub/users/claw/dot/exmh with screenshots at ftp://ftp.kanga.nu/pub/user s/claw/screenshots/exmh -- J C Lawrence <claw@kanga.nu>


Updated on 12 Oct 2004, 02:57 GMT
Search - Recent Changes - Reference - Index - Go to Beedub's Wiki - Help