From 25ae57058383ea58a8c77e709f3509fd64a47afe Mon Sep 17 00:00:00 2001 From: jao Date: Sun, 9 Jan 2022 03:43:14 +0000 Subject: notmuch: message counts only in header line --- lib/net/jao-notmuch.el | 64 +++++++++++++++++++------------------------------- notmuch.org | 9 +++---- 2 files changed, 27 insertions(+), 46 deletions(-) diff --git a/lib/net/jao-notmuch.el b/lib/net/jao-notmuch.el index ea8dc2a..f11556e 100644 --- a/lib/net/jao-notmuch.el +++ b/lib/net/jao-notmuch.el @@ -228,18 +228,6 @@ ;;;; Keeping track of unread messages in current tree view -(defvar-local jao-notmuch--query-name nil) - -(defun jao-notmuch--query-name () - (when notmuch-tree-basic-query - (or jao-notmuch--query-name - (setq jao-notmuch--query-name - (let ((q (seq-find (lambda (q) - (string= (or (plist-get q :query) "") - notmuch-tree-basic-query)) - notmuch-saved-searches))) - (or (plist-get q :name) notmuch-tree-basic-query)))))) - (defun jao-notmuch--looking-at-new-p (&optional p) (when-let (ts (if p (plist-get p :tags) (notmuch-show-get-tags))) (or (member "unread" ts) (member "new" ts)))) @@ -247,7 +235,7 @@ (defsubst jao-notmuch-tree--first-p (&optional msg) (plist-get (or msg (notmuch-tree-get-message-properties)) :first)) -(defun jao-notmuch--unread-counts (&optional thread) +(defun jao-notmuch--message-counts (&optional thread) (let ((cnt) (total 0) (match 0) (msg)) (save-excursion (if thread @@ -265,41 +253,38 @@ (forward-line 1))) (when cnt (list total match cnt)))) -(defvar jao-notmuch-tree-buffer-name-format "%Q") -(defvar jao-notmuch-header-line-format "[%N / %M / %T] %n / %m / %t - %S") +(defvar jao-notmuch-header-line-format "%S - %Q [%N / %M / %T] %n / %m / %t") -(defun jao-notmuch-tree--format-name (sb query total match new ttotal tmatch tnew) - (format-spec (if sb - jao-notmuch-header-line-format - jao-notmuch-tree-buffer-name-format) +(defun jao-notmuch--format-counts (sb query total match new ttotal tmatch tnew) + (format-spec jao-notmuch-header-line-format `((?S . ,sb) (?Q . ,query) (?T . ,total) (?N . ,new) (?M . ,match) (?t . ,ttotal) (?n . ,tnew) (?m . ,tmatch)))) -(defun jao-notmuch--update-header-line (q nc) - (let ((s (thread-last (notmuch-show-get-subject) - (notmuch-show-strip-re) - (notmuch-sanitize)))) - (setq-local header-line-format - (apply 'jao-notmuch-tree--format-name s q nc)))) - -(defun jao-notmuch--tree-update-buffer-name (&optional mb) - (when-let* ((n (jao-notmuch--unread-counts)) - (nc (append n (jao-notmuch--unread-counts t))) - (q (jao-notmuch--query-name))) - (prog1 (rename-buffer (apply #'jao-notmuch-tree--format-name nil q nc)) - (when mb (with-current-buffer mb (jao-notmuch--update-header-line q nc))) - (when (fboundp 'jao-minibuffer-refresh) (jao-minibuffer-refresh))))) - -(defun jao-notmuch-tree--find-update-buffer-name (&rest _args) - (when-let ((mb (window-buffer notmuch-tree-message-window))) +(defun jao-notmuch--update-header-line (mb) + (let* ((n (or (jao-notmuch--message-counts) '(0 0 0))) + (nc (append n (or (jao-notmuch--message-counts t) '(0 0 0)))) + (q (buffer-name))) + (with-current-buffer mb + (let ((s (thread-last (notmuch-show-get-subject) + (notmuch-show-strip-re) + (notmuch-sanitize)))) + (setq-local header-line-format + (apply 'jao-notmuch--format-counts s q nc)))))) + +(defun jao-notmuch-tree--find-update-header-line (&rest _args) + (when-let ((mb (if (derived-mode-p 'notmuch-show-mode) + (current-buffer) + (window-buffer notmuch-tree-message-window)))) (seq-find (lambda (b) (with-current-buffer b (and (derived-mode-p 'notmuch-tree-mode) - (eq notmuch-tree-message-buffer mb) - (jao-notmuch--tree-update-buffer-name mb)))) + (or (null notmuch-tree-message-buffer) + (eq notmuch-tree-message-buffer mb)) + (jao-notmuch--update-header-line mb)))) (buffer-list)))) -(add-hook 'notmuch-after-tag-hook #'jao-notmuch-tree--find-update-buffer-name) +(add-hook 'notmuch-after-tag-hook #'jao-notmuch-tree--find-update-header-line) +(add-hook 'notmuch-show-hook #'jao-notmuch-tree--find-update-header-line) ;;;; Outline mode for tree view @@ -375,7 +360,6 @@ (defun jao-notmuch--tree-sentinel (proc &rest _) (when (eq (process-status proc) 'exit) - (jao-notmuch--tree-update-buffer-name) (jao-notmuch-tree-hide-others))) (defun jao-notmuch-tree-setup (&optional prefix) diff --git a/notmuch.org b/notmuch.org index 781a718..b571bff 100644 --- a/notmuch.org +++ b/notmuch.org @@ -186,9 +186,7 @@ #+end_src * package #+begin_src emacs-lisp - (if (< emacs-major-version 28) - (jao-load-path "notmuch") - (add-to-list 'load-path "/usr/local/share/emacs/site-lisp/")) + (add-to-list 'load-path "/usr/local/share/emacs/site-lisp/") (use-package notmuch :init @@ -337,13 +335,12 @@ notmuch-wash-wrap-lines-length 80 notmuch-wash-citation-lines-prefix 10 notmuch-wash-citation-lines-suffix 20 - notmuch-show-text/html-blocked-images ".") + notmuch-show-text/html-blocked-images "." + notmuch-show-header-line t) :config (advice-add 'notmuch-clean-address :filter-args #'jao-mail-clean-address) - ;; (defun jao-notmuch-show-setup () (setq header-line-format nil)) - ;; (add-hook 'notmuch-show-hook #'jao-notmuch-show-setup) (jao-notmuch-show-prefer-html) :bind -- cgit v1.2.3