From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by arlo.cworth.org (Postfix) with ESMTP id 0B8346DE1411 for ; Fri, 12 Apr 2019 05:01:52 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at cworth.org X-Spam-Flag: NO X-Spam-Score: -2.693 X-Spam-Level: X-Spam-Status: No, score=-2.693 tagged_above=-999 required=5 tests=[AWL=-0.191, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001] autolearn=disabled Received: from arlo.cworth.org ([127.0.0.1]) by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 9jHiFqgmxubv for ; Fri, 12 Apr 2019 05:01:51 -0700 (PDT) Received: from smtp-4.sys.kth.se (smtp-4.sys.kth.se [130.237.48.193]) by arlo.cworth.org (Postfix) with ESMTPS id 0F3276DE0EEA for ; Fri, 12 Apr 2019 05:01:41 -0700 (PDT) Received: from smtp-4.sys.kth.se (localhost.localdomain [127.0.0.1]) by smtp-4.sys.kth.se (Postfix) with ESMTP id 721D22854 for ; Fri, 12 Apr 2019 14:01:39 +0200 (CEST) X-Virus-Scanned: by amavisd-new at kth.se Received: from smtp-4.sys.kth.se ([127.0.0.1]) by smtp-4.sys.kth.se (smtp-4.sys.kth.se [127.0.0.1]) (amavisd-new, port 10024) with LMTP id vWpRJQEO358H; Fri, 12 Apr 2019 14:01:38 +0200 (CEST) X-KTH-Auth: ekeberg [2001:6b0:1:1de0:5018:5c50:6d6d:7a4] DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kth.se; s=default; t=1555070498; bh=JYUDhwng8gB9hRP5doBrS8AqLG3rPtzsJ0Uvx/HarYQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=XF6r0qLmCORzVcnE89rZD3L+8+v/Z+s/IcMsGnvT+HTLwhbi5MunwxF0AnF9q/u4y m3K2u90bEwQS7JJf6MqAnVqNx4w6Htt4jc5DgM78TVv8tRXdaUktN7tGePvLGQv3Q3 HbtwztjhE0EoefpTxQV5Bed9jAESV3imdK3A1AhQ= X-KTH-mail-from: ekeberg@kth.se Received: from swing.nada.kth.se (unknown [IPv6:2001:6b0:1:1de0:5018:5c50:6d6d:7a4]) by smtp-4.sys.kth.se (Postfix) with ESMTPSA id AC6492750; Fri, 12 Apr 2019 14:01:38 +0200 (CEST) From: =?UTF-8?q?=C3=96rjan=20Ekeberg?= 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 Message-Id: <20190412120113.8047-3-ekeberg@kth.se> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190412120113.8047-1-ekeberg@kth.se> References: <20190404230126.4283-1-ekeberg@kth.se> <20190412120113.8047-1-ekeberg@kth.se> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 12 Apr 2019 12:01:52 -0000 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