[Patch v3 5/8] emacs: show: mark tags changed since buffer loaded
[notmuch-archives.git] / 4e / f3d8f5b61738462990cee02944dc2c7d39e155
1 Return-Path: <jrollins@finestructure.net>\r
2 X-Original-To: notmuch@notmuchmail.org\r
3 Delivered-To: notmuch@notmuchmail.org\r
4 Received: from localhost (localhost [127.0.0.1])\r
5         by olra.theworths.org (Postfix) with ESMTP id 6C198418C31\r
6         for <notmuch@notmuchmail.org>; Mon,  9 Apr 2012 00:15:24 -0700 (PDT)\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
8 X-Spam-Flag: NO\r
9 X-Spam-Score: -2.29\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=-2.29 tagged_above=-999 required=5\r
12         tests=[RCVD_IN_DNSWL_MED=-2.3, T_MIME_NO_TEXT=0.01] autolearn=disabled\r
13 Received: from olra.theworths.org ([127.0.0.1])\r
14         by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
15         with ESMTP id 9ZQ4XpWdA12P for <notmuch@notmuchmail.org>;\r
16         Mon,  9 Apr 2012 00:15:23 -0700 (PDT)\r
17 Received: from outgoing-mail.its.caltech.edu (outgoing-mail.its.caltech.edu\r
18         [131.215.239.19])\r
19         by olra.theworths.org (Postfix) with ESMTP id B696F418C2C\r
20         for <notmuch@notmuchmail.org>; Mon,  9 Apr 2012 00:15:23 -0700 (PDT)\r
21 Received: from earth-doxen.imss.caltech.edu (localhost [127.0.0.1])\r
22         by earth-doxen-postvirus (Postfix) with ESMTP id 3700C66E00FE;\r
23         Mon,  9 Apr 2012 00:15:21 -0700 (PDT)\r
24 X-Spam-Scanned: at Caltech-IMSS on earth-doxen by amavisd-new\r
25 Received: from finestructure.net (unknown [76.89.193.65])\r
26         (Authenticated sender: jrollins)\r
27         by earth-doxen-submit (Postfix) with ESMTP id 291B566E00DD;\r
28         Mon,  9 Apr 2012 00:15:18 -0700 (PDT)\r
29 Received: by finestructure.net (Postfix, from userid 1000)\r
30         id CEF3B360; Mon,  9 Apr 2012 00:15:17 -0700 (PDT)\r
31 From: Jameson Graef Rollins <jrollins@finestructure.net>\r
32 To: Mark Walters <markwalters1009@gmail.com>,\r
33         Notmuch Mail <notmuch@notmuchmail.org>\r
34 Subject: Re: [PATCH 7/8] emacs: modify show tag functions to use new\r
35         notmuch-tag interface\r
36 In-Reply-To: <87zkam6fn3.fsf@qmul.ac.uk>\r
37 References: <1333354853-25729-1-git-send-email-jrollins@finestructure.net>\r
38         <1333845338-22960-1-git-send-email-jrollins@finestructure.net>\r
39         <1333845338-22960-2-git-send-email-jrollins@finestructure.net>\r
40         <1333845338-22960-3-git-send-email-jrollins@finestructure.net>\r
41         <1333845338-22960-4-git-send-email-jrollins@finestructure.net>\r
42         <1333845338-22960-5-git-send-email-jrollins@finestructure.net>\r
43         <1333845338-22960-6-git-send-email-jrollins@finestructure.net>\r
44         <1333845338-22960-7-git-send-email-jrollins@finestructure.net>\r
45         <1333845338-22960-8-git-send-email-jrollins@finestructure.net>\r
46         <87zkam6fn3.fsf@qmul.ac.uk>\r
47 User-Agent: Notmuch/0.12+108~g7bdb40c (http://notmuchmail.org) Emacs/23.4.1\r
48         (x86_64-pc-linux-gnu)\r
49 Date: Mon, 09 Apr 2012 00:15:15 -0700\r
50 Message-ID: <87d37hl6kc.fsf@servo.finestructure.net>\r
51 MIME-Version: 1.0\r
52 Content-Type: multipart/signed; boundary="=-=-=";\r
53         micalg=pgp-sha256; protocol="application/pgp-signature"\r
54 X-BeenThere: notmuch@notmuchmail.org\r
55 X-Mailman-Version: 2.1.13\r
56 Precedence: list\r
57 List-Id: "Use and development of the notmuch mail system."\r
58         <notmuch.notmuchmail.org>\r
59 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
60         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
61 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
62 List-Post: <mailto:notmuch@notmuchmail.org>\r
63 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
64 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
65         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
66 X-List-Received-Date: Mon, 09 Apr 2012 07:15:24 -0000\r
67 \r
68 --=-=-=\r
69 \r
70 On Sat, Apr 07 2012, Mark Walters <markwalters1009@gmail.com> wrote:\r
71 > I think this is what is making the two tests fail: they count the number\r
72 > of invocations of notmuch and in case there is one invocation of notmuch\r
73 > show and one of notmuch tag -unread message-id, where before it was just\r
74 > the single notmuch show.\r
75 \r
76 Good call, Mark.  After a bit of testing it looks like that is what's\r
77 going on.  I was confused, since I had thought that the call to\r
78 notmuch-show should have involved two notmuch calls originally as well,\r
79 one for retrieving the message and the other removing the unread tag.\r
80 However, it appears the messages in those tests don't have unread tags\r
81 after all.  Not sure why, but that explains it.\r
82 \r
83 So I guess the upshot is that moving all the common prompting and tag\r
84 validation stuff into notmuch-tag means that in certain cases there will\r
85 be extra notmuch calls, even if no tags are changed.  Is that a problem?\r
86 \r
87 What I can do, though, is add extra validation to notmuch-tag to not\r
88 actually call notmuch tag, or any of the pre- and post- tagging hooks,\r
89 if no tags are changing.  This will still require one call to notmuch to\r
90 retrieve the current set of tags for the query, but at least it wont tag\r
91 or call the hooks if nothing is changing.  That seems reasonable to me,\r
92 but please let me know if you think it's not.\r
93 \r
94 I've pasted below a new version of notmuch-tag that addresses these\r
95 issues.  Let me know what you think, and I'll resubmit the series.\r
96 \r
97 jamie.\r
98 \r
99 \r
100 (defun notmuch-tag (query &optional tag-changes)\r
101   "Add/remove tags in TAG-CHANGES to messages matching QUERY.\r
102 \r
103 QUERY should be a string containing the search-terms.\r
104 TAG-CHANGES can take multiple forms.  If TAG-CHANGES is a list of\r
105 strings of the form \"+tag\" or \"-tag\" then those are the tag\r
106 changes applied.  If TAG-CHANGES is a string then it is\r
107 interpreted as a single tag change.  If TAG-CHANGES is the string\r
108 \"-\" or \"+\", or null, then the user is prompted to enter the\r
109 tag changes.\r
110 \r
111 Note: Other code should always use this function alter tags of\r
112 messages instead of running (notmuch-call-notmuch-process \"tag\" ..)\r
113 directly, so that hooks specified in notmuch-before-tag-hook and\r
114 notmuch-after-tag-hook will be run."\r
115   ;; Perform some validation\r
116   (if (string-or-null-p tag-changes)\r
117       (if (or (string= tag-changes "-") (string= tag-changes "+") (null tag-changes))\r
118           (setq tag-changes (notmuch-read-tag-changes tag-changes query))\r
119         (setq tag-changes (list tag-changes))))\r
120   (mapc (lambda (tag-change)\r
121           (unless (string-match-p "^[-+]\\S-+$" tag-change)\r
122             (error "Tag must be of the form `+this_tag' or `-that_tag'")))\r
123         tag-changes)\r
124   (let* ((current-tags (notmuch-tag-completions (list query)))\r
125          (new-tags (notmuch-update-tags current-tags tag-changes)))\r
126     (if (equal current-tags new-tags)\r
127         ;; if no tags are changing, return nil\r
128         nil\r
129       (run-hooks 'notmuch-before-tag-hook)\r
130       (apply 'notmuch-call-notmuch-process "tag"\r
131              (append tag-changes (list "--" query)))\r
132       (run-hooks 'notmuch-after-tag-hook)\r
133       ;; otherwise, return the list of actual changed tags\r
134       tag-changes)))\r
135 \r
136 --=-=-=\r
137 Content-Type: application/pgp-signature\r
138 \r
139 -----BEGIN PGP SIGNATURE-----\r
140 Version: GnuPG v1.4.12 (GNU/Linux)\r
141 \r
142 iQIcBAEBCAAGBQJPgoyDAAoJEO00zqvie6q88ksP/3IfJ97TQK/1FFlqom2AbXye\r
143 1GuTX/i5IfNO7RHOB7e3t0xRLuEKuAavpgMXM/MiCg1Wwemd7/Zdlqy23aFvfpw6\r
144 vzwvt2MRov+I4qs8CEL4Jxwx6rtxBa482+m4CYmPnPNtQZ0Ni+GfHGC1+6LAKmN3\r
145 6dTUsPeJGqu2Z+GTCG7q1zEQC+LMju3QM2M2ryhWmaPd54thfKGkSgkFjrqwuooh\r
146 h5+JsmmwaRJLw3eGozl8LQFH18/pi5xRyCJjBZeBqQM0ANRsewJxfEXno2Kx4XHo\r
147 8t9GXJoEnQsWAZMy7jQH9GbJ33qHdq2EIX5OzNQyRWBMhe6AdDwX0FEL7QiUCyd4\r
148 mimpq26jHCg2fZrpD5W33Xym0XYIsLIpgVJqLz3+6BGbOlyjtaBDi/+ol+Mugwp5\r
149 bqlXj/2BYZK673DqxmzSatEHZECxcJ9dQ6dfWaxQS/4rl0C2crlif6CASU3SsL63\r
150 Ba/jPMUt1wlxM/YzoHwiLVxGmvln/ri0enRW6k87snTMR8pBmt10qXHBuLl5J4E0\r
151 WfQjE/yLvoP/xjiddJo7tdnKDRmGsu++obiP0Hcvexr1/dqRyfFXOfsEWFXEKjUi\r
152 spQ75Q9qYv/hUSRD87XZpJBQ76NaUK+HNACZ7EFTaotlpsTwLbGd0pqdtPFw9mVS\r
153 RLVGTsX/alSrNDzr9IIr\r
154 =zAnc\r
155 -----END PGP SIGNATURE-----\r
156 --=-=-=--\r