Re: [feature request] emacs: use `notmuch insert` for FCC
[notmuch-archives.git] / 06 / 3f2ef2422fbddb0b32766e6a4cd88221677d38
1 Return-Path: <amdragon@mit.edu>\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 17D10431FB6\r
6         for <notmuch@notmuchmail.org>; Sat,  5 Apr 2014 17:58:29 -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: -0.7\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5\r
12         tests=[RCVD_IN_DNSWL_LOW=-0.7] 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 OvvoJ5CJKs6a for <notmuch@notmuchmail.org>;\r
16         Sat,  5 Apr 2014 17:58:25 -0700 (PDT)\r
17 Received: from dmz-mailsec-scanner-1.mit.edu (dmz-mailsec-scanner-1.mit.edu\r
18         [18.9.25.12])\r
19         (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits))\r
20         (No client certificate requested)\r
21         by olra.theworths.org (Postfix) with ESMTPS id 23143431FAF\r
22         for <notmuch@notmuchmail.org>; Sat,  5 Apr 2014 17:58:25 -0700 (PDT)\r
23 X-AuditID: 1209190c-f794a6d000000c27-88-5340a6b00a96\r
24 Received: from mailhub-auth-3.mit.edu ( [18.9.21.43])\r
25         (using TLS with cipher AES256-SHA (256/256 bits))\r
26         (Client did not present a certificate)\r
27         by dmz-mailsec-scanner-1.mit.edu (Symantec Messaging Gateway) with SMTP\r
28         id 14.61.03111.0B6A0435; Sat,  5 Apr 2014 20:58:24 -0400 (EDT)\r
29 Received: from outgoing.mit.edu (outgoing-auth-1.mit.edu [18.9.28.11])\r
30         by mailhub-auth-3.mit.edu (8.13.8/8.9.2) with ESMTP id s360wMlr028426; \r
31         Sat, 5 Apr 2014 20:58:23 -0400\r
32 Received: from awakening.csail.mit.edu (awakening.csail.mit.edu [18.26.4.91])\r
33         (authenticated bits=0)\r
34         (User authenticated as amdragon@ATHENA.MIT.EDU)\r
35         by outgoing.mit.edu (8.13.8/8.12.4) with ESMTP id s360wKZ2013328\r
36         (version=TLSv1/SSLv3 cipher=DHE-RSA-AES128-SHA bits=128 verify=NOT);\r
37         Sat, 5 Apr 2014 20:58:21 -0400\r
38 Received: from amthrax by awakening.csail.mit.edu with local (Exim 4.80)\r
39         (envelope-from <amdragon@mit.edu>)\r
40         id 1WWbPg-0006wI-5q; Sat, 05 Apr 2014 20:58:20 -0400\r
41 Date: Sat, 5 Apr 2014 20:58:20 -0400\r
42 From: Austin Clements <amdragon@MIT.EDU>\r
43 To: Mark Walters <markwalters1009@gmail.com>\r
44 Subject: Re: [PATCH 1/5] emacs: hello: add helper functions for saved-searches\r
45 Message-ID: <20140406005820.GD15472@mit.edu>\r
46 References: <1396733065-32602-1-git-send-email-markwalters1009@gmail.com>\r
47         <1396733065-32602-2-git-send-email-markwalters1009@gmail.com>\r
48 MIME-Version: 1.0\r
49 Content-Type: text/plain; charset=us-ascii\r
50 Content-Disposition: inline\r
51 In-Reply-To: <1396733065-32602-2-git-send-email-markwalters1009@gmail.com>\r
52 User-Agent: Mutt/1.5.21 (2010-09-15)\r
53 X-Brightmail-Tracker:\r
54  H4sIAAAAAAAAA+NgFmpmleLIzCtJLcpLzFFi42IR4hTV1t2wzCHY4OxnPovVc3ksrt+cyezA\r
55         5LFz1l12j2erbjEHMEVx2aSk5mSWpRbp2yVwZfz82sZW0CZZ0Xp7AmMD4wPhLkZODgkBE4lp\r
56         J68wQ9hiEhfurWfrYuTiEBKYzSRx4swxZghnA6PE6rMPmCCcU0wS6/YsZgJpERJYwihxeBYP\r
57         iM0ioCJxddM0FhCbTUBDYtv+5YwgtoiAjsTtQwvYQWxmAWmJb7+bwXqFBfwkDkw7DWbzAtWc\r
58         /9UDtaCTUeLWj/WMEAlBiZMzn7BANGtJ3Pj3EqiIA2zQ8n8cIGFOAS+J3ct3gM0XBbphyslt\r
59         bBMYhWYh6Z6FpHsWQvcCRuZVjLIpuVW6uYmZOcWpybrFyYl5ealFuoZ6uZkleqkppZsYwWEt\r
60         ybOD8c1BpUOMAhyMSjy8F/IcgoVYE8uKK3MPMUpyMCmJ8nbNAArxJeWnVGYkFmfEF5XmpBYf\r
61         YpTgYFYS4X0SBJTjTUmsrEotyodJSXOwKInzvrW2ChYSSE8sSc1OTS1ILYLJynBwKEnw7l0K\r
62         1ChYlJqeWpGWmVOCkGbi4AQZzgM0/B5IDW9xQWJucWY6RP4Uo6KUOO+MJUAJAZBERmkeXC8s\r
63         7bxiFAd6RZhXB6SdB5iy4LpfAQ1mAhrcEGYHMrgkESEl1cBYWCwwe5LGS+s3+hqbcmWn/Lqe\r
64         dLX9cMtXPYMIK+8vrG+Vtm172JrV0r5mhrVqnmfRzA33PJse7pR/Kbtk/+ygOXMWF8e3JkfM\r
65         t9hdxJe4+tP5kNTlsc3TEn1mJTQ2ZJT9bNoY2rn3zfp/50+q2+j+nG+wZtKT5Czla6kXfzM8\r
66         KtJfl1qxpm+KEktxRqKhFnNRcSIAT+c/TBYDAAA=\r
67 Cc: notmuch@notmuchmail.org\r
68 X-BeenThere: notmuch@notmuchmail.org\r
69 X-Mailman-Version: 2.1.13\r
70 Precedence: list\r
71 List-Id: "Use and development of the notmuch mail system."\r
72         <notmuch.notmuchmail.org>\r
73 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
74         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
75 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
76 List-Post: <mailto:notmuch@notmuchmail.org>\r
77 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
78 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
79         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
80 X-List-Received-Date: Sun, 06 Apr 2014 00:58:29 -0000\r
81 \r
82 Quoth Mark Walters on Apr 05 at 10:24 pm:\r
83 > Add helper functions to for saved searches to ease the transition to\r
84 > the new plist form while maintaining backwards compatibility. They\r
85 > will be used in the next patch.\r
86 > ---\r
87 >  emacs/notmuch-hello.el |   39 +++++++++++++++++++++++++++++++++++++++\r
88 >  1 file changed, 39 insertions(+)\r
89\r
90 > diff --git a/emacs/notmuch-hello.el b/emacs/notmuch-hello.el\r
91 > index e325cd3..0b9ed16 100644\r
92 > --- a/emacs/notmuch-hello.el\r
93 > +++ b/emacs/notmuch-hello.el\r
94 > @@ -269,6 +269,45 @@ (defun notmuch-hello-search (&optional search)\r
95 >        (add-to-history 'notmuch-search-history search)))\r
96 >    (notmuch-search search notmuch-search-oldest-first))\r
97 >  \r
98 > +(defun notmuch-saved-search-get (saved-search field)\r
99 > +  "Get FIELD from SAVED-SEARCH.\r
100 > +\r
101 > +In the new style saved-search (a plist) this is just plist-get\r
102 \r
103 It won't be "new style" once this has been in for a while.  Perhaps\r
104 "If SAVED-SEARCH is a plist, this is just `plist-get', but for\r
105 backwards compatibility, ..."\r
106 \r
107 > +but, for backwards compatibility, this deals with the two\r
108 > +old-style forms: cons cells (NAME . QUERY) and lists (NAME QUERY\r
109 > +COUNT-QUERY)."\r
110 > +  (cond\r
111 > +   ((plist-get saved-search :name)\r
112 \r
113 Rather than depending on :name, maybe this should be a more generic\r
114 plist test like (keywordp (car saved-search))?\r
115 \r
116 > +    (plist-get saved-search field))\r
117 > +   ;; It is not a plist so it is an old-style entry.\r
118 > +   ((consp (cdr saved-search)) ;; It is a list (NAME QUERY COUNT-QUERY)\r
119 > +    (case field\r
120 > +      (:name (car saved-search))\r
121 \r
122 Use `first' for consistency with the other case cases?\r
123 \r
124 > +      (:query (second saved-search))\r
125 > +      (:count-query (third saved-search))\r
126 > +      (t nil)))\r
127 > +   (t  ;; It is a cons-cell (NAME . QUERY)\r
128 > +    (case field\r
129 > +      (:name (car saved-search))\r
130 > +      (:query (cdr saved-search))\r
131 > +      (t nil)))))\r
132 > +\r
133 > +(defun notmuch-hello-saved-search-to-plist (saved-search)\r
134 > +  "Convert a saved-search variable into plist form.\r
135 \r
136 This takes a value, not a variable.  But it could be more succinct and\r
137 more accurate: "Return a copy of SAVED-SEARCH in plist form."\r
138 \r
139 > +\r
140 > +The new style saved search is just a plist, but for backwards\r
141 \r
142 Same comment about "new style".\r
143 \r
144 > +compatatibility we use this function to give them in\r
145 > +plist-form. In all cases a new copy is returned so it is safe to\r
146 \r
147 Grammar error?\r
148 \r
149 > +modify the returned value."\r
150 > +  (if (and (listp (cdr saved-search)) (plist-member saved-search :name))\r
151 > +      (copy-seq saved-search)\r
152 > +    (let ((fields (list :name :query :count-query))\r
153 > +       (plist-search))\r
154 \r
155 Personally I prefer to either explicitly initialize nil variables or\r
156 to list them without the parenthesis at all (for some reason my brain\r
157 automatically reads this as an application), but if you prefer this,\r
158 that's fine, too.\r
159 \r
160 > +      (dolist (field fields plist-search)\r
161 > +     (let ((string (notmuch-saved-search-get saved-search field)))\r
162 > +       (when string\r
163 > +         (setq plist-search (append plist-search (list field string)))))))))\r
164 > +\r
165 >  (defun notmuch-hello-add-saved-search (widget)\r
166 >    (interactive)\r
167 >    (let ((search (widget-value\r