[PATCH] emacs: show: improve handling of mark read tagging errors

Mark Walters markwalters1009 at gmail.com
Tue Jun 7 14:51:32 PDT 2016


Previously if a marking read tag change (i.e., removing the unread
tag) failed for some reason, such as a locked database, then no more
mark read tag changes would be attempted in that buffer.

This handles the error more gracefully. There is not much we can do
yet about dealing with the error itself, and marking read is probably
not important enough to warrant keeping a queue of pending changes or
anything.

However this commit changes it so that

- we do try and make future mark read tag changes.

- we display the tag state correctly: i.e. we don't display the tag as
  deleted (no strike through)

- and since we know the tag change failed we can try to mark this
  message read in the future. Indeed, since the code uses the
  post-command hook we will try again on the next keypress (unless the
  user has left the message).

Since we could have many failed attempts at tagging, we just show a
message once per buffer.
---

This came up on irc today. The only real question is where to catch
the error. I think manual tag changes should give an actual error, so
we only want to catch errors from automatic tag-changes. By far the
most common of these is the mark read change, so just catch errors for
that.

Best wishes

Mark


emacs/notmuch-show.el | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el
index fea39fa..1753cac 100644
--- a/emacs/notmuch-show.el
+++ b/emacs/notmuch-show.el
@@ -1691,6 +1691,9 @@ marked as unread, i.e. the tag changes in
     (apply 'notmuch-show-tag-message
 	   (notmuch-tag-change-list notmuch-show-mark-read-tags unread))))
 
+(defvar notmuch-show--seen-has-errored nil)
+(make-variable-buffer-local 'notmuch-show--seen-has-errored)
+
 (defun notmuch-show-seen-current-message (start end)
   "Mark the current message read if it is open.
 
@@ -1698,8 +1701,14 @@ We only mark it read once: if it is changed back then that is a
 user decision and we should not override it."
   (when (and (notmuch-show-message-visible-p)
 	     (not (notmuch-show-get-prop :seen)))
-	(notmuch-show-mark-read)
-	(notmuch-show-set-prop :seen t)))
+    (condition-case err
+	(progn
+	  (notmuch-show-mark-read)
+	  (notmuch-show-set-prop :seen t))
+      (error
+       (unless notmuch-show--seen-has-errored
+	 (setq notmuch-show--seen-has-errored 't)
+	 (message "Warning: marking message read failed"))))))
 
 (defun notmuch-show-command-hook ()
   (when (eq major-mode 'notmuch-show-mode)
-- 
2.1.4



More information about the notmuch mailing list