[PATCH 3/3] emacs: generalize notmuch-message-mark-replied

Subject: [PATCH 3/3] emacs: generalize notmuch-message-mark-replied

Date: Fri, 13 May 2011 17:07:50 +0200

To: Notmuch Mail

Cc:

From: Pieter Praet


Renamed 'notmuch-message-mark-replied' to 'notmuch-message-mod-tags'.

Previously (semi)hardcoded vars are now to be provided as arguments,
allowing much more flexibility re autotagging in message-mode.

Paving the way towards proper draft handling?

Signed-off-by: Pieter Praet <pieter@praet.org>
---
 emacs/notmuch-message.el |   27 ++++++++++++++++++---------
 1 files changed, 18 insertions(+), 9 deletions(-)

diff --git a/emacs/notmuch-message.el b/emacs/notmuch-message.el
index c8b19c3..6026740 100644
--- a/emacs/notmuch-message.el
+++ b/emacs/notmuch-message.el
@@ -22,6 +22,8 @@
 (require 'message)
 (require 'notmuch-mua)
 
+(defvar notmuch-message-parent nil)
+
 (defcustom notmuch-message-replied-tags '("replied")
   "Tags to be automatically added to or removed from a message when it is replied to.
 Any tag in the list will be added to a replied message or,
@@ -33,20 +35,27 @@ the \"inbox\" and \"todo\", you would set
   :type 'list
   :group 'notmuch)
 
-(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)
-      ;; add a "+" to any tag that is doesn't already begin with a "+"
-      ;; or "-"
+(defun notmuch-message-mod-tags (msgid tagops)
+    (when (and msgid tagops)
+      ;; prepend operator-less tags with a "+"
       (let ((tags (mapcar '(lambda (str)
 			     (if (not (string-match "^[+-]" str))
 				 (concat "+" str)
 			       str))
-			  notmuch-message-replied-tags)))
+			  tagops)))
 	(apply 'notmuch-call-notmuch-process "tag"
-	       (append tags (list (concat "id:" (car (car rep)))) nil))))))
+	       (append tags (list (concat "id:" msgid)) nil)))))
+
+(add-hook 'message-setup-hook
+          (lambda ()
+            (set (make-local-variable 'notmuch-message-parent)
+                 ;; get the in-reply-to header and parse it for the message id.
+                 (car (car (mail-header-parse-addresses (message-field-value "In-Reply-To")))))))
+
+(add-hook 'message-sent-hook
+          (lambda ()
+            (notmuch-message-mod-tags notmuch-message-parent
+                                      notmuch-message-replied-tags)))
 
-(add-hook 'message-sent-hook 'notmuch-message-mark-replied)
 
 (provide 'notmuch-message)
-- 
1.7.4.1


Thread: