]> code.delx.au - gnu-emacs/blobdiff - lisp/mail/rmailsum.el
* emacs-lisp/autoload.el (generated-autoload-feature): Remove.
[gnu-emacs] / lisp / mail / rmailsum.el
index 86a68457ada03f6607892b7a94fc9292157bd163..09e6329a23080b0c4640c2650bff886236a4d000 100644 (file)
 (require 'rmail)
 
 (defcustom rmail-summary-scroll-between-messages t
-  "Non-nil means Rmail summary scroll commands move between messages."
+  "Non-nil means Rmail summary scroll commands move between messages.
+That is, after `rmail-summary-scroll-msg-up' reaches the end of a
+message, it moves to the next message; and similarly for
+`rmail-summary-scroll-msg-down'."
   :type 'boolean
   :group 'rmail-summary)
 
+;; FIXME could do with a :set function that regenerates the summary
+;; and updates rmail-summary-vector.
 (defcustom rmail-summary-line-count-flag t
-  "Non-nil means Rmail summary should show the number of lines in each message."
+  "Non-nil means Rmail summary should show the number of lines in each message.
+Setting this option to nil might speed up the generation of summaries."
   :type 'boolean
   :group 'rmail-summary)
 
@@ -92,6 +98,10 @@ LABELS should be a string containing the desired labels, separated by commas."
                             (mail-comma-list-regexp labels)
                             "\\)\\(,\\|\\'\\)")))
 
+;; FIXME "a string of regexps separated by commas" makes no sense because:
+;;  i) it's pointless (you can just use \\|)
+;; ii) it's broken (you can't specify a literal comma)
+;; rmail-summary-by-topic and rmail-summary-by-senders have the same issue.
 ;;;###autoload
 (defun rmail-summary-by-recipients (recipients &optional primary-only)
   "Display a summary of all messages with the given RECIPIENTS.
@@ -118,12 +128,15 @@ RECIPIENTS is a string of regexps separated by commas."
       (if (not primary-only)
          (string-match recipients (or (mail-fetch-field "Cc") "")))))
 
+;; FIXME I find this a non-obvious name for what this function does.
+;; Also, the optional WHOLE-MESSAGE argument of r-s-by-topic would
+;; seem more natural here.
 ;;;###autoload
 (defun rmail-summary-by-regexp (regexp)
   "Display a summary of all messages according to regexp REGEXP.
 If the regular expression is found in the header of the message
 \(including in the date and other lines, as well as the subject line),
-Emacs will list the header line in the RMAIL-summary."
+Emacs will list the message in the summary."
   (interactive "sRegexp to summarize by: ")
   (if (string= regexp "")
       (setq regexp (or rmail-last-regexp
@@ -174,8 +187,8 @@ SUBJECT is a string of regexps separated by commas."
 
 ;;;###autoload
 (defun rmail-summary-by-senders (senders)
-  "Display a summary of all messages with the given SENDERS.
-SENDERS is a string of names separated by commas."
+  "Display a summary of all messages whose \"From\" field matches SENDERS.
+SENDERS is a string of regexps separated by commas."
   (interactive "sSenders to summarize by: ")
   (rmail-new-summary
    (concat "senders " senders)
@@ -278,7 +291,8 @@ message."
                                    summary-msgs))))
                  (setq msgnum (1+ msgnum))
                  ;; Provide a periodic User progress message.
-                 (if (zerop (% rmail-new-summary-line-count 10))
+                 (if (and (not (zerop rmail-new-summary-line-count))
+                          (zerop (% rmail-new-summary-line-count 10)))
                      (message "Computing summary lines...%d"
                               rmail-new-summary-line-count)))
                (setq summary-msgs (nreverse summary-msgs)))
@@ -317,11 +331,14 @@ message."
     sumbuf))
 
 (defun rmail-get-create-summary-buffer ()
-  "Obtain a summary buffer by re-using an existing summary
-buffer, or by creating a new summary buffer."
+  "Return the Rmail summary buffer.
+If necessary, it is created and undo is disabled."
   (if (and rmail-summary-buffer (buffer-name rmail-summary-buffer))
       rmail-summary-buffer
-    (generate-new-buffer (concat (buffer-name) "-summary"))))
+    (let ((buff (generate-new-buffer (concat (buffer-name) "-summary"))))
+      (with-current-buffer buff
+       (setq buffer-undo-list t))
+      buff)))
 
 \f
 ;; Low levels of generating a summary.
