Some fixes to follow coding conventions in files maintained by FSF.
[bpt/emacs.git] / lisp / mail / rmailkwd.el
index ba921a9..693fbc6 100644 (file)
@@ -1,6 +1,6 @@
-;;; rmailkwd.el --- part of the "RMAIL" mail reader for Emacs.
+;;; rmailkwd.el --- part of the "RMAIL" mail reader for Emacs
 
-;; Copyright (C) 1985, 1988, 1994 Free Software Foundation, Inc.
+;; Copyright (C) 1985, 1988, 1994, 2001 Free Software Foundation, Inc.
 
 ;; Maintainer: FSF
 ;; Keywords: mail
 ;; GNU General Public License for more details.
 
 ;; You should have received a copy of the GNU General Public License
-;; along with GNU Emacs; see the file COPYING.  If not, write to
-;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
+;; along with GNU Emacs; see the file COPYING.  If not, write to the
+;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+;; Boston, MA 02111-1307, USA.
+
+;;; Commentary:
 
 ;;; Code:
 
 
 ;; Named list of symbols representing valid message keywords in RMAIL.
 
-(defvar rmail-keywords nil)
+(defvar rmail-keywords)
 \f
+;;;###autoload
 (defun rmail-add-label (string)
   "Add LABEL to labels associated with current RMAIL message.
 Completion is performed over known labels when reading."
   (interactive (list (rmail-read-label "Add label")))
   (rmail-set-label string t))
 
+;;;###autoload
 (defun rmail-kill-label (string)
   "Remove LABEL from labels associated with current RMAIL message.
 Completion is performed over known labels when reading."
   (interactive (list (rmail-read-label "Remove label")))
   (rmail-set-label string nil))
 
+;;;###autoload
 (defun rmail-read-label (prompt)
-  (if (not rmail-keywords) (rmail-parse-file-keywords))
-  (let ((result
-        (completing-read (concat prompt
-                                 (if rmail-last-label
-                                     (concat " (default "
-                                             (symbol-name rmail-last-label)
-                                             "): ")
-                                   ": "))
-                         rmail-label-obarray
-                         nil
-                         nil)))
-    (if (string= result "")
-       rmail-last-label
-      (setq rmail-last-label (rmail-make-label result t)))))
+  (with-current-buffer rmail-buffer
+    (if (not rmail-keywords) (rmail-parse-file-keywords))
+    (let ((result
+          (completing-read (concat prompt
+                                   (if rmail-last-label
+                                       (concat " (default "
+                                               (symbol-name rmail-last-label)
+                                               "): ")
+                                     ": "))
+                           rmail-label-obarray
+                           nil
+                           nil)))
+      (if (string= result "")
+         rmail-last-label
+       (setq rmail-last-label (rmail-make-label result t))))))
 
 (defun rmail-set-label (l state &optional n)
-  (rmail-maybe-set-message-counters)
-  (if (not n) (setq n rmail-current-message))
-  (aset rmail-summary-vector (1- n) nil)
-  (let* ((attribute (rmail-attribute-p l))
-        (keyword (and (not attribute)
-                      (or (rmail-keyword-p l)
-                          (rmail-install-keyword l))))
-        (label (or attribute keyword)))
-    (if label
-       (let ((omax (- (buffer-size) (point-max)))
-             (omin (- (buffer-size) (point-min)))
-             (buffer-read-only nil)
-             (case-fold-search t))
-         (unwind-protect
-             (save-excursion
-               (widen)
-               (goto-char (rmail-msgbeg n))
-               (forward-line 1)
-               (if (not (looking-at "[01],"))
-                   nil
-                 (let ((start (1+ (point)))
-                       (bound))
-                   (narrow-to-region (point) (progn (end-of-line) (point)))
-                   (setq bound (point-max))
-                   (search-backward ",," nil t)
-                   (if attribute
-                       (setq bound (1+ (point)))
-                     (setq start (1+ (point))))
-                   (goto-char start)
-;                  (while (re-search-forward "[ \t]*,[ \t]*" nil t)
-;                    (replace-match ","))
-;                  (goto-char start)
-                   (if (re-search-forward
+  (with-current-buffer rmail-buffer
+    (rmail-maybe-set-message-counters)
+    (if (not n) (setq n rmail-current-message))
+    (aset rmail-summary-vector (1- n) nil)
+    (let* ((attribute (rmail-attribute-p l))
+          (keyword (and (not attribute)
+                        (or (rmail-keyword-p l)
+                            (rmail-install-keyword l))))
+          (label (or attribute keyword)))
+      (if label
+         (let ((omax (- (buffer-size) (point-max)))
+               (omin (- (buffer-size) (point-min)))
+               (buffer-read-only nil)
+               (case-fold-search t))
+           (unwind-protect
+               (save-excursion
+                 (widen)
+                 (goto-char (rmail-msgbeg n))
+                 (forward-line 1)
+                 (if (not (looking-at "[01],"))
+                     nil
+                   (let ((start (1+ (point)))
+                         (bound))
+                     (narrow-to-region (point) (progn (end-of-line) (point)))
+                     (setq bound (point-max))
+                     (search-backward ",," nil t)
+                     (if attribute
+                         (setq bound (1+ (point)))
+                       (setq start (1+ (point))))
+                     (goto-char start)
+;                    (while (re-search-forward "[ \t]*,[ \t]*" nil t)
+;                      (replace-match ","))
+;                    (goto-char start)
+                     (if (re-search-forward
                           (concat ", " (rmail-quote-label-name label) ",")
                           bound
                           'move)
-                       (if (not state) (replace-match ","))
-                     (if state (insert " " (symbol-name label) ",")))
-                   (if (eq label rmail-deleted-label)
-                       (rmail-set-message-deleted-p n state)))))
-           (narrow-to-region (- (buffer-size) omin) (- (buffer-size) omax))
-           (if (= n rmail-current-message) (rmail-display-labels)))))))
+                         (if (not state) (replace-match ","))
+                       (if state (insert " " (symbol-name label) ",")))
+                     (if (eq label rmail-deleted-label)
+                         (rmail-set-message-deleted-p n state)))))
+             (narrow-to-region (- (buffer-size) omin) (- (buffer-size) omax))
+             (if (= n rmail-current-message) (rmail-display-labels))))))))
 \f
 ;; Commented functions aren't used by RMAIL but might be nice for user
 ;; packages that do stuff with RMAIL.  Note that rmail-message-labels-p
@@ -168,6 +176,7 @@ Completion is performed over known labels when reading."
 \f
 ;; Motion on messages with keywords.
 
+;;;###autoload
 (defun rmail-previous-labeled-message (n labels)
   "Show previous message with one of the labels LABELS.
 LABELS should be a comma-separated list of label names.
@@ -176,6 +185,7 @@ With prefix argument N moves backward N messages with these labels."
   (interactive "p\nsMove to previous msg with labels: ")
   (rmail-next-labeled-message (- n) labels))
 
+;;;###autoload
 (defun rmail-next-labeled-message (n labels)
   "Show next message with one of the labels LABELS.
 LABELS should be a comma-separated list of label names.
@@ -186,6 +196,7 @@ With prefix argument N moves forward N messages with these labels."
       (setq labels rmail-last-multi-labels))
   (or labels
       (error "No labels to find have been specified previously"))
+  (set-buffer rmail-buffer)
   (setq rmail-last-multi-labels labels)
   (rmail-maybe-set-message-counters)
   (let ((lastwin rmail-current-message)