]> git.notmuchmail.org Git - notmuch/commitdiff
emacs: Use a buffer-local variable to update tags when sending replies
authorÖrjan Ekeberg <ekeberg@kth.se>
Fri, 12 Apr 2019 12:01:11 +0000 (14:01 +0200)
committerDavid Bremner <david@tethera.net>
Sun, 14 Apr 2019 10:58:06 +0000 (07:58 -0300)
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
emacs/notmuch-mua.el

index 55e4cfee98cee93cc2e6f06591f0bad81b7cc1ca..0d4a8eeef72f429550dc20e73cdfffc6fe1150de 100644 (file)
@@ -23,7 +23,6 @@
 
 (require 'message)
 (require 'notmuch-tag)
 
 (require 'message)
 (require 'notmuch-tag)
-(require 'notmuch-mua)
 
 (defcustom notmuch-message-replied-tags '("+replied")
   "List of tag changes to apply to a message when it has been replied to.
 
 (defcustom notmuch-message-replied-tags '("+replied")
   "List of tag changes to apply to a message when it has been replied to.
@@ -34,18 +33,26 @@ 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:
 
 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)
 
   :type '(repeat string)
   :group 'notmuch-send)
 
-(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"))))
-    (when (and notmuch-message-replied-tags rep)
-      (notmuch-tag (notmuch-id-to-query (car (car rep)))
-              (notmuch-tag-change-list notmuch-message-replied-tags)))))
+(defconst notmuch-message-queued-tag-changes nil
+  "List of messages and corresponding tag-changes to be applied when sending a message.
 
 
-(add-hook 'message-send-hook 'notmuch-message-mark-replied)
+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)
 
 
 (provide 'notmuch-message)
 
index 23f3d8b12cf10dbca3f6e8cdc8079718fbc04ab5..2f0de92c6ec28f7fb511a1938698685fc41c17c8 100644 (file)
@@ -28,6 +28,7 @@
 (require 'notmuch-lib)
 (require 'notmuch-address)
 (require 'notmuch-draft)
 (require 'notmuch-lib)
 (require 'notmuch-address)
 (require 'notmuch-draft)
+(require 'notmuch-message)
 
 (eval-when-compile (require 'cl))
 
 
 (eval-when-compile (require 'cl))
 
@@ -259,6 +260,11 @@ Typically this is added to `notmuch-mua-send-hook'."
                            (notmuch-headers-plist-to-alist reply-headers)
                            nil (notmuch-mua-get-switch-function))))
 
                            (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.
       ;; 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.