From: Austin Clements Date: Sun, 2 Dec 2012 02:40:00 +0000 (+1900) Subject: [PATCH 08/10] emacs: Factor out synchronous notmuch JSON invocations X-Git-Url: http://git.tremily.us/gitweb.cgi?a=commitdiff_plain;h=399ba4b1922c1287e2d211a7d504421b82430058;p=notmuch-archives.git [PATCH 08/10] emacs: Factor out synchronous notmuch JSON invocations --- diff --git a/df/ce52ded9393e7db6b22ffa52c8e45f12658e6f b/df/ce52ded9393e7db6b22ffa52c8e45f12658e6f new file mode 100644 index 000000000..5ae8b39ff --- /dev/null +++ b/df/ce52ded9393e7db6b22ffa52c8e45f12658e6f @@ -0,0 +1,153 @@ +Return-Path: +X-Original-To: notmuch@notmuchmail.org +Delivered-To: notmuch@notmuchmail.org +Received: from localhost (localhost [127.0.0.1]) + by olra.theworths.org (Postfix) with ESMTP id 2DA56431FC7 + for ; Sat, 1 Dec 2012 18:40:15 -0800 (PST) +X-Virus-Scanned: Debian amavisd-new at olra.theworths.org +X-Spam-Flag: NO +X-Spam-Score: -0.7 +X-Spam-Level: +X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5 + tests=[RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled +Received: from olra.theworths.org ([127.0.0.1]) + by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) + with ESMTP id s3cBDBYoXoUA for ; + Sat, 1 Dec 2012 18:40:14 -0800 (PST) +Received: from dmz-mailsec-scanner-4.mit.edu (DMZ-MAILSEC-SCANNER-4.MIT.EDU + [18.9.25.15]) + by olra.theworths.org (Postfix) with ESMTP id 84BFB431FBD + for ; Sat, 1 Dec 2012 18:40:13 -0800 (PST) +X-AuditID: 1209190f-b7fec6d00000090d-86-50babf8c3c95 +Received: from mailhub-auth-1.mit.edu ( [18.9.21.35]) + by dmz-mailsec-scanner-4.mit.edu (Symantec Messaging Gateway) with SMTP + id 5F.F5.02317.C8FBAB05; Sat, 1 Dec 2012 21:40:12 -0500 (EST) +Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103]) + by mailhub-auth-1.mit.edu (8.13.8/8.9.2) with ESMTP id qB22eBs1013710; + Sat, 1 Dec 2012 21:40:11 -0500 +Received: from drake.dyndns.org + (209-6-116-242.c3-0.arl-ubr1.sbo-arl.ma.cable.rcn.com + [209.6.116.242]) (authenticated bits=0) + (User authenticated as amdragon@ATHENA.MIT.EDU) + by outgoing.mit.edu (8.13.6/8.12.4) with ESMTP id qB22e6tc025604 + (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT); + Sat, 1 Dec 2012 21:40:10 -0500 (EST) +Received: from amthrax by drake.dyndns.org with local (Exim 4.77) + (envelope-from ) + id 1TezTS-0000xk-3Y; Sat, 01 Dec 2012 21:40:06 -0500 +From: Austin Clements +To: notmuch@notmuchmail.org +Subject: [PATCH 08/10] emacs: Factor out synchronous notmuch JSON invocations +Date: Sat, 1 Dec 2012 21:40:00 -0500 +Message-Id: <1354416002-3557-8-git-send-email-amdragon@mit.edu> +X-Mailer: git-send-email 1.7.10.4 +In-Reply-To: <1354416002-3557-1-git-send-email-amdragon@mit.edu> +References: <1354416002-3557-1-git-send-email-amdragon@mit.edu> +X-Brightmail-Tracker: + H4sIAAAAAAAAA+NgFtrIIsWRmVeSWpSXmKPExsUixCmqrNuzf1eAwf038hbXb85kdmD0eLbq + FnMAYxSXTUpqTmZZapG+XQJXxquL7YwFz8UrVjfeYW9gnC/cxcjBISFgInGpLbWLkRPIFJO4 + cG89WxcjF4eQwD5GiY+NT6Cc9YwSL5+dY4FwHjJJ9B1dAuXMZZRo29/BCtLPJqAhsW3/ckYQ + W0RAWmLn3dmsICuYBdQk/nSpgISFBXwllt48xgRiswioSvw9vY0dxOYVsJeY+ABkNcgZihLd + zyawgbRyCjhIrOjmAQkLAZX8/32NbQIj/wJGhlWMsim5Vbq5iZk5xanJusXJiXl5qUW6Jnq5 + mSV6qSmlmxjBISPJv4Px20GlQ4wCHIxKPLyMs3YFCLEmlhVX5h5ilORgUhLlvbIDKMSXlJ9S + mZFYnBFfVJqTWnyIUYKDWUmEl8UEKMebklhZlVqUD5OS5mBREue9mnLTX0ggPbEkNTs1tSC1 + CCYrw8GhJMFbvQ+oUbAoNT21Ii0zpwQhzcTBCTKcB2j4o70gw4sLEnOLM9Mh8qcYFaXEea+B + JARAEhmleXC9sJh+xSgO9IowryfICh5gOoDrfgU0mAlo8Jtl20EGlyQipKQaGLNPvb0uUsQ5 + 85PQmtxrS57wNi3rtFuwUGL3nqu3Lixjtr1cfDR23b1tfoXSRh8jG7UWW+6JcTYyn2pedyd9 + kebHY2wqUtX/zRpnX8/eqrWT+XKXvsEV4TPMHj1VO0949vpoySjYXe6Yf3575uSpKzXNPh0L + 3paYFhKjLybRUaGyKMBN4VdPoBJLcUaioRZzUXEiAMlW5JjEAgAA +X-BeenThere: notmuch@notmuchmail.org +X-Mailman-Version: 2.1.13 +Precedence: list +List-Id: "Use and development of the notmuch mail system." + +List-Unsubscribe: , + +List-Archive: +List-Post: +List-Help: +List-Subscribe: , + +X-List-Received-Date: Sun, 02 Dec 2012 02:40:15 -0000 + +Previously this code was duplicated between show and reply. This +factors out synchronously invoking notmuch and parsing the output as +JSON. +--- + emacs/notmuch-lib.el | 14 ++++++++++++++ + emacs/notmuch-mua.el | 8 +------- + emacs/notmuch-query.el | 11 ++--------- + 3 files changed, 17 insertions(+), 16 deletions(-) + +diff --git a/emacs/notmuch-lib.el b/emacs/notmuch-lib.el +index 49b0da6..31c69dc 100644 +--- a/emacs/notmuch-lib.el ++++ b/emacs/notmuch-lib.el +@@ -357,6 +357,20 @@ You may need to restart Emacs or upgrade your notmuch package.")) + (error "Bad exit status %d" exit-status))) + (error "notmuch CLI version mismatch")) + ++(defun notmuch-call-notmuch-json (&rest args) ++ "Invoke `notmuch-command' with `args' and return the parsed JSON output. ++ ++The returned output will represent objects using property lists ++and arrays as lists." ++ ++ (with-temp-buffer ++ (apply #'call-process notmuch-command nil (list t nil) nil args) ++ (goto-char (point-min)) ++ (let ((json-object-type 'plist) ++ (json-array-type 'list) ++ (json-false 'nil)) ++ (json-read)))) ++ + ;; Compatibility functions for versions of emacs before emacs 23. + ;; + ;; Both functions here were copied from emacs 23 with the following copyright: +diff --git a/emacs/notmuch-mua.el b/emacs/notmuch-mua.el +index 408b49e..ac2d29e 100644 +--- a/emacs/notmuch-mua.el ++++ b/emacs/notmuch-mua.el +@@ -158,13 +158,7 @@ list." + (setq args (append args (list query-string))) + + ;; Get the reply object as JSON, and parse it into an elisp object. +- (with-temp-buffer +- (apply 'call-process (append (list notmuch-command nil (list t nil) nil) args)) +- (goto-char (point-min)) +- (let ((json-object-type 'plist) +- (json-array-type 'list) +- (json-false 'nil)) +- (setq reply (json-read)))) ++ (setq reply (apply #'notmuch-call-notmuch-json args)) + + ;; Extract the original message to simplify the following code. + (setq original (plist-get reply :original)) +diff --git a/emacs/notmuch-query.el b/emacs/notmuch-query.el +index d66baea..e7e3520 100644 +--- a/emacs/notmuch-query.el ++++ b/emacs/notmuch-query.el +@@ -29,18 +29,11 @@ A thread is a forest or list of trees. A tree is a two element + list where the first element is a message, and the second element + is a possibly empty forest of replies. + " +- (let ((args '("show" "--format=json")) +- (json-object-type 'plist) +- (json-array-type 'list) +- (json-false 'nil)) ++ (let ((args '("show" "--format=json"))) + (if notmuch-show-process-crypto + (setq args (append args '("--decrypt")))) + (setq args (append args search-terms)) +- (with-temp-buffer +- (progn +- (apply 'call-process (append (list notmuch-command nil (list t nil) nil) args)) +- (goto-char (point-min)) +- (json-read))))) ++ (apply #'notmuch-call-notmuch-json args))) + + ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + ;; Mapping functions across collections of messages. +-- +1.7.10.4 +