From 4f7050f5a08e9624e19950e28d9a6ec6d4b1f1c1 Mon Sep 17 00:00:00 2001 From: jao Date: Sun, 12 Sep 2021 02:28:41 +0100 Subject: notmuch: separate formatters and co. --- lib/net/jao-notmuch.el | 45 +++++++++++++++++++++++++++++++++++++-------- 1 file changed, 37 insertions(+), 8 deletions(-) (limited to 'lib/net') diff --git a/lib/net/jao-notmuch.el b/lib/net/jao-notmuch.el index 9a8ba5c..d5e239e 100644 --- a/lib/net/jao-notmuch.el +++ b/lib/net/jao-notmuch.el @@ -65,19 +65,28 @@ (pop-to-buffer jao-notmuch--tree-buffer nil no-record) (user-error "No tree view for this buffer"))) +(defun jao-notmuch-tree--looking-at-message () + (when-let (id (plist-get (notmuch-tree-get-message-properties) :id)) + (equal (concat "*notmuch-id:" id "*") + (buffer-name (window-buffer notmuch-tree-message-window))))) + (defun jao-notmuch-tree-scroll-or-next () "Scroll or next message in forest or exit if none." (interactive) - (if (notmuch-tree-scroll-message-window) - (jao-notmuch-tree-next nil) - (when (not (window-live-p notmuch-tree-message-window)) - (notmuch-tree-show-message nil))) - (jao-notmuch--tree-update-buffer-name)) + (if (not (jao-notmuch-tree--looking-at-message)) + (jao-notmuch-tree-show-or-scroll t) + (if (notmuch-tree-scroll-message-window) + (jao-notmuch-tree-next nil) + (when (not (window-live-p notmuch-tree-message-window)) + (notmuch-tree-show-message nil))) + (jao-notmuch--tree-update-buffer-name))) (defun jao-notmuch-tree-show-or-scroll (force) "Show current message, or scroll it if visible." (interactive "P") - (if (and (not force) (window-live-p notmuch-tree-message-window)) + (if (and (not force) + (window-live-p notmuch-tree-message-window) + (jao-notmuch-tree--looking-at-message)) (scroll-other-window 1) (notmuch-tree-show-message nil) (jao-notmuch--tree-update-buffer-name))) @@ -320,7 +329,7 @@ (defun jao-notmuch-tree-next-thread (&optional exit) "Next thread in forest, taking care of thread visibility." (interactive "P") - (jao-notmuch-tree--next nil t (not exit))) + (jao-notmuch-tree--next nil t exit)) (defun jao-notmuch-tree-previous (thread) "Previous message or thread in forest, taking care of thread visibility." @@ -330,7 +339,7 @@ (defun jao-notmuch-tree-previous-thread (&optional exit) "Previous thread in forest, taking care of thread visibility." (interactive "P") - (jao-notmuch-tree--next t t (not exit))) + (jao-notmuch-tree--next t t exit)) ;;;; Updating the tree window after insertion @@ -378,6 +387,26 @@ (let ((tags (if unmark '("-spam") '("-unread" "-new" "+spam")))) (jao-notmuch-tree--tag-and-next tags nil nil))) +;;;; Results formatters + +(defun jao-notmuch-format-tags (fmt msg) + (let ((ts (thread-last (notmuch-tree-format-field "tags" "%s" msg) + (split-string) + (seq-sort-by #'length #'<)))) + (format-spec fmt `((?s . ,(mapconcat #'identity ts " ")))))) + +(defun jao-notmuch-tree-and-subject (fmt msg) + (let ((tr (notmuch-tree-format-field "tree" " %s" msg)) + (sb (notmuch-tree-format-field "subject" " %s" msg))) + (format-spec fmt `((?s . ,(concat tr sb)))))) + +(defun jao-notmuch-msg-ticks (mails-rx msg) + (let ((headers (plist-get msg :headers))) + (cond ((string-match-p mails-rx (or (plist-get headers :To) "")) + (propertize " »" 'face 'notmuch-tree-match-tree-face)) + ((string-match-p mails-rx (or (plist-get headers :Cc) "")) + (propertize " ¬" 'face 'notmuch-tree-match-tree-face)) + (t " ")))) (provide 'jao-notmuch) ;;; jao-notmuch.el ends here -- cgit v1.2.3