Return-Path: X-Original-To: notmuch@notmuchmail.org Delivered-To: notmuch@notmuchmail.org Received: from localhost (localhost [127.0.0.1]) by olra.theworths.org (Postfix) with ESMTP id 64DF8429E2C for ; Fri, 13 May 2011 08:08:39 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: -0.7 X-Spam-Level: X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5 tests=[RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled Received: from olra.theworths.org ([127.0.0.1]) by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id irR9awqoo7v3 for ; Fri, 13 May 2011 08:08:39 -0700 (PDT) Received: from mail-ww0-f45.google.com (mail-ww0-f45.google.com [74.125.82.45]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) (No client certificate requested) by olra.theworths.org (Postfix) with ESMTPS id C4EF3431FD0 for ; Fri, 13 May 2011 08:08:38 -0700 (PDT) Received: by wwi36 with SMTP id 36so2394516wwi.2 for ; Fri, 13 May 2011 08:08:37 -0700 (PDT) Received: by 10.227.178.135 with SMTP id bm7mr1544984wbb.52.1305299317443; Fri, 13 May 2011 08:08:37 -0700 (PDT) Received: from localhost (54.209-242-81.adsl-dyn.isp.belgacom.be [81.242.209.54]) by mx.google.com with ESMTPS id bo14sm1018033wbb.28.2011.05.13.08.08.24 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 13 May 2011 08:08:35 -0700 (PDT) From: Pieter Praet To: Notmuch Mail Subject: [PATCH 3/3] emacs: generalize notmuch-message-mark-replied Date: Fri, 13 May 2011 17:07:50 +0200 Message-Id: <1305299270-4316-3-git-send-email-pieter@praet.org> X-Mailer: git-send-email 1.7.4.1 In-Reply-To: <1305299270-4316-1-git-send-email-pieter@praet.org> References: <1305275652-22956-1-git-send-email-pieter@praet.org> <1305299270-4316-1-git-send-email-pieter@praet.org> X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.13 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, 13 May 2011 15:08:39 -0000 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 --- 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