changeset 104249:592d4dbcbe86

* mail/rmail.el (rmail-set-message-counters): Call rmail-set-message-counters-counter just once. It returns # msgs after point. (rmail-set-message-counters-counter): Arg is now SPOT-TO-FIND. Return # messages after that one. * mail/rmail.el (rmail-forget-messages): Ignore nil elt in rmail-message-vector. Use dotimes.
author Richard M. Stallman <rms@gnu.org>
date Thu, 13 Aug 2009 01:13:09 +0000
parents 0655506844f6
children a6cdfcf4b769
files lisp/ChangeLog lisp/mail/rmail.el
diffstat 2 files changed, 36 insertions(+), 22 deletions(-) [+]
line wrap: on
line diff
--- a/lisp/ChangeLog	Thu Aug 13 01:04:37 2009 +0000
+++ b/lisp/ChangeLog	Thu Aug 13 01:13:09 2009 +0000
@@ -3,6 +3,9 @@
 	* mail/rmail.el (rmail-get-attr-names):
 	Accept an attribute header that is too short.
 
+	* mail/rmail.el (rmail-forget-messages):
+	Ignore nil elt in rmail-message-vector.  Use dotimes.
+
 	* progmodes/compile.el (compilation-goto-locus):
 	Use next-error-move-function.
 
--- a/lisp/mail/rmail.el	Thu Aug 13 01:04:37 2009 +0000
+++ b/lisp/mail/rmail.el	Thu Aug 13 01:13:09 2009 +0000
@@ -2369,12 +2369,11 @@
 (defun rmail-forget-messages ()
   (unwind-protect
       (if (vectorp rmail-message-vector)
-	  (let* ((i 0)
-		 (v rmail-message-vector)
+	  (let* ((v rmail-message-vector)
 		 (n (length v)))
-	    (while (< i n)
-	      (move-marker (aref v i)  nil)
-	      (setq i (1+ i)))))
+	    (dotimes (i n)
+	      (if (aref v i)
+		  (move-marker (aref v i)  nil)))))
     (setq rmail-message-vector nil)
     (setq rmail-msgref-vector nil)
     (setq rmail-deleted-vector nil)))
@@ -2440,20 +2439,25 @@
 	;; the entry for message N+1, which marks
 	;; the end of message N.  (N = number of messages).
 	(setq messages-head (list (point-marker)))
-	(rmail-set-message-counters-counter (min (point) point-save))
-	(setq messages-after-point total-messages)
-
-	;; Determine how many precede point.
-	(rmail-set-message-counters-counter)
+	(setq messages-after-point 
+	      (or (rmail-set-message-counters-counter (min (point) point-save))
+		  0))
+
 	(setq rmail-total-messages total-messages)
 	(setq rmail-current-message
 	      (min total-messages
 		   (max 1 (- total-messages messages-after-point))))
-	(setq rmail-message-vector
-	      (apply 'vector (cons (point-min-marker) messages-head))
-	      rmail-deleted-vector (concat "0" deleted-head)
-	      rmail-summary-vector (make-vector rmail-total-messages nil)
+
+	;; Make an element 0 in rmail-message-vector and rmail-deleted-vector
+	;; which will never be used.
+	(push nil messages-head)
+	(push ?0 deleted-head)
+	(setq rmail-message-vector (apply 'vector messages-head)
+	      rmail-deleted-vector (concat deleted-head))
+
+	(setq rmail-summary-vector (make-vector rmail-total-messages nil)
 	      rmail-msgref-vector (make-vector (1+ rmail-total-messages) nil))
+
 	(let ((i 0))
 	  (while (<= i rmail-total-messages)
 	    (aset rmail-msgref-vector i (list i))
@@ -2480,12 +2484,17 @@
 		    ?D
 		  ?\s) deleted-head))))
 
-(defun rmail-set-message-counters-counter (&optional stop)
-  ;; Collect the start position for each message into 'messages-head.
-  (let ((start (point)))
-    (while (search-backward "\n\nFrom " stop t)
+(defun rmail-set-message-counters-counter (&optional spot-to-find)
+  "Collect the start positions of messages in list `messages-head'.
+Return the number of messages after the one containing SPOT-TO-FIND."
+  (let ((start (point))
+	messages-after-spot)
+    (while (search-backward "\n\nFrom " nil t)
       (forward-char 2)
       (when (looking-at rmail-unix-mail-delimiter)
+	(if (and (<= (point) spot-to-find)
+		 (null messages-after-spot))
+	    (setq messages-after-spot total-messages))
 	(rmail-collect-deleted start)
 	(setq messages-head (cons (point-marker) messages-head)
 	      total-messages (1+ total-messages)
@@ -2494,13 +2503,15 @@
 	(if (zerop (% total-messages 20))
 	    (message "Counting messages...%d" total-messages))))
     ;; Handle the first message, maybe.
-    (if stop
-	(goto-char stop)
-      (goto-char (point-min)))
+    (goto-char (point-min))
     (unless (not (looking-at rmail-unix-mail-delimiter))
+      (if (and (<= (point) spot-to-find)
+	       (null messages-after-spot))
+	  (setq messages-after-spot total-messages))
       (rmail-collect-deleted start)
       (setq messages-head (cons (point-marker) messages-head)
-	    total-messages (1+ total-messages)))))
+	    total-messages (1+ total-messages)))
+    messages-after-spot))
 
 ;; Display a message.