summaryrefslogtreecommitdiffhomepage
path: root/lib/net
diff options
context:
space:
mode:
authorjao <jao@gnu.org>2022-06-02 02:25:00 +0100
committerjao <jao@gnu.org>2022-06-02 02:25:00 +0100
commitc2fdc5b445aa5ff8c53aa4ef6e098aa0dd180d96 (patch)
tree746038e75c9a136f27d9b6d61c38e115407a6e79 /lib/net
parentb221688313e7c39024417fedda997297ca69a30d (diff)
downloadelibs-c2fdc5b445aa5ff8c53aa4ef6e098aa0dd180d96.tar.gz
elibs-c2fdc5b445aa5ff8c53aa4ef6e098aa0dd180d96.tar.bz2
notmuch: counters as header line format
Diffstat (limited to 'lib/net')
-rw-r--r--lib/net/jao-notmuch.el92
1 files changed, 45 insertions, 47 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