[PATCH 1/2] emacs: Use a buffer-local variable to update tags when sending replies
Örjan Ekeberg
ekeberg at kth.se
Sat Mar 30 14:48:20 PDT 2019
Instead of relying on the "In-Reply-To" header, use a buffer-local variable,
notmuch-message-queued-tag-changes, to add and remove tags to affected
messages when the message-send-hook is triggered.
---
emacs/notmuch-message.el | 21 +++++++++++++++++++--
emacs/notmuch-mua.el | 5 +++++
2 files changed, 24 insertions(+), 2 deletions(-)
diff --git a/emacs/notmuch-message.el b/emacs/notmuch-message.el
index 55e4cfee..513bbe66 100644
--- a/emacs/notmuch-message.el
+++ b/emacs/notmuch-message.el
@@ -34,10 +34,11 @@ will be removed from the message being replied to.
For example, if you wanted to add a \"replied\" tag and remove
the \"inbox\" and \"todo\" tags, you would set:
- (\"+replied\" \"-inbox\" \"-todo\"\)"
+ (\"+replied\" \"-inbox\" \"-todo\")"
:type '(repeat string)
:group 'notmuch-send)
+;; This function is not used by default, but kept for backward compatibility
(defun notmuch-message-mark-replied ()
;; get the in-reply-to header and parse it for the message id.
(let ((rep (mail-header-parse-addresses (message-field-value "In-Reply-To"))))
@@ -45,7 +46,23 @@ the \"inbox\" and \"todo\" tags, you would set:
(notmuch-tag (notmuch-id-to-query (car (car rep)))
(notmuch-tag-change-list notmuch-message-replied-tags)))))
-(add-hook 'message-send-hook 'notmuch-message-mark-replied)
+
+(defconst notmuch-message-queued-tag-changes nil
+ "List of messages and corresponding tag-changes to be applied when sending a message.
+
+This variable is overridden by buffer-local versions in message
+buffers where tag changes should be triggered when sending off
+the message. Each item in this list is a list of strings, where
+the first is a notmuch query and the rest are the tag changes to
+be applied to the matching messages.")
+
+(defun notmuch-message-apply-queued-tag-changes ()
+ ;; Apply the tag changes queued in the buffer-local variable notmuch-message-queued-tag-changes.
+ (dolist (query-and-tags notmuch-message-queued-tag-changes)
+ (notmuch-tag (car query-and-tags)
+ (cdr query-and-tags))))
+
+(add-hook 'message-send-hook 'notmuch-message-apply-queued-tag-changes)
(provide 'notmuch-message)
diff --git a/emacs/notmuch-mua.el b/emacs/notmuch-mua.el
index ed15bbb2..b23a8c2d 100644
--- a/emacs/notmuch-mua.el
+++ b/emacs/notmuch-mua.el
@@ -259,6 +259,11 @@ Typically this is added to `notmuch-mua-send-hook'."
(notmuch-headers-plist-to-alist reply-headers)
nil (notmuch-mua-get-switch-function))))
+ ;; Create a buffer-local queue for tag changes triggered when sending the reply
+ (when notmuch-message-replied-tags
+ (setq-local notmuch-message-queued-tag-changes
+ (list (cons query-string notmuch-message-replied-tags))))
+
;; Insert the message body - but put it in front of the signature
;; if one is present, and after any other content
;; message*setup-hooks may have added to the message body already.
--
2.20.1
More information about the notmuch
mailing list