Re: [PATCH 7/8] emacs: modify show tag functions to use new notmuch-tag interface
authorJameson Graef Rollins <jrollins@finestructure.net>
Mon, 9 Apr 2012 07:15:15 +0000 (00:15 +1700)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:46:09 +0000 (09:46 -0800)
4e/f3d8f5b61738462990cee02944dc2c7d39e155 [new file with mode: 0644]

diff --git a/4e/f3d8f5b61738462990cee02944dc2c7d39e155 b/4e/f3d8f5b61738462990cee02944dc2c7d39e155
new file mode 100644 (file)
index 0000000..48aed75
--- /dev/null
@@ -0,0 +1,156 @@
+Return-Path: <jrollins@finestructure.net>\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 6C198418C31\r
+       for <notmuch@notmuchmail.org>; Mon,  9 Apr 2012 00:15:24 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -2.29\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-2.29 tagged_above=-999 required=5\r
+       tests=[RCVD_IN_DNSWL_MED=-2.3, T_MIME_NO_TEXT=0.01] 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 9ZQ4XpWdA12P for <notmuch@notmuchmail.org>;\r
+       Mon,  9 Apr 2012 00:15:23 -0700 (PDT)\r
+Received: from outgoing-mail.its.caltech.edu (outgoing-mail.its.caltech.edu\r
+       [131.215.239.19])\r
+       by olra.theworths.org (Postfix) with ESMTP id B696F418C2C\r
+       for <notmuch@notmuchmail.org>; Mon,  9 Apr 2012 00:15:23 -0700 (PDT)\r
+Received: from earth-doxen.imss.caltech.edu (localhost [127.0.0.1])\r
+       by earth-doxen-postvirus (Postfix) with ESMTP id 3700C66E00FE;\r
+       Mon,  9 Apr 2012 00:15:21 -0700 (PDT)\r
+X-Spam-Scanned: at Caltech-IMSS on earth-doxen by amavisd-new\r
+Received: from finestructure.net (unknown [76.89.193.65])\r
+       (Authenticated sender: jrollins)\r
+       by earth-doxen-submit (Postfix) with ESMTP id 291B566E00DD;\r
+       Mon,  9 Apr 2012 00:15:18 -0700 (PDT)\r
+Received: by finestructure.net (Postfix, from userid 1000)\r
+       id CEF3B360; Mon,  9 Apr 2012 00:15:17 -0700 (PDT)\r
+From: Jameson Graef Rollins <jrollins@finestructure.net>\r
+To: Mark Walters <markwalters1009@gmail.com>,\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: <87zkam6fn3.fsf@qmul.ac.uk>\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
+User-Agent: Notmuch/0.12+108~g7bdb40c (http://notmuchmail.org) Emacs/23.4.1\r
+       (x86_64-pc-linux-gnu)\r
+Date: Mon, 09 Apr 2012 00:15:15 -0700\r
+Message-ID: <87d37hl6kc.fsf@servo.finestructure.net>\r
+MIME-Version: 1.0\r
+Content-Type: multipart/signed; boundary="=-=-=";\r
+       micalg=pgp-sha256; protocol="application/pgp-signature"\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 07:15:24 -0000\r
+\r
+--=-=-=\r
+\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
+--=-=-=\r
+Content-Type: application/pgp-signature\r
+\r
+-----BEGIN PGP SIGNATURE-----\r
+Version: GnuPG v1.4.12 (GNU/Linux)\r
+\r
+iQIcBAEBCAAGBQJPgoyDAAoJEO00zqvie6q88ksP/3IfJ97TQK/1FFlqom2AbXye\r
+1GuTX/i5IfNO7RHOB7e3t0xRLuEKuAavpgMXM/MiCg1Wwemd7/Zdlqy23aFvfpw6\r
+vzwvt2MRov+I4qs8CEL4Jxwx6rtxBa482+m4CYmPnPNtQZ0Ni+GfHGC1+6LAKmN3\r
+6dTUsPeJGqu2Z+GTCG7q1zEQC+LMju3QM2M2ryhWmaPd54thfKGkSgkFjrqwuooh\r
+h5+JsmmwaRJLw3eGozl8LQFH18/pi5xRyCJjBZeBqQM0ANRsewJxfEXno2Kx4XHo\r
+8t9GXJoEnQsWAZMy7jQH9GbJ33qHdq2EIX5OzNQyRWBMhe6AdDwX0FEL7QiUCyd4\r
+mimpq26jHCg2fZrpD5W33Xym0XYIsLIpgVJqLz3+6BGbOlyjtaBDi/+ol+Mugwp5\r
+bqlXj/2BYZK673DqxmzSatEHZECxcJ9dQ6dfWaxQS/4rl0C2crlif6CASU3SsL63\r
+Ba/jPMUt1wlxM/YzoHwiLVxGmvln/ri0enRW6k87snTMR8pBmt10qXHBuLl5J4E0\r
+WfQjE/yLvoP/xjiddJo7tdnKDRmGsu++obiP0Hcvexr1/dqRyfFXOfsEWFXEKjUi\r
+spQ75Q9qYv/hUSRD87XZpJBQ76NaUK+HNACZ7EFTaotlpsTwLbGd0pqdtPFw9mVS\r
+RLVGTsX/alSrNDzr9IIr\r
+=zAnc\r
+-----END PGP SIGNATURE-----\r
+--=-=-=--\r