]> code.delx.au - gnu-emacs/blobdiff - lisp/mh-e/mh-utils.el
* mh-customize.el: Sync docstrings with manual for faces and sort them
[gnu-emacs] / lisp / mh-e / mh-utils.el
index b589b63b597dc79e4f9629e0d3fa7cf331380968..e008c93916eb6c056cd42241a8e6685269db8595 100644 (file)
 (defvar font-lock-defaults)
 (defvar mark-active)
 
+\f
+
 ;;; Autoloads
+
 (autoload 'gnus-article-highlight-citation "gnus-cite")
 (autoload 'message-fetch-field "message")
 (autoload 'message-tokenize-header "message")
 (unless (fboundp 'make-hash-table)
   (autoload 'make-hash-table "cl"))
 
+\f
+
 ;;; CL Replacements
+
 (defun mh-search-from-end (char string)
   "Return the position of last occurrence of CHAR in STRING.
-If CHAR is not present in STRING then return nil. The function is used in lieu
-of `search' in the CL package."
+If CHAR is not present in STRING then return nil. The function is
+used in lieu of `search' in the CL package."
   (loop for index from (1- (length string)) downto 0
         when (equal (aref string index) char) return index
         finally return nil))
 
-;;; Additional header fields that might someday be added:
-;;; "Sender: " "Reply-to: "
+;; Additional header fields that might someday be added:
+;; "Sender: " "Reply-to: "
 
 \f
+
 ;;; Scan Line Formats
 
 (defvar mh-scan-msg-number-regexp "^ *\\([0-9]+\\)"
-  "This regexp is used to extract the message number from a scan line.
-Note that the message number must be placed in a parenthesized expression as
-in the default of \"^ *\\\\([0-9]+\\\\)\".")
+  "This regular expression extracts the message number.
+
+It must match from the beginning of the line. Note that the
+message number must be placed in a parenthesized expression as in
+the default of \"^ *\\\\([0-9]+\\\\)\".")
 
 (defvar mh-scan-msg-overflow-regexp "^[?0-9][0-9]"
-  "This regexp matches scan lines in which the message number overflowed.")
+  "This regular expression matches overflowed message numbers.")
 
 (defvar mh-scan-msg-format-regexp "%\\([0-9]*\\)(msg)"
-  "This regexp is used to find the message number width in a scan format.
-Note that the message number must be placed in a parenthesized expression as
-in the default of \"%\\\\([0-9]*\\\\)(msg)\".")
+  "This regular expression finds the message number width in a scan format.
+
+Note that the message number must be placed in a parenthesized
+expression as in the default of \"%\\\\([0-9]*\\\\)(msg)\". This
+variable is only consulted if `mh-scan-format-file' is set to
+\"Use MH-E scan Format\".")
 
 (defvar mh-scan-msg-format-string "%d"
   "This is a format string for width of the message number in a scan format.
-Use `0%d' for zero-filled message numbers.")
+
+Use \"0%d\" for zero-filled message numbers. This variable is only
+consulted if `mh-scan-format-file' is set to \"Use MH-E scan
+Format\".")
 
 (defvar mh-scan-msg-search-regexp "^[^0-9]*%d[^0-9]"
-  "This format string regexp matches the scan line for a particular message.
-Use `%d' to represent the location of the message number within the
-expression as in the default of \"^[^0-9]*%d[^0-9]\".")
+  "This regular expression matches a particular message.
+
+It is a format string; use \"%d\" to represent the location of the
+message number within the expression as in the default of
+\"^[^0-9]*%d[^0-9]\".")
 
 (defvar mh-cmd-note 4
-  "This is the number of characters to skip over before inserting notation.
-This variable should be set with the function `mh-set-cmd-note'. This variable
-may be updated dynamically if `mh-adaptive-cmd-note-flag' is non-nil and
-`mh-scan-format-file' is t.")
+  "Column for notations.
+
+This variable should be set with the function `mh-set-cmd-note'.
+This variable may be updated dynamically if
+`mh-adaptive-cmd-note-flag' is on.
+
+Note that columns in Emacs start with 0.")
 (make-variable-buffer-local 'mh-cmd-note)
 
 (defvar mh-note-seq ?%
   "Messages in a user-defined sequence are marked by this character.
-Messages in the `search' sequence are marked by this character as well.")
+
+Messages in the \"search\" sequence are marked by this character as
+well.")
 
 \f
 
 (defvar mh-show-buffer-mode-line-buffer-id "    {show-%s} %d"
   "Format string to produce `mode-line-buffer-identification' for show buffers.
-First argument is folder name.  Second is message number.")
+
+First argument is folder name. Second is message number.")
 
 \f
 
 (defvar mh-mail-header-separator "--------"
   "*Line used by MH to separate headers from text in messages being composed.
-This variable should not be used directly in programs. Programs should use
-`mail-header-separator' instead. `mail-header-separator' is initialized to
-`mh-mail-header-separator' in `mh-letter-mode'; in other contexts, you may
-have to perform this initialization yourself.
 
-Do not make this a regexp as it may be the argument to `insert' and it is
-passed through `regexp-quote' before being used by functions like
-`re-search-forward'.")
+This variable should not be used directly in programs. Programs
+should use `mail-header-separator' instead.
+`mail-header-separator' is initialized to
+`mh-mail-header-separator' in `mh-letter-mode'; in other
+contexts, you may have to perform this initialization yourself.
+
+Do not make this a regular expression as it may be the argument
+to `insert' and it is passed through `regexp-quote' before being
+used by functions like `re-search-forward'.")
 
 (defvar mh-signature-separator-regexp "^-- $"
-  "Regexp used to find signature separator.
+  "This regular expression matches the signature separator.
 See `mh-signature-separator'.")
 
 (defvar mh-signature-separator "-- \n"
   "Text of a signature separator.
-A signature separator is used to separate the body of a message from the
-signature. This can be used by user agents such as MH-E to render the
-signature differently or to suppress the inclusion of the signature in a
-reply.
-Use `mh-signature-separator-regexp' when searching for a separator.")
+
+A signature separator is used to separate the body of a message
+from the signature. This can be used by user agents such as MH-E
+to render the signature differently or to suppress the inclusion
+of the signature in a reply. Use `mh-signature-separator-regexp'
+when searching for a separator.")
 
 (defun mh-signature-separator-p ()
   "Return non-nil if buffer includes \"^-- $\"."
@@ -167,7 +193,8 @@ Use `mh-signature-separator-regexp' when searching for a separator.")
                                         ; this number
   (part-index-hash (make-hash-table)))  ; Avoid incrementing the part number
                                         ; for nested messages
-;;; This has to be a macro, since we do: (setf (mh-buffer-data) ...)
+
+;; This has to be a macro, since we do: (setf (mh-buffer-data) ...)
 (defmacro mh-buffer-data ()
   "Convenience macro to get the MIME data structures of the current buffer."
   `(gethash (current-buffer) mh-globals-hash))
@@ -175,8 +202,8 @@ Use `mh-signature-separator-regexp' when searching for a separator.")
 (defvar mh-globals-hash (make-hash-table)
   "Keeps track of MIME data on a per buffer basis.")
 
-(defvar mh-gnus-pgp-support-flag (not (not (locate-library "mml2015")))
-  "Non-nil means installed Gnus has PGP support.")
+(defvar mh-pgp-support-flag (not (not (locate-library "mml2015")))
+  "Non-nil means PGP support is available.")
 
 (defvar mh-mm-inline-media-tests
   `(("image/jpeg"
@@ -276,8 +303,9 @@ Use `mh-signature-separator-regexp' when searching for a separator.")
 
 (defun mh-goto-address-find-address-at-point ()
   "Find e-mail address around or before point.
-Then search backwards to beginning of line for the start of an e-mail
-address.  If no e-mail address found, return nil."
+
+Then search backwards to beginning of line for the start of an
+e-mail address. If no e-mail address found, return nil."
   (re-search-backward "[^-_A-z0-9.@]" (line-beginning-position) 'lim)
   (if (or (looking-at mh-address-mail-regexp)  ; already at start
          (and (re-search-forward mh-address-mail-regexp
@@ -287,8 +315,10 @@ address.  If no e-mail address found, return nil."
 
 (defun mh-mail-header-end ()
   "Substitute for `mail-header-end' that doesn't widen the buffer.
-In MH-E we frequently need to find the end of headers in nested messages, where
-the buffer has been narrowed. This function works in this situation."
+
+In MH-E we frequently need to find the end of headers in nested
+messages, where the buffer has been narrowed. This function works
+in this situation."
   (save-excursion
     ;; XXX: The following replaces a call to rfc822-goto-eoh. Occasionally,
     ;; mail headers that MH-E has to read contains lines of the form:
@@ -372,18 +402,30 @@ Argument LIMIT limits search."
 (eval-and-compile
   ;; Otherwise byte-compilation fails on `mh-show-font-lock-keywords-with-cite'
   (defvar mh-show-font-lock-keywords
-    '(("^\\(From:\\|Sender:\\)\\(.*\\)"  (1 'default) (2 mh-show-from-face))
-      (mh-header-to-font-lock            (0 'default) (1 mh-show-to-face))
-      (mh-header-cc-font-lock            (0 'default) (1 mh-show-cc-face))
+    '(("^\\(From:\\|Sender:\\)\\(.*\\)"
+       (1 'default)
+       (2 'mh-show-from))
+      (mh-header-to-font-lock
+       (0 'default)
+       (1 'mh-show-to))
+      (mh-header-cc-font-lock
+       (0 'default)
+       (1 'mh-show-cc))
       ("^\\(Reply-To:\\|Return-Path:\\)\\(.*\\)$"
-       (1 'default) (2 mh-show-from-face))
-      (mh-header-subject-font-lock       (0 'default) (1 mh-show-subject-face))
+       (1 'default)
+       (2 'mh-show-from))
+      (mh-header-subject-font-lock
+       (0 'default)
+       (1 'mh-show-subject))
       ("^\\(Apparently-To:\\|Newsgroups:\\)\\(.*\\)"
-       (1 'default) (2 mh-show-cc-face))
+       (1 'default)
+       (2 'mh-show-cc))
       ("^\\(In-reply-to\\|Date\\):\\(.*\\)$"
-       (1 'default) (2 mh-show-date-face))
-      (mh-letter-header-font-lock        (0 mh-show-header-face append t)))
-    "Additional expressions to highlight in MH-show mode."))
+       (1 'default)
+       (2 'mh-show-date))
+      (mh-letter-header-font-lock
+       (0 'mh-show-header append t)))
+    "Additional expressions to highlight in MH-Show buffers."))
 
 (defvar mh-show-font-lock-keywords-with-cite
   (eval-when-compile
@@ -402,18 +444,22 @@ Argument LIMIT limits search."
            (beginning-of-line) (end-of-line)
            (2 font-lock-constant-face nil t)
            (4 font-lock-comment-face nil t)))))))
-  "Additional expressions to highlight in MH-show mode.")
+  "Additional expressions to highlight in MH-Show buffers.")
 
 (defvar mh-letter-font-lock-keywords
   `(,@mh-show-font-lock-keywords-with-cite
-    (mh-font-lock-field-data (1 'mh-letter-header-field prepend t))))
+    (mh-font-lock-field-data
+     (1 'mh-letter-header-field prepend t)))
+  "Additional expressions to highlight in MH-Letter buffers.")
 
 (defun mh-show-font-lock-fontify-region (beg end loudly)
   "Limit font-lock in `mh-show-mode' to the header.
-Used when `mh-highlight-citation-p' is set to gnus, leaving the body to be
-dealt with by gnus highlighting. The region between BEG and END is
-given over to be fontified and LOUDLY controls if a user sees a
-message about the fontification operation."
+
+Used when the option `mh-highlight-citation-style' is set to
+\"Gnus\", leaving the body to be dealt with by Gnus highlighting.
+The region between BEG and END is given over to be fontified and
+LOUDLY controls if a user sees a message about the fontification
+operation."
   (let ((header-end (mh-mail-header-end)))
     (cond
      ((and (< beg header-end)(< end header-end))
@@ -432,7 +478,7 @@ message about the fontification operation."
         (require 'gnus-cite))))
 
 (defun mh-gnus-article-highlight-citation ()
-  "Highlight cited text in current buffer using gnus."
+  "Highlight cited text in current buffer using Gnus."
   (interactive)
   ;; Requiring gnus-cite should have been sufficient. However for Emacs21.1,
   ;; recursive-load-depth-limit is only 10, so an error occurs. Also it may be
@@ -452,30 +498,31 @@ message about the fontification operation."
       (gnus-article-highlight-citation t)
       (set-buffer-modified-p modified))))
 
+\f
+
 ;;; Internal bookkeeping variables:
 
-;; Cached value of the `Path:' component in the user's MH profile.
-;; User's mail folder directory.
-(defvar mh-user-path nil)
+(defvar mh-user-path nil
+  "Cached value of the \"Path:\" MH profile component.
+User's mail folder directory.")
 
-;; An mh-draft-folder of nil means do not use a draft folder.
-;; Cached value of the `Draft-Folder:' component in the user's MH profile.
-;; Name of folder containing draft messages.
-(defvar mh-draft-folder nil)
+(defvar mh-draft-folder nil
+  "Cached value of the \"Draft-Folder:\" MH profile component.
+Name of folder containing draft messages.
+Nil means do not use a draft folder.")
 
-;; Cached value of the `Unseen-Sequence:' component in the user's MH profile.
-;; Name of the Unseen sequence.
-(defvar mh-unseen-seq nil)
+(defvar mh-unseen-seq nil
+  "Cached value of the \"Unseen-Sequence:\" MH profile component.
+Name of the Unseen sequence.")
 
-;; Cached value of the `Previous-Sequence:' component in the user's MH
-;; profile.
-;; Name of the Previous sequence.
-(defvar mh-previous-seq nil)
+(defvar mh-previous-seq nil
+  "Cached value of the \"Previous-Sequence:\" MH profile component.
+Name of the Previous sequence.")
 
-;; Cached value of the `Inbox:' component in the user's MH profile,
-;; or "+inbox" if no such component.
-;; Name of the Inbox folder.
-(defvar mh-inbox nil)
+(defvar mh-inbox nil
+  "Cached value of the \"Inbox:\" MH profile component.
+Set to \"+inbox\" if no such component.
+Name of the Inbox folder.")
 
 ;; The names of ephemeral buffers have a " *mh-" prefix (so that they are
 ;; hidden and can be programmatically removed in mh-quit), and the variable
@@ -496,31 +543,33 @@ message about the fontification operation."
 (defconst mh-recipients-buffer "*MH-E Recipients*") ;killed when draft sent
 (defconst mh-sequences-buffer "*MH-E Sequences*") ;sequences list
 
-;; Number of lines to keep in mh-log-buffer.
-(defvar mh-log-buffer-lines 100)
+(defvar mh-log-buffer-lines 100
+  "Number of lines to keep in `mh-log-buffer'.")
+
+(defvar mh-previous-window-config nil
+  "Window configuration before MH-E command.")
 
-;; Window configuration before MH-E command.
-(defvar mh-previous-window-config nil)
+(defvar mh-page-to-next-msg-flag nil
+  "Non-nil means next SPC or whatever goes to next undeleted message.")
 
-;;Non-nil means next SPC or whatever goes to next undeleted message.
-(defvar mh-page-to-next-msg-flag nil)
+\f
 
 ;;; Internal variables local to a folder.
 
-;; Name of current folder, a string.
-(defvar mh-current-folder nil)
+(defvar mh-current-folder nil
+  "Name of current folder, a string.")
 
-;; Buffer that displays message for this folder.
-(defvar mh-show-buffer nil)
+(defvar mh-show-buffer nil
+  "Buffer that displays message for this folder.")
 
-;; Full path of directory for this folder.
-(defvar mh-folder-filename nil)
+(defvar mh-folder-filename nil
+  "Full path of directory for this folder.")
 
-;;Number of msgs in buffer.
-(defvar mh-msg-count nil)
+(defvar mh-msg-count nil
+  "Number of msgs in buffer.")
 
-;; If non-nil, show the message in a separate window.
-(defvar mh-showing-mode nil)
+(defvar mh-showing-mode nil
+  "If non-nil, show the message in a separate window.")
 
 (defvar mh-show-mode-map (make-sparse-keymap)
   "Keymap used by the show buffer.")
@@ -549,25 +598,27 @@ message about the fontification operation."
             (cons modeline-buffer-id-left-extent "XEmacs%N:"))
           (cons modeline-buffer-id-right-extent " %17b")))))
 
-;;; This holds a documentation string used by describe-mode.
 (defun mh-showing-mode (&optional arg)
   "Change whether messages should be displayed.
-With arg, display messages iff ARG is positive."
+
+With ARG, display messages iff ARG is positive."
   (setq mh-showing-mode
         (if (null arg)
             (not mh-showing-mode)
           (> (prefix-numeric-value arg) 0))))
 
-;; The sequences of this folder.  An alist of (seq . msgs).
-(defvar mh-seq-list nil)
+(defvar mh-seq-list nil
+  "Alist of this folder's sequences.
+Elements have the form (SEQUENCE . MESSAGES).")
 
-;; List of displayed messages to be removed from the Unseen sequence.
-(defvar mh-seen-list nil)
+(defvar mh-seen-list nil
+  "List of displayed messages to be removed from the \"Unseen\" sequence.")
 
-;; If non-nil, show buffer contains message with all headers.
-;; If nil, show buffer contains message processed normally.
-;; Showing message with headers or normally.
-(defvar mh-showing-with-headers nil)
+(defvar mh-showing-with-headers nil
+  "If non-nil, MH-Show buffer contains message with all header fields.
+If nil, MH-Show buffer contains message processed normally.")
+
+\f
 
 ;;; MH-E macros
 
@@ -575,8 +626,8 @@ With arg, display messages iff ARG is positive."
   "Format is (with-mh-folder-updating (SAVE-MODIFICATION-FLAG) &body BODY).
 Execute BODY, which can modify the folder buffer without having to
 worry about file locking or the read-only flag, and return its result.
-If SAVE-MODIFICATION-FLAG is non-nil, the buffer's modification
-flag is unchanged, otherwise it is cleared."
+If SAVE-MODIFICATION-FLAG is non-nil, the buffer's modification flag
+is unchanged, otherwise it is cleared."
   (setq save-modification-flag (car save-modification-flag)) ; CL style
   `(prog1
        (let ((mh-folder-updating-mod-flag (buffer-modified-p))
@@ -608,8 +659,9 @@ Stronger than `save-excursion', weaker than `save-window-excursion'."
 
 (defmacro mh-do-at-event-location (event &rest body)
   "Switch to the location of EVENT and execute BODY.
-After BODY has been executed return to original window. The modification flag
-of the buffer in the event window is preserved."
+After BODY has been executed return to original window. The
+modification flag of the buffer in the event window is
+preserved."
   (let ((event-window (make-symbol "event-window"))
         (event-position (make-symbol "event-position"))
         (original-window (make-symbol "original-window"))
@@ -653,9 +705,12 @@ of the buffer in the event window is preserved."
 
 (defun mh-recenter (arg)
   "Like recenter but with three improvements:
+
 - At the end of the buffer it tries to show fewer empty lines.
+
 - operates only if the current buffer is in the selected window.
   (Commands like `save-some-buffers' can make this false.)
+
 - nil ARG means recenter as if prefix argument had been given."
   (cond ((not (eq (get-buffer-window (current-buffer)) (selected-window)))
          nil)
@@ -699,8 +754,8 @@ of the buffer in the event window is preserved."
 
 (defun mh-get-msg-num (error-if-no-message)
   "Return the message number of the displayed message.
-If the argument ERROR-IF-NO-MESSAGE is non-nil, then complain if the cursor is
-not pointing to a message."
+If the argument ERROR-IF-NO-MESSAGE is non-nil, then complain if
+the cursor is not pointing to a message."
   (save-excursion
     (beginning-of-line)
     (cond ((looking-at mh-scan-msg-number-regexp)
@@ -712,7 +767,8 @@ not pointing to a message."
 
 (defun mh-folder-name-p (name)
   "Return non-nil if NAME is the name of a folder.
-A name (a string or symbol) can be a folder name if it begins with \"+\"."
+A name (a string or symbol) can be a folder name if it begins
+with \"+\"."
   (if (symbolp name)
       (eq (aref (symbol-name name) 0) ?+)
     (and (> (length name) 0)
@@ -735,17 +791,17 @@ See `expand-file-name' for description of DEFAULT."
                         (mh-expand-file-name folder)
                       mh-folder-filename)))
 
-;;; Infrastructure to generate show-buffer functions from folder functions
-;;; XEmacs does not have deactivate-mark? What is the equivalent of
-;;; transient-mark-mode for XEmacs? Should we be restoring the mark in the
-;;; folder buffer after the operation has been carried out.
+;; Infrastructure to generate show-buffer functions from folder functions
+;; XEmacs does not have deactivate-mark? What is the equivalent of
+;; transient-mark-mode for XEmacs? Should we be restoring the mark in the
+;; folder buffer after the operation has been carried out.
 (defmacro mh-defun-show-buffer (function original-function
                                          &optional dont-return)
   "Define FUNCTION to run ORIGINAL-FUNCTION in folder buffer.
-If the buffer we start in is still visible and DONT-RETURN is nil then switch
-to it after that."
+If the buffer we start in is still visible and DONT-RETURN is nil
+then switch to it after that."
   `(defun ,function ()
-     ,(format "Calls %s from the message's folder.\n%s\nSee `%s' for more info.\n"
+     ,(format "Calls %s from the message's folder.\n%s\nSee \"%s\" for more info.\n"
               original-function
               (if dont-return ""
                 "When function completes, returns to the show buffer if it is
@@ -779,8 +835,8 @@ still visible.\n")
                                            (get-buffer cur-buffer-name))))
                       (pop-to-buffer (get-buffer cur-buffer-name) nil)))))))))
 
-;;; Generate interactive functions for the show buffer from the corresponding
-;;; folder functions.
+;; Generate interactive functions for the show buffer from the corresponding
+;; folder functions.
 (mh-defun-show-buffer mh-show-previous-undeleted-msg
                       mh-previous-undeleted-msg)
 (mh-defun-show-buffer mh-show-next-undeleted-msg
@@ -870,17 +926,18 @@ still visible.\n")
 (mh-defun-show-buffer mh-show-index-sequenced-messages
                       mh-index-sequenced-messages)
 (mh-defun-show-buffer mh-show-catchup mh-catchup)
-(mh-defun-show-buffer mh-show-ps-print-toggle-mime mh-ps-print-toggle-mime)
 (mh-defun-show-buffer mh-show-ps-print-toggle-color mh-ps-print-toggle-color)
 (mh-defun-show-buffer mh-show-ps-print-toggle-faces mh-ps-print-toggle-faces)
 (mh-defun-show-buffer mh-show-ps-print-msg-file mh-ps-print-msg-file)
 (mh-defun-show-buffer mh-show-ps-print-msg mh-ps-print-msg)
-(mh-defun-show-buffer mh-show-ps-print-msg-show mh-ps-print-msg-show)
 (mh-defun-show-buffer mh-show-toggle-mime-buttons mh-toggle-mime-buttons)
 (mh-defun-show-buffer mh-show-display-with-external-viewer
                       mh-display-with-external-viewer)
 
-;;; Populate mh-show-mode-map
+\f
+
+;;; Build mh-show-mode keymaps
+
 (gnus-define-keys mh-show-mode-map
   " "    mh-show-page-msg
   "!"    mh-show-refile-or-write-again
@@ -958,14 +1015,11 @@ still visible.\n")
 
 (gnus-define-keys (mh-show-ps-print-map "P" mh-show-mode-map)
   "?"  mh-prefix-help
-  "A"  mh-show-ps-print-toggle-mime
   "C"  mh-show-ps-print-toggle-color
   "F"  mh-show-ps-print-toggle-faces
-  "M"  mh-show-ps-print-toggle-mime
   "f"  mh-show-ps-print-msg-file
   "l"   mh-show-print-msg
-  "p"  mh-show-ps-print-msg
-  "s"  mh-show-ps-print-msg-show)
+  "p"  mh-show-ps-print-msg)
 
 (gnus-define-keys (mh-show-thread-map "T" mh-show-mode-map)
   "?"    mh-prefix-help
@@ -1081,7 +1135,7 @@ still visible.\n")
     ["Quit MH-E"                        mh-quit t]))
 
 
-;;; Ensure new buffers won't get this mode if default-major-mode is nil.
+;; Ensure new buffers won't get this mode if default-major-mode is nil.
 (put 'mh-show-mode 'mode-class 'special)
 
 ;; Avoid compiler warnings in XEmacs and Emacs 20
@@ -1091,8 +1145,9 @@ still visible.\n")
 
 (define-derived-mode mh-show-mode text-mode "MH-Show"
   "Major mode for showing messages in MH-E.\\<mh-show-mode-map>
-The value of `mh-show-mode-hook' is a list of functions to
-be called, with no arguments, upon entry to this mode.
+
+The hook `mh-show-mode-hook' is called upon entry to this mode.
+
 See also `mh-folder-mode'.
 
 \\{mh-show-mode-map}"
@@ -1106,9 +1161,9 @@ See also `mh-folder-mode'.
   (make-local-variable 'font-lock-defaults)
   ;;(set (make-local-variable 'font-lock-support-mode) nil)
   (cond
-   ((equal mh-highlight-citation-p 'font-lock)
+   ((equal mh-highlight-citation-style 'font-lock)
     (setq font-lock-defaults '(mh-show-font-lock-keywords-with-cite t)))
-   ((equal mh-highlight-citation-p 'gnus)
+   ((equal mh-highlight-citation-style 'gnus)
     (setq font-lock-defaults '((mh-show-font-lock-keywords)
                                t nil nil nil
                                (font-lock-fontify-region-function
@@ -1120,7 +1175,7 @@ See also `mh-folder-mode'.
            font-lock-auto-fontify)
       (turn-on-font-lock))
   (set (make-local-variable 'tool-bar-map) mh-show-tool-bar-map)
-  (mh-funcall-if-exists mh-toolbar-init :show)
+  (mh-funcall-if-exists mh-tool-bar-init :show)
   (when mh-decode-mime-flag
     (mh-make-local-hook 'kill-buffer-hook)
     (add-hook 'kill-buffer-hook 'mh-mime-cleanup nil t))
@@ -1188,10 +1243,36 @@ See also `mh-folder-mode'.
 
 (mh-do-in-xemacs (defvar default-enable-multibyte-characters))
 
+(defmacro mh-face-foreground-compat (face &optional frame inherit)
+  "Return the foreground color name of FACE, or nil if unspecified.
+See documentation for `face-foreground' for a description of the
+arguments FACE, FRAME, and INHERIT.
+
+Calls `face-foreground' correctly in older environments. Versions
+of Emacs prior to version 22 lacked an INHERIT argument which
+when t tells `face-foreground' to consider an inherited value for
+the foreground if the face does not define one itself."
+  (if (>= emacs-major-version 22)
+      `(face-foreground ,face ,frame ,inherit)
+    `(face-foreground ,face ,frame)))
+
+(defmacro mh-face-background-compat (face &optional frame inherit)
+  "Return the background color name of face, or nil if unspecified.
+See documentation for `back-foreground' for a description of the
+arguments FACE, FRAME, and INHERIT.
+
+Calls `face-background' correctly in older environments. Versions
+of Emacs prior to version 22 lacked an INHERIT argument which
+when t tells `face-background' to consider an inherited value for
+the background if the face does not define one itself."
+  (if (>= emacs-major-version 22)
+      `(face-background ,face ,frame ,inherit)
+    `(face-background ,face ,frame)))
+
 (defun mh-face-display-function ()
   "Display a Face, X-Face, or X-Image-URL header field.
-If more than one of these are present, then the first one found in this order
-is used."
+If more than one of these are present, then the first one found
+in this order is used."
   (save-restriction
     (goto-char (point-min))
     (re-search-forward "\n\n" (point-max) t)
@@ -1218,9 +1299,11 @@ is used."
               (mh-funcall-if-exists
                insert-image (create-image
                              raw type t
-                             :foreground (face-foreground 'mh-show-xface)
-                             :background (face-background 'mh-show-xface))
-                            " ")))
+                             :foreground
+                             (mh-face-foreground-compat 'mh-show-xface nil t)
+                             :background
+                             (mh-face-background-compat 'mh-show-xface nil t))
+               " ")))
           ;; XEmacs
           (mh-do-in-xemacs
             (cond
@@ -1254,16 +1337,16 @@ is used."
 (defun mh-show-xface ()
   "Display X-Face."
   (when (and window-system mh-show-use-xface-flag
-             (or mh-decode-mime-flag mhl-formfile
+             (or mh-decode-mime-flag mh-mhl-format-file
                  mh-clean-message-header-flag))
     (funcall mh-show-xface-function)))
 
 \f
 
-;; Picon display
+;;; Picon display
 
-;;; XXX: This should be customizable. As a side-effect of setting this
-;;;   variable, arrange to reset mh-picon-existing-directory-list to 'unset.
+;; XXX: This should be customizable. As a side-effect of setting this
+;;   variable, arrange to reset mh-picon-existing-directory-list to 'unset.
 (defvar mh-picon-directory-list
   '("~/.picons" "~/.picons/users" "~/.picons/usenix" "~/.picons/news"
     "~/.picons/domains" "~/.picons/misc"
@@ -1357,9 +1440,9 @@ The directories are searched for in the order they appear in the list.")
 
 (defun mh-picon-file-contents (file)
   "Return details about FILE.
-A list of consisting of a symbol for the type of the file and the file
-contents as a string is returned. If FILE is nil, then both elements of the
-list are nil."
+A list of consisting of a symbol for the type of the file and the
+file contents as a string is returned. If FILE is nil, then both
+elements of the list are nil."
   (if (stringp file)
       (with-temp-buffer
         (let ((type (and (string-match ".*\\.\\(...\\)$" file)
@@ -1370,8 +1453,9 @@ list are nil."
 
 (defun mh-picon-generate-path (host-list user directory)
   "Generate the image file path.
-HOST-LIST is the parsed host address of the email address, USER the username
-and DIRECTORY is the directory relative to which the path is generated."
+HOST-LIST is the parsed host address of the email address, USER
+the username and DIRECTORY is the directory relative to which the
+path is generated."
   (loop with acc = ""
         for elem in host-list
         do (setq acc (format "%s/%s" elem acc))
@@ -1442,9 +1526,9 @@ Replace the ?/ character with a ?! character and append .png."
 
 (defun mh-x-image-url-fetch-image (url cache-file marker sentinel)
   "Fetch and display the image specified by URL.
-After the image is fetched, it is stored in CACHE-FILE. It will be displayed
-in a buffer and position specified by MARKER. The actual display is carried
-out by the SENTINEL function."
+After the image is fetched, it is stored in CACHE-FILE. It will
+be displayed in a buffer and position specified by MARKER. The
+actual display is carried out by the SENTINEL function."
   (if mh-wget-executable
       (let ((buffer (get-buffer-create (generate-new-buffer-name
                                         mh-temp-fetch-buffer)))
@@ -1556,24 +1640,24 @@ If optional arg MSG is non-nil, display that message instead."
   (if mh-showing-mode (mh-show msg)))
 
 (defun mh-show (&optional message redisplay-flag)
-  "Show message at cursor.
-If optional argument MESSAGE is non-nil, display that message instead.
-Force a two-window display with the folder window on top (size given by the
-variable `mh-summary-height') and the show buffer below it.
-If the message is already visible, display the start of the message.
-
-If REDISPLAY-FLAG is non-nil, the default when called interactively, the
-message is redisplayed even if the show buffer was already displaying the
-correct message.
-
-Display of the message is controlled by setting the variables
-`mh-clean-message-header-flag' and `mhl-formfile'.  The default behavior is
-to scroll uninteresting headers off the top of the window.
-Type \"\\[mh-header-display]\" to see the message with all its headers."
+  "Display message\\<mh-folder-mode-map>.
+
+If the message under the cursor is already displayed, this command
+scrolls to the beginning of the message. MH-E normally hides a lot of
+the superfluous header fields that mailers add to a message, but if
+you wish to see all of them, use the command \\[mh-header-display].
+
+From a program, optional argument MESSAGE can be used to display an
+alternative message. The optional argument REDISPLAY-FLAG forces the
+redisplay of the message even if the show buffer was already
+displaying the correct message.
+
+See the \"mh-show\" customization group for a litany of options that
+control what displayed messages look like."
   (interactive (list nil t))
   (when (or redisplay-flag
             (and mh-showing-with-headers
-                 (or mhl-formfile mh-clean-message-header-flag)))
+                 (or mh-mhl-format-file mh-clean-message-header-flag)))
     (mh-invalidate-show-buffer))
   (mh-show-msg message))
 
@@ -1593,8 +1677,9 @@ The current frame height is taken into consideration."
 
 (defun mh-show-msg (msg)
   "Show MSG.
-The value of `mh-show-hook' is a list of functions to be called, with no
-arguments, after the message has been displayed."
+
+The hook `mh-show-hook' is called after the message has been
+displayed."
   (if (not msg)
       (setq msg (mh-get-msg-num t)))
   (mh-showing-mode t)
@@ -1635,13 +1720,15 @@ arguments, after the message has been displayed."
     (run-hooks 'mh-show-hook)))
 
 (defun mh-modify (&optional message)
-  "Edit message at cursor.
-If optional argument MESSAGE is non-nil, edit that message instead.
-Force a two-window display with the folder window on top (size given by the
-value of the variable `mh-summary-height') and the message editing buffer below
-it.
+  "Edit message.
+
+There are times when you need to edit a message. For example, you
+may need to fix a broken Content-Type header field. You can do
+this with this command. It displays the raw message in an
+editable buffer. When you are done editing, save and kill the
+buffer as you would any other.
 
-The message is displayed in raw form."
+From a program, edit MESSAGE instead if it is non-nil."
   (interactive)
   (let* ((message (or message (mh-get-msg-num t)))
          (msg-filename (mh-msg-filename message))
@@ -1696,7 +1783,7 @@ Sets the current buffer to the show buffer."
     (unless (mh-buffer-data)
       (setf (mh-buffer-data) (mh-make-buffer-data)))
     ;; Bind variables in folder buffer in case they are local
-    (let ((formfile mhl-formfile)
+    (let ((formfile mh-mhl-format-file)
           (clean-message-header mh-clean-message-header-flag)
           (invisible-headers mh-invisible-header-fields-compiled)
           (visible-headers nil)
@@ -1718,6 +1805,8 @@ Sets the current buffer to the show buffer."
       (cond ((not (equal msg-filename buffer-file-name))
              (mh-unvisit-file)
              (setq buffer-read-only nil)
+             ;; Cleanup old mime handles
+             (mh-mime-cleanup)
              (erase-buffer)
              ;; Changing contents, so this hook needs to be reinitialized.
              ;; pgp.el uses this.
@@ -1729,8 +1818,6 @@ Sets the current buffer to the show buffer."
                                              (list "-form" formfile))
                                          msg-filename)
                (insert-file-contents-literally msg-filename))
-             ;; Cleanup old mime handles
-             (mh-mime-cleanup)
              ;; Use mm to display buffer
              (when (and mh-decode-mime-flag (not formfile))
                (mh-add-missing-mime-version-header)
@@ -1773,13 +1860,14 @@ Sets the current buffer to the show buffer."
 
 (defun mh-clean-msg-header (start invisible-headers visible-headers)
   "Flush extraneous lines in message header.
-Header is cleaned from START to the end of the message header.
-INVISIBLE-HEADERS contains a regular expression specifying lines to delete
-from the header. VISIBLE-HEADERS contains a regular expression specifying the
-lines to display. INVISIBLE-HEADERS is ignored if VISIBLE-HEADERS is non-nil.
 
-Note that MH-E no longer supports the `mh-visible-headers' variable, so
-this function could be trimmed of this feature too."
+Header is cleaned from START to the end of the message header.
+INVISIBLE-HEADERS contains a regular expression specifying lines
+to delete from the header. VISIBLE-HEADERS contains a regular
+expression specifying the lines to display. INVISIBLE-HEADERS is
+ignored if VISIBLE-HEADERS is non-nil."
+  ;; XXX Note that MH-E no longer supports the `mh-visible-headers'
+  ;; variable, so this function could be trimmed of this feature too."
   (let ((case-fold-search t)
         (buffer-read-only nil)
         (after-change-functions nil))   ;Work around emacs-20 font-lock bug
@@ -1822,8 +1910,10 @@ If NOTATION is nil then no change in the buffer occurs."
         (with-mh-folder-updating (t)
           (beginning-of-line)
           (forward-char offset)
-          (let* ((change-stack-flag (and (equal offset (1+ mh-cmd-note))
-                                         (not (eq notation mh-note-seq))))
+          (let* ((change-stack-flag
+                  (and (equal offset
+                              (+ mh-cmd-note mh-scan-field-destination-offset))
+                       (not (eq notation mh-note-seq))))
                  (msg (and change-stack-flag (or msg (mh-get-msg-num nil))))
                  (stack (and msg (gethash msg mh-sequence-notation-history)))
                  (notation (or notation (char-after))))
@@ -1843,17 +1933,22 @@ If NOTATION is nil then no change in the buffer occurs."
               (mh-thread-update-scan-line-map msg notation offset)))))))
 
 (defun mh-goto-msg (number &optional no-error-if-no-message dont-show)
-  "Position the cursor at message NUMBER.
-Optional non-nil second argument NO-ERROR-IF-NO-MESSAGE means return nil
-instead of signaling an error if message does not exist; in this case, the
-cursor is positioned near where the message would have been.
-Non-nil third argument DONT-SHOW means not to show the message."
+  "Go to a message\\<mh-folder-mode-map>.
+
+You can enter the message NUMBER either before or after typing
+\\[mh-goto-msg]. In the latter case, Emacs prompts you.
+
+In a program, optional non-nil second argument NO-ERROR-IF-NO-MESSAGE
+means return nil instead of signaling an error if message does not
+exist\; in this case, the cursor is positioned near where the message
+would have been. Non-nil third argument DONT-SHOW means not to show
+the message."
   (interactive "NGo to message: ")
   (setq number (prefix-numeric-value number))
   (let ((point (point))
         (return-value t))
     (goto-char (point-min))
-    (unless (re-search-forward (format "^[ ]*%s[^0-9]+" number) nil t)
+    (unless (re-search-forward (format mh-scan-msg-search-regexp number) nil t)
       (goto-char point)
       (unless no-error-if-no-message
         (error "No message %d" number))
@@ -1880,10 +1975,18 @@ Returns nil if the field is not in the buffer."
 
 (defun mh-find-path ()
   "Set variables from user's MH profile.
-Set `mh-user-path', `mh-draft-folder', `mh-unseen-seq', `mh-previous-seq',
-`mh-inbox' from user's MH profile.
-The value of `mh-find-path-hook' is a list of functions to be called, with no
-arguments, after these variable have been set."
+
+This function sets `mh-user-path' from your \"Path:\" MH profile
+component (but defaults to \"Mail\" if one isn't present),
+`mh-draft-folder' from \"Draft-Folder:\", `mh-unseen-seq' from
+\"Unseen-Sequence:\", `mh-previous-seq' from
+\"Previous-Sequence:\", and `mh-inbox' from \"Inbox:\" (defaults
+to \"+inbox\").
+
+The hook `mh-find-path-hook' is run after these variables have
+been set. This hook can be used the change the value of these
+variables if you need to run with different values between MH and
+MH-E."
   (mh-variants)
   (unless mh-find-path-run
     (setq mh-find-path-run t)
@@ -1938,8 +2041,8 @@ arguments, after these variable have been set."
 
 (defun mh-install (profile error-val)
   "Initialize the MH environment.
-This is called if we fail to read the PROFILE file. ERROR-VAL is the error
-that made this call necessary."
+This is called if we fail to read the PROFILE file. ERROR-VAL is
+the error that made this call necessary."
   (if (or (getenv "MH")
           (file-exists-p profile)
           mh-no-install)
@@ -1975,9 +2078,9 @@ that made this call necessary."
 (defun mh-update-scan-format (fmt width)
   "Return a scan format with the (msg) width in the FMT replaced with WIDTH.
 
-The message number width portion of the format is discovered using
-`mh-scan-msg-format-regexp'. Its replacement is controlled with
-`mh-scan-msg-format-string'."
+The message number width portion of the format is discovered
+using `mh-scan-msg-format-regexp'. Its replacement is controlled
+with `mh-scan-msg-format-string'."
   (or (and
        (string-match mh-scan-msg-format-regexp fmt)
        (let ((begin (match-beginning 1))
@@ -1987,8 +2090,8 @@ The message number width portion of the format is discovered using
                  (substring fmt end))))
       fmt))
 
-(defun mh-message-number-width (folder)
-  "Return the widest message number in this FOLDER."
+(defun mh-msg-num-width (folder)
+  "Return the width of the largest message number in this FOLDER."
   (or mh-progs (mh-find-path))
   (let ((tmp-buffer (get-buffer-create mh-temp-buffer))
         (width 0))
@@ -2006,12 +2109,13 @@ The message number width portion of the format is discovered using
 
 (defun mh-add-msgs-to-seq (msgs seq &optional internal-flag dont-annotate-flag)
   "Add MSGS to SEQ.
-Remove duplicates and keep sequence sorted. If optional INTERNAL-FLAG is
-non-nil, do not mark the message in the scan listing or inform MH of the
-addition.
 
-If DONT-ANNOTATE-FLAG is non-nil then the annotations in the folder buffer are
-not updated."
+Remove duplicates and keep sequence sorted. If optional
+INTERNAL-FLAG is non-nil, do not mark the message in the scan
+listing or inform MH of the addition.
+
+If DONT-ANNOTATE-FLAG is non-nil then the annotations in the
+folder buffer are not updated."
   (let ((entry (mh-find-seq seq))
         (internal-seq-flag (mh-internal-seq seq)))
     (if (and msgs (atom msgs)) (setq msgs (list msgs)))
@@ -2045,7 +2149,7 @@ not updated."
 
 ;; Initialize mh-sub-folders-cache...
 (defun mh-collect-folder-names ()
-  "Collect folder names by running `flists'."
+  "Collect folder names by running \"flists\"."
   (unless mh-flists-process
     (setq mh-flists-process
           (mh-exec-cmd-daemon "folders" 'mh-collect-folder-names-filter
@@ -2053,8 +2157,8 @@ not updated."
 
 (defun mh-collect-folder-names-filter (process output)
   "Read folder names.
-PROCESS is the flists process that was run to collect folder names and the
-function is called when OUTPUT is available."
+PROCESS is the flists process that was run to collect folder
+names and the function is called when OUTPUT is available."
   (let ((position 0)
        (prevailing-match-data (match-data))
        line-end folder)
@@ -2092,16 +2196,18 @@ function is called when OUTPUT is available."
 (defun mh-normalize-folder-name (folder &optional empty-string-okay
                                         dont-remove-trailing-slash)
   "Normalizes FOLDER name.
-Makes sure that two '/' characters never occur next to each other. Also all
-occurrences of \"..\" and \".\" are suitably processed. So \"+inbox/../news\"
-will be normalized to \"+news\".
 
-If optional argument EMPTY-STRING-OKAY is nil then a '+' is added at the
-front if FOLDER lacks one. If non-nil and FOLDER is the empty string then
-nothing is added.
+Makes sure that two '/' characters never occur next to each
+other. Also all occurrences of \"..\" and \".\" are suitably
+processed. So \"+inbox/../news\" will be normalized to \"+news\".
 
-If optional argument DONT-REMOVE-TRAILING-SLASH is non-nil then a trailing '/'
-if present is retained (if present), otherwise it is removed."
+If optional argument EMPTY-STRING-OKAY is nil then a '+' is added
+at the front if FOLDER lacks one. If non-nil and FOLDER is the
+empty string then nothing is added.
+
+If optional argument DONT-REMOVE-TRAILING-SLASH is non-nil then a
+trailing '/' if present is retained (if present), otherwise it is
+removed."
   (when (stringp folder)
     ;; Replace two or more consecutive '/' characters with a single '/'
     (while (string-match "//" folder)
@@ -2144,11 +2250,12 @@ if present is retained (if present), otherwise it is removed."
 
 (defun mh-sub-folders (folder &optional add-trailing-slash-flag)
   "Find the subfolders of FOLDER.
-The function avoids running folders unnecessarily by caching the results of
-the actual folders call.
+The function avoids running folders unnecessarily by caching the
+results of the actual folders call.
 
-If optional argument ADD-TRAILING-SLASH-FLAG is non-nil then a slash is added
-to each of the sub-folder names that may have nested folders within them."
+If optional argument ADD-TRAILING-SLASH-FLAG is non-nil then a
+slash is added to each of the sub-folder names that may have
+nested folders within them."
   (let* ((folder (mh-normalize-folder-name folder))
          (match (gethash folder mh-sub-folders-cache 'no-result))
          (sub-folders (cond ((eq match 'no-result)
@@ -2163,8 +2270,8 @@ to each of the sub-folder names that may have nested folders within them."
 
 (defun mh-sub-folders-actual (folder)
   "Execute the command folders to return the sub-folders of FOLDER.
-Filters out the folder names that start with \".\" so that directories that
-aren't usually mail folders are hidden."
+Filters out the folder names that start with \".\" so that
+directories that aren't usually mail folders are hidden."
   (let ((arg-list `(,(expand-file-name "folders" mh-progs)
                     nil (t nil) nil "-noheader" "-norecurse" "-nototal"
                     ,@(if (stringp folder) (list folder) ())))
@@ -2211,13 +2318,15 @@ aren't usually mail folders are hidden."
 
 (defun mh-remove-from-sub-folders-cache (folder)
   "Remove FOLDER and its parent from `mh-sub-folders-cache'.
-FOLDER should be unconditionally removed from the cache. Also the last ancestor
-of FOLDER present in the cache must be removed as well.
-
-To see why this is needed assume we have a folder +foo which has a single
-sub-folder qux. Now we create the folder +foo/bar/baz. Here we will need to
-invalidate the cached sub-folders of +foo, otherwise completion on +foo won't
-tell us about the option +foo/bar!"
+FOLDER should be unconditionally removed from the cache. Also the
+last ancestor of FOLDER present in the cache must be removed as
+well.
+
+To see why this is needed assume we have a folder +foo which has
+a single sub-folder qux. Now we create the folder +foo/bar/baz.
+Here we will need to invalidate the cached sub-folders of +foo,
+otherwise completion on +foo won't tell us about the option
++foo/bar!"
   (remhash folder mh-sub-folders-cache)
   (block ancestor-found
     (let ((parent folder)
@@ -2238,13 +2347,14 @@ tell us about the option +foo/bar!"
 
 (defvar mh-allow-root-folder-flag nil
   "Non-nil means \"+\" is an acceptable folder name.
-This variable is used to communicate with `mh-folder-completion-function'. That
-function can have exactly three arguments so we bind this variable to t or nil.
+This variable is used to communicate with
+`mh-folder-completion-function'. That function can have exactly
+three arguments so we bind this variable to t or nil.
 
 This variable should never be set.")
 
 (defvar mh-folder-completion-map (copy-keymap minibuffer-local-completion-map))
-(define-key mh-folder-completion-map " " 'minibuffer-complete)
+(define-key mh-folder-completion-map " " 'minibuffer-complete)  ;Why???
 
 (defvar mh-speed-flists-inhibit-flag nil)
 
@@ -2256,9 +2366,9 @@ This variable should never be set.")
 
 (defun mh-folder-completion-function (name predicate flag)
   "Programmable completion for folder names.
-NAME is the partial folder name that has been input. PREDICATE if non-nil is a
-function that is used to filter the possible choices and FLAG determines
-whether the completion is over."
+NAME is the partial folder name that has been input. PREDICATE if
+non-nil is a function that is used to filter the possible choices
+and FLAG determines whether the completion is over."
   (let* ((orig-name name)
          (name (mh-normalize-folder-name name nil t))
          (last-slash (mh-search-from-end ?/ name))
@@ -2293,8 +2403,8 @@ whether the completion is over."
 
 (defun mh-folder-completing-read (prompt default allow-root-folder-flag)
   "Read folder name with PROMPT and default result DEFAULT.
-If ALLOW-ROOT-FOLDER-FLAG is non-nil then \"+\" is allowed to be a folder name
-corresponding to `mh-user-path'."
+If ALLOW-ROOT-FOLDER-FLAG is non-nil then \"+\" is allowed to be
+a folder name corresponding to `mh-user-path'."
   (mh-normalize-folder-name
    (let ((minibuffer-completing-file-name t)
          (completion-root-regexp "^[+/]")
@@ -2307,12 +2417,13 @@ corresponding to `mh-user-path'."
 (defun mh-prompt-for-folder (prompt default can-create
                              &optional default-string allow-root-folder-flag)
   "Prompt for a folder name with PROMPT.
-Returns the folder's name as a string. DEFAULT is used if the folder exists
-and the user types return. If the CAN-CREATE flag is t, then a folder is
-created if it doesn't already exist. If optional argument DEFAULT-STRING is
-non-nil, use it in the prompt instead of DEFAULT. If ALLOW-ROOT-FOLDER-FLAG is
-non-nil then the function will accept the folder +, which means all folders
-when used in searching."
+Returns the folder's name as a string. DEFAULT is used if the
+folder exists and the user types return. If the CAN-CREATE flag
+is t, then a folder is created if it doesn't already exist. If
+optional argument DEFAULT-STRING is non-nil, use it in the prompt
+instead of DEFAULT. If ALLOW-ROOT-FOLDER-FLAG is non-nil then the
+function will accept the folder +, which means all folders when
+used in searching."
   (if (null default)
       (setq default ""))
   (let* ((default-string (cond (default-string (format " (default %s)" default-string))
@@ -2347,6 +2458,7 @@ when used in searching."
     (let ((new-file-flag
            (not (file-exists-p (mh-expand-file-name folder-name)))))
       (cond ((and new-file-flag
+                  can-create
                   (y-or-n-p
                    (format "Folder %s does not exist.  Create it? "
                            folder-name)))
@@ -2357,7 +2469,7 @@ when used in searching."
                (mh-speed-add-folder folder-name))
              (message "Creating %s...done" folder-name))
             (new-file-flag
-             (error "Folder %s is not created" folder-name))
+             (error "Folder %s does not exist" folder-name))
             ((not (file-directory-p (mh-expand-file-name folder-name)))
              (error "\"%s\" is not a directory"
                     (mh-expand-file-name folder-name)))))
@@ -2365,9 +2477,10 @@ when used in searching."
 
 (defun mh-truncate-log-buffer ()
   "If `mh-log-buffer' is too big then truncate it.
-If the number of lines in `mh-log-buffer' exceeds `mh-log-buffer-lines' then
-keep only the last `mh-log-buffer-lines'. As a side effect the point is set to
-the end of the log buffer.
+If the number of lines in `mh-log-buffer' exceeds
+`mh-log-buffer-lines' then keep only the last
+`mh-log-buffer-lines'. As a side effect the point is set to the
+end of the log buffer.
 
 The function returns the size of the final size of the log buffer."
   (with-current-buffer (get-buffer-create mh-log-buffer)
@@ -2381,13 +2494,15 @@ The function returns the size of the final size of the log buffer."
       (insert "\n\f\n"))
     (buffer-size)))
 
+\f
+
 ;;; Issue commands to MH.
 
 (defun mh-exec-cmd (command &rest args)
   "Execute mh-command COMMAND with ARGS.
-The side effects are what is desired.
-Any output is assumed to be an error and is shown to the user.
-The output is not read or parsed by MH-E."
+The side effects are what is desired. Any output is assumed to be
+an error and is shown to the user. The output is not read or
+parsed by MH-E."
   (save-excursion
     (set-buffer (get-buffer-create mh-log-buffer))
     (let* ((initial-size (mh-truncate-log-buffer))
@@ -2424,9 +2539,9 @@ Signals an error if process does not complete successfully."
 (defun mh-exec-cmd-daemon (command filter &rest args)
   "Execute MH command COMMAND in the background.
 
-If FILTER is non-nil then it is used to process the output otherwise the
-default filter `mh-process-daemon' is used. See `set-process-filter' for more
-details of FILTER.
+If FILTER is non-nil then it is used to process the output
+otherwise the default filter `mh-process-daemon' is used. See
+`set-process-filter' for more details of FILTER.
 
 ARGS are passed to COMMAND as command line arguments."
   (save-excursion
@@ -2446,9 +2561,9 @@ ARGS are passed to COMMAND as command line arguments."
 ENV is nil or a string of space-separated \"var=value\" elements.
 Signals an error if process does not complete successfully.
 
-If FILTER is non-nil then it is used to process the output otherwise the
-default filter `mh-process-daemon' is used. See `set-process-filter' for more
-details of FILTER.
+If FILTER is non-nil then it is used to process the output
+otherwise the default filter `mh-process-daemon' is used. See
+`set-process-filter' for more details of FILTER.
 
 ARGS are passed to COMMAND as command line arguments."
   (let ((process-environment process-environment))
@@ -2458,17 +2573,20 @@ ARGS are passed to COMMAND as command line arguments."
 
 (defun mh-process-daemon (process output)
   "PROCESS daemon that puts OUTPUT into a temporary buffer.
-Any output from the process is displayed in an asynchronous pop-up window."
-  (set-buffer (get-buffer-create mh-log-buffer))
-  (insert-before-markers output)
-  (display-buffer mh-log-buffer))
+Any output from the process is displayed in an asynchronous
+pop-up window."
+  (with-current-buffer (get-buffer-create mh-log-buffer)
+    (insert-before-markers output)
+    (display-buffer mh-log-buffer)))
 
 (defun mh-exec-cmd-quiet (raise-error command &rest args)
   "Signal RAISE-ERROR if COMMAND with ARGS fails.
-Execute MH command COMMAND with ARGS.  ARGS is a list of strings.
-Return at start of mh-temp buffer, where output can be parsed and used.
-Returns value of `call-process', which is 0 for success, unless RAISE-ERROR is
-non-nil, in which case an error is signaled if `call-process' returns non-0."
+Execute MH command COMMAND with ARGS. ARGS is a list of strings.
+Return at start of mh-temp buffer, where output can be parsed and
+used.
+Returns value of `call-process', which is 0 for success, unless
+RAISE-ERROR is non-nil, in which case an error is signaled if
+`call-process' returns non-0."
   (set-buffer (get-buffer-create mh-temp-buffer))
   (erase-buffer)
   (let ((value
@@ -2488,8 +2606,8 @@ non-nil, in which case an error is signaled if `call-process' returns non-0."
 
 (defun mh-exchange-point-and-mark-preserving-active-mark ()
   "Put the mark where point is now, and point where the mark is now.
-This command works even when the mark is not active, and preserves whether the
-mark is active or not."
+This command works even when the mark is not active, and
+preserves whether the mark is active or not."
   (interactive nil)
   (let ((is-active (and (boundp 'mark-active) mark-active)))
     (let ((omark (mark t)))
@@ -2503,7 +2621,8 @@ mark is active or not."
 
 (defun mh-exec-cmd-output (command display &rest args)
   "Execute MH command COMMAND with DISPLAY flag and ARGS.
-Put the output into buffer after point.  Set mark after inserted text.
+Put the output into buffer after point.
+Set mark after inserted text.
 Output is expected to be shown to user, not parsed by MH-E."
   (push-mark (point) t)
   (apply 'call-process
@@ -2519,7 +2638,8 @@ Output is expected to be shown to user, not parsed by MH-E."
 
 (defun mh-exec-lib-cmd-output (command &rest args)
   "Execute MH library command COMMAND with ARGS.
-Put the output into buffer after point.  Set mark after inserted text."
+Put the output into buffer after point.
+Set mark after inserted text."
   (apply 'mh-exec-cmd-output (expand-file-name command mh-lib-progs) nil args))
 
 (defun mh-handle-process-error (command status)
@@ -2571,11 +2691,13 @@ Put the output into buffer after point.  Set mark after inserted text."
   "Replace REGEXP with NEWTEXT everywhere in STRING and return result.
 NEWTEXT is taken literally---no \\DIGIT escapes will be recognized.
 
-The function body was copied from `dired-replace-in-string' in dired.el.
-Emacs21 has `replace-regexp-in-string' while XEmacs has `replace-in-string'.
-Neither is present in Emacs20. The file gnus-util.el in Gnus 5.10.1 and above
-has `gnus-replace-in-string'. We should use that when we decide to not support
-older versions of Gnus."
+The function body was copied from `dired-replace-in-string' in
+dired.el.
+Emacs21 has `replace-regexp-in-string' while XEmacs has
+`replace-in-string'.
+Neither is present in Emacs20. The file gnus-util.el in Gnus 5.10.1
+and above has `gnus-replace-in-string'. We should use that when we
+decide to not support older versions of Gnus."
   (let ((result "") (start 0) mb me)
     (while (string-match regexp string start)
       (setq mb (match-beginning 0)
@@ -2586,10 +2708,10 @@ older versions of Gnus."
 
 (provide 'mh-utils)
 
-;;; Local Variables:
-;;; indent-tabs-mode: nil
-;;; sentence-end-double-space: nil
-;;; End:
+;; Local Variables:
+;; indent-tabs-mode: nil
+;; sentence-end-double-space: nil
+;; End:
 
-;;; arch-tag: 1af39fdf-f66f-4b06-9b48-18a7656c8e36
+;; arch-tag: 1af39fdf-f66f-4b06-9b48-18a7656c8e36
 ;;; mh-utils.el ends here