Mail Composition in New Frame

If you add the following to your .emacs, then MH-E will start composition of new drafts in a fresh frame. When C-c C-c is used to send the mail or C-c C-q is used to kill the draft the frame will get deleted as well. This code will become a part of the mh-e-contrib module soon!

;; Should we delete the frame?
(defvar mh-delete-mail-frame-flag nil
  "Non-nil means the mail composition frame is to be deleted.")

;; Frame creation advice...
(defmacro mh-advise-mh-frame-creation (func)
  "Advise FUNC to create new frames during MH message composition."
  `(defadvice ,func (around mh-new-frame activate)
     "Compose message in new frame."
     (select-frame (make-frame))
     (prog1 ad-do-it
       (set (make-variable-buffer-local 'mh-delete-mail-frame-flag) t)
       (delete-other-windows))))

;; Frame deletion advice...
(defmacro mh-advise-mh-frame-deletion (func)
  "Advise FUNC to delete frame after execution."
  `(defadvice ,func (around mh-delete-frame activate)
     "Delete frame if the draft buffer doesn't exist anymore."
     (let ((buffer-name (buffer-name))
           (delete-frame-flag mh-delete-mail-frame-flag))
       (prog1 ad-do-it
         (when (and delete-frame-flag (not (equal (buffer-name) buffer-name)))
           (delete-frame))))))

;; Advise the appropriate functions...
(mh-advise-mh-frame-creation mh-send)
(mh-advise-mh-frame-creation mh-reply)
(mh-advise-mh-frame-creation mh-forward)
(mh-advise-mh-frame-creation mh-edit-again)
(mh-advise-mh-frame-creation mh-extract-rejected-mail)
(mh-advise-mh-frame-deletion mh-send-letter)
(mh-advise-mh-frame-deletion mh-fully-kill-draft)

Satyaki Das
Last modified: Wed May 7 15:30:21 PDT 2003