diff options
author | jao <jao@gnu.org> | 2022-06-02 02:25:00 +0100 |
---|---|---|
committer | jao <jao@gnu.org> | 2022-06-02 02:25:00 +0100 |
commit | c2fdc5b445aa5ff8c53aa4ef6e098aa0dd180d96 (patch) | |
tree | 746038e75c9a136f27d9b6d61c38e115407a6e79 | |
parent | b221688313e7c39024417fedda997297ca69a30d (diff) | |
download | elibs-c2fdc5b445aa5ff8c53aa4ef6e098aa0dd180d96.tar.gz elibs-c2fdc5b445aa5ff8c53aa4ef6e098aa0dd180d96.tar.bz2 |
notmuch: counters as header line format
-rw-r--r-- | lib/net/jao-notmuch.el | 92 | ||||
-rw-r--r-- | notmuch.org | 6 |
2 files changed, 48 insertions, 50 deletions
diff --git a/lib/net/jao-notmuch.el b/lib/net/jao-notmuch.el index d5a312d..05ec394 100644 --- a/lib/net/jao-notmuch.el +++ b/lib/net/jao-notmuch.el @@ -211,8 +211,14 @@ (when (fboundp 'jao-notmuch--w3m-toggle-images) (jao-notmuch--w3m-toggle-images))) (window-system (jao-notmuch--shr-toggle-images)) - (t (with-current-buffer notmuch-tree-message-buffer - (jao-notmuch--view-html))))) + (notmuch-tree-message-buffer + (if nil ;;(fboundp 'jao-open-in-x-frame) + (let ((w (get-buffer-window notmuch-tree-message-buffer))) + (jao-open-in-x-frame (window-width w) (window-height w)) + (jao-notmuch--shr-toggle-images) + (delete-window)) + (with-current-buffer notmuch-tree-message-buffer + (jao-notmuch--view-html)))))) ;;;; Keeping track of unread messages in current tree view @@ -224,23 +230,24 @@ (defsubst jao-notmuch-tree--first-p (&optional msg) (plist-get (or msg (notmuch-tree-get-message-properties)) :first)) -(defun jao-notmuch--message-counts (&optional thread) - (let ((cnt) (total 0) (match 0) (msg)) - (save-excursion - (if thread - (while (and (not (jao-notmuch-tree--first-p)) - (zerop (forward-line -1)))) - (goto-char (point-min))) - (while (and (setq msg (notmuch-tree-get-message-properties)) - (or (not cnt) - (not thread) - (not (jao-notmuch-tree--first-p msg)))) - (unless cnt (setq cnt 0)) - (setq total (1+ total)) - (when (plist-get msg :match) (setq match (1+ match))) - (when (jao-notmuch--looking-at-new-p msg) (setq cnt (1+ cnt))) - (forward-line 1))) - (when cnt (list total match cnt)))) +(defun jao-notmuch--message-counts (tree-buffer &optional thread) + (with-current-buffer tree-buffer + (let ((cnt) (total 0) (match 0) (msg)) + (save-excursion + (if thread + (while (and (not (jao-notmuch-tree--first-p)) + (zerop (forward-line -1)))) + (goto-char (point-min))) + (while (and (setq msg (notmuch-tree-get-message-properties)) + (or (not cnt) + (not thread) + (not (jao-notmuch-tree--first-p msg)))) + (unless cnt (setq cnt 0)) + (setq total (1+ total)) + (when (plist-get msg :match) (setq match (1+ match))) + (when (jao-notmuch--looking-at-new-p msg) (setq cnt (1+ cnt))) + (forward-line 1))) + (when cnt (list total match cnt))))) (defvar jao-notmuch-header-line-format "%Q [%N / %M / %T] %n / %m / %t") @@ -249,36 +256,27 @@ `((?Q . ,query) (?T . ,total) (?N . ,new) (?M . ,match) (?t . ,ttotal) (?n . ,tnew) (?m . ,tmatch)))) -(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 +(defun jao-notmuch--format-header-line (tree-buffer buffer subject) + (let* ((n (jao-notmuch--message-counts tree-buffer)) + (nc (jao-notmuch--message-counts tree-buffer t))) + (with-current-buffer buffer (when (derived-mode-p 'notmuch-show-mode) - (let* ((s (thread-last (notmuch-show-get-subject) - (notmuch-show-strip-re) - (notmuch-sanitize))) + (let* ((nc (append (or n '(0 0 0)) (or nc '(0 0 0)))) + (q (if (string= tree-buffer subject) "" tree-buffer)) (c (apply 'jao-notmuch--format-counts q nc)) - (n (- (window-width) 3 (string-width s) (string-width c))) - (s (if (< n 0) (substring s 0 (- n 4)) s)) - (n (if (< n 0) 5 (1+ n)))) - (setq-local header-line-format - (concat " " s (make-string n ? ) c))))))) - -(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) - (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-header-line) -(add-hook 'notmuch-show-hook #'jao-notmuch-tree--find-update-header-line) + (n (- (window-width) 2 (string-width subject) (string-width c))) + (subject (if (< n 0) (substring subject 0 n) subject)) + (n (if (< n 0) 2 (+ n 2)))) + (concat (when window-system " ") subject (make-string n ? ) c)))))) + +(defun jao-notmuch-message-header-line (subject) + (if-let* ((cb (buffer-name (current-buffer))) + (tb (seq-find (lambda (b) + (with-current-buffer b + (and (derived-mode-p 'notmuch-tree-mode) b))) + (buffer-list)))) + `((:eval (jao-notmuch--format-header-line ,(buffer-name tb) ,cb ,subject))) + (concat " " subject))) ;;;; Outline mode for tree view diff --git a/notmuch.org b/notmuch.org index 3b203fe..a8792c1 100644 --- a/notmuch.org +++ b/notmuch.org @@ -18,7 +18,7 @@ :query "tag:new and tag:jao and tag:inbox" :face jao-themes-warning) (:name "J" - :query "tag:new and tag:jao and not tag:\"/local|hacking|draft|inbox/\"" + :query "tag:new and tag:jao and not tag:\"/local|hacking|draft|inbox|prog|words/\"" :face default) (:name "H" :query "tag:new and tag:hacking and not tag:\"/emacs/\"") (:name "E" :query "tag:new and tag:\"/emacs/\"") @@ -75,11 +75,11 @@ (defvar jao-notmuch-feed-searches-hack (mapcar #'jao-notmuch--sq - '("xmobar" "geiser" "lobsters" "mailutils" "notmuch"))) + '("xmobar" "geiser" "mdk" "mailutils" "notmuch"))) (defvar jao-notmuch-feed-searches-lang (append (mapcar #'jao-notmuch--sq - '("clojure" "lisp" "scheme" + '( "lobsters" "clojure" "lisp" "scheme" "haskell" "idris" "erlang" "pharo")) `(,(jao-notmuch--qn "feeds" "prog" "fp" '("tag:prog" "not tag:\"/emacs/\""))))) |