database error
[notmuch-archives.git] / e7 / 8199c51ae8a5d3a070326bb276912688774055
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 68ED9431FAF\r
6         for <notmuch@notmuchmail.org>; Sun, 29 Jul 2012 12:30:38 -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 46HhlBRGLICn for <notmuch@notmuchmail.org>;\r
17         Sun, 29 Jul 2012 12:30:36 -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 45B68431FAE\r
22         for <notmuch@notmuchmail.org>; Sun, 29 Jul 2012 12:30:36 -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 1SvZCA-0000oX-R2; Sun, 29 Jul 2012 20:30:31 +0100\r
27 Received: from 94-192-233-223.zone6.bethere.co.uk ([94.192.233.223]\r
28         helo=localhost)\r
29         by smtp.qmul.ac.uk with esmtpsa (TLSv1:AES128-SHA:128) (Exim 4.69)\r
30         (envelope-from <m.walters@qmul.ac.uk>)\r
31         id 1SvZCA-0007gM-E0; Sun, 29 Jul 2012 20:30:30 +0100\r
32 From: Mark Walters <markwalters1009@gmail.com>\r
33 To: Austin Clements <amdragon@MIT.EDU>, notmuch@notmuchmail.org\r
34 Subject: Re: [PATCH] emacs: move async json parser to its own function\r
35 In-Reply-To: <87k3xo85tv.fsf@qmul.ac.uk>\r
36 References: <87k3xo85tv.fsf@qmul.ac.uk>\r
37 User-Agent: Notmuch/0.13.2+96~g634443c (http://notmuchmail.org) Emacs/23.4.1\r
38         (x86_64-pc-linux-gnu)\r
39 Date: Sun, 29 Jul 2012 20:30:28 +0100\r
40 Message-ID: <878ve2wejv.fsf@qmul.ac.uk>\r
41 MIME-Version: 1.0\r
42 Content-Type: text/plain; charset=us-ascii\r
43 X-Sender-Host-Address: 94.192.233.223\r
44 X-QM-SPAM-Info: Sender has good ham record.  :)\r
45 X-QM-Body-MD5: 8b0bd039762d575cd45016ec350c2e25 (of first 20000 bytes)\r
46 X-SpamAssassin-Score: -1.8\r
47 X-SpamAssassin-SpamBar: -\r
48 X-SpamAssassin-Report: The QM spam filters have analysed this message to\r
49         determine if it is\r
50         spam. We require at least 5.0 points to mark a message as spam.\r
51         This message scored -1.8 points.\r
52         Summary of the scoring: \r
53         * -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at http://www.dnswl.org/,\r
54         *      medium trust\r
55         *      [138.37.6.40 listed in list.dnswl.org]\r
56         * 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail\r
57         provider *      (markwalters1009[at]gmail.com)\r
58         * -0.0 T_RP_MATCHES_RCVD Envelope sender domain matches handover relay\r
59         *      domain\r
60         *  0.5 AWL AWL: From: address is in the auto white-list\r
61 X-QM-Scan-Virus: ClamAV says the message is clean\r
62 X-BeenThere: notmuch@notmuchmail.org\r
63 X-Mailman-Version: 2.1.13\r
64 Precedence: list\r
65 List-Id: "Use and development of the notmuch mail system."\r
66         <notmuch.notmuchmail.org>\r
67 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
68         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
69 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
70 List-Post: <mailto:notmuch@notmuchmail.org>\r
71 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
72 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
73         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
74 X-List-Received-Date: Sun, 29 Jul 2012 19:30:38 -0000\r
75 \r
76 \r
77 Hi\r
78 \r
79 This patch is buggy as it doesn't take buffer local variables from the\r
80 right buffer (so it goes wrong if the buffer changes while the process\r
81 is still running). I have a patch which seems to be correct but I want\r
82 to do a bit more testing before posting.\r
83 \r
84 Best wishes\r
85 \r
86 Mark\r
87 \r
88 \r
89 \r
90 On Sat, 28 Jul 2012, Mark Walters <markwalters1009@gmail.com> wrote:\r
91 > We separate out the json parser into its own function. \r
92 > ---\r
93 >\r
94 > Hi\r
95 >\r
96 > Notmuch pick uses the new asynchronous json parser and the code to do so\r
97 > is almost identical to that for the search mode. Thus separate out the\r
98 > parsing in search mode into a more general function that can easily be\r
99 > used by both pick and search.\r
100 >\r
101 > This saves nearly 50 lines of duplicated code in notmuch-pick.el.\r
102 >\r
103 > The function notmuch-json-async-parse should probably be move in\r
104 > notmuch-lib but that can be a follow on patch.\r
105 >\r
106 > Best wishes\r
107 >\r
108 > Mark\r
109 >\r
110 >  emacs/notmuch.el |   46 ++++++++++++++++++++++++++++++++++++----------\r
111 >  1 files changed, 36 insertions(+), 10 deletions(-)\r
112 >\r
113 > diff --git a/emacs/notmuch.el b/emacs/notmuch.el\r
114 > index fd1836f..ee01028 100644\r
115 > --- a/emacs/notmuch.el\r
116 > +++ b/emacs/notmuch.el\r
117 > @@ -816,7 +816,32 @@ non-authors is found, assume that all of the authors match."\r
118 >    "Incremental JSON parser for the search process filter.")\r
119 >  \r
120 >  (defun notmuch-search-process-filter (proc string)\r
121 > -  "Process and filter the output of \"notmuch search\""\r
122 > +  "Process and filter the output of  \"notmuch search\" using the asynchronous parser."\r
123 > +  (setq notmuch-search-process-state\r
124 > +     (notmuch-json-async-parse proc\r
125 > +                               string\r
126 > +                               notmuch-search-process-state\r
127 > +                               notmuch-search-json-parser\r
128 > +                               'notmuch-search-show-result\r
129 > +                               'notmuch-search-show-error)))\r
130 > +\r
131 > +(defun notmuch-json-async-parse (proc string process-state parser result-function error-function)\r
132 > +  "Process and filter the output using the asynchronous parser.\r
133 > +\r
134 > +This function steps into the first level of JSON nesting and then\r
135 > +applies RESULT-FUNCTION to each complete JSON object as it comes\r
136 > +in.\r
137 > +\r
138 > +PROC is the process: it should have a results buffer as\r
139 > +process-buffer and a 'parse-buf for the incoming json.\r
140 > +PROCESS-STATE the current state of filter process\r
141 > +STRING the incoming data\r
142 > +PARSER the parser\r
143 > +RESULT-FUNCTION a function to call on complete pieces of json\r
144 > +ERROR-FUNCTION the function to call on errors\r
145 > +\r
146 > +The function returns the new PROCESS-STATE"\r
147 > +\r
148 >    (let ((results-buf (process-buffer proc))\r
149 >       (parse-buf (process-get proc 'parse-buf))\r
150 >       (inhibit-read-only t)\r
151 > @@ -831,28 +856,28 @@ non-authors is found, assume that all of the authors match."\r
152 >        (with-current-buffer results-buf\r
153 >       (while (not done)\r
154 >         (condition-case nil\r
155 > -           (case notmuch-search-process-state\r
156 > +           (case process-state\r
157 >               ((begin)\r
158 >                ;; Enter the results list\r
159 >                (if (eq (notmuch-json-begin-compound\r
160 > -                       notmuch-search-json-parser) 'retry)\r
161 > +                       parser) 'retry)\r
162 >                    (setq done t)\r
163 > -                (setq notmuch-search-process-state 'result)))\r
164 > +                (setq process-state 'result)))\r
165 >               ((result)\r
166 >                ;; Parse a result\r
167 > -              (let ((result (notmuch-json-read notmuch-search-json-parser)))\r
168 > +              (let ((result (notmuch-json-read parser)))\r
169 >                  (case result\r
170 >                    ((retry) (setq done t))\r
171 > -                  ((end) (setq notmuch-search-process-state 'end))\r
172 > -                  (otherwise (notmuch-search-show-result result)))))\r
173 > +                  ((end) (setq process-state 'end))\r
174 > +                  (otherwise (funcall result-function result)))))\r
175 >               ((end)\r
176 >                ;; Any trailing data is unexpected\r
177 > -              (notmuch-json-eof notmuch-search-json-parser)\r
178 > +              (notmuch-json-eof parser)\r
179 >                (setq done t)))\r
180 >           (json-error\r
181 >            ;; Do our best to resynchronize and ensure forward\r
182 >            ;; progress\r
183 > -          (notmuch-search-show-error\r
184 > +          (funcall error-function\r
185 >             "%s"\r
186 >             (with-current-buffer parse-buf\r
187 >               (let ((bad (buffer-substring (line-beginning-position)\r
188 > @@ -861,7 +886,8 @@ non-authors is found, assume that all of the authors match."\r
189 >                 bad))))))\r
190 >       ;; Clear out what we've parsed\r
191 >       (with-current-buffer parse-buf\r
192 > -       (delete-region (point-min) (point)))))))\r
193 > +       (delete-region (point-min) (point))))\r
194 > +      process-state)))\r
195 >  \r
196 >  (defun notmuch-search-tag-all (&optional tag-changes)\r
197 >    "Add/remove tags from all messages in current search buffer.\r
198 > -- \r
199 > 1.7.9.1\r