--- /dev/null
+Return-Path: <markwalters1009@gmail.com>\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 5B6F9431FCB\r
+ for <notmuch@notmuchmail.org>; Tue, 23 Oct 2012 17:13:48 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: 0.201\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=0.201 tagged_above=-999 required=5\r
+ tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1,\r
+ FREEMAIL_ENVFROM_END_DIGIT=1, FREEMAIL_FROM=0.001,\r
+ RCVD_IN_DNSWL_LOW=-0.7] 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 o-h3yGoALOa4 for <notmuch@notmuchmail.org>;\r
+ Tue, 23 Oct 2012 17:13:46 -0700 (PDT)\r
+Received: from mail-wg0-f45.google.com (mail-wg0-f45.google.com\r
+ [74.125.82.45]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) (No client\r
+ certificate requested) by olra.theworths.org (Postfix) with ESMTPS id\r
+ 2B6C9431FC0 for <notmuch@notmuchmail.org>; Tue, 23 Oct 2012 17:13:42 -0700\r
+ (PDT)\r
+Received: by mail-wg0-f45.google.com with SMTP id dq12so2953273wgb.2\r
+ for <notmuch@notmuchmail.org>; Tue, 23 Oct 2012 17:13:41 -0700 (PDT)\r
+DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113;\r
+ h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references;\r
+ bh=1zXFN2oflQeuX5kAairCL9cYqVSD9spBXIsA7TdXAhM=;\r
+ b=J1gLZCHIWCHaW76T+p5iVmqfV58ttB3oqxDoyjL8i3p2B1DagXsMm421x6HvpfP4Nr\r
+ uf3spYyv5NQ66pTW15YmVVRI/hnnbSOCxg7nCjNmO3GFqYqgX2USDendqL5TKOYdgGgE\r
+ QJS3T2d0Wo+KGM421Ms6qdZPnD8lbSjaQlOS8suggzWwfjRJSBK4CMlhkh2XZQ/hNdib\r
+ eH0qu/v/frjnb1j9UHi+7353aGeNxkf2PUPnbXf18ugV37IHjF+K5Vtb5GBPys6h/6H1\r
+ pYbqI7AkpyX6PTtQakUzSdTYCuIA5X7da7XN08iBbcYXItHu8G23vwPb7MQFp88XU77f\r
+ 2j3Q==\r
+Received: by 10.216.214.198 with SMTP id c48mr8048533wep.216.1351037621860;\r
+ Tue, 23 Oct 2012 17:13:41 -0700 (PDT)\r
+Received: from localhost (93-97-24-31.zone5.bethere.co.uk. [93.97.24.31])\r
+ by mx.google.com with ESMTPS id ay10sm1601200wib.2.2012.10.23.17.13.40\r
+ (version=TLSv1/SSLv3 cipher=OTHER);\r
+ Tue, 23 Oct 2012 17:13:40 -0700 (PDT)\r
+From: Mark Walters <markwalters1009@gmail.com>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH v3 1/3] emacs: Split out the incremental json parser into its\r
+ own function.\r
+Date: Wed, 24 Oct 2012 01:13:20 +0100\r
+Message-Id: <1351037602-11157-2-git-send-email-markwalters1009@gmail.com>\r
+X-Mailer: git-send-email 1.7.9.1\r
+In-Reply-To: <1351037602-11157-1-git-send-email-markwalters1009@gmail.com>\r
+References: <1351037602-11157-1-git-send-email-markwalters1009@gmail.com>\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: Wed, 24 Oct 2012 00:13:48 -0000\r
+\r
+This patch splits out the incremental json parser into its own\r
+function.\r
+\r
+It moves the main logic of the parser to happen inside the parse\r
+buffer rather than inside the results buffer, but makes sure all\r
+results and all errors are displayed in the results buffer.\r
+\r
+It also changes the local parser variables from being buffer\r
+local to the results buffer to being buffer local to the parse buffer,\r
+and sets them up automatically so the caller does not need to.\r
+\r
+Finally to keep the diff small this patch does not fix the whitespace,\r
+not complete the code movement (these are done in subsequent patches)\r
+but it should contain all the functional changes.\r
+---\r
+ emacs/notmuch.el | 39 +++++++++++++++++++++++++++------------\r
+ 1 files changed, 27 insertions(+), 12 deletions(-)\r
+\r
+diff --git a/emacs/notmuch.el b/emacs/notmuch.el\r
+index 1c43d3e..72a73dc 100644\r
+--- a/emacs/notmuch.el\r
++++ b/emacs/notmuch.el\r
+@@ -830,8 +830,28 @@ non-authors is found, assume that all of the authors match."\r
+ ;; Insert new data\r
+ (save-excursion\r
+ (goto-char (point-max))\r
+- (insert string)))\r
+- (with-current-buffer results-buf\r
++ (insert string))\r
++ (notmuch-json-parse-partial-list 'notmuch-search-show-result\r
++ 'notmuch-search-show-error\r
++ results-buf)))))\r
++\r
++(defun notmuch-json-parse-partial-list (result-function error-function results-buf)\r
++ "Parse a partial JSON list from current buffer.\r
++\r
++This function consumes a JSON list from the current buffer,\r
++applying RESULT-FUNCTION in buffer RESULT-BUFFER to each complete\r
++value in the list. It operates incrementally and should be\r
++called whenever the buffer has been extended with additional\r
++data.\r
++\r
++If there is a syntax error, this will attempt to resynchronize\r
++with the input and will apply ERROR-FUNCTION in buffer\r
++RESULT-BUFFER to any input that was skipped."\r
++ (let (done)\r
++ (unless (local-variable-p 'notmuch-search-json-parser)\r
++ (set (make-local-variable 'notmuch-search-json-parser)\r
++ (notmuch-json-create-parser (current-buffer)))\r
++ (set (make-local-variable 'notmuch-search-process-state) 'begin))\r
+ (while (not done)\r
+ (condition-case nil\r
+ (case notmuch-search-process-state\r
+@@ -847,7 +867,8 @@ non-authors is found, assume that all of the authors match."\r
+ (case result\r
+ ((retry) (setq done t))\r
+ ((end) (setq notmuch-search-process-state 'end))\r
+- (otherwise (notmuch-search-show-result result)))))\r
++ (otherwise (with-current-buffer results-buf\r
++ (funcall result-function result))))))\r
+ ((end)\r
+ ;; Any trailing data is unexpected\r
+ (notmuch-json-eof notmuch-search-json-parser)\r
+@@ -855,16 +876,13 @@ non-authors is found, assume that all of the authors match."\r
+ (json-error\r
+ ;; Do our best to resynchronize and ensure forward\r
+ ;; progress\r
+- (notmuch-search-show-error\r
+- "%s"\r
+- (with-current-buffer parse-buf\r
+ (let ((bad (buffer-substring (line-beginning-position)\r
+ (line-end-position))))\r
+ (forward-line)\r
+- bad))))))\r
++ (with-current-buffer results-buf\r
++ (funcall error-function "%s" 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
+ \r
+ (defun notmuch-search-tag-all (&optional tag-changes)\r
+ "Add/remove tags from all messages in current search buffer.\r
+@@ -976,9 +994,6 @@ Other optional parameters are used as follows:\r
+ ;; This buffer will be killed by the sentinel, which\r
+ ;; should be called no matter how the process dies.\r
+ (parse-buf (generate-new-buffer " *notmuch search parse*")))\r
+- (set (make-local-variable 'notmuch-search-process-state) 'begin)\r
+- (set (make-local-variable 'notmuch-search-json-parser)\r
+- (notmuch-json-create-parser parse-buf))\r
+ (process-put proc 'parse-buf parse-buf)\r
+ (set-process-sentinel proc 'notmuch-search-process-sentinel)\r
+ (set-process-filter proc 'notmuch-search-process-filter)\r
+-- \r
+1.7.9.1\r
+\r