From 6008ec7a6f24d940d83ae6dd930d3634f7f116a1 Mon Sep 17 00:00:00 2001 From: jao Date: Sun, 6 Jun 2021 22:15:22 +0100 Subject: notmuch: unread message count based on notmuch text properties --- email.org | 58 ++++++++++++++++++++++++++++------------------------------ 1 file changed, 28 insertions(+), 30 deletions(-) (limited to 'email.org') 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) -- cgit v1.2.3