--- /dev/null
+Return-Path: <amdragon@mit.edu>\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 E18D8431FC2\r
+ for <notmuch@notmuchmail.org>; Fri, 14 Dec 2012 21:15:30 -0800 (PST)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -0.7\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5\r
+ tests=[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 JV1Ix6Siceg7 for <notmuch@notmuchmail.org>;\r
+ Fri, 14 Dec 2012 21:15:30 -0800 (PST)\r
+Received: from dmz-mailsec-scanner-3.mit.edu (DMZ-MAILSEC-SCANNER-3.MIT.EDU\r
+ [18.9.25.14])\r
+ by olra.theworths.org (Postfix) with ESMTP id C119B431FC9\r
+ for <notmuch@notmuchmail.org>; Fri, 14 Dec 2012 21:15:28 -0800 (PST)\r
+X-AuditID: 1209190e-b7f516d0000008e4-1e-50cc07706446\r
+Received: from mailhub-auth-2.mit.edu ( [18.7.62.36])\r
+ by dmz-mailsec-scanner-3.mit.edu (Symantec Messaging Gateway) with SMTP\r
+ id 42.8A.02276.0770CC05; Sat, 15 Dec 2012 00:15:28 -0500 (EST)\r
+Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103])\r
+ by mailhub-auth-2.mit.edu (8.13.8/8.9.2) with ESMTP id qBF5FQS4023579; \r
+ Sat, 15 Dec 2012 00:15:26 -0500\r
+Received: from drake.dyndns.org\r
+ (209-6-116-242.c3-0.arl-ubr1.sbo-arl.ma.cable.rcn.com\r
+ [209.6.116.242]) (authenticated bits=0)\r
+ (User authenticated as amdragon@ATHENA.MIT.EDU)\r
+ by outgoing.mit.edu (8.13.6/8.12.4) with ESMTP id qBF5FOK6011445\r
+ (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT);\r
+ Sat, 15 Dec 2012 00:15:25 -0500 (EST)\r
+Received: from amthrax by drake.dyndns.org with local (Exim 4.77)\r
+ (envelope-from <amdragon@mit.edu>)\r
+ id 1Tjk5s-0002kO-71; Sat, 15 Dec 2012 00:15:24 -0500\r
+From: Austin Clements <amdragon@MIT.EDU>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH 3/7] emacs: Factor out synchronous notmuch JSON invocations\r
+Date: Sat, 15 Dec 2012 00:15:09 -0500\r
+Message-Id: <1355548513-10085-4-git-send-email-amdragon@mit.edu>\r
+X-Mailer: git-send-email 1.7.10.4\r
+In-Reply-To: <1355548513-10085-1-git-send-email-amdragon@mit.edu>\r
+References: <1355548513-10085-1-git-send-email-amdragon@mit.edu>\r
+X-Brightmail-Tracker:\r
+ H4sIAAAAAAAAA+NgFtrNIsWRmVeSWpSXmKPExsUixG6nolvAfibA4GIPj8XquTwW12/OZHZg\r
+ 8tg56y67x7NVt5gDmKK4bFJSczLLUov07RK4Mp70r2QseCNeceviMbYGxgXCXYycHBICJhLN\r
+ u5+zQdhiEhfurQeyuTiEBPYxSmx4fZ0ZwtnAKNH1YBYLSJWQwCMmiTdHwiAScxklWp/9ZwVJ\r
+ sAloSGzbv5wRxBYRkJbYeXc2WJxZwFHi8/5FYCuEBbwlVt46BmRzcLAIqEr8uq4IEuYVcJC4\r
+ 92geK8QVihLdzyaAlXMCtS77eA5qr4PE2Vd3WScw8i9gZFjFKJuSW6Wbm5iZU5yarFucnJiX\r
+ l1qka6yXm1mil5pSuokRFEacknw7GL8eVDrEKMDBqMTDuyPidIAQa2JZcWXuIUZJDiYlUd5b\r
+ DGcChPiS8lMqMxKLM+KLSnNSiw8xSnAwK4nwim0BKudNSaysSi3Kh0lJc7AoifNeSbnpLySQ\r
+ nliSmp2aWpBaBJOV4eBQkuD9wQY0VLAoNT21Ii0zpwQhzcTBCTKcB2j4fpAa3uKCxNzizHSI\r
+ /ClGRSlx3qsgCQGQREZpHlwvLM5fMYoDvSLMGw1SxQNMEXDdr4AGMwENjrt0HGRwSSJCSgoY\r
+ 3Uvjlz7JlIy225aXvPTkj5vma+TD1O+YdV0L36fCIv7x7fGn0Q/ue3y87x295vTnF32Lphxa\r
+ y/teqnD58gkdK5pj1tq0LY/bwqjh0/xQ3SBHOq19evotay3pspdL1rt0M8R6O6u1ZDGrpFTw\r
+ JhtOnvhoQplsztQNlx+f++OQ06z/6qdBYGCKEktxRqKhFnNRcSIACa1iqc4CAAA=\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, 15 Dec 2012 05:15:31 -0000\r
+\r
+Previously this code was duplicated between show and reply. This\r
+factors out synchronously invoking notmuch and parsing the output as\r
+JSON.\r
+---\r
+ emacs/notmuch-lib.el | 14 ++++++++++++++\r
+ emacs/notmuch-mua.el | 8 +-------\r
+ emacs/notmuch-query.el | 11 ++---------\r
+ 3 files changed, 17 insertions(+), 16 deletions(-)\r
+\r
+diff --git a/emacs/notmuch-lib.el b/emacs/notmuch-lib.el\r
+index 851098f..4b71116 100644\r
+--- a/emacs/notmuch-lib.el\r
++++ b/emacs/notmuch-lib.el\r
+@@ -369,6 +369,20 @@ contents of ERR-FILE will be included in the error message."\r
+ ;; Mimic `process-lines'\r
+ (error "%s exited with status %s" (car command) exit-status))))\r
+ \r
++(defun notmuch-call-notmuch-json (&rest args)\r
++ "Invoke `notmuch-command' with `args' and return the parsed JSON output.\r
++\r
++The returned output will represent objects using property lists\r
++and arrays as lists."\r
++\r
++ (with-temp-buffer\r
++ (apply #'call-process notmuch-command nil (list t nil) nil args)\r
++ (goto-char (point-min))\r
++ (let ((json-object-type 'plist)\r
++ (json-array-type 'list)\r
++ (json-false 'nil))\r
++ (json-read))))\r
++\r
+ ;; Compatibility functions for versions of emacs before emacs 23.\r
+ ;;\r
+ ;; Both functions here were copied from emacs 23 with the following copyright:\r
+diff --git a/emacs/notmuch-mua.el b/emacs/notmuch-mua.el\r
+index 408b49e..ac2d29e 100644\r
+--- a/emacs/notmuch-mua.el\r
++++ b/emacs/notmuch-mua.el\r
+@@ -158,13 +158,7 @@ list."\r
+ (setq args (append args (list query-string)))\r
+ \r
+ ;; Get the reply object as JSON, and parse it into an elisp object.\r
+- (with-temp-buffer\r
+- (apply 'call-process (append (list notmuch-command nil (list t nil) nil) args))\r
+- (goto-char (point-min))\r
+- (let ((json-object-type 'plist)\r
+- (json-array-type 'list)\r
+- (json-false 'nil))\r
+- (setq reply (json-read))))\r
++ (setq reply (apply #'notmuch-call-notmuch-json args))\r
+ \r
+ ;; Extract the original message to simplify the following code.\r
+ (setq original (plist-get reply :original))\r
+diff --git a/emacs/notmuch-query.el b/emacs/notmuch-query.el\r
+index d66baea..e7e3520 100644\r
+--- a/emacs/notmuch-query.el\r
++++ b/emacs/notmuch-query.el\r
+@@ -29,18 +29,11 @@ A thread is a forest or list of trees. A tree is a two element\r
+ list where the first element is a message, and the second element\r
+ is a possibly empty forest of replies.\r
+ "\r
+- (let ((args '("show" "--format=json"))\r
+- (json-object-type 'plist)\r
+- (json-array-type 'list)\r
+- (json-false 'nil))\r
++ (let ((args '("show" "--format=json")))\r
+ (if notmuch-show-process-crypto\r
+ (setq args (append args '("--decrypt"))))\r
+ (setq args (append args search-terms))\r
+- (with-temp-buffer\r
+- (progn\r
+- (apply 'call-process (append (list notmuch-command nil (list t nil) nil) args))\r
+- (goto-char (point-min))\r
+- (json-read)))))\r
++ (apply #'notmuch-call-notmuch-json args)))\r
+ \r
+ ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;\r
+ ;; Mapping functions across collections of messages.\r
+-- \r
+1.7.10.4\r
+\r