@@ -471,25 +488,6 @@ LINES is the number of lines in the message (if we should display that)
             (concat prefix basic-start linecount-string " "
                     labels basic-end))))
 
-;; FIXME move to rmail.el?
-;;;###autoload
-(defcustom rmail-user-mail-address-regexp nil
-  "Regexp matching user mail addresses.
-If non-nil, this variable is used to identify the correspondent
-when receiving new mail.  If it matches the address of the sender,
-the recipient is taken as correspondent of a mail.
-If nil \(default value\), your `user-login-name' and `user-mail-address'
-are used to exclude yourself as correspondent.
-
-Usually you don't have to set this variable, except if you collect mails
-sent by you under different user names.
-Then it should be a regexp matching your mail addresses.
-
-Setting this variable has an effect only before reading a mail."
-  :type '(choice (const :tag "None" nil) regexp)
-  :group 'rmail-retrieve
-  :version "21.1")
-
 (defun rmail-header-summary ()
   "Return a message summary based on the message headers.
 The value is a list of two strings, the first and second parts of the summary.
@@ -501,16 +499,19 @@ the message being processed."
    (concat (save-excursion
             (if (not (re-search-forward "^Date:" nil t))
                 "      "
-              (cond ((re-search-forward "\\([^0-9:]\\)\\([0-3]?[0-9]\\)\\([- \t_]+\\)\\([adfjmnos][aceopu][bcglnprtvy]\\)"
-                      (line-end-position) t)
+              ;; Match month names case-insensitively
+              (cond ((let ((case-fold-search t))
+                       (re-search-forward "\\([^0-9:]\\)\\([0-3]?[0-9]\\)\\([- \t_]+\\)\\([adfjmnos][aceopu][bcglnprtvy]\\)"
+                                          (line-end-position) t))
                      (format "%2d-%3s"
                              (string-to-number (buffer-substring
                                                 (match-beginning 2)
                                                 (match-end 2)))
                              (buffer-substring
                               (match-beginning 4) (match-end 4))))
-                    ((re-search-forward "\\([^a-z]\\)\\([adfjmnos][acepou][bcglnprtvy]\\)\\([-a-z \t_]*\\)\\([0-9][0-9]?\\)"
-                      (line-end-position) t)
+                    ((let ((case-fold-search t))
+                       (re-search-forward "\\([^a-z]\\)\\([adfjmnos][acepou][bcglnprtvy]\\)\\([-a-z \t_]*\\)\\([0-9][0-9]?\\)"
+                                          (line-end-position) t))
                      (format "%2d-%3s"
                              (string-to-number (buffer-substring
                                                 (match-beginning 4)
@@ -642,8 +643,7 @@ non-deleted messages."
 With prefix argument N moves forward N messages with these labels."
   (interactive "p\nsMove to next msg with labels: ")
   (let (msg)
-    (save-excursion
-      (set-buffer rmail-buffer)
+    (with-current-buffer rmail-buffer
       (rmail-next-labeled-message n labels)
       (setq msg rmail-current-message))
     (rmail-summary-goto-msg msg)))
@@ -653,8 +653,7 @@ With prefix argument N moves forward N messages with these labels."
 With prefix argument N moves backward N messages with these labels."
   (interactive "p\nsMove to previous msg with labels: ")
   (let (msg)
-    (save-excursion
-      (set-buffer rmail-buffer)
+    (with-current-buffer rmail-buffer
       (rmail-previous-labeled-message n labels)
       (setq msg rmail-current-message))
     (rmail-summary-goto-msg msg)))
@@ -808,8 +807,7 @@ Optional prefix ARG means undelete ARG previous messages."
 (defun rmail-summary-undelete-many (&optional n)
   "Undelete all deleted msgs, optional prefix arg N means undelete N prev msgs."
   (interactive "P")
-  (save-excursion
-    (set-buffer rmail-buffer)
+  (with-current-buffer rmail-buffer
     (let* ((init-msg (if n rmail-current-message rmail-total-messages))
           (rmail-current-message init-msg)
           (n (or n rmail-total-messages))
@@ -966,8 +964,7 @@ Search, the `unseen' attribute is restored.")
                        (rmail-show-message msg-num t))
                    (select-window owin))
                (if (buffer-name rmail-buffer)
-                   (save-excursion
-                     (set-buffer rmail-buffer)
+                   (with-current-buffer rmail-buffer
                      (rmail-show-message msg-num t))))))
        (rmail-summary-update-highlight nil)))))
 
@@ -1004,6 +1001,8 @@ Search, the `unseen' attribute is restored.")
   (define-key rmail-summary-mode-map "\e\C-l" 'rmail-summary-by-labels)
   (define-key rmail-summary-mode-map "\e\C-r" 'rmail-summary-by-recipients)
   (define-key rmail-summary-mode-map "\e\C-s" 'rmail-summary-by-regexp)
+  ;; `f' for "from".
+  (define-key rmail-summary-mode-map "\e\C-f" 'rmail-summary-by-senders)
   (define-key rmail-summary-mode-map "\e\C-t" 'rmail-summary-by-topic)
   (define-key rmail-summary-mode-map "m"      'rmail-summary-mail)
   (define-key rmail-summary-mode-map "\M-m"   'rmail-summary-retry-failure)
@@ -1011,7 +1010,7 @@ Search, the `unseen' attribute is restored.")
   (define-key rmail-summary-mode-map "\en"    'rmail-summary-next-all)
   (define-key rmail-summary-mode-map "\e\C-n" 'rmail-summary-next-labeled-message)
   (define-key rmail-summary-mode-map "o"      'rmail-summary-output)
-  (define-key rmail-summary-mode-map "\C-o"   'rmail-summary-output)
+  (define-key rmail-summary-mode-map "\C-o"   'rmail-summary-output-as-seen)
   (define-key rmail-summary-mode-map "p"      'rmail-summary-previous-msg)
   (define-key rmail-summary-mode-map "\ep"    'rmail-summary-previous-all)
   (define-key rmail-summary-mode-map "\e\C-p" 'rmail-summary-previous-labeled-message)
@@ -1019,12 +1018,15 @@ Search, the `unseen' attribute is restored.")
   (define-key rmail-summary-mode-map "Q"      'rmail-summary-wipe)
   (define-key rmail-summary-mode-map "r"      'rmail-summary-reply)
   (define-key rmail-summary-mode-map "s"      'rmail-summary-expunge-and-save)
+  ;; See rms's comment in rmail.el
+;;;  (define-key rmail-summary-mode-map "\er"    'rmail-summary-search-backward)
   (define-key rmail-summary-mode-map "\es"    'rmail-summary-search)
   (define-key rmail-summary-mode-map "t"      'rmail-summary-toggle-header)
   (define-key rmail-summary-mode-map "u"      'rmail-summary-undelete)
   (define-key rmail-summary-mode-map "\M-u"   'rmail-summary-undelete-many)
   (define-key rmail-summary-mode-map "x"      'rmail-summary-expunge)
   (define-key rmail-summary-mode-map "w"      'rmail-summary-output-body)
+  (define-key rmail-summary-mode-map "v"      'rmail-mime)
   (define-key rmail-summary-mode-map "."      'rmail-summary-beginning-of-message)
   (define-key rmail-summary-mode-map "/"      'rmail-summary-end-of-message)
   (define-key rmail-summary-mode-map "<"      'rmail-summary-first-message)
@@ -1071,13 +1073,13 @@ Search, the `unseen' attribute is restored.")
   '(nil))
 
 (define-key rmail-summary-mode-map [menu-bar classify output-body]
-  '("Output (body)..." . rmail-summary-output-body))
+  '("Output body..." . rmail-summary-output-body))
 
 (define-key rmail-summary-mode-map [menu-bar classify output-inbox]
-  '("Output (inbox)..." . rmail-summary-output))
+  '("Output..." . rmail-summary-output))
 
 (define-key rmail-summary-mode-map [menu-bar classify output]
-  '("Output (Rmail)..." . rmail-summary-output))
+  '("Output as seen..." . rmail-summary-output-as-seen))
 
 (define-key rmail-summary-mode-map [menu-bar classify kill-label]
   '("Kill Label..." . rmail-summary-kill-label))
@@ -1200,7 +1202,7 @@ Returns non-nil if message N was found."
         (curmsg (string-to-number
                  (buffer-substring (point)
                                    (min (point-max) (+ 6 (point))))))
-        (total (save-excursion (set-buffer buf) rmail-total-messages)))
+        (total (with-current-buffer buf rmail-total-messages)))
     ;; If message number N was specified, find that message's line
     ;; or set message-not-found.
     ;; If N wasn't specified or that message can't be found.
@@ -1362,7 +1364,7 @@ Position it according to WHERE which can be BEG or END"
 (defun rmail-summary-wipe ()
   "Kill and wipe away Rmail summary, remaining within Rmail."
   (interactive)
-  (save-excursion (set-buffer rmail-buffer) (setq rmail-summary-buffer nil))
+  (with-current-buffer rmail-buffer (setq rmail-summary-buffer nil))
   (let ((local-rmail-buffer rmail-buffer))
     (kill-buffer (current-buffer))
     ;; Delete window if not only one.
@@ -1374,8 +1376,7 @@ Position it according to WHERE which can be BEG or END"
 (defun rmail-summary-expunge ()
   "Actually erase all deleted messages and recompute summary headers."
   (interactive)
-  (save-excursion
-    (set-buffer rmail-buffer)
+  (with-current-buffer rmail-buffer
     (when (rmail-expunge-confirmed)
       (rmail-only-expunge)))
   (rmail-update-summary))
@@ -1399,8 +1400,7 @@ argument says to read a file name and use that file as the inbox."
    (list (if current-prefix-arg
             (read-file-name "Get new mail from file: "))))
   (let (msg)
-    (save-excursion
-      (set-buffer rmail-buffer)
+    (with-current-buffer rmail-buffer
       (rmail-get-new-mail file-name)
       ;; Get the proper new message number.
       (setq msg rmail-current-message))
@@ -1487,12 +1487,8 @@ Interactively, empty argument means use same regexp used last time."
            (prefix-numeric-value current-prefix-arg))))
   ;; Don't use save-excursion because that prevents point from moving
   ;; properly in the summary buffer.
-  (let ((buffer (current-buffer)))
-    (unwind-protect
-       (progn
-         (set-buffer rmail-buffer)
-         (rmail-search regexp (- n)))
-      (set-buffer buffer))))
+  (with-current-buffer rmail-buffer
+    (rmail-search regexp (- n))))
 
 (defun rmail-summary-search (regexp &optional n)
   "Show message containing next match for REGEXP.
@@ -1519,11 +1515,13 @@ Interactively, empty argument means use same regexp used last time."
            (prefix-numeric-value current-prefix-arg))))
   ;; Don't use save-excursion because that prevents point from moving
   ;; properly in the summary buffer.
-  (let ((buffer (current-buffer)))
+  (let ((buffer (current-buffer))
+       (selwin (selected-window)))
     (unwind-protect
        (progn
-         (set-buffer rmail-buffer)
+         (pop-to-buffer rmail-buffer)
          (rmail-search regexp n))
+      (select-window selwin)
       (set-buffer buffer))))
 
 (defun rmail-summary-toggle-header ()
@@ -1548,21 +1546,17 @@ Interactively, empty argument means use same regexp used last time."
 (defun rmail-summary-add-label (label)
   "Add LABEL to labels associated with current Rmail message.
 Completion is performed over known labels when reading."
-  (interactive (list (save-excursion
-                      (set-buffer rmail-buffer)
+  (interactive (list (with-current-buffer rmail-buffer
                       (rmail-read-label "Add label"))))
-  (save-excursion
-    (set-buffer rmail-buffer)
+  (with-current-buffer rmail-buffer
     (rmail-add-label label)))
 
 (defun rmail-summary-kill-label (label)
   "Remove LABEL from labels associated with current Rmail message.
 Completion is performed over known labels when reading."
-  (interactive (list (save-excursion
-                      (set-buffer rmail-buffer)
+  (interactive (list (with-current-buffer rmail-buffer
                       (rmail-read-label "Kill label"))))
-  (save-excursion
-    (set-buffer rmail-buffer)
+  (with-current-buffer rmail-buffer
     (rmail-set-label label nil)))
 \f
 ;;;; *** Rmail Summary Mailing Commands ***
@@ -1729,8 +1723,7 @@ Also set the default for subsequent \\[rmail-output-to-babyl-file] commands.
 The variables `rmail-secondary-file-directory' and
 `rmail-secondary-file-regexp' control which files are offered in the menu."
   (interactive)
-  (save-excursion
-    (set-buffer rmail-buffer)
+  (with-current-buffer rmail-buffer
     (let ((rmail-delete-after-output nil))
       (call-interactively 'rmail-output-menu)))
   (if rmail-delete-after-output
@@ -1759,8 +1752,7 @@ The variables `rmail-secondary-file-directory' and
   "Write this message body to the file FILE-NAME.
 FILE-NAME defaults, interactively, from the Subject field of the message."
   (interactive)
-  (save-excursion
-    (set-buffer rmail-buffer)
+  (with-current-buffer rmail-buffer
     (let ((rmail-delete-after-output nil))
       (if file-name
          (rmail-output-body-to-file file-name)
@@ -1771,53 +1763,61 @@ FILE-NAME defaults, interactively, from the Subject field of the message."
 ;; Sorting messages in Rmail Summary buffer.
 
 (defun rmail-summary-sort-by-date (reverse)
-  "Sort messages of current Rmail summary by date.
-If prefix argument REVERSE is non-nil, sort them in reverse order."
+  "Sort messages of current Rmail summary by \"Date\" header.
+If prefix argument REVERSE is non-nil, sorts in reverse order."
   (interactive "P")
   (rmail-sort-from-summary (function rmail-sort-by-date) reverse))
 
 (defun rmail-summary-sort-by-subject (reverse)
-  "Sort messages of current Rmail summary by subject.
-If prefix argument REVERSE is non-nil, sort them in reverse order."
+  "Sort messages of current Rmail summary by \"Subject\" header.
+Ignores any \"Re: \" prefix.  If prefix argument REVERSE is
+non-nil, sorts in reverse order."
   (interactive "P")
   (rmail-sort-from-summary (function rmail-sort-by-subject) reverse))
 
 (defun rmail-summary-sort-by-author (reverse)
   "Sort messages of current Rmail summary by author.
-If prefix argument REVERSE is non-nil, sort them in reverse order."
+This uses either the \"From\" or \"Sender\" header, downcased.
+If prefix argument REVERSE is non-nil, sorts in reverse order."
   (interactive "P")
   (rmail-sort-from-summary (function rmail-sort-by-author) reverse))
 
 (defun rmail-summary-sort-by-recipient (reverse)
   "Sort messages of current Rmail summary by recipient.
-If prefix argument REVERSE is non-nil, sort them in reverse order."
+This uses either the \"To\" or \"Apparently-To\" header, downcased.
+If prefix argument REVERSE is non-nil, sorts in reverse order."
   (interactive "P")
   (rmail-sort-from-summary (function rmail-sort-by-recipient) reverse))
 
 (defun rmail-summary-sort-by-correspondent (reverse)
   "Sort messages of current Rmail summary by other correspondent.
-If prefix argument REVERSE is non-nil, sort them in reverse order."
+This uses either the \"From\", \"Sender\", \"To\", or
+\"Apparently-To\" header, downcased.  Uses the first header not
+excluded by `rmail-dont-reply-to-names'.  If prefix argument
+REVERSE is non-nil, sorts in reverse order."
   (interactive "P")
   (rmail-sort-from-summary (function rmail-sort-by-correspondent) reverse))
 
 (defun rmail-summary-sort-by-lines (reverse)
-  "Sort messages of current Rmail summary by lines of the message.
-If prefix argument REVERSE is non-nil, sort them in reverse order."
+  "Sort messages of current Rmail summary by the number of lines.
+If prefix argument REVERSE is non-nil, sorts in reverse order."
   (interactive "P")
   (rmail-sort-from-summary (function rmail-sort-by-lines) reverse))
 
 (defun rmail-summary-sort-by-labels (reverse labels)
   "Sort messages of current Rmail summary by labels.
-If prefix argument REVERSE is non-nil, sort them in reverse order.
-KEYWORDS is a comma-separated list of labels."
+LABELS is a comma-separated list of labels.
+If prefix argument REVERSE is non-nil, sorts in reverse order."
   (interactive "P\nsSort by labels: ")
   (rmail-sort-from-summary
-   (function (lambda (reverse)
-              (rmail-sort-by-labels reverse labels)))
+   (lambda (reverse) (rmail-sort-by-labels reverse labels))
    reverse))
 
 (defun rmail-sort-from-summary (sortfun reverse)
-  "Sort Rmail messages from Summary buffer and update it after sorting."
+  "Sort the Rmail buffer using sorting function SORTFUN.
+Passes REVERSE to SORTFUN as its sole argument.  Then regenerates
+the summary.  Note that the whole Rmail buffer is sorted, even if
+the summary is only showing a subset of messages."
   (require 'rmailsort)
   (let ((selwin (selected-window)))
     (unwind-protect
@@ -1827,5 +1827,9 @@ KEYWORDS is a comma-separated list of labels."
 
 (provide 'rmailsum)
 
+;; Local Variables:
+;; generated-autoload-file: "rmail.el"
+;; End:
+
 ;; arch-tag: 80b0a27a-a50d-4f37-9466-83d32d1e0ca8
 ;;; rmailsum.el ends here