[PATCH v4 3/3] emacs: Move the incremental JSON parser to notmuch-lib.el
authorMark Walters <markwalters1009@gmail.com>
Sat, 27 Oct 2012 09:34:12 +0000 (10:34 +0100)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:50:05 +0000 (09:50 -0800)
57/8d9fe5952afaf3c09dcbd84ca22fc0d95a6030 [new file with mode: 0644]

diff --git a/57/8d9fe5952afaf3c09dcbd84ca22fc0d95a6030 b/57/8d9fe5952afaf3c09dcbd84ca22fc0d95a6030
new file mode 100644 (file)
index 0000000..f0c252d
--- /dev/null
@@ -0,0 +1,240 @@
+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 3CBCB431FAE\r
+       for <notmuch@notmuchmail.org>; Sat, 27 Oct 2012 02:34:30 -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 DIvgVJ84Q67x for <notmuch@notmuchmail.org>;\r
+       Sat, 27 Oct 2012 02:34:27 -0700 (PDT)\r
+Received: from mail-wi0-f173.google.com (mail-wi0-f173.google.com\r
+       [209.85.212.173]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
+       (No client certificate requested)\r
+       by olra.theworths.org (Postfix) with ESMTPS id 379AA429E31\r
+       for <notmuch@notmuchmail.org>; Sat, 27 Oct 2012 02:34:26 -0700 (PDT)\r
+Received: by mail-wi0-f173.google.com with SMTP id hm4so822748wib.2\r
+       for <notmuch@notmuchmail.org>; Sat, 27 Oct 2012 02:34:24 -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=oniCK/ZY6Z1v/prdVAZ+7F+TvTh2rw/L1hNDN5I/gaM=;\r
+       b=mIk7P6gbCWlbIBVcmN+UQkAQzn0+jT87AVPHccw1G55NcQN3PSgWVNUf6LtBCzp4pH\r
+       /BFTb1V/X8d7Ceb15N1RF5MgLVVeShsH+xvyJOi613sKc8tMLkBxmLIhaFg6lFQLYT3r\r
+       fXSlon143KLv1e1eDicuwAfkKsOIiu+eYi2OEosF9p3dTHoTUQdFQtcXTwXU8ADIV8rH\r
+       p8xMTRF4JBuTMmfWhyBGvgIZmXyhLqF9jEoGMV5JbIAJWgwQrW4QRv5E6VzSKTqI0Fph\r
+       2ABnBRb+rir7kh/4qpuf8w6q9dBqptMySEeecgFh6Mqmwr6GPYa2fN1Z9AsYmqvf+6YU\r
+       iaNQ==\r
+Received: by 10.216.197.205 with SMTP id t55mr15020046wen.156.1351330464756;\r
+       Sat, 27 Oct 2012 02:34:24 -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 hv8sm1607198wib.0.2012.10.27.02.34.23\r
+       (version=TLSv1/SSLv3 cipher=OTHER);\r
+       Sat, 27 Oct 2012 02:34:24 -0700 (PDT)\r
+From: Mark Walters <markwalters1009@gmail.com>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH v4 3/3] emacs: Move the incremental JSON parser to\r
+       notmuch-lib.el\r
+Date: Sat, 27 Oct 2012 10:34:12 +0100\r
+Message-Id: <1351330452-8348-4-git-send-email-markwalters1009@gmail.com>\r
+X-Mailer: git-send-email 1.7.9.1\r
+In-Reply-To: <1351330452-8348-1-git-send-email-markwalters1009@gmail.com>\r
+References: <1351330452-8348-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: Sat, 27 Oct 2012 09:34:30 -0000\r
+\r
+This just moves the newly split out incremental json parser (together\r
+with its state variables) to lib.\r
+\r
+There should be no functional change.\r
+---\r
+ emacs/notmuch-lib.el |   66 ++++++++++++++++++++++++++++++++++++++++++++++++++\r
+ emacs/notmuch.el     |   63 -----------------------------------------------\r
+ 2 files changed, 66 insertions(+), 63 deletions(-)\r
+\r
+diff --git a/emacs/notmuch-lib.el b/emacs/notmuch-lib.el\r
+index 69867ad..8b6115b 100644\r
+--- a/emacs/notmuch-lib.el\r
++++ b/emacs/notmuch-lib.el\r
+@@ -341,6 +341,16 @@ was called."\r
\r
+ ;; Incremental JSON parsing\r
\r
++;; These two variables are internal variables to the parsing\r
++;; routines. They are always used buffer local but need to be declared\r
++;; globally to avoid compiler warnings.\r
++\r
++(defvar notmuch-json-parser nil\r
++  "Internal incremental JSON parser object: local to the buffer being parsed.")\r
++\r
++(defvar notmuch-json-state nil\r
++  "State of the internal JSON parser: local to the buffer being parsed.")\r
++\r
+ (defun notmuch-json-create-parser (buffer)\r
+   "Return a streaming JSON parser that consumes input from BUFFER.\r
\r
+@@ -535,6 +545,62 @@ of the buffer if there is only trailing whitespace."\r
+     (unless (eobp)\r
+       (signal 'json-error (list "Trailing garbage following JSON data")))))\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
++\r
++It sets up all the needed internal variables: the caller just\r
++needs to call it with point in the same place that the parser\r
++left it."\r
++  (let (done)\r
++    (unless (local-variable-p 'notmuch-json-parser)\r
++      (set (make-local-variable 'notmuch-json-parser)\r
++         (notmuch-json-create-parser (current-buffer)))\r
++      (set (make-local-variable 'notmuch-json-state) 'begin))\r
++    (while (not done)\r
++      (condition-case nil\r
++        (case notmuch-json-state\r
++              ((begin)\r
++               ;; Enter the results list\r
++               (if (eq (notmuch-json-begin-compound\r
++                        notmuch-json-parser) 'retry)\r
++                   (setq done t)\r
++                 (setq notmuch-json-state 'result)))\r
++              ((result)\r
++               ;; Parse a result\r
++               (let ((result (notmuch-json-read notmuch-json-parser)))\r
++                 (case result\r
++                       ((retry) (setq done t))\r
++                       ((end) (setq notmuch-json-state 'end))\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-json-parser)\r
++               (setq done t)))\r
++      (json-error\r
++       ;; Do our best to resynchronize and ensure forward\r
++       ;; progress\r
++       (let ((bad (buffer-substring (line-beginning-position)\r
++                                    (line-end-position))))\r
++         (forward-line)\r
++         (with-current-buffer results-buf\r
++           (funcall error-function "%s" bad))))))\r
++    ;; Clear out what we've parsed\r
++    (delete-region (point-min) (point))))\r
++\r
++\r
++\r
++\r
+ (provide 'notmuch-lib)\r
\r
+ ;; Local Variables:\r
+diff --git a/emacs/notmuch.el b/emacs/notmuch.el\r
+index e3610d6..e304dde 100644\r
+--- a/emacs/notmuch.el\r
++++ b/emacs/notmuch.el\r
+@@ -820,16 +820,6 @@ non-authors is found, assume that all of the authors match."\r
+     (insert (apply #'format string objects))\r
+     (insert "\n")))\r
\r
+-;; These two variables are internal variables to the parsing\r
+-;; routines. They are always used buffer local but need to be declared\r
+-;; globally to avoid compiler warnings.\r
+-\r
+-(defvar notmuch-json-state nil\r
+-  "Internal incremental JSON parser object: local to the buffer being parsed.")\r
+-\r
+-(defvar notmuch-json-parser nil\r
+-  "State of the internal JSON parser: local to the buffer being parsed.")\r
+-\r
+ (defun notmuch-search-process-filter (proc string)\r
+   "Process and filter the output of \"notmuch search\""\r
+   (let ((results-buf (process-buffer proc))\r
+@@ -847,59 +837,6 @@ non-authors is found, assume that all of the authors match."\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
+-\r
+-It sets up all the needed internal variables: the caller just\r
+-needs to call it with point in the same place that the parser\r
+-left it."\r
+-  (let (done)\r
+-    (unless (local-variable-p 'notmuch-json-parser)\r
+-      (set (make-local-variable 'notmuch-json-parser)\r
+-         (notmuch-json-create-parser (current-buffer)))\r
+-      (set (make-local-variable 'notmuch-json-state) 'begin))\r
+-    (while (not done)\r
+-      (condition-case nil\r
+-        (case notmuch-json-state\r
+-              ((begin)\r
+-               ;; Enter the results list\r
+-               (if (eq (notmuch-json-begin-compound\r
+-                        notmuch-json-parser) 'retry)\r
+-                   (setq done t)\r
+-                 (setq notmuch-json-state 'result)))\r
+-              ((result)\r
+-               ;; Parse a result\r
+-               (let ((result (notmuch-json-read notmuch-json-parser)))\r
+-                 (case result\r
+-                       ((retry) (setq done t))\r
+-                       ((end) (setq notmuch-json-state 'end))\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-json-parser)\r
+-               (setq done t)))\r
+-      (json-error\r
+-       ;; Do our best to resynchronize and ensure forward\r
+-       ;; progress\r
+-       (let ((bad (buffer-substring (line-beginning-position)\r
+-                                    (line-end-position))))\r
+-         (forward-line)\r
+-         (with-current-buffer results-buf\r
+-           (funcall error-function "%s" bad))))))\r
+-    ;; Clear out what we've parsed\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
\r
+-- \r
+1.7.9.1\r
+\r