From f4197d5356b401e941dd0471a7b62fc026af4d67 Mon Sep 17 00:00:00 2001 From: jao Date: Fri, 11 Mar 2022 21:44:18 +0000 Subject: toggling automatic notmuch tagging on gnus' moves --- lib/net/jao-notmuch-gnus.el | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) (limited to 'lib/net') diff --git a/lib/net/jao-notmuch-gnus.el b/lib/net/jao-notmuch-gnus.el index 4bc86c4..b505ced 100644 --- a/lib/net/jao-notmuch-gnus.el +++ b/lib/net/jao-notmuch-gnus.el @@ -66,10 +66,10 @@ (when-let (id (jao-notmuch-gnus-message-id)) (message "%s" (string-join (jao-notmuch-gnus-message-tags id) " ")))) -(defun jao-notmuch-gnus-toggle-tags (tags &optional id) +(defun jao-notmuch-gnus-toggle-tags (tags &optional id current) "Toggle the given TAGS list for the current Gnus message." (let* ((id (or id (jao-notmuch-gnus-message-id))) - (current (jao-notmuch-gnus-message-tags id)) + (current (or current (jao-notmuch-gnus-message-tags id))) (tags (mapcar (lambda (x) (concat (if (member x current) "-" "+") x)) tags))) @@ -87,13 +87,11 @@ (when (string-match ".+:\\(.+\\)" group) (split-string (match-string 1 group) "\\."))) -(defun jao-notmuch-gnus-tag-on-move (operation headers from to d) - (when-let (id (and to (jao-notmuch-gnus--notmuch-id (mail-header-id headers)))) - (when-let* ((to-tags (jao-notmuch-gnus--group-tags to)) - (from-tags (jao-notmuch-gnus--group-tags from)) - (new-tags (seq-difference to-tags from-tags)) - (new-tags (mapcar (lambda (x) (concat "+" x)) new-tags))) - (notmuch-tag (concat "id:" id) new-tags)))) +(defun jao-notmuch-gnus-tag-on-move (_operation headers from to _d) + (when-let* ((to-tags (when to (jao-notmuch-gnus--group-tags to))) + (id (jao-notmuch-gnus--notmuch-id (mail-header-id headers)))) + (let ((from-tags (seq-difference (jao-notmuch-gnus--group-tags from) to-tags))) + (jao-notmuch-gnus-toggle-tags (append from-tags to-tags) id from-tags)))) (add-hook 'gnus-summary-article-move-hook #'jao-notmuch-gnus-tag-on-move) (add-hook 'gnus-summary-article-expire-hook #'jao-notmuch-gnus-tag-on-move) -- cgit v1.2.3