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 ++++++++++++++++++++++++++++---------------------- 1 file changed, 47 insertions(+), 37 deletions(-) (limited to 'lib') 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))) -- cgit v1.2.3