unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
From: "Örjan Ekeberg" <ekeberg@kth.se>
To: notmuch@notmuchmail.org
Subject: [PATCH v4 2/4] emacs: Use a buffer-local variable to update tags when sending replies
Date: Fri, 12 Apr 2019 14:01:11 +0200	[thread overview]
Message-ID: <20190412120113.8047-3-ekeberg@kth.se> (raw)
In-Reply-To: <20190412120113.8047-1-ekeberg@kth.se>

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 | 25 ++++++++++++++++---------
 emacs/notmuch-mua.el     |  6 ++++++
 2 files changed, 22 insertions(+), 9 deletions(-)

diff --git a/emacs/notmuch-message.el b/emacs/notmuch-message.el
index 55e4cfee..0d4a8eee 100644
--- a/emacs/notmuch-message.el
+++ b/emacs/notmuch-message.el
@@ -23,7 +23,6 @@
 
 (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.
@@ -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:
-    (\"+replied\" \"-inbox\" \"-todo\"\)"
+    (\"+replied\" \"-inbox\" \"-todo\")"
   :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)
 
diff --git a/emacs/notmuch-mua.el b/emacs/notmuch-mua.el
index 23f3d8b1..2f0de92c 100644
--- a/emacs/notmuch-mua.el
+++ b/emacs/notmuch-mua.el
@@ -28,6 +28,7 @@
 (require 'notmuch-lib)
 (require 'notmuch-address)
 (require 'notmuch-draft)
+(require 'notmuch-message)
 
 (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))))
 
+      ;; 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

  parent reply	other threads:[~2019-04-12 12:01 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-03-30 21:48 [PATCH 0/2] Updating tags when replying or forwarding via a buffer-local variable Örjan Ekeberg
2019-03-30 21:48 ` [PATCH 1/2] emacs: Use a buffer-local variable to update tags when sending replies Örjan Ekeberg
2019-03-30 21:48 ` [PATCH 2/2] emacs: Tag forwarded messages with +forwarded (customizable) Örjan Ekeberg
2019-03-31 22:34 ` [PATCH 0/2] Updating tags when replying or forwarding via a buffer-local variable Daniel Kahn Gillmor
2019-04-01 21:24 ` Tomi Ollila
2019-04-02  9:12   ` Örjan Ekeberg
2019-04-03 20:10     ` Tomi Ollila
2019-04-04 23:01       ` Örjan Ekeberg
2019-04-04 23:01         ` [PATCH v2 1/4] emacs: Add References header to forwarded messages Örjan Ekeberg
2019-04-04 23:01         ` [PATCH v2 2/4] emacs: Use a buffer-local variable to update tags when sending replies Örjan Ekeberg
2019-04-04 23:01         ` [PATCH v2 3/4] emacs: Tag forwarded messages with +forwarded (customizable) Örjan Ekeberg
2019-04-04 23:01         ` [PATCH v2 4/4] test: add test for checking forwarded messages Örjan Ekeberg
2019-04-07 19:39           ` Tomi Ollila
2019-04-07 20:24             ` Örjan Ekeberg
2019-04-08 14:21           ` David Edmondson
2019-04-10 12:19             ` Updated testing script Örjan Ekeberg
2019-04-10 12:19               ` [PATCH v3 4/4] test: add test for checking forwarded messages Örjan Ekeberg
2019-04-10 20:25                 ` Tomi Ollila
2019-04-11 11:26                   ` Örjan Ekeberg
2019-04-12 12:01         ` Updated version of the patch-set for tagging " Örjan Ekeberg
2019-04-12 12:01           ` [PATCH v4 1/4] emacs: Add References header to " Örjan Ekeberg
2019-04-12 12:01           ` Örjan Ekeberg [this message]
2019-04-12 12:01           ` [PATCH v4 3/4] emacs: Tag forwarded messages with +forwarded (customizable) Örjan Ekeberg
2019-04-12 12:01           ` [PATCH v4 4/4] test: add test for checking forwarded messages Örjan Ekeberg
2019-04-13 10:19           ` Updated version of the patch-set for tagging " Tomi Ollila
2019-04-14 11:30           ` David Bremner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://notmuchmail.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190412120113.8047-3-ekeberg@kth.se \
    --to=ekeberg@kth.se \
    --cc=notmuch@notmuchmail.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://yhetil.org/notmuch.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).