--- /dev/null
+Return-Path: <m.walters@qmul.ac.uk>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+ by olra.theworths.org (Postfix) with ESMTP id 020FA40DDF8\r
+ for <notmuch@notmuchmail.org>; Mon, 9 Apr 2012 11:22:34 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -1.098\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-1.098 tagged_above=-999 required=5\r
+ tests=[DKIM_ADSP_CUSTOM_MED=0.001, FREEMAIL_FROM=0.001,\r
+ NML_ADSP_CUSTOM_MED=1.2, RCVD_IN_DNSWL_MED=-2.3] autolearn=disabled\r
+Received: from olra.theworths.org ([127.0.0.1])\r
+ by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
+ with ESMTP id hbH9rhrTtKqN for <notmuch@notmuchmail.org>;\r
+ Mon, 9 Apr 2012 11:22:34 -0700 (PDT)\r
+Received: from mail2.qmul.ac.uk (mail2.qmul.ac.uk [138.37.6.6])\r
+ (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits))\r
+ (No client certificate requested)\r
+ by olra.theworths.org (Postfix) with ESMTPS id 0F2C540EC50\r
+ for <notmuch@notmuchmail.org>; Mon, 9 Apr 2012 11:22:34 -0700 (PDT)\r
+Received: from smtp.qmul.ac.uk ([138.37.6.40])\r
+ by mail2.qmul.ac.uk with esmtp (Exim 4.71)\r
+ (envelope-from <m.walters@qmul.ac.uk>)\r
+ id 1SHJEV-00043L-Qs; Mon, 09 Apr 2012 19:22:32 +0100\r
+Received: from 94-192-233-223.zone6.bethere.co.uk ([94.192.233.223]\r
+ helo=localhost)\r
+ by smtp.qmul.ac.uk with esmtpsa (TLSv1:AES128-SHA:128) (Exim 4.69)\r
+ (envelope-from <m.walters@qmul.ac.uk>)\r
+ id 1SHJEV-0003uK-Eq; Mon, 09 Apr 2012 19:22:31 +0100\r
+From: Mark Walters <markwalters1009@gmail.com>\r
+To: Jameson Graef Rollins <jrollins@finestructure.net>,\r
+ Notmuch Mail <notmuch@notmuchmail.org>\r
+Subject: Re: [PATCH 7/8] emacs: modify show tag functions to use new\r
+ notmuch-tag interface\r
+In-Reply-To: <87d37hl6kc.fsf@servo.finestructure.net>\r
+References: <1333354853-25729-1-git-send-email-jrollins@finestructure.net>\r
+ <1333845338-22960-1-git-send-email-jrollins@finestructure.net>\r
+ <1333845338-22960-2-git-send-email-jrollins@finestructure.net>\r
+ <1333845338-22960-3-git-send-email-jrollins@finestructure.net>\r
+ <1333845338-22960-4-git-send-email-jrollins@finestructure.net>\r
+ <1333845338-22960-5-git-send-email-jrollins@finestructure.net>\r
+ <1333845338-22960-6-git-send-email-jrollins@finestructure.net>\r
+ <1333845338-22960-7-git-send-email-jrollins@finestructure.net>\r
+ <1333845338-22960-8-git-send-email-jrollins@finestructure.net>\r
+ <87zkam6fn3.fsf@qmul.ac.uk>\r
+ <87d37hl6kc.fsf@servo.finestructure.net>\r
+User-Agent: Notmuch/0.12+111~g5c30f66 (http://notmuchmail.org) Emacs/23.3.1\r
+ (x86_64-pc-linux-gnu)\r
+Date: Mon, 09 Apr 2012 19:22:48 +0100\r
+Message-ID: <874nssn4sn.fsf@qmul.ac.uk>\r
+MIME-Version: 1.0\r
+Content-Type: text/plain; charset=us-ascii\r
+X-Sender-Host-Address: 94.192.233.223\r
+X-QM-SPAM-Info: Sender has good ham record. :)\r
+X-QM-Body-MD5: b438f2750443f1b281dd866b915fdd97 (of first 20000 bytes)\r
+X-SpamAssassin-Score: -1.8\r
+X-SpamAssassin-SpamBar: -\r
+X-SpamAssassin-Report: The QM spam filters have analysed this message to\r
+ determine if it is\r
+ spam. We require at least 5.0 points to mark a message as spam.\r
+ This message scored -1.8 points.\r
+ Summary of the scoring: \r
+ * -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at http://www.dnswl.org/,\r
+ * medium trust\r
+ * [138.37.6.40 listed in list.dnswl.org]\r
+ * 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail\r
+ provider * (markwalters1009[at]gmail.com)\r
+ * -0.0 T_RP_MATCHES_RCVD Envelope sender domain matches handover relay\r
+ * domain\r
+ * 0.5 AWL AWL: From: address is in the auto white-list\r
+X-QM-Scan-Virus: ClamAV says the message is clean\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.13\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+ <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Mon, 09 Apr 2012 18:22:35 -0000\r
+\r
+On Mon, 09 Apr 2012, Jameson Graef Rollins <jrollins@finestructure.net> wrote:\r
+> On Sat, Apr 07 2012, Mark Walters <markwalters1009@gmail.com> wrote:\r
+>> I think this is what is making the two tests fail: they count the number\r
+>> of invocations of notmuch and in case there is one invocation of notmuch\r
+>> show and one of notmuch tag -unread message-id, where before it was just\r
+>> the single notmuch show.\r
+>\r
+> Good call, Mark. After a bit of testing it looks like that is what's\r
+> going on. I was confused, since I had thought that the call to\r
+> notmuch-show should have involved two notmuch calls originally as well,\r
+> one for retrieving the message and the other removing the unread tag.\r
+> However, it appears the messages in those tests don't have unread tags\r
+> after all. Not sure why, but that explains it.\r
+>\r
+> So I guess the upshot is that moving all the common prompting and tag\r
+> validation stuff into notmuch-tag means that in certain cases there will\r
+> be extra notmuch calls, even if no tags are changed. Is that a problem?\r
+>\r
+> What I can do, though, is add extra validation to notmuch-tag to not\r
+> actually call notmuch tag, or any of the pre- and post- tagging hooks,\r
+> if no tags are changing. This will still require one call to notmuch to\r
+> retrieve the current set of tags for the query, but at least it wont tag\r
+> or call the hooks if nothing is changing. That seems reasonable to me,\r
+> but please let me know if you think it's not.\r
+>\r
+> I've pasted below a new version of notmuch-tag that addresses these\r
+> issues. Let me know what you think, and I'll resubmit the series.\r
+>\r
+> jamie.\r
+>\r
+>\r
+> (defun notmuch-tag (query &optional tag-changes)\r
+> "Add/remove tags in TAG-CHANGES to messages matching QUERY.\r
+>\r
+> QUERY should be a string containing the search-terms.\r
+> TAG-CHANGES can take multiple forms. If TAG-CHANGES is a list of\r
+> strings of the form \"+tag\" or \"-tag\" then those are the tag\r
+> changes applied. If TAG-CHANGES is a string then it is\r
+> interpreted as a single tag change. If TAG-CHANGES is the string\r
+> \"-\" or \"+\", or null, then the user is prompted to enter the\r
+> tag changes.\r
+>\r
+> Note: Other code should always use this function alter tags of\r
+> messages instead of running (notmuch-call-notmuch-process \"tag\" ..)\r
+> directly, so that hooks specified in notmuch-before-tag-hook and\r
+> notmuch-after-tag-hook will be run."\r
+> ;; Perform some validation\r
+> (if (string-or-null-p tag-changes)\r
+> (if (or (string= tag-changes "-") (string= tag-changes "+") (null tag-changes))\r
+> (setq tag-changes (notmuch-read-tag-changes tag-changes query))\r
+> (setq tag-changes (list tag-changes))))\r
+> (mapc (lambda (tag-change)\r
+> (unless (string-match-p "^[-+]\\S-+$" tag-change)\r
+> (error "Tag must be of the form `+this_tag' or `-that_tag'")))\r
+> tag-changes)\r
+> (let* ((current-tags (notmuch-tag-completions (list query)))\r
+> (new-tags (notmuch-update-tags current-tags tag-changes)))\r
+> (if (equal current-tags new-tags)\r
+> ;; if no tags are changing, return nil\r
+> nil\r
+> (run-hooks 'notmuch-before-tag-hook)\r
+> (apply 'notmuch-call-notmuch-process "tag"\r
+> (append tag-changes (list "--" query)))\r
+> (run-hooks 'notmuch-after-tag-hook)\r
+> ;; otherwise, return the list of actual changed tags\r
+> tag-changes)))\r
+\r
+Does this actually do the right thing if tagging more than one message?\r
+It looks to me like it would go wrong if you tried +inbox to a thread\r
+where some messages already have tag inbox (but I could be confused)?\r
+\r
+Also, I was going to say that I was not sure there was much point in\r
+optimising in the emacs code when the cli does anyway, but there is a\r
+question with xapian locking: with the orginally posted patch you can't\r
+use n or p in show view while the database is locked (eg a background\r
+notmuch new) as you get "A Xapian exception occurred opening database:\r
+Unable to get write lock on ..."\r
+\r
+Possibly, you could pass a current-tags variable to notmuch tag (and it\r
+would not add anything in that list or delete anything not in the\r
+list). But the 2 code paths might be viewed as being too different to be\r
+worth unifying. Or possibly have a "tag-single-message" command? \r
+\r
+Best wishes\r
+\r
+Mark\r
+\r