--- /dev/null
+Return-Path: <m.walters@qmul.ac.uk>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+ by olra.theworths.org (Postfix) with ESMTP id 68ED9431FAF\r
+ for <notmuch@notmuchmail.org>; Sun, 29 Jul 2012 12:30:38 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -1.098\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-1.098 tagged_above=-999 required=5\r
+ tests=[DKIM_ADSP_CUSTOM_MED=0.001, FREEMAIL_FROM=0.001,\r
+ NML_ADSP_CUSTOM_MED=1.2, RCVD_IN_DNSWL_MED=-2.3] autolearn=disabled\r
+Received: from olra.theworths.org ([127.0.0.1])\r
+ by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
+ with ESMTP id 46HhlBRGLICn for <notmuch@notmuchmail.org>;\r
+ Sun, 29 Jul 2012 12:30:36 -0700 (PDT)\r
+Received: from mail2.qmul.ac.uk (mail2.qmul.ac.uk [138.37.6.6])\r
+ (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits))\r
+ (No client certificate requested)\r
+ by olra.theworths.org (Postfix) with ESMTPS id 45B68431FAE\r
+ for <notmuch@notmuchmail.org>; Sun, 29 Jul 2012 12:30:36 -0700 (PDT)\r
+Received: from smtp.qmul.ac.uk ([138.37.6.40])\r
+ by mail2.qmul.ac.uk with esmtp (Exim 4.71)\r
+ (envelope-from <m.walters@qmul.ac.uk>)\r
+ id 1SvZCA-0000oX-R2; Sun, 29 Jul 2012 20:30:31 +0100\r
+Received: from 94-192-233-223.zone6.bethere.co.uk ([94.192.233.223]\r
+ helo=localhost)\r
+ by smtp.qmul.ac.uk with esmtpsa (TLSv1:AES128-SHA:128) (Exim 4.69)\r
+ (envelope-from <m.walters@qmul.ac.uk>)\r
+ id 1SvZCA-0007gM-E0; Sun, 29 Jul 2012 20:30:30 +0100\r
+From: Mark Walters <markwalters1009@gmail.com>\r
+To: Austin Clements <amdragon@MIT.EDU>, notmuch@notmuchmail.org\r
+Subject: Re: [PATCH] emacs: move async json parser to its own function\r
+In-Reply-To: <87k3xo85tv.fsf@qmul.ac.uk>\r
+References: <87k3xo85tv.fsf@qmul.ac.uk>\r
+User-Agent: Notmuch/0.13.2+96~g634443c (http://notmuchmail.org) Emacs/23.4.1\r
+ (x86_64-pc-linux-gnu)\r
+Date: Sun, 29 Jul 2012 20:30:28 +0100\r
+Message-ID: <878ve2wejv.fsf@qmul.ac.uk>\r
+MIME-Version: 1.0\r
+Content-Type: text/plain; charset=us-ascii\r
+X-Sender-Host-Address: 94.192.233.223\r
+X-QM-SPAM-Info: Sender has good ham record. :)\r
+X-QM-Body-MD5: 8b0bd039762d575cd45016ec350c2e25 (of first 20000 bytes)\r
+X-SpamAssassin-Score: -1.8\r
+X-SpamAssassin-SpamBar: -\r
+X-SpamAssassin-Report: The QM spam filters have analysed this message to\r
+ determine if it is\r
+ spam. We require at least 5.0 points to mark a message as spam.\r
+ This message scored -1.8 points.\r
+ Summary of the scoring: \r
+ * -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at http://www.dnswl.org/,\r
+ * medium trust\r
+ * [138.37.6.40 listed in list.dnswl.org]\r
+ * 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail\r
+ provider * (markwalters1009[at]gmail.com)\r
+ * -0.0 T_RP_MATCHES_RCVD Envelope sender domain matches handover relay\r
+ * domain\r
+ * 0.5 AWL AWL: From: address is in the auto white-list\r
+X-QM-Scan-Virus: ClamAV says the message is clean\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.13\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+ <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Sun, 29 Jul 2012 19:30:38 -0000\r
+\r
+\r
+Hi\r
+\r
+This patch is buggy as it doesn't take buffer local variables from the\r
+right buffer (so it goes wrong if the buffer changes while the process\r
+is still running). I have a patch which seems to be correct but I want\r
+to do a bit more testing before posting.\r
+\r
+Best wishes\r
+\r
+Mark\r
+\r
+\r
+\r
+On Sat, 28 Jul 2012, Mark Walters <markwalters1009@gmail.com> wrote:\r
+> We separate out the json parser into its own function. \r
+> ---\r
+>\r
+> Hi\r
+>\r
+> Notmuch pick uses the new asynchronous json parser and the code to do so\r
+> is almost identical to that for the search mode. Thus separate out the\r
+> parsing in search mode into a more general function that can easily be\r
+> used by both pick and search.\r
+>\r
+> This saves nearly 50 lines of duplicated code in notmuch-pick.el.\r
+>\r
+> The function notmuch-json-async-parse should probably be move in\r
+> notmuch-lib but that can be a follow on patch.\r
+>\r
+> Best wishes\r
+>\r
+> Mark\r
+>\r
+> emacs/notmuch.el | 46 ++++++++++++++++++++++++++++++++++++----------\r
+> 1 files changed, 36 insertions(+), 10 deletions(-)\r
+>\r
+> diff --git a/emacs/notmuch.el b/emacs/notmuch.el\r
+> index fd1836f..ee01028 100644\r
+> --- a/emacs/notmuch.el\r
+> +++ b/emacs/notmuch.el\r
+> @@ -816,7 +816,32 @@ non-authors is found, assume that all of the authors match."\r
+> "Incremental JSON parser for the search process filter.")\r
+> \r
+> (defun notmuch-search-process-filter (proc string)\r
+> - "Process and filter the output of \"notmuch search\""\r
+> + "Process and filter the output of \"notmuch search\" using the asynchronous parser."\r
+> + (setq notmuch-search-process-state\r
+> + (notmuch-json-async-parse proc\r
+> + string\r
+> + notmuch-search-process-state\r
+> + notmuch-search-json-parser\r
+> + 'notmuch-search-show-result\r
+> + 'notmuch-search-show-error)))\r
+> +\r
+> +(defun notmuch-json-async-parse (proc string process-state parser result-function error-function)\r
+> + "Process and filter the output using the asynchronous parser.\r
+> +\r
+> +This function steps into the first level of JSON nesting and then\r
+> +applies RESULT-FUNCTION to each complete JSON object as it comes\r
+> +in.\r
+> +\r
+> +PROC is the process: it should have a results buffer as\r
+> +process-buffer and a 'parse-buf for the incoming json.\r
+> +PROCESS-STATE the current state of filter process\r
+> +STRING the incoming data\r
+> +PARSER the parser\r
+> +RESULT-FUNCTION a function to call on complete pieces of json\r
+> +ERROR-FUNCTION the function to call on errors\r
+> +\r
+> +The function returns the new PROCESS-STATE"\r
+> +\r
+> (let ((results-buf (process-buffer proc))\r
+> (parse-buf (process-get proc 'parse-buf))\r
+> (inhibit-read-only t)\r
+> @@ -831,28 +856,28 @@ non-authors is found, assume that all of the authors match."\r
+> (with-current-buffer results-buf\r
+> (while (not done)\r
+> (condition-case nil\r
+> - (case notmuch-search-process-state\r
+> + (case process-state\r
+> ((begin)\r
+> ;; Enter the results list\r
+> (if (eq (notmuch-json-begin-compound\r
+> - notmuch-search-json-parser) 'retry)\r
+> + parser) 'retry)\r
+> (setq done t)\r
+> - (setq notmuch-search-process-state 'result)))\r
+> + (setq process-state 'result)))\r
+> ((result)\r
+> ;; Parse a result\r
+> - (let ((result (notmuch-json-read notmuch-search-json-parser)))\r
+> + (let ((result (notmuch-json-read parser)))\r
+> (case result\r
+> ((retry) (setq done t))\r
+> - ((end) (setq notmuch-search-process-state 'end))\r
+> - (otherwise (notmuch-search-show-result result)))))\r
+> + ((end) (setq process-state 'end))\r
+> + (otherwise (funcall result-function result)))))\r
+> ((end)\r
+> ;; Any trailing data is unexpected\r
+> - (notmuch-json-eof notmuch-search-json-parser)\r
+> + (notmuch-json-eof parser)\r
+> (setq done t)))\r
+> (json-error\r
+> ;; Do our best to resynchronize and ensure forward\r
+> ;; progress\r
+> - (notmuch-search-show-error\r
+> + (funcall error-function\r
+> "%s"\r
+> (with-current-buffer parse-buf\r
+> (let ((bad (buffer-substring (line-beginning-position)\r
+> @@ -861,7 +886,8 @@ non-authors is found, assume that all of the authors match."\r
+> bad))))))\r
+> ;; Clear out what we've parsed\r
+> (with-current-buffer parse-buf\r
+> - (delete-region (point-min) (point)))))))\r
+> + (delete-region (point-min) (point))))\r
+> + process-state)))\r
+> \r
+> (defun notmuch-search-tag-all (&optional tag-changes)\r
+> "Add/remove tags from all messages in current search buffer.\r
+> -- \r
+> 1.7.9.1\r