From 82bbdb507ad058353209e5963229caca2d4d7785 Mon Sep 17 00:00:00 2001
From: Raul Benencia <id@rbenencia.name>
Date: Thu, 12 Jan 2023 07:34:41 -0800
Subject: emacs: refresh notmuch after archiving

---
 .emacs.local.d/modes/notmuch.el | 25 +++++++++++++++++++++++--
 1 file changed, 23 insertions(+), 2 deletions(-)

diff --git a/.emacs.local.d/modes/notmuch.el b/.emacs.local.d/modes/notmuch.el
index b22ede3..42bdc45 100644
--- a/.emacs.local.d/modes/notmuch.el
+++ b/.emacs.local.d/modes/notmuch.el
@@ -61,13 +61,15 @@
   (lambda ()
     "archive"
     (interactive)
-    (notmuch-show-tag (list "+archive" "-inbox" "-unread"))))
+    (notmuch-show-tag (list "+archive" "-inbox" "-unread"))
+    (notmuch-refresh-this-buffer)))
 
 (define-key notmuch-search-mode-map "A"
   (lambda (&optional beg end)
     "mark thread as spam"
     (interactive (notmuch-search-interactive-region))
-    (notmuch-search-tag (list "+archive" "-inbox" "-unread") beg end)))
+    (notmuch-search-tag (list "+archive" "-inbox" "-unread") beg end)
+    (notmuch-refresh-this-buffer)))
 
 ; Mark as read
 (define-key notmuch-search-mode-map "R"
@@ -101,4 +103,23 @@ than one email. Use notmuch-show otherwise."
                    (when overlay
                      (overlay-put overlay 'face '((:inherit bold) (:foreground "green")))))))))))
 
+(defvar notmuch-hello-refresh-count 0)
+(defun notmuch-hello-refresh-status-message ()
+  (let* ((new-count
+          (string-to-number
+           (car (process-lines notmuch-command "count"))))
+         (diff-count (- new-count notmuch-hello-refresh-count)))
+    (cond
+     ((= notmuch-hello-refresh-count 0)
+      (message "You have %s messages."
+               (notmuch-hello-nice-number new-count)))
+     ((> diff-count 0)
+      (message "You have %s more messages since last refresh."
+               (notmuch-hello-nice-number diff-count)))
+     ((< diff-count 0)
+      (message "You have %s fewer messages since last refresh."
+               (notmuch-hello-nice-number (- diff-count)))))
+    (setq notmuch-hello-refresh-count new-count)))
+
 (add-hook 'notmuch-hello-refresh-hook 'color-inbox-if-unread)
+(add-hook 'notmuch-hello-refresh-hook 'notmuch-hello-refresh-status-message)
-- 
cgit v1.2.3