From 1a6b9ba762fddc95bce00dc1a94dfd10c24dee60 Mon Sep 17 00:00:00 2001 From: jao Date: Mon, 26 Sep 2022 23:52:01 +0100 Subject: back to the future: using notmuch-tree-outline as submitted --- custom/jao-custom-notmuch.el | 27 +++++++++++----- lib/net/jao-notmuch.el | 75 +++++++++++++++++++------------------------- 2 files changed, 52 insertions(+), 50 deletions(-) diff --git a/custom/jao-custom-notmuch.el b/custom/jao-custom-notmuch.el index 5b6601c..731a277 100644 --- a/custom/jao-custom-notmuch.el +++ b/custom/jao-custom-notmuch.el @@ -148,6 +148,9 @@ (jao-notmuch-def-searches dynamic `(,(jao-notmuch--q "new" nil "nn" '("tag:new" "not tag:draft")) ,(jao-notmuch--q "jao" "drafts" "d" '("tag:draft")) + ,(jao-notmuch--q "bml" "sent-today" "ts" + '("tag:bigml" "date:24h.." "tag:sent")) + ,(jao-notmuch--q "jao" "sent-today" "tS" '("tag:jao" "date:24h.." "tag:sent")) ,(jao-notmuch--q "bml" "today" "tb" '("tag:bigml" "date:24h..")) ,(jao-notmuch--q "jao" "today" "tj" '("tag:jao" "date:24h.." @@ -161,7 +164,9 @@ '("feeds" "hacking" "bills" "jao"))) (jao-notmuch-def-searches nil - '((:query "not tag:gmane" :name "email") + '((:query "tag:sent and tag:bigml" :name "bigml/sent") + (:query "tag:sent and not tag:bigml" :name "jao/sent") + (:query "not tag:gmane" :name "email") (:query "tag:gmane" :name "gmane") (:query "*" :name "messages"))) @@ -459,15 +464,16 @@ ;; '((prefix . " ") (top . " ") (top-tee . " ") ;; (vertical . " ") (vertical-tee . " ") (bottom . " ") ;; (arrow . "")) - ) + notmuch-tree-outline-enabled t + notmuch-tree-outline-visibility 'hide-others + notmuch-tree-outline-auto-close t + notmuch-tree-outline-open-on-next t) :config (when (display-graphic-p) (jao-notmuch-adjust-tree-fonts (when (string-prefix-p "Hack" jao-themes-default-face) "Source Code Pro"))) - (jao-notmuch-tree-setup "T") - (defun jao-notmuch-before-tree (&rest args) (when (string= (buffer-name) "*notmuch-hello*") (split-window-right 40) @@ -482,6 +488,16 @@ (delete-window) (jao-notmuch-refresh-hello (= 0 (mod (cl-incf jao-notmuch--visits) 100))))) + (defun jao-notmuch-tree--sentinel (proc) + (when (eq (process-status proc) 'exit) + (let ((inhibit-read-only t)) + (save-excursion + (goto-char (point-max)) + (when (re-search-backward "^End of search results." nil t) + (delete-line)))))) + + (add-hook 'notmuch-tree-process-exit-functions #'jao-notmuch-tree--sentinel) + (advice-add 'notmuch-tree :before #'jao-notmuch-before-tree) (advice-add 'notmuch-tree-quit :after #'jao-notmuch-after-tree-quit) @@ -491,13 +507,10 @@ ("D" . jao-notmuch-tree-toggle-delete-thread) ("h" . jao-notmuch-goto-message-buffer) ("i" . jao-notmuch-toggle-images) - ("K" . jao-notmuch-tag-jump-and-next) ("k" . jao-notmuch-tree-read-thread) - ("n" . jao-notmuch-tree-next) ("N" . jao-notmuch-tree--forward) ("O" . notmuch-tree-toggle-order) ("o" . jao-notmuch-tree-widen-search) - ("p" . jao-notmuch-tree-previous) ("P" . jao-notmuch-tree--backward) ("r" . notmuch-tree-reply) ("R" . notmuch-tree-reply-sender) diff --git a/lib/net/jao-notmuch.el b/lib/net/jao-notmuch.el index 6dcb73e..aa82459 100644 --- a/lib/net/jao-notmuch.el +++ b/lib/net/jao-notmuch.el @@ -79,7 +79,7 @@ (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) + (notmuch-tree-outline-next) (when (not (window-live-p notmuch-tree-message-window)) (notmuch-tree-show-message nil))))) @@ -212,7 +212,7 @@ (with-current-buffer notmuch-tree-message-buffer (jao-notmuch--view-html)))))) -;;; keeping track of unread messages in current tree view +;;; header line with thread message counts (defun jao-notmuch--looking-at-new-p (&optional p) (when-let (ts (if p (plist-get p :tags) (notmuch-show-get-tags))) @@ -269,74 +269,64 @@ `((:eval (jao-notmuch--format-header-line ,(buffer-name tb) ,cb ,subject))) (concat " " subject))) - -;;; tree setup overall function - -(defun jao-notmuch-tree--sentinel (proc) - (when (eq (process-status proc) 'exit) - (let ((inhibit-read-only t)) - (save-excursion - (goto-char (point-max)) - (when (re-search-backward "^End of search results." nil t) - (let ((kill-whole-line t)) (kill-line))))) - (jao-notmuch-tree-hide-others))) - -(defun jao-notmuch-tree-setup (&optional prefix) - "Set up display of trees, with PREFIX key for outline commands." - (add-hook 'notmuch-tree-process-exit-functions #'jao-notmuch-tree--sentinel) - (jao-notmuch-tree-outline-setup prefix)) - ;;; tagging (defsubst jao-notmuch--has-tag (tag) (member tag (notmuch-tree-get-tags))) -(defun jao-notmuch-tag-jump-and-next (reverse) - (interactive "P") - (notmuch-tag-jump reverse) - (jao-notmuch-tree-next nil t)) - -(defun jao-notmuch-tree--tag (tags reverse whole-thread) +(defun jao-notmuch-tree--tag (tags reverse) (let ((c (notmuch-tag-change-list tags reverse))) - (if whole-thread (notmuch-tree-tag-thread c) (notmuch-tree-tag c)))) - -(defun jao-notmuch-tree--tag-and-next (tags reverse whole-thread) - (jao-notmuch-tree--tag tags reverse whole-thread) - (jao-notmuch-tree-next whole-thread t)) + (notmuch-tree-tag c))) + +(defun jao-notmuch-tree-tag-thread (tags reverse full) + (when full (notmuch-tree-thread-top)) + (let ((c (notmuch-tag-change-list tags reverse)) + (level (or (notmuch-tree-get-prop :level) 0)) + (go t)) + (while go + (notmuch-tree-tag c) + (forward-line) + (setq go (> (or (notmuch-tree-get-prop :level) 0) level))) + (when notmuch-tree-outline-mode + (ignore-errors (outline-show-branches)) + (notmuch-tree-outline-next)))) + +(defun jao-notmuch-tree--tag-and-next (tags reverse) + (jao-notmuch-tree--tag tags reverse) + (notmuch-tree-outline-next t)) (defun jao-notmuch-tree-toggle-delete () (interactive) (let ((undo (jao-notmuch--has-tag "deleted"))) - (jao-notmuch-tree--tag-and-next '("+deleted" "-new" "-unread") undo nil))) + (jao-notmuch-tree--tag-and-next '("+deleted" "-new" "-unread") undo))) -(defun jao-notmuch-tree-toggle-delete-thread () - (interactive) +(defun jao-notmuch-tree-toggle-delete-thread (full) + (interactive "P") (let ((undo (jao-notmuch--has-tag "deleted"))) - (jao-notmuch-tree--tag-and-next '("+deleted" "-new" "-unread") undo t))) + (jao-notmuch-tree-tag-thread '("+deleted" "-new" "-unread") undo full))) -(defun jao-notmuch-tree-read-thread (unread) +(defun jao-notmuch-tree-read-thread (full) (interactive "P") - (jao-notmuch-tree--tag-and-next '("-unread" "-new") unread t)) + (jao-notmuch-tree-tag-thread '("-unread" "-new") nil full)) (defun jao-notmuch-tree-toggle-flag () (interactive) (let ((tags (if (jao-notmuch--has-tag "flagged") '("-flagged") '("-unread" "-new" "-deleted" "+flagged")))) - (jao-notmuch-tree--tag-and-next tags nil nil))) + (jao-notmuch-tree--tag-and-next tags nil))) (defun jao-notmuch-tree-toggle-spam () (interactive) (let ((tags (if (jao-notmuch--has-tag "spam") '("-spam") '("-unread" "-new" "+spam")))) - (jao-notmuch-tree--tag-and-next tags nil nil))) + (jao-notmuch-tree--tag-and-next tags nil))) -(defun jao-notmuch-tree-reset-tags (&optional and-next) - (interactive "P") +(defun jao-notmuch-tree-reset-tags () + (interactive) (let ((tags (plist-get (notmuch-tree-get-message-properties) :orig-tags))) - (jao-notmuch-tree--tag tags nil nil) - (when and-next (jao-notmuch-tree--next nil nil t t)))) + (jao-notmuch-tree--tag tags nil))) (defvar jao-notmuch-mua-reply-not-inherited '("attachment" "sent" "new" "bigml" "jao" "trove")) @@ -359,7 +349,6 @@ (advice-add 'notmuch-mua-new-reply :around #'jao-notmuch-mua-new-reply) - ;;; results formatters (defun jao-notmuch-format-tags (fmt msg) -- cgit v1.2.3