Mercurial > emacs
changeset 97920:92a6838937ab
Fix the expunge operation.
pmail.el (pmail-only-expunge): Manage pmail-total-messages in the
callback handler; remove the extra show message call.
(pmail-expunge-callback): Rewrite to handle all possible conditions.
pmaildesc.el (pmail-desc-get-previous, pmail-desc-get-match-index):
New functions.
author | Paul Reilly <pmr@pajato.com> |
---|---|
date | Mon, 01 Sep 2008 08:35:24 +0000 |
parents | 678a47bfb54c |
children | 7704da81c9da |
files | lisp/mail/pmail.el lisp/mail/pmaildesc.el |
diffstat | 2 files changed, 35 insertions(+), 10 deletions(-) [+] |
line wrap: on
line diff
--- a/lisp/mail/pmail.el Mon Sep 01 08:18:32 2008 +0000 +++ b/lisp/mail/pmail.el Mon Sep 01 08:35:24 2008 +0000 @@ -2622,10 +2622,8 @@ ;; Remove the messages from the buffer and from the Pmail message ;; descriptor vector. (pmail-desc-prune-deleted-messages 'pmail-expunge-callback) - ;; Update the Pmail message counter, deal with the summary buffer, - ;; show the current message and update the User status. - (setq pmail-total-messages (pmail-desc-get-count)) - (pmail-show-message pmail-current-message t) + ;; Deal with the summary buffer and update + ;; the User status. (let* ((omax (- (buffer-size) (point-max))) (omin (- (buffer-size) (point-min))) (opoint (if (and (> pmail-current-message 0) @@ -2650,8 +2648,15 @@ (defun pmail-expunge-callback (n) "Called after message N has been pruned to update the current Pmail message counter." - (if (< n pmail-current-message) - (setq pmail-current-message (1- pmail-current-message)))) + ;; 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)))) ;;; mbox: ready (defun pmail-expunge ()
--- a/lisp/mail/pmaildesc.el Mon Sep 01 08:18:32 2008 +0000 +++ b/lisp/mail/pmaildesc.el Mon Sep 01 08:35:24 2008 +0000 @@ -354,6 +354,27 @@ (nth pmail-desc-date-month-index (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. +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))) + (setq index (1- index))) + (or result 0))) + +(defun pmail-desc-get-match-index (attr-index sense n) + "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." + (let (flag (pmail-desc-attr-p attr-index n)) + (if (or (and flag (not sense)) (and (not flag) sense)) + n + nil))) + (defun pmail-desc-get-sender (n) "Return the User registered as the mail sender." (nth pmail-desc-sender-index (pmail-desc-get-descriptor n))) @@ -395,11 +416,10 @@ Return the number of messages removed. Invoke CALLBACK immediately after a message has been deleted.." - ;; Set the callback. + ;; Set the callback and remove all messages marked for deletion from + ;; the Pmail buffer and their descriptors from the Pmail message + ;; vector. (setq pmail-desc-delete-callback callback) - - ;; Remove all messages marked for deletion from the Pmail buffer and - ;; their descriptors from the Pmail message vector. (let ((result (length (delq t (mapcar 'pmail-desc-delete-maybe (pmail-desc-make-index-list)))))) (setq pmail-desc-vector