[PATCH 0/6] Use notmuch insert for fcc
[notmuch-archives.git] / 57 / 8d9fe5952afaf3c09dcbd84ca22fc0d95a6030
1 Return-Path: <markwalters1009@gmail.com>\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 3CBCB431FAE\r
6         for <notmuch@notmuchmail.org>; Sat, 27 Oct 2012 02:34:30 -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.201\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=0.201 tagged_above=-999 required=5\r
12         tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1,\r
13         FREEMAIL_ENVFROM_END_DIGIT=1, FREEMAIL_FROM=0.001,\r
14         RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled\r
15 Received: from olra.theworths.org ([127.0.0.1])\r
16         by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
17         with ESMTP id DIvgVJ84Q67x for <notmuch@notmuchmail.org>;\r
18         Sat, 27 Oct 2012 02:34:27 -0700 (PDT)\r
19 Received: from mail-wi0-f173.google.com (mail-wi0-f173.google.com\r
20         [209.85.212.173]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
21         (No client certificate requested)\r
22         by olra.theworths.org (Postfix) with ESMTPS id 379AA429E31\r
23         for <notmuch@notmuchmail.org>; Sat, 27 Oct 2012 02:34:26 -0700 (PDT)\r
24 Received: by mail-wi0-f173.google.com with SMTP id hm4so822748wib.2\r
25         for <notmuch@notmuchmail.org>; Sat, 27 Oct 2012 02:34:24 -0700 (PDT)\r
26 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113;\r
27         h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references;\r
28         bh=oniCK/ZY6Z1v/prdVAZ+7F+TvTh2rw/L1hNDN5I/gaM=;\r
29         b=mIk7P6gbCWlbIBVcmN+UQkAQzn0+jT87AVPHccw1G55NcQN3PSgWVNUf6LtBCzp4pH\r
30         /BFTb1V/X8d7Ceb15N1RF5MgLVVeShsH+xvyJOi613sKc8tMLkBxmLIhaFg6lFQLYT3r\r
31         fXSlon143KLv1e1eDicuwAfkKsOIiu+eYi2OEosF9p3dTHoTUQdFQtcXTwXU8ADIV8rH\r
32         p8xMTRF4JBuTMmfWhyBGvgIZmXyhLqF9jEoGMV5JbIAJWgwQrW4QRv5E6VzSKTqI0Fph\r
33         2ABnBRb+rir7kh/4qpuf8w6q9dBqptMySEeecgFh6Mqmwr6GPYa2fN1Z9AsYmqvf+6YU\r
34         iaNQ==\r
35 Received: by 10.216.197.205 with SMTP id t55mr15020046wen.156.1351330464756;\r
36         Sat, 27 Oct 2012 02:34:24 -0700 (PDT)\r
37 Received: from localhost (93-97-24-31.zone5.bethere.co.uk. [93.97.24.31])\r
38         by mx.google.com with ESMTPS id hv8sm1607198wib.0.2012.10.27.02.34.23\r
39         (version=TLSv1/SSLv3 cipher=OTHER);\r
40         Sat, 27 Oct 2012 02:34:24 -0700 (PDT)\r
41 From: Mark Walters <markwalters1009@gmail.com>\r
42 To: notmuch@notmuchmail.org\r
43 Subject: [PATCH v4 3/3] emacs: Move the incremental JSON parser to\r
44         notmuch-lib.el\r
45 Date: Sat, 27 Oct 2012 10:34:12 +0100\r
46 Message-Id: <1351330452-8348-4-git-send-email-markwalters1009@gmail.com>\r
47 X-Mailer: git-send-email 1.7.9.1\r
48 In-Reply-To: <1351330452-8348-1-git-send-email-markwalters1009@gmail.com>\r
49 References: <1351330452-8348-1-git-send-email-markwalters1009@gmail.com>\r
50 X-BeenThere: notmuch@notmuchmail.org\r
51 X-Mailman-Version: 2.1.13\r
52 Precedence: list\r
53 List-Id: "Use and development of the notmuch mail system."\r
54         <notmuch.notmuchmail.org>\r
55 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
56         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
57 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
58 List-Post: <mailto:notmuch@notmuchmail.org>\r
59 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
60 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
61         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
62 X-List-Received-Date: Sat, 27 Oct 2012 09:34:30 -0000\r
63 \r
64 This just moves the newly split out incremental json parser (together\r
65 with its state variables) to lib.\r
66 \r
67 There should be no functional change.\r
68 ---\r
69  emacs/notmuch-lib.el |   66 ++++++++++++++++++++++++++++++++++++++++++++++++++\r
70  emacs/notmuch.el     |   63 -----------------------------------------------\r
71  2 files changed, 66 insertions(+), 63 deletions(-)\r
72 \r
73 diff --git a/emacs/notmuch-lib.el b/emacs/notmuch-lib.el\r
74 index 69867ad..8b6115b 100644\r
75 --- a/emacs/notmuch-lib.el\r
76 +++ b/emacs/notmuch-lib.el\r
77 @@ -341,6 +341,16 @@ was called."\r
78  \r
79  ;; Incremental JSON parsing\r
80  \r
81 +;; These two variables are internal variables to the parsing\r
82 +;; routines. They are always used buffer local but need to be declared\r
83 +;; globally to avoid compiler warnings.\r
84 +\r
85 +(defvar notmuch-json-parser nil\r
86 +  "Internal incremental JSON parser object: local to the buffer being parsed.")\r
87 +\r
88 +(defvar notmuch-json-state nil\r
89 +  "State of the internal JSON parser: local to the buffer being parsed.")\r
90 +\r
91  (defun notmuch-json-create-parser (buffer)\r
92    "Return a streaming JSON parser that consumes input from BUFFER.\r
93  \r
94 @@ -535,6 +545,62 @@ of the buffer if there is only trailing whitespace."\r
95      (unless (eobp)\r
96        (signal 'json-error (list "Trailing garbage following JSON data")))))\r
97  \r
98 +(defun notmuch-json-parse-partial-list (result-function error-function results-buf)\r
99 +  "Parse a partial JSON list from current buffer.\r
100 +\r
101 +This function consumes a JSON list from the current buffer,\r
102 +applying RESULT-FUNCTION in buffer RESULT-BUFFER to each complete\r
103 +value in the list.  It operates incrementally and should be\r
104 +called whenever the buffer has been extended with additional\r
105 +data.\r
106 +\r
107 +If there is a syntax error, this will attempt to resynchronize\r
108 +with the input and will apply ERROR-FUNCTION in buffer\r
109 +RESULT-BUFFER to any input that was skipped.\r
110 +\r
111 +It sets up all the needed internal variables: the caller just\r
112 +needs to call it with point in the same place that the parser\r
113 +left it."\r
114 +  (let (done)\r
115 +    (unless (local-variable-p 'notmuch-json-parser)\r
116 +      (set (make-local-variable 'notmuch-json-parser)\r
117 +          (notmuch-json-create-parser (current-buffer)))\r
118 +      (set (make-local-variable 'notmuch-json-state) 'begin))\r
119 +    (while (not done)\r
120 +      (condition-case nil\r
121 +         (case notmuch-json-state\r
122 +               ((begin)\r
123 +                ;; Enter the results list\r
124 +                (if (eq (notmuch-json-begin-compound\r
125 +                         notmuch-json-parser) 'retry)\r
126 +                    (setq done t)\r
127 +                  (setq notmuch-json-state 'result)))\r
128 +               ((result)\r
129 +                ;; Parse a result\r
130 +                (let ((result (notmuch-json-read notmuch-json-parser)))\r
131 +                  (case result\r
132 +                        ((retry) (setq done t))\r
133 +                        ((end) (setq notmuch-json-state 'end))\r
134 +                        (otherwise (with-current-buffer results-buf\r
135 +                                     (funcall result-function result))))))\r
136 +               ((end)\r
137 +                ;; Any trailing data is unexpected\r
138 +                (notmuch-json-eof notmuch-json-parser)\r
139 +                (setq done t)))\r
140 +       (json-error\r
141 +        ;; Do our best to resynchronize and ensure forward\r
142 +        ;; progress\r
143 +        (let ((bad (buffer-substring (line-beginning-position)\r
144 +                                     (line-end-position))))\r
145 +          (forward-line)\r
146 +          (with-current-buffer results-buf\r
147 +            (funcall error-function "%s" bad))))))\r
148 +    ;; Clear out what we've parsed\r
149 +    (delete-region (point-min) (point))))\r
150 +\r
151 +\r
152 +\r
153 +\r
154  (provide 'notmuch-lib)\r
155  \r
156  ;; Local Variables:\r
157 diff --git a/emacs/notmuch.el b/emacs/notmuch.el\r
158 index e3610d6..e304dde 100644\r
159 --- a/emacs/notmuch.el\r
160 +++ b/emacs/notmuch.el\r
161 @@ -820,16 +820,6 @@ non-authors is found, assume that all of the authors match."\r
162      (insert (apply #'format string objects))\r
163      (insert "\n")))\r
164  \r
165 -;; These two variables are internal variables to the parsing\r
166 -;; routines. They are always used buffer local but need to be declared\r
167 -;; globally to avoid compiler warnings.\r
168 -\r
169 -(defvar notmuch-json-state nil\r
170 -  "Internal incremental JSON parser object: local to the buffer being parsed.")\r
171 -\r
172 -(defvar notmuch-json-parser nil\r
173 -  "State of the internal JSON parser: local to the buffer being parsed.")\r
174 -\r
175  (defun notmuch-search-process-filter (proc string)\r
176    "Process and filter the output of \"notmuch search\""\r
177    (let ((results-buf (process-buffer proc))\r
178 @@ -847,59 +837,6 @@ non-authors is found, assume that all of the authors match."\r
179                                          'notmuch-search-show-error\r
180                                          results-buf)))))\r
181  \r
182 -(defun notmuch-json-parse-partial-list (result-function error-function results-buf)\r
183 -  "Parse a partial JSON list from current buffer.\r
184 -\r
185 -This function consumes a JSON list from the current buffer,\r
186 -applying RESULT-FUNCTION in buffer RESULT-BUFFER to each complete\r
187 -value in the list.  It operates incrementally and should be\r
188 -called whenever the buffer has been extended with additional\r
189 -data.\r
190 -\r
191 -If there is a syntax error, this will attempt to resynchronize\r
192 -with the input and will apply ERROR-FUNCTION in buffer\r
193 -RESULT-BUFFER to any input that was skipped.\r
194 -\r
195 -It sets up all the needed internal variables: the caller just\r
196 -needs to call it with point in the same place that the parser\r
197 -left it."\r
198 -  (let (done)\r
199 -    (unless (local-variable-p 'notmuch-json-parser)\r
200 -      (set (make-local-variable 'notmuch-json-parser)\r
201 -          (notmuch-json-create-parser (current-buffer)))\r
202 -      (set (make-local-variable 'notmuch-json-state) 'begin))\r
203 -    (while (not done)\r
204 -      (condition-case nil\r
205 -         (case notmuch-json-state\r
206 -               ((begin)\r
207 -                ;; Enter the results list\r
208 -                (if (eq (notmuch-json-begin-compound\r
209 -                         notmuch-json-parser) 'retry)\r
210 -                    (setq done t)\r
211 -                  (setq notmuch-json-state 'result)))\r
212 -               ((result)\r
213 -                ;; Parse a result\r
214 -                (let ((result (notmuch-json-read notmuch-json-parser)))\r
215 -                  (case result\r
216 -                        ((retry) (setq done t))\r
217 -                        ((end) (setq notmuch-json-state 'end))\r
218 -                        (otherwise (with-current-buffer results-buf\r
219 -                                     (funcall result-function result))))))\r
220 -               ((end)\r
221 -                ;; Any trailing data is unexpected\r
222 -                (notmuch-json-eof notmuch-json-parser)\r
223 -                (setq done t)))\r
224 -       (json-error\r
225 -        ;; Do our best to resynchronize and ensure forward\r
226 -        ;; progress\r
227 -        (let ((bad (buffer-substring (line-beginning-position)\r
228 -                                     (line-end-position))))\r
229 -          (forward-line)\r
230 -          (with-current-buffer results-buf\r
231 -            (funcall error-function "%s" bad))))))\r
232 -    ;; Clear out what we've parsed\r
233 -    (delete-region (point-min) (point))))\r
234 -\r
235  (defun notmuch-search-tag-all (&optional tag-changes)\r
236    "Add/remove tags from all messages in current search buffer.\r
237  \r
238 -- \r
239 1.7.9.1\r
240 \r