Function: mh-read-draft

mh-read-draft is a byte-compiled function defined in mh-comp.el.gz.

Signature

(mh-read-draft USE INITIAL-CONTENTS DELETE-CONTENTS-FILE)

Documentation

Read draft file into a draft buffer and make that buffer the current one.

USE is a message used for prompting about the intended use of the message. INITIAL-CONTENTS is filename that is read into an empty buffer, or nil if buffer should not be modified. Delete the initial-contents file if DELETE-CONTENTS-FILE flag is set. Returns the draft folder's name. If the draft folder facility is enabled in ~/.mh_profile, a new buffer is used each time and saved in the draft folder. The draft file can then be reused.

Source Code

;; Defined in /usr/src/emacs/lisp/mh-e/mh-comp.el.gz
(defun mh-read-draft (use initial-contents delete-contents-file)
  "Read draft file into a draft buffer and make that buffer the current one.

USE is a message used for prompting about the intended use of the
message.
INITIAL-CONTENTS is filename that is read into an empty buffer, or nil
if buffer should not be modified. Delete the initial-contents file if
DELETE-CONTENTS-FILE flag is set.
Returns the draft folder's name.
If the draft folder facility is enabled in ~/.mh_profile, a new buffer
is used each time and saved in the draft folder. The draft file can
then be reused."
  (cond (mh-draft-folder
         (let ((orig-default-dir default-directory)
               (draft-file-name (mh-new-draft-name)))
           (pop-to-buffer (generate-new-buffer
                           (format "draft-%s"
                                   (file-name-nondirectory draft-file-name))))
           (condition-case ()
               (insert-file-contents draft-file-name t)
             (file-error))
           (setq default-directory orig-default-dir)))
        (t
         (let ((draft-name (expand-file-name "draft" mh-user-path)))
           (pop-to-buffer "draft")      ; Create if necessary
           (if (buffer-modified-p)
               (if (y-or-n-p "Draft has been modified; kill anyway? ")
                   (set-buffer-modified-p nil)
                 (error "Draft preserved")))
           (setq buffer-file-name draft-name)
           (clear-visited-file-modtime)
           (unlock-buffer)
           (cond ((and (file-exists-p draft-name)
                       (not (equal draft-name initial-contents)))
                  (insert-file-contents draft-name)
                  (delete-file draft-name))))))
  (cond ((and initial-contents
              (or (zerop (buffer-size))
                  (if (y-or-n-p
                       (format "A draft exists.  Use for %s? " use))
                      (if mh-error-if-no-draft
                          (error "A prior draft exists"))
                    t)))
         (erase-buffer)
         (insert-file-contents initial-contents)
         (if delete-contents-file (delete-file initial-contents))))
  (auto-save-mode 1)
  (if mh-draft-folder
      (save-buffer))                    ; Do not reuse draft name
  (buffer-name))