From 76e1e40b4eeb45f485f03069a0a9a43480779dfc Mon Sep 17 00:00:00 2001 From: "Richard M. Stallman" Date: Thu, 13 Aug 2009 01:13:09 +0000 Subject: [PATCH] * 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. --- lisp/ChangeLog | 3 +++ lisp/mail/rmail.el | 53 ++++++++++++++++++++++++++++------------------ 2 files changed, 35 insertions(+), 21 deletions(-) diff --git a/lisp/ChangeLog b/lisp/ChangeLog index ad18578e4c4..9bd9643568e 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -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. diff --git a/lisp/mail/rmail.el b/lisp/mail/rmail.el index 2fd99fbd282..c61efeb30be 100644 --- a/lisp/mail/rmail.el +++ b/lisp/mail/rmail.el @@ -2369,12 +2369,11 @@ change the invisible header text." (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 @@ Output a helpful message unless NOMSG is non-nil." ;; 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) + (setq messages-after-point + (or (rmail-set-message-counters-counter (min (point) point-save)) + 0)) - ;; Determine how many precede point. - (rmail-set-message-counters-counter) (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 @@ the message. Point is at the beginning of the message." ?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 @@ the message. Point is at the beginning of the message." (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. -- 2.39.2