Mercurial > emacs
changeset 97967:cc9bb337ef7c
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.
author | Paul Reilly <pmr@pajato.com> |
---|---|
date | Wed, 03 Sep 2008 15:33:38 +0000 |
parents | 52f84cb577bb |
children | 13858591278a |
files | lisp/mail/pmail.el lisp/mail/pmaildesc.el lisp/mail/pmailout.el |
diffstat | 3 files changed, 22 insertions(+), 20 deletions(-) [+] |
line wrap: on
line diff
--- a/lisp/mail/pmail.el Wed Sep 03 14:09:49 2008 +0000 +++ b/lisp/mail/pmail.el Wed Sep 03 15:33:38 2008 +0000 @@ -186,6 +186,11 @@ (defvar pmail-encoded-remote-password nil) +(defvar pmail-expunge-counter 0 + "A counter used to keep track of the number of expunged +messages with a lower message number than the current message +index.") + (defcustom pmail-preserve-inbox nil "*Non-nil means leave incoming mail in the user's inbox--don't delete it." :type 'boolean @@ -1908,7 +1913,7 @@ (let ((attr-index (pmail-desc-get-attr-index attr))) (set-buffer pmail-buffer) (or msgnum (setq msgnum pmail-current-message)) - (pmail-desc-set-attribute attr-index state msgnum) + (pmail-desc-set-attribute msgnum attr-index state) ;; Deal with the summary buffer. (when pmail-summary-buffer (pmail-summary-update msgnum)))))) @@ -2143,7 +2148,7 @@ ;; Clear the "unseen" attribute when we show a message, unless ;; it is already cleared. (when (pmail-desc-attr-p pmail-desc-unseen-index n) - (pmail-desc-set-attribute pmail-desc-unseen-index nil n)) + (pmail-desc-set-attribute n pmail-desc-unseen-index nil)) (pmail-display-labels) ;; Deal with MIME (if (eq pmail-enable-mime t) @@ -2554,7 +2559,7 @@ (defun pmail-delete-message () "Delete this message and stay on it." (interactive) - (pmail-desc-set-attribute pmail-desc-deleted-index t pmail-current-message) + (pmail-desc-set-attribute pmail-current-message pmail-desc-deleted-index t) (run-hooks 'pmail-delete-message-hook) (pmail-show-message pmail-current-message)) @@ -2568,7 +2573,7 @@ (setq msg (1- msg))) (if (= msg 0) (error "No previous deleted message") - (pmail-desc-set-attribute pmail-desc-deleted-index nil msg) + (pmail-desc-set-attribute msg pmail-desc-deleted-index nil) (pmail-show-message msg) (if (pmail-summary-exists) (save-excursion @@ -2584,7 +2589,7 @@ Returns t if a new message is displayed after the delete, or nil otherwise." (interactive "P") - (pmail-desc-set-attribute pmail-desc-deleted-index t pmail-current-message) + (pmail-desc-set-attribute pmail-current-message pmail-desc-deleted-index t) (run-hooks 'pmail-delete-message-hook) (let ((del-msg pmail-current-message)) (if (pmail-summary-exists) @@ -2621,7 +2626,9 @@ (or (eq buffer-undo-list t) (setq buffer-undo-list nil)) ;; Remove the messages from the buffer and from the Pmail message ;; descriptor vector. + (setq pmail-expunge-counter 0) (pmail-desc-prune-deleted-messages 'pmail-expunge-callback) + (setq pmail-current-message (- pmail-current-message pmail-expunge-counter)) ;; Deal with the summary buffer and update ;; the User status. (let* ((omax (- (buffer-size) (point-max))) @@ -2650,13 +2657,9 @@ message counter." ;; Process the various possible states to set the current message ;; counter. - (setq pmail-total-messages (1- pmail-total-messages) - pmail-current-message - (cond - ((= 0 pmail-total-messages) 0) - ((> pmail-current-message n) (pmail-desc-get-previous pmail-desc-deleted-index n)) - ((> pmail-current-message n) 0) - (t pmail-current-message)))) + (setq pmail-total-messages (1- pmail-total-messages)) + (if (>= pmail-current-message n) + (setq pmail-expunge-counter (1+ pmail-expunge-counter)))) ;;; mbox: ready (defun pmail-expunge () @@ -2793,7 +2796,7 @@ (let ((n (car msgnum-list))) (set-buffer pmail-buffer) (pmail-narrow-to-message n) - (pmail-desc-set-attribute attr-index t n)))) + (pmail-desc-set-attribute n attr-index t)))) (defun pmail-narrow-to-message (n) "Narrow the current (pmail) buffer to bracket message N."
--- a/lisp/mail/pmaildesc.el Wed Sep 03 14:09:49 2008 +0000 +++ b/lisp/mail/pmaildesc.el Wed Sep 03 15:33:38 2008 +0000 @@ -355,18 +355,18 @@ (nth pmail-desc-date-index (pmail-desc-get-descriptor n)))) (defun pmail-desc-get-previous (n attr-index &optional sense) - "Return the index for the previous matching descriptor. + "Return the message index for the previous matching descriptor. Starting with descriptor at index N locate the first previous descriptor such that the attribute ATTR is set. SENSE, if non-null will reverse the sense of the attribute test." (let ((index (1- n)) flag result) (while (and (> index 0) (not result)) - (if (listp (aref pmail-desc-vector index)) - (setq result (pmail-desc-get-match-index attr-index sense index))) + (if (listp (aref pmail-desc-vector (1- index))) + (setq result (pmail-desc-get-match-index index attr-index sense))) (setq index (1- index))) (or result 0))) -(defun pmail-desc-get-match-index (attr-index sense n) +(defun pmail-desc-get-match-index (n attr-index sense) "Return the index N if the associated descriptor has a matching attribute, nil otherwise. The attribute value must be set if SENSE is nil, or unset if SENSE is non-nil." @@ -426,7 +426,7 @@ (vconcat (delq t (append pmail-desc-vector nil)))) result)) -(defun pmail-desc-set-attribute (attr-index state n) +(defun pmail-desc-set-attribute (n attr-index state) "Set the attribute denoted by ATTR-INDEX in message N according to STATE. If STATE is non-nil the attribute will be set to the single character code associated with ATTR-INDEX in pmail-desc-attr-alist, otherwise the attribute is
--- a/lisp/mail/pmailout.el Wed Sep 03 14:09:49 2008 +0000 +++ b/lisp/mail/pmailout.el Wed Sep 03 15:33:38 2008 +0000 @@ -244,8 +244,7 @@ (error "Operation aborted")) (write-region (point) (point-max) file-name) (when (equal major-mode 'pmail-mode) - (pmail-desc-set-attribute pmail-desc-stored-index - t pmail-current-message))) + (pmail-desc-set-attribute pmail-current-message pmail-desc-stored-index t))) (when pmail-delete-after-output (pmail-delete-forward)))