aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Reilly2008-09-03 15:33:38 +0000
committerPaul Reilly2008-09-03 15:33:38 +0000
commit73ead349fce932acd50b4cc8af8e333bc81729aa (patch)
tree36e749c744de6101e9f57ff3c8dc3bcd07001284
parent15c72e1d4a26582d5d0efa85fc3f0e0e403ea760 (diff)
downloademacs-73ead349fce932acd50b4cc8af8e333bc81729aa.tar.gz
emacs-73ead349fce932acd50b4cc8af8e333bc81729aa.zip
Fix the expunge command so that the current message index is correct.
* pmail.el (pmail-expunge-counter): New variable (pmail-set-attribute): Canonicalize the calling sequence to index, attribute, state. (pmail-show-message, pmail-delete-message, pmail-undelete-previous-message, pmail-delete-forward, pmail-mark-message): Use the new canonical calling sequence. (pmail-only-expunge): Use the expunge counter to update the current message index. (pmail-expunge-callback): Simplify. Just count the expunged messages with a lower index than the current message index. * pmaildesc.el (pmail-desc-get-previous): Fix an "off by one" issue. (pmail-desc-set-attribute): Canonicalize the calling sequence to index, attribute, state. * pmailout.el (pmail-output-body-to-file): Use the canonical calling sequence.
-rw-r--r--lisp/mail/pmail.el29
-rw-r--r--lisp/mail/pmaildesc.el10
-rw-r--r--lisp/mail/pmailout.el3
3 files changed, 22 insertions, 20 deletions
diff --git a/lisp/mail/pmail.el b/lisp/mail/pmail.el
index cfa6c3f95ad..38a6a2cd6c5 100644
--- a/lisp/mail/pmail.el
+++ b/lisp/mail/pmail.el
@@ -186,6 +186,11 @@ please report it with \\[report-emacs-bug].")
186 186
187(defvar pmail-encoded-remote-password nil) 187(defvar pmail-encoded-remote-password nil)
188 188
189(defvar pmail-expunge-counter 0
190 "A counter used to keep track of the number of expunged
191messages with a lower message number than the current message
192index.")
193
189(defcustom pmail-preserve-inbox nil 194(defcustom pmail-preserve-inbox nil
190 "*Non-nil means leave incoming mail in the user's inbox--don't delete it." 195 "*Non-nil means leave incoming mail in the user's inbox--don't delete it."
191 :type 'boolean 196 :type 'boolean
@@ -1908,7 +1913,7 @@ default, the current message is changed."
1908 (let ((attr-index (pmail-desc-get-attr-index attr))) 1913 (let ((attr-index (pmail-desc-get-attr-index attr)))
1909 (set-buffer pmail-buffer) 1914 (set-buffer pmail-buffer)
1910 (or msgnum (setq msgnum pmail-current-message)) 1915 (or msgnum (setq msgnum pmail-current-message))
1911 (pmail-desc-set-attribute attr-index state msgnum) 1916 (pmail-desc-set-attribute msgnum attr-index state)
1912 ;; Deal with the summary buffer. 1917 ;; Deal with the summary buffer.
1913 (when pmail-summary-buffer 1918 (when pmail-summary-buffer
1914 (pmail-summary-update msgnum)))))) 1919 (pmail-summary-update msgnum))))))
@@ -2143,7 +2148,7 @@ If NO-SUMMARY is non-nil, then do not update the summary buffer."
2143 ;; Clear the "unseen" attribute when we show a message, unless 2148 ;; Clear the "unseen" attribute when we show a message, unless
2144 ;; it is already cleared. 2149 ;; it is already cleared.
2145 (when (pmail-desc-attr-p pmail-desc-unseen-index n) 2150 (when (pmail-desc-attr-p pmail-desc-unseen-index n)
2146 (pmail-desc-set-attribute pmail-desc-unseen-index nil n)) 2151 (pmail-desc-set-attribute n pmail-desc-unseen-index nil))
2147 (pmail-display-labels) 2152 (pmail-display-labels)
2148 ;; Deal with MIME 2153 ;; Deal with MIME
2149 (if (eq pmail-enable-mime t) 2154 (if (eq pmail-enable-mime t)
@@ -2554,7 +2559,7 @@ If N is negative, go forwards instead."
2554(defun pmail-delete-message () 2559(defun pmail-delete-message ()
2555 "Delete this message and stay on it." 2560 "Delete this message and stay on it."
2556 (interactive) 2561 (interactive)
2557 (pmail-desc-set-attribute pmail-desc-deleted-index t pmail-current-message) 2562 (pmail-desc-set-attribute pmail-current-message pmail-desc-deleted-index t)
2558 (run-hooks 'pmail-delete-message-hook) 2563 (run-hooks 'pmail-delete-message-hook)
2559 (pmail-show-message pmail-current-message)) 2564 (pmail-show-message pmail-current-message))
2560 2565
@@ -2568,7 +2573,7 @@ If N is negative, go forwards instead."
2568 (setq msg (1- msg))) 2573 (setq msg (1- msg)))
2569 (if (= msg 0) 2574 (if (= msg 0)
2570 (error "No previous deleted message") 2575 (error "No previous deleted message")
2571 (pmail-desc-set-attribute pmail-desc-deleted-index nil msg) 2576 (pmail-desc-set-attribute msg pmail-desc-deleted-index nil)
2572 (pmail-show-message msg) 2577 (pmail-show-message msg)
2573 (if (pmail-summary-exists) 2578 (if (pmail-summary-exists)
2574 (save-excursion 2579 (save-excursion
@@ -2584,7 +2589,7 @@ With prefix argument, delete and move backward.
2584 2589
2585Returns t if a new message is displayed after the delete, or nil otherwise." 2590Returns t if a new message is displayed after the delete, or nil otherwise."
2586 (interactive "P") 2591 (interactive "P")
2587 (pmail-desc-set-attribute pmail-desc-deleted-index t pmail-current-message) 2592 (pmail-desc-set-attribute pmail-current-message pmail-desc-deleted-index t)
2588 (run-hooks 'pmail-delete-message-hook) 2593 (run-hooks 'pmail-delete-message-hook)
2589 (let ((del-msg pmail-current-message)) 2594 (let ((del-msg pmail-current-message))
2590 (if (pmail-summary-exists) 2595 (if (pmail-summary-exists)
@@ -2621,7 +2626,9 @@ See also user-option `pmail-confirm-expunge'."
2621 (or (eq buffer-undo-list t) (setq buffer-undo-list nil)) 2626 (or (eq buffer-undo-list t) (setq buffer-undo-list nil))
2622 ;; Remove the messages from the buffer and from the Pmail message 2627 ;; Remove the messages from the buffer and from the Pmail message
2623 ;; descriptor vector. 2628 ;; descriptor vector.
2629 (setq pmail-expunge-counter 0)
2624 (pmail-desc-prune-deleted-messages 'pmail-expunge-callback) 2630 (pmail-desc-prune-deleted-messages 'pmail-expunge-callback)
2631 (setq pmail-current-message (- pmail-current-message pmail-expunge-counter))
2625 ;; Deal with the summary buffer and update 2632 ;; Deal with the summary buffer and update
2626 ;; the User status. 2633 ;; the User status.
2627 (let* ((omax (- (buffer-size) (point-max))) 2634 (let* ((omax (- (buffer-size) (point-max)))
@@ -2650,13 +2657,9 @@ See also user-option `pmail-confirm-expunge'."
2650 message counter." 2657 message counter."
2651 ;; Process the various possible states to set the current message 2658 ;; Process the various possible states to set the current message
2652 ;; counter. 2659 ;; counter.
2653 (setq pmail-total-messages (1- pmail-total-messages) 2660 (setq pmail-total-messages (1- pmail-total-messages))
2654 pmail-current-message 2661 (if (>= pmail-current-message n)
2655 (cond 2662 (setq pmail-expunge-counter (1+ pmail-expunge-counter))))
2656 ((= 0 pmail-total-messages) 0)
2657 ((> pmail-current-message n) (pmail-desc-get-previous pmail-desc-deleted-index n))
2658 ((> pmail-current-message n) 0)
2659 (t pmail-current-message))))
2660 2663
2661;;; mbox: ready 2664;;; mbox: ready
2662(defun pmail-expunge () 2665(defun pmail-expunge ()
@@ -2793,7 +2796,7 @@ message buffers. MSGNUM-LIST is a list of the form (MSGNUM)."
2793 (let ((n (car msgnum-list))) 2796 (let ((n (car msgnum-list)))
2794 (set-buffer pmail-buffer) 2797 (set-buffer pmail-buffer)
2795 (pmail-narrow-to-message n) 2798 (pmail-narrow-to-message n)
2796 (pmail-desc-set-attribute attr-index t n)))) 2799 (pmail-desc-set-attribute n attr-index t))))
2797 2800
2798(defun pmail-narrow-to-message (n) 2801(defun pmail-narrow-to-message (n)
2799 "Narrow the current (pmail) buffer to bracket message N." 2802 "Narrow the current (pmail) buffer to bracket message N."
diff --git a/lisp/mail/pmaildesc.el b/lisp/mail/pmaildesc.el
index a63ea5cb207..9372be8ca20 100644
--- a/lisp/mail/pmaildesc.el
+++ b/lisp/mail/pmaildesc.el
@@ -355,18 +355,18 @@ This includes the attributes."
355 (nth pmail-desc-date-index (pmail-desc-get-descriptor n)))) 355 (nth pmail-desc-date-index (pmail-desc-get-descriptor n))))
356 356
357(defun pmail-desc-get-previous (n attr-index &optional sense) 357(defun pmail-desc-get-previous (n attr-index &optional sense)
358 "Return the index for the previous matching descriptor. 358 "Return the message index for the previous matching descriptor.
359Starting with descriptor at index N locate the first previous 359Starting with descriptor at index N locate the first previous
360descriptor such that the attribute ATTR is set. SENSE, if 360descriptor such that the attribute ATTR is set. SENSE, if
361non-null will reverse the sense of the attribute test." 361non-null will reverse the sense of the attribute test."
362 (let ((index (1- n)) flag result) 362 (let ((index (1- n)) flag result)
363 (while (and (> index 0) (not result)) 363 (while (and (> index 0) (not result))
364 (if (listp (aref pmail-desc-vector index)) 364 (if (listp (aref pmail-desc-vector (1- index)))
365 (setq result (pmail-desc-get-match-index attr-index sense index))) 365 (setq result (pmail-desc-get-match-index index attr-index sense)))
366 (setq index (1- index))) 366 (setq index (1- index)))
367 (or result 0))) 367 (or result 0)))
368 368
369(defun pmail-desc-get-match-index (attr-index sense n) 369(defun pmail-desc-get-match-index (n attr-index sense)
370 "Return the index N if the associated descriptor has a matching 370 "Return the index N if the associated descriptor has a matching
371attribute, nil otherwise. The attribute value must be set if 371attribute, nil otherwise. The attribute value must be set if
372SENSE is nil, or unset if SENSE is non-nil." 372SENSE is nil, or unset if SENSE is non-nil."
@@ -426,7 +426,7 @@ after a message has been deleted.."
426 (vconcat (delq t (append pmail-desc-vector nil)))) 426 (vconcat (delq t (append pmail-desc-vector nil))))
427 result)) 427 result))
428 428
429(defun pmail-desc-set-attribute (attr-index state n) 429(defun pmail-desc-set-attribute (n attr-index state)
430 "Set the attribute denoted by ATTR-INDEX in message N according to STATE. 430 "Set the attribute denoted by ATTR-INDEX in message N according to STATE.
431If STATE is non-nil the attribute will be set to the single character code 431If STATE is non-nil the attribute will be set to the single character code
432associated with ATTR-INDEX in pmail-desc-attr-alist, otherwise the attribute is 432associated with ATTR-INDEX in pmail-desc-attr-alist, otherwise the attribute is
diff --git a/lisp/mail/pmailout.el b/lisp/mail/pmailout.el
index d8e71646f7a..4d776bf357d 100644
--- a/lisp/mail/pmailout.el
+++ b/lisp/mail/pmailout.el
@@ -244,8 +244,7 @@ FILE-NAME defaults, interactively, from the Subject field of the message."
244 (error "Operation aborted")) 244 (error "Operation aborted"))
245 (write-region (point) (point-max) file-name) 245 (write-region (point) (point-max) file-name)
246 (when (equal major-mode 'pmail-mode) 246 (when (equal major-mode 'pmail-mode)
247 (pmail-desc-set-attribute pmail-desc-stored-index 247 (pmail-desc-set-attribute pmail-current-message pmail-desc-stored-index t)))
248 t pmail-current-message)))
249 (when pmail-delete-after-output 248 (when pmail-delete-after-output
250 (pmail-delete-forward))) 249 (pmail-delete-forward)))
251 250