summaryrefslogtreecommitdiffhomepage
path: root/email.org
diff options
context:
space:
mode:
authorjao <jao@gnu.org>2021-06-06 22:15:22 +0100
committerjao <jao@gnu.org>2021-06-06 22:15:22 +0100
commit6008ec7a6f24d940d83ae6dd930d3634f7f116a1 (patch)
treee7e47af1a30f2eeda6574981892c593522ea92e0 /email.org
parent1bdcf80a11af8b1b7c0eac8bb704cc4b55330ca1 (diff)
downloadelibs-6008ec7a6f24d940d83ae6dd930d3634f7f116a1.tar.gz
elibs-6008ec7a6f24d940d83ae6dd930d3634f7f116a1.tar.bz2
notmuch: unread message count based on notmuch text properties
Diffstat (limited to 'email.org')
-rw-r--r--email.org58
1 files changed, 28 insertions, 30 deletions
diff --git a/email.org b/email.org
index 669607d..73e28da 100644
--- a/email.org
+++ b/email.org
@@ -480,29 +480,30 @@
(shr-blocked-images nil))
(notmuch-refresh-this-buffer)))))
- (defvar-local jao-notmuch--tree-count nil)
-
- (defun jao-notmuch--tree-set-buffer-name ()
- (when (derived-mode-p 'notmuch-tree-mode)
+ (defun jao-notmuch--unread-count ()
+ (save-excursion
+ (goto-char (point-min))
+ (let ((p) (cnt))
+ (while (setq p (text-property-search-forward
+ :notmuch-message-properties))
+ (let ((tags (plist-get (prop-match-value p) :tags)))
+ (when (or (member "unread" tags) (member "new" tags))
+ (setq cnt (1+ (or cnt 0))))))
+ cnt)))
+
+ (defun jao-notmuch-tree-update-buffer-name (&optional n)
+ (when-let ((n (or n (jao-notmuch--unread-count))))
(rename-buffer (format "*%s - {%s messages left}*"
notmuch-tree-basic-query
- jao-notmuch--tree-count))))
-
- (defun jao-notmuch---tree-update-buffer-name ()
- (when (derived-mode-p 'notmuch-tree-mode)
- (let ((cnt (or jao-notmuch--tree-count
- (plist-get (jao-notmuch-tree-count) :count)
- 1)))
- (setq-local jao-notmuch--tree-count (1- cnt))
- (jao-notmuch--tree-set-buffer-name))))
+ n))))
(defun jao-notmuch-tree-next (thread &optional no-exit)
"Next message or thread in forest or exit if none."
(interactive "P")
- (jao-notmuch---tree-update-buffer-name)
(if thread
(notmuch-tree-next-thread)
- (notmuch-tree-next-matching-message (not no-exit))))
+ (notmuch-tree-next-matching-message (not no-exit)))
+ (jao-notmuch-tree-update-buffer-name))
(defun jao-notmuch-tag-jump-and-next (reverse)
(interactive "P")
@@ -516,20 +517,18 @@
(defun jao-notmuch-tree-delete-message (undelete)
(interactive "P")
- (jao-notmuch-tree--tag-and-next '("+deleted" "-new") undelete nil))
+ (jao-notmuch-tree--tag-and-next '("+deleted" "-new" "-unread")
+ undelete
+ nil))
(defun jao-notmuch-tree-delete-thread ()
(interactive)
- (jao-notmuch-tree--tag-and-next '("+deleted" "-new") nil t))
+ (jao-notmuch-tree--tag-and-next '("+deleted" "-new" "-unread") nil t))
(defun jao-notmuch-tree-read-thread ()
(interactive)
(jao-notmuch-tree--tag-and-next '("-unread" "-new") nil t))
- (defun jao-notmuch-tree-count ()
- (when-let ((q (or notmuch-tree-basic-query notmuch-search-query-string)))
- (car (notmuch-hello-query-counts `((:query ,q))))))
-
(defun jao-notmuch-tree-scroll-or-next ()
"Scroll or next message in forest or exit if none."
(interactive)
@@ -537,7 +536,7 @@
(notmuch-tree-next-matching-message t)
(when (not (window-live-p notmuch-tree-message-window))
(notmuch-tree-show-message nil)))
- (jao-notmuch---tree-update-buffer-name))
+ (jao-notmuch-tree-update-buffer-name))
(defun jao-notmuch-tree-show-or-scroll ()
"Show current message, or scroll it if visible."
@@ -545,19 +544,19 @@
(if (window-live-p notmuch-tree-message-window)
(scroll-other-window 1)
(notmuch-tree-show-message nil)
- (jao-notmuch---tree-update-buffer-name)))
+ (jao-notmuch-tree-update-buffer-name)))
(use-package notmuch-tree
:config
+
(dolist (f '(notmuch-tree-match-tree-face
notmuch-tree-no-match-tree-face))
- (set-face-attribute f nil
- :family "Source Code Pro" :foreground "grey60"))
+ (set-face-attribute f nil :family "Fira Code" :foreground "grey60"))
(defun jao-notmuch--format-field (fun field &rest args)
(let ((rs (apply fun field args)))
(cond ((and (stringp field) (string= field "tree"))
- (replace-regexp-in-string "►" "" rs))
+ (replace-regexp-in-string "►" "→" rs))
((not (stringp field)) (truncate-string-to-width rs 100))
(t rs))))
@@ -566,10 +565,9 @@
(defun jao-notmuch-echo-count ()
(interactive)
- (when-let ((cnts (jao-notmuch-tree-count)))
- (setq-local jao-notmuch--tree-count (plist-get cnts :count))
- (jao-notmuch--tree-set-buffer-name)
- (message "%s messages left" jao-notmuch--tree-count)))
+ (when-let ((n (jao-notmuch--unread-count)))
+ (jao-notmuch-tree-update-buffer-name n)
+ (message "%s messages left" n)))
:bind (:map notmuch-tree-mode-map
(("." . jao-notmuch-toggle-mime-parts)