]> code.delx.au - gnu-emacs/blobdiff - lisp/mail/mh-comp.el
(report-emacs-bug-text-prompt): New variable.
[gnu-emacs] / lisp / mail / mh-comp.el
index fcf5a64d0ba9be4816da0e9c16e2bf8d0d26adf3..bc6556cc31b8d1b5a820307cfa9a6800e745d34a 100644 (file)
@@ -1,9 +1,13 @@
-;;; mh-comp --- mh-e functions for composing messages
-;; Time-stamp: <95/08/19 17:48:59 gildea>
+;;; mh-comp.el --- mh-e functions for composing messages
+;; Time-stamp: <2001-12-20 18:55:07 pavel>
 
-;; Copyright (C) 1993, 1995, 1997 Free Software Foundation, Inc.
+;; Copyright (C) 1993,1995,1997,2000  Free Software Foundation, Inc.
 
-;; This file is part of mh-e, part of GNU Emacs.
+;; Maintainer: Bill Wohler <wohler@newt.com>
+;; Keywords: mail
+;; Bug-reports: include `M-x mh-version' output in any correspondence
+
+;; This file is part of GNU Emacs.
 
 ;; GNU Emacs is free software; you can redistribute it and/or modify
 ;; it under the terms of the GNU General Public License as published by
@@ -26,7 +30,7 @@
 
 ;;; Change Log:
 
-;; $Id: mh-comp.el,v 1.11 1997/09/15 19:45:16 rms Exp rms $
+;; $Id: mh-comp.el,v 1.22 2001/07/15 19:53:53 pj Exp $
 
 ;;; Code:
 
@@ -100,7 +104,9 @@ If non-nil, include the entire message.  If the symbol `body', then yank the
 message minus the header.  If nil, yank only the portion of the message
 following the point.  If the show buffer has a region, this variable is
 ignored."
-  :type '(choice (const t) (const nil) (const body))
+  :type '(choice (const :tag "Below point" nil)
+                (const :tag "Without header" body)
+                (other :tag "Entire message" t))
   :group 'mh-compose)
 
 (defcustom mh-ins-buf-prefix "> "
@@ -145,6 +151,13 @@ Default is \"replcomps\".  If not an absolute file name, the file
 is searched for first in the user's MH directory, then in the
 system MH lib directory.")
 
+(defvar mh-repl-group-formfile "replgroupcomps"
+  "Name of file to be used as a skeleton for replying to the sender
+and all recipients of a messages.  Only used if mh-nmh-p is non-nil.
+Default is \"replgroupcomps\".  If not an absolute file name, the file
+is searched for first in the user's MH directory, then in the system
+MH lib directory.")
+
 ;;; Hooks:
 
 (defcustom mh-letter-mode-hook nil
@@ -155,7 +168,7 @@ system MH lib directory.")
 (defcustom mh-compose-letter-function nil
   "Invoked when setting up a letter draft.
 It is passed three arguments: TO recipients, SUBJECT, and CC recipients."
-  :type 'function
+  :type '(choice (const nil) function)
   :group 'mh-compose)
 
 (defcustom mh-before-send-letter-hook nil
@@ -215,7 +228,7 @@ See documentation of `\\[mh-send]' for more details on composing mail."
 
 
 ;;;###autoload
-(defun mh-smail-batch (&rest ignored)
+(defun mh-smail-batch (&optional to subject other-headers &rest ignored)
   "Set up a mail composition draft with the MH mail system.
 This function is an entry point to mh-e, the Emacs front end
 to the MH mail system.  This function does not prompt the user
@@ -224,7 +237,7 @@ that want to create a mail buffer.
 Users should use `\\[mh-smail]' to compose mail."
   (mh-find-path)
   (let ((mh-error-if-no-draft t))
-    (mh-send "" "" "")))
+    (mh-send (or to "") "" (or subject ""))))
 
 
 (defun mh-edit-again (msg)
@@ -298,23 +311,27 @@ See also documentation for `\\[mh-send]' function."
                         (mh-insert-fields "To:" to "Cc:" cc)
                         (save-buffer)))
                      (t
-                      (mh-read-draft "" draft-name nil)))))
+                      (mh-read-draft "" draft-name nil))))
+        (fwd-msg-file (mh-msg-filename (if (numberp msg-or-seq)
+                                           msg-or-seq
+                                         (car (mh-seq-to-msgs msg-or-seq)))
+                                       folder)))
     (let (orig-from
          orig-subject)
-      (goto-char (point-min))
-      (re-search-forward "^------- Forwarded Message")
-      (forward-line 1)
-      (skip-chars-forward " \t\n")
-      (save-restriction
-       (narrow-to-region (point) (point-max))
+      (save-excursion
+       (set-buffer (get-buffer-create mh-temp-buffer))
+       (erase-buffer)
+       (insert-file-contents fwd-msg-file)
        (setq orig-from (mh-get-header-field "From:"))
        (setq orig-subject (mh-get-header-field "Subject:")))
       (let ((forw-subject
             (mh-forwarded-letter-subject orig-from orig-subject)))
        (mh-insert-fields "Subject:" forw-subject)
        (goto-char (point-min))
-       (re-search-forward "^------- Forwarded Message")
-       (forward-line -1)
+       (if (re-search-forward "^------- Forwarded Message" nil t)
+           (forward-line -1)
+         (re-search-forward "^--------")
+         (forward-line 1))
        (delete-other-windows)
        (if (numberp msg-or-seq)
            (mh-add-msgs-to-seq msg-or-seq 'forwarded t)
@@ -405,25 +422,32 @@ for the reply.  See also documentation for `\\[mh-send]' function."
   (interactive (list (mh-get-msg-num t) current-prefix-arg))
   (let ((minibuffer-help-form
         "from => Sender only\nto => Sender and primary recipients\ncc or all => Sender and all recipients"))
-    (let ((reply-to (or mh-reply-default-reply-to
+    (let* ((reply-to (or mh-reply-default-reply-to
                        (completing-read "Reply to whom: "
                                         '(("from") ("to") ("cc") ("all"))
                                         nil
                                         t)))
-         (folder mh-current-folder)
-         (show-buffer mh-show-buffer)
-         (config (current-window-configuration)))
+          (folder mh-current-folder)
+          (show-buffer mh-show-buffer)
+          (config (current-window-configuration))
+          (group-reply (or (equal reply-to "cc") (equal reply-to "all")))
+          (form-file (cond ((and mh-nmh-p group-reply
+                                 (stringp mh-repl-group-formfile))
+                            mh-repl-group-formfile)
+                           ((stringp mh-repl-formfile) mh-repl-formfile)
+                           (t nil))))
       (message "Composing a reply...")
       (mh-exec-cmd "repl" "-build" "-noquery" "-nodraftfolder"
-            (if (stringp mh-repl-formfile) ;must be string, but we're paranoid
-                (list "-form" mh-repl-formfile))
+            (if form-file
+                (list "-form" form-file))
             mh-current-folder message
             (cond ((or (equal reply-to "from") (equal reply-to ""))
                    '("-nocc" "all"))
                   ((equal reply-to "to")
                    '("-cc" "to"))
-                  ((or (equal reply-to "cc") (equal reply-to "all"))
-                   '("-cc" "all" "-nocc" "me")))
+                  (group-reply (if mh-nmh-p
+                                   '("-group" "-nocc" "me")
+                                 '("-cc" "all" "-nocc" "me"))))
             (if includep
                 '("-filter" "mhl.reply")))
       (let ((draft (mh-read-draft "reply"
@@ -495,6 +519,12 @@ See also documentation for `\\[mh-send]' function."
                       (setq components
                             (expand-file-name mh-comp-formfile mh-lib)))
                      components)
+                    ((file-exists-p
+                      (setq components
+                            (expand-file-name mh-comp-formfile
+                                              ;; What is this mh-etc ??  -sm
+                                              (and (boundp 'mh-etc) mh-etc))))
+                     components)
                     (t
                      (error (format "Can't find components file \"%s\""
                                     components)))))
@@ -510,7 +540,7 @@ See also documentation for `\\[mh-send]' function."
 (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
+  ;; 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.
@@ -546,7 +576,7 @@ See also documentation for `\\[mh-send]' function."
                  (if (y-or-n-p
                        (format "A draft exists.  Use for %s? " use))
                      (if mh-error-if-no-draft
-                         (error "A prior draft exists."))
+                         (error "A prior draft exists"))
                    t)))
         (erase-buffer)
         (insert-file-contents initial-contents)
@@ -621,7 +651,7 @@ See also documentation for `\\[mh-send]' function."
 (defun mh-goto-header-field (field)
   ;; Move to FIELD in the message header.
   ;; Move to the end of the FIELD name, which should end in a colon.
-  ;; Returns T if found, NIL if not.
+  ;; Returns t if found, nil if not.
   (goto-char (point-min))
   (let ((case-fold-search t)
        (headers-end (save-excursion
@@ -667,7 +697,7 @@ See also documentation for `\\[mh-send]' function."
 (put 'mh-letter-mode 'mode-class 'special)
 
 ;;;###autoload
-(defun mh-letter-mode ()
+(define-derived-mode mh-letter-mode text-mode "MH-Letter"
   "Mode for composing letters in mh-e.\\<mh-letter-mode-map>
 When you have finished composing, type \\[mh-send-letter] to send the message
 using the MH mail handling system.
@@ -696,8 +726,6 @@ Variables controlling this mode (defaults in parentheses):
     File to be inserted into message by \\[mh-insert-signature].
 
 This command runs the normal hooks `text-mode-hook' and `mh-letter-mode-hook'."
-
-  (interactive)
   (or mh-user-path (mh-find-path))
   (make-local-variable 'paragraph-start)
   (setq paragraph-start (concat "^[ \t]*[-_][-_][-_]+$\\|" paragraph-start))
@@ -712,19 +740,10 @@ This command runs the normal hooks `text-mode-hook' and `mh-letter-mode-hook'."
   (make-local-variable 'mh-sent-from-msg)
   (make-local-variable 'mail-header-separator)
   (setq mail-header-separator "--------") ;for Hyperbole
-  (use-local-map mh-letter-mode-map)
-  (setq major-mode 'mh-letter-mode)
-  (mh-set-mode-name "MH-Letter")
-  (set-syntax-table mh-letter-mode-syntax-table)
-  (run-hooks 'text-mode-hook)
   ;; if text-mode-hook turned on auto-fill, tune it for messages
-  (cond ((and (boundp 'auto-fill-hook) auto-fill-hook) ;emacs 18
-        (make-local-variable 'auto-fill-hook)
-        (setq auto-fill-hook 'mh-auto-fill-for-letter)))
-  (cond ((and (boundp 'auto-fill-function) auto-fill-function) ;emacs 19
-        (make-local-variable 'auto-fill-function)
-        (setq auto-fill-function 'mh-auto-fill-for-letter)))
-  (run-hooks 'mh-letter-mode-hook))
+  (when auto-fill-function
+    (make-local-variable 'auto-fill-function)
+    (setq auto-fill-function 'mh-auto-fill-for-letter)))
 
 
 (defun mh-auto-fill-for-letter ()
@@ -987,10 +1006,9 @@ yanked message will be deleted."
         (run-hooks 'mh-yank-hooks))
        (t
         (or (bolp) (forward-line 1))
-        (let ((zmacs-regions nil))     ;so "(mark)" works in XEmacs
-          (while (< (point) (mark))
-            (insert mh-ins-string)
-            (forward-line 1))))))
+        (while (< (point) (mark))
+          (insert mh-ins-string)
+          (forward-line 1)))))
 
 
 (defun mh-fully-kill-draft ()
@@ -1085,3 +1103,5 @@ various types of components in a message, see
 (autoload 'mh-revert-mhn-edit "mh-mime"
   "Undoes the effect of \\[mh-edit-mhn] by reverting to the backup file.
 Optional non-nil argument means don't ask for confirmation." t)
+
+;;; mh-comp.el ends here