Re: [PATCH 9/9] add has: query prefix to search for specific properties
[notmuch-archives.git] / f4 / 8272cf45ef60587135c91830e7e45e085ab34e
1 Return-Path: <m.walters@qmul.ac.uk>\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 6F7C7431FC7\r
6         for <notmuch@notmuchmail.org>; Fri, 31 May 2013 15:38:51 -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: -1.098\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=-1.098 tagged_above=-999 required=5\r
12         tests=[DKIM_ADSP_CUSTOM_MED=0.001, FREEMAIL_FROM=0.001,\r
13         NML_ADSP_CUSTOM_MED=1.2, RCVD_IN_DNSWL_MED=-2.3] autolearn=disabled\r
14 Received: from olra.theworths.org ([127.0.0.1])\r
15         by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
16         with ESMTP id kOoW14aSfhcj for <notmuch@notmuchmail.org>;\r
17         Fri, 31 May 2013 15:38:45 -0700 (PDT)\r
18 Received: from mail2.qmul.ac.uk (mail2.qmul.ac.uk [138.37.6.6])\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 340EF431FBD\r
22         for <notmuch@notmuchmail.org>; Fri, 31 May 2013 15:38:45 -0700 (PDT)\r
23 Received: from smtp.qmul.ac.uk ([138.37.6.40])\r
24         by mail2.qmul.ac.uk with esmtp (Exim 4.71)\r
25         (envelope-from <m.walters@qmul.ac.uk>)\r
26         id 1UiXy3-0005ti-Bl; Fri, 31 May 2013 23:38:39 +0100\r
27 Received: from 93-97-24-31.zone5.bethere.co.uk ([93.97.24.31] helo=localhost)\r
28         by smtp.qmul.ac.uk with esmtpsa (TLSv1:AES128-SHA:128) (Exim 4.71)\r
29         (envelope-from <m.walters@qmul.ac.uk>)\r
30         id 1UiXy2-0005Mf-Re; Fri, 31 May 2013 23:38:39 +0100\r
31 From: Mark Walters <markwalters1009@gmail.com>\r
32 To: Austin Clements <amdragon@MIT.EDU>, notmuch@notmuchmail.org\r
33 Subject: Re: [PATCH v2 0/5] Make Emacs search use sexp format\r
34 In-Reply-To: <1369934016-22308-1-git-send-email-amdragon@mit.edu>\r
35 References: <1369934016-22308-1-git-send-email-amdragon@mit.edu>\r
36 User-Agent: Notmuch/0.14+255~gff3cc55 (http://notmuchmail.org) Emacs/23.4.1\r
37         (i486-pc-linux-gnu)\r
38 Date: Fri, 31 May 2013 23:38:37 +0100\r
39 Message-ID: <87y5aug4gi.fsf@qmul.ac.uk>\r
40 MIME-Version: 1.0\r
41 Content-Type: text/plain; charset=us-ascii\r
42 X-Sender-Host-Address: 93.97.24.31\r
43 X-QM-SPAM-Info: Sender has good ham record.  :)\r
44 X-QM-Body-MD5: 511131fa4828e08db958fc2e8fc6ab79 (of first 20000 bytes)\r
45 X-SpamAssassin-Score: -0.1\r
46 X-SpamAssassin-SpamBar: /\r
47 X-SpamAssassin-Report: The QM spam filters have analysed this message to\r
48         determine if it is\r
49         spam. We require at least 5.0 points to mark a message as spam.\r
50         This message scored -0.1 points.\r
51         Summary of the scoring: \r
52         * 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail\r
53         provider *      (markwalters1009[at]gmail.com)\r
54         * -0.1 AWL AWL: From: address is in the auto white-list\r
55 X-QM-Scan-Virus: ClamAV says the message is clean\r
56 Cc: tomi.ollila@iki.fi\r
57 X-BeenThere: notmuch@notmuchmail.org\r
58 X-Mailman-Version: 2.1.13\r
59 Precedence: list\r
60 List-Id: "Use and development of the notmuch mail system."\r
61         <notmuch.notmuchmail.org>\r
62 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
63         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
64 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
65 List-Post: <mailto:notmuch@notmuchmail.org>\r
66 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
67 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
68         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
69 X-List-Received-Date: Fri, 31 May 2013 22:38:51 -0000\r
70 \r
71 \r
72 This version LGTM +1. I will let you and Tomi decide which shell magic\r
73 to go with.\r
74 \r
75 One very trivial comment on a comment below\r
76 \r
77 Best wishes\r
78 \r
79 Mark\r
80 \r
81 Austin Clements <amdragon@MIT.EDU> writes:\r
82 \r
83 > This is v2 of id:1368851472-5382-1-git-send-email-amdragon@mit.edu.\r
84 > The most substantial change from v1 is that the streaming S-expression\r
85 > parser now requires the caller to invoke it from the appropriate\r
86 > buffer and no longer attempts to track the buffer itself.  For subtle\r
87 > reasons arising from per-window points, the only *correct* way to use\r
88 > the interface before required the caller to invoke it from the\r
89 > appropriate buffer anyway (or risk losing track of what had been\r
90 > parsed).  The only place that currently invokes the streaming\r
91 > S-expression parser already satisfied this requirement.\r
92 >\r
93 > I decided *not* to use --stderr to redirect stderr.  As discussed on\r
94 > IRC, --stderr causes serious problems for wrapper scripts, which\r
95 > either have to handle --stderr themselves or risk mixing their own\r
96 > stderr with stdout (e.g., errors from ssh) or, worse, redirecting\r
97 > notmuch's stderr to a (world-readable) file on a *remote* machine.  I\r
98 > did fix the exec-path problem that Tomi pointed out, so\r
99 > notmuch-command will continue to be searched for in exec-path, like it\r
100 > currently is.\r
101 >\r
102 > The diff from v1 is below, with whitespace changes because of\r
103 > re-indentation in the S-expression parser.\r
104 >\r
105 > diff --git a/emacs/notmuch-lib.el b/emacs/notmuch-lib.el\r
106 > index a543471..180f63d 100644\r
107 > --- a/emacs/notmuch-lib.el\r
108 > +++ b/emacs/notmuch-lib.el\r
109 > @@ -493,10 +493,13 @@ status."\r
110 >    (let* ((err-file (make-temp-file "nmerr"))\r
111 >        ;; Use a pipe\r
112 >        (process-connection-type nil)\r
113 > +      ;; Find notmuch using Emacs' `exec-path'\r
114 > +      (command (or (executable-find notmuch-command)\r
115 > +                   (error "command not found: %s" notmuch-command)))\r
116 >        (proc (apply #'start-process name buffer\r
117 >                     "sh" "-c"\r
118 >                     "ERR=\"$1\"; shift; exec \"$0\" \"$@\" 2>\"$ERR\""\r
119 > -                   notmuch-command err-file args)))\r
120 > +                   command err-file args)))\r
121 >      (process-put proc 'err-file err-file)\r
122 >      (process-put proc 'sub-sentinel sentinel)\r
123 >      (process-put proc 'real-command (cons notmuch-command args))\r
124 > @@ -507,7 +510,7 @@ status."\r
125 >    (let ((err-file (process-get proc 'err-file))\r
126 >       (sub-sentinel (process-get proc 'sub-sentinel))\r
127 >       (real-command (process-get proc 'real-command)))\r
128 > -    (condition-case-unless-debug err\r
129 > +    (condition-case err\r
130 >       (progn\r
131 >         ;; Invoke the sub-sentinel, if any\r
132 >         (when sub-sentinel\r
133 > @@ -530,7 +533,8 @@ status."\r
134 >           (when warnings\r
135 >             (notmuch-logged-error (car warnings) (cdr warnings)))))\r
136 >        (error\r
137 > -       ;; Don't signal an error from a sentinel\r
138 > +       ;; Emacs behaves strangely if error an error escapes from a\r
139 > +       ;; sentinel, so turns errors into messages.\r
140 \r
141 2 typos: "error an error" and turns should be turn.\r
142 \r
143 >         (message "%s" (error-message-string err))))\r
144 >      (ignore-errors (delete-file err-file))))\r
145 >  \r
146 > diff --git a/emacs/notmuch-parser.el b/emacs/notmuch-parser.el\r
147 > index 1b7cf64..d59c0e1 100644\r
148 > --- a/emacs/notmuch-parser.el\r
149 > +++ b/emacs/notmuch-parser.el\r
150 > @@ -21,8 +21,8 @@\r
151 >  \r
152 >  (require 'cl)\r
153 >  \r
154 > -(defun notmuch-sexp-create-parser (buffer)\r
155 > -  "Return a streaming S-expression parser that reads from BUFFER.\r
156 > +(defun notmuch-sexp-create-parser ()\r
157 > +  "Return a new streaming S-expression parser.\r
158 >  \r
159 >  This parser is designed to incrementally read an S-expression\r
160 >  whose structure is known to the caller.  Like a typical\r
161 > @@ -33,12 +33,11 @@ input to be a list and descends into it, allowing its elements to\r
162 >  be read one at a time or further descended into.  Both functions\r
163 >  can return 'retry to indicate that not enough input is available.\r
164 >  \r
165 > -The parser always consumes input from BUFFER's point.  Hence, the\r
166 > -caller is allowed to delete any data before point and may\r
167 > -resynchronize after an error by moving point."\r
168 > +The parser always consumes input from point in the current\r
169 > +buffer.  Hence, the caller is allowed to delete any data before\r
170 > +point and may resynchronize after an error by moving point."\r
171 >  \r
172 >    (vector 'notmuch-sexp-parser\r
173 > -       buffer\r
174 >         ;; List depth\r
175 >         0\r
176 >         ;; Partial parse position marker\r
177 > @@ -46,13 +45,12 @@ resynchronize after an error by moving point."\r
178 >         ;; Partial parse state\r
179 >         nil))\r
180 >  \r
181 > -(defmacro notmuch-sexp--buffer (sp)        `(aref ,sp 1))\r
182 > -(defmacro notmuch-sexp--depth (sp)         `(aref ,sp 2))\r
183 > -(defmacro notmuch-sexp--partial-pos (sp)   `(aref ,sp 3))\r
184 > -(defmacro notmuch-sexp--partial-state (sp) `(aref ,sp 4))\r
185 > +(defmacro notmuch-sexp--depth (sp)         `(aref ,sp 1))\r
186 > +(defmacro notmuch-sexp--partial-pos (sp)   `(aref ,sp 2))\r
187 > +(defmacro notmuch-sexp--partial-state (sp) `(aref ,sp 3))\r
188 >  \r
189 >  (defun notmuch-sexp-read (sp)\r
190 > -  "Consume and return the value at point in SP's buffer.\r
191 > +  "Consume and return the value at point in the current buffer.\r
192 >  \r
193 >  Returns 'retry if there is insufficient input to parse a complete\r
194 >  value (though it may still move point over whitespace).  If the\r
195 > @@ -61,14 +59,13 @@ list, this moves point just past the terminator and returns 'end.\r
196 >  Otherwise, this moves point to just past the end of the value and\r
197 >  returns the value."\r
198 >  \r
199 > -  (with-current-buffer (notmuch-sexp--buffer sp)\r
200 >    (skip-chars-forward " \n\r\t")\r
201 >    (cond ((eobp) 'retry)\r
202 >       ((= (char-after) ?\))\r
203 >        ;; We've reached the end of a list\r
204 >        (if (= (notmuch-sexp--depth sp) 0)\r
205 >            ;; .. but we weren't in a list.  Let read signal the\r
206 > -            ;; error.\r
207 > +          ;; error to be consistent with all other code paths.\r
208 >            (read (current-buffer))\r
209 >          ;; Go up a level and return an end token\r
210 >          (decf (notmuch-sexp--depth sp))\r
211 > @@ -124,7 +121,7 @@ returns the value."\r
212 >                  'retry))\r
213 >            (end-of-file\r
214 >             (goto-char start)\r
215 > -             'retry)))))))\r
216 > +           'retry))))))\r
217 >  \r
218 >  (defun notmuch-sexp-begin-list (sp)\r
219 >    "Parse the beginning of a list value and enter the list.\r
220 > @@ -136,7 +133,6 @@ returns t.  Later calls to `notmuch-sexp-read' will return the\r
221 >  elements inside the list.  If the input in buffer is not the\r
222 >  beginning of a list, throw invalid-read-syntax."\r
223 >  \r
224 > -  (with-current-buffer (notmuch-sexp--buffer sp)\r
225 >    (skip-chars-forward " \n\r\t")\r
226 >    (cond ((eobp) 'retry)\r
227 >       ((= (char-after) ?\()\r
228 > @@ -146,7 +142,7 @@ beginning of a list, throw invalid-read-syntax."\r
229 >       (t\r
230 >        ;; Skip over the bad character like `read' does\r
231 >        (forward-char)\r
232 > -        (signal 'invalid-read-syntax (list (string (char-before))))))))\r
233 > +      (signal 'invalid-read-syntax (list (string (char-before)))))))\r
234 >  \r
235 >  (defun notmuch-sexp-eof (sp)\r
236 >    "Signal an error if there is more data in SP's buffer.\r
237 > @@ -154,10 +150,9 @@ beginning of a list, throw invalid-read-syntax."\r
238 >  Moves point to the beginning of any trailing data or to the end\r
239 >  of the buffer if there is only trailing whitespace."\r
240 >  \r
241 > -  (with-current-buffer (notmuch-sexp--buffer sp)\r
242 >    (skip-chars-forward " \n\r\t")\r
243 >    (unless (eobp)\r
244 > -      (error "Trailing garbage following expression"))))\r
245 > +    (error "Trailing garbage following expression")))\r
246 >  \r
247 >  (defvar notmuch-sexp--parser nil\r
248 >    "The buffer-local notmuch-sexp-parser instance.\r
249 > @@ -170,7 +165,7 @@ Used by `notmuch-sexp-parse-partial-list'.")\r
250 >  (defun notmuch-sexp-parse-partial-list (result-function result-buffer)\r
251 >    "Incrementally parse an S-expression list from the current buffer.\r
252 >  \r
253 > -This function consume an S-expression list from the current\r
254 > +This function consumes an S-expression list from the current\r
255 >  buffer, applying RESULT-FUNCTION in RESULT-BUFFER to each\r
256 >  complete value in the list.  It operates incrementally and should\r
257 >  be called whenever the input buffer has been extended with\r
258 > @@ -180,7 +175,7 @@ move point in the input buffer."\r
259 >    ;; Set up the initial state\r
260 >    (unless (local-variable-p 'notmuch-sexp--parser)\r
261 >      (set (make-local-variable 'notmuch-sexp--parser)\r
262 > -      (notmuch-sexp-create-parser (current-buffer)))\r
263 > +      (notmuch-sexp-create-parser))\r
264 >      (set (make-local-variable 'notmuch-sexp--state) 'begin))\r
265 >    (let (done)\r
266 >      (while (not done)\r