From 2ed606540fd3a4302aae86a838f61650a7e2725e Mon Sep 17 00:00:00 2001 From: jao Date: Wed, 3 Nov 2021 03:40:43 +0000 Subject: notmuch tweaks (tags toggling) --- lib/net/jao-notmuch.el | 84 ++++++++++++++++++++++++++++---------------------- notmuch.org | 44 +++++++++++++------------- 2 files changed, 68 insertions(+), 60 deletions(-) diff --git a/lib/net/jao-notmuch.el b/lib/net/jao-notmuch.el index 77d0d13..fd5df2c 100644 --- a/lib/net/jao-notmuch.el +++ b/lib/net/jao-notmuch.el @@ -60,8 +60,18 @@ (unless (eq 'url (jao-notmuch-goto-message-buffer t t)) (pop-to-buffer b)))) +(defun jao-notmuch-tree--find-tree-buffer () + (or jao-notmuch--tree-buffer + (let ((mb (current-buffer))) + (seq-find (lambda (b) + (with-current-buffer b + (and (derived-mode-p 'notmuch-tree-mode) + (eq notmuch-tree-message-buffer mb)))) + (buffer-list))))) + (defun jao-notmuch-goto-tree-buffer (&optional no-record) (interactive) + (setq jao-notmuch--tree-buffer (jao-notmuch-tree--find-tree-buffer)) (if (buffer-live-p jao-notmuch--tree-buffer) (pop-to-buffer jao-notmuch--tree-buffer nil no-record) (user-error "No tree view for this buffer"))) @@ -183,38 +193,30 @@ (unless jao-notmuch--showing-images notmuch-show-text/html-blocked-images)) (when activate + (setq-local scroll-margin 0) (w3m-toggle-inline-images (if jao-notmuch--showing-images t 'turnoff)))) (defun jao-notmuch-show-images () (interactive) - (save-window-excursion - (when (or (derived-mode-p 'notmuch-show-mode) - (jao-notmuch-goto-message-buffer nil t)) - (goto-char (point-min)) - (when (re-search-forward "^\\[ text/html " nil t) - (when (looking-at-p "(hidden)") - (notmuch-show-toggle-part-invisibility)) - (forward-line 1) - (setq jao-notmuch--showing-images (not jao-notmuch--showing-images)) - (jao-notmuch--setup-w3m-images t))))) + (if (eq mm-text-html-renderer 'shr) + (let ((shr-blocked-images nil) + (shr-inhibit-images nil) + (notmuch-show-text/html-blocked-images nil)) + (notmuch-tree-close-message-window) + (notmuch-tree-show-message nil)) + (save-window-excursion + (when (or (derived-mode-p 'notmuch-show-mode) + (jao-notmuch-goto-message-buffer nil t)) + (goto-char (point-min)) + (when (re-search-forward "^\\[ text/html " nil t) + (when (looking-at-p "(hidden)") + (notmuch-show-toggle-part-invisibility)) + (forward-line 1) + (setq jao-notmuch--showing-images (not jao-notmuch--showing-images)) + (jao-notmuch--setup-w3m-images t)))))) (add-hook 'notmuch-show-mode-hook #'jao-notmuch--setup-w3m-images) - -;;;; w3m renderer - -(defun jao-w3m-gnus-html-renderer (handle) - (let ((w3m-message-silent t) - (mm-w3m-safe-url-regexp nil)) - (condition-case nil - (mm-inline-text-html-render-with-w3m handle) - (error (delete-region (point) (point-max)) - (let ((shr-use-fonts nil) - (shr-use-colors nil)) - (mm-shr handle)))))) - -(setq mm-text-html-renderer #'jao-w3m-gnus-html-renderer) - ;;;; Keeping track of unread messages in current tree view @@ -370,6 +372,9 @@ ;;;; 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) @@ -381,29 +386,34 @@ (defun jao-notmuch-tree--tag-and-next (tags reverse whole-thread) (jao-notmuch-tree--tag tags reverse whole-thread) - (jao-notmuch-tree--forward) (jao-notmuch-tree-next whole-thread t)) -(defun jao-notmuch-tree-delete-message (undelete) - (interactive "P") - (jao-notmuch-tree--tag-and-next '("+deleted" "-new" "-unread") undelete nil)) +(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))) -(defun jao-notmuch-tree-delete-thread () +(defun jao-notmuch-tree-toggle-delete-thread () (interactive) - (jao-notmuch-tree--tag-and-next '("+deleted" "-new" "-unread") nil t)) + (let ((undo (jao-notmuch--has-tag "deleted"))) + (jao-notmuch-tree--tag-and-next '("+deleted" "-new" "-unread") undo t))) (defun jao-notmuch-tree-read-thread (unread) (interactive "P") (jao-notmuch-tree--tag-and-next '("-unread" "-new") unread t)) -(defun jao-notmuch-tree-flag (unmark) - (interactive "P") - (let ((tags (if unmark '("-flagged") '("-unread" "-new" "-deleted" "+flagged")))) +(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))) -(defun jao-notmuch-tree-spam (unmark) - (interactive "P") - (let ((tags (if unmark '("-spam") '("-unread" "-new" "+spam")))) +(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))) diff --git a/notmuch.org b/notmuch.org index 5d89ca5..8683045 100644 --- a/notmuch.org +++ b/notmuch.org @@ -11,14 +11,18 @@ (:name "b" :query "tag:new and tag:bigml and tag:bugs" :face jao-themes-error) (:name "S" :query "tag:new and tag:bigml and tag:support" :face default) - (:name "W" :query "tag:new and tag:bigml" :face default) + (:name "W" + :query "tag:new and tag:bigml and not tag:\"/support|bugs|inbox/\"" + :face default) (:name "H" :query "tag:new and tag:jao and tag:hacking") (:name "T" :query "tag:new and tag:think") (:name "E" :query "tag:new and tag:\"/emacs/\"") (:name "l" :query "tag:new and tag:local") - (:name "J" :query "tag:new and tag:jao and not tag:\"/local|hacking/\"" + (:name "J" + :query "tag:new and tag:jao and not tag:\"/local|hacking|draft/\"" :face default) - (:name "F" :query "tag:new and tag:feeds and not tag:\"/emacs|papers/\"") + (:name "F" :query + "tag:new and tag:feeds and not tag:\"/emacs|papers|think/\"") (:name "G" :query "tag:new and tag:gmane and not tag:\"/emacs|papers/\"") (:name "P" :query "tag:new and tag:papers"))) @@ -62,10 +66,14 @@ (defun jao-notmuch--sec (q) (append q '(:secondary t))) - (defun jao-notmuch--sq (tag k &optional d0 d1) + (defun jao-notmuch--sq (tag &optional k d0 d1) (jao-notmuch--sec (jao-notmuch--qn (or d0 "feeds") (or d1 tag) k (list (concat "tag:" tag))))) + (defvar jao-notmuch--feeds + '("clojure" "elixir" "erlang" "gnus" "haskell" "idris" + "lobsters" "mailutils" "notmuch" "papers" "scheme" "xmobar")) + (setq notmuch-saved-searches `(,(jao-notmuch--q "bigml" "inbox" "bi") ,(jao-notmuch--q "bigml" "support" "bs") @@ -78,22 +86,11 @@ ,(jao-notmuch--sq "emacs-devel" "ed" "emacs" "devel") ,(jao-notmuch--sq "emacs-bugs" "eb" "emacs" "bugs") ,(jao-notmuch--sq "emacs-diffs" "ec" "emacs" "diffs") - ,(jao-notmuch--sq "clojure" "fc") - ,(jao-notmuch--sq "elixir" "fex") - ,(jao-notmuch--sq "erlang" "fe") - ,(jao-notmuch--sq "gnus" "fg") - ,(jao-notmuch--sq "haskell" "fh") - ,(jao-notmuch--sq "idris" "fid") - ,(jao-notmuch--sq "lobsters" "fl") - ,(jao-notmuch--sq "mailutils" "fm") - ,(jao-notmuch--sq "notmuch" "fn") - ,(jao-notmuch--sq "papers" "fax") - ,(jao-notmuch--sq "scheme" "fl") - ,(jao-notmuch--sq "xmobar" "fx") + ,@(mapcar #'jao-notmuch--sq jao-notmuch--feeds) ,(jao-notmuch--sec (jao-notmuch--qn "feeds" "prog" "fp" '("tag:prog" - "not tag:\"/(lobsters|clojure|xmobar|gmane)/\""))) + "not tag:\"/(lobsters|clojure|erlang|xmobar|gmane)/\""))) ,@(mapcar #'jao-notmuch--sec (jao-notmuch--mboxes-search "feeds" "emacs" "prog")))) @@ -105,7 +102,8 @@ "not tag:\"/(feeds|spam|local)/\"")) ,(jao-notmuch--q "bml" "flagged" "rb" '("tag:flagged" "tag:bigml")) ,(jao-notmuch--q "jao" "flagged" "rj" '("tag:flagged" "not tag:bigml")) - ,(jao-notmuch--q "unread" nil "n" '("tag:unread")))) + ,(jao-notmuch--q "new" nil "nn" '("tag:new")) + ,(jao-notmuch--q "unread" nil "nu" '("tag:unread")))) (defun jao-notmuch-tree-widen-search () (interactive) @@ -402,8 +400,8 @@ :bind (:map notmuch-tree-mode-map (("b" . jao-notmuch-browse-urls) ("C" . jao-notmuch-echo-count) - ("d" . jao-notmuch-tree-delete-message) - ("D" . jao-notmuch-tree-delete-thread) + ("d" . jao-notmuch-tree-toggle-delete) + ("D" . jao-notmuch-tree-toggle-delete-thread) ("h" . jao-notmuch-goto-message-buffer) ("H" . jao-notmuch-click-message-buffer) ("i" . jao-notmuch-show-images) @@ -417,14 +415,14 @@ ("P" . jao-notmuch-tree--backward) ("r" . notmuch-tree-reply) ("R" . notmuch-tree-reply-sender) - ("s" . jao-notmuch-tree-spam) - ("u" . jao-notmuch-tree-flag) + ("s" . jao-notmuch-tree-toggle-spam) + ("u" . jao-notmuch-tree-toggle-flag) ("v" . notmuch-tree-scroll-message-window) ("V" . notmuch-tree-scroll-message-window-back) ("x" . jao-notmuch-arXiv-capture) ("<" . jao-notmuch-tree-beginning-of-buffer) (">" . jao-notmuch-tree-end-of-buffer) - ("/" . notmuch-tree-view-raw-message) + ("\\" . notmuch-tree-view-raw-message) ("." . jao-notmuch-toggle-mime-parts) ("=" . jao-notmuch-tree-toggle-message) ("RET" . jao-notmuch-tree-show-or-scroll) -- cgit v1.2.3