From: Austin Clements Date: Sat, 15 Dec 2012 20:04:16 +0000 (+1900) Subject: [PATCH v2 3/7] emacs: Factor out synchronous notmuch JSON invocations X-Git-Url: http://git.tremily.us/gitweb.cgi?a=commitdiff_plain;h=6ebc492b3a4ecb186d9d7b5b3b5dad7057677244;p=notmuch-archives.git [PATCH v2 3/7] emacs: Factor out synchronous notmuch JSON invocations --- diff --git a/36/81a1b1db75e85396e58cb0c0cf948595569417 b/36/81a1b1db75e85396e58cb0c0cf948595569417 new file mode 100644 index 000000000..52a853f79 --- /dev/null +++ b/36/81a1b1db75e85396e58cb0c0cf948595569417 @@ -0,0 +1,155 @@ +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 7DF61431FDA + for ; Sat, 15 Dec 2012 12:04:37 -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 P-r50hoNwUEE for ; + Sat, 15 Dec 2012 12:04:36 -0800 (PST) +Received: from dmz-mailsec-scanner-3.mit.edu (DMZ-MAILSEC-SCANNER-3.MIT.EDU + [18.9.25.14]) + by olra.theworths.org (Postfix) with ESMTP id 3E69E431FBF + for ; Sat, 15 Dec 2012 12:04:35 -0800 (PST) +X-AuditID: 1209190e-b7f516d0000008e4-ec-50ccd7d2aebf +Received: from mailhub-auth-2.mit.edu ( [18.7.62.36]) + by dmz-mailsec-scanner-3.mit.edu (Symantec Messaging Gateway) with SMTP + id 7F.06.02276.2D7DCC05; Sat, 15 Dec 2012 15:04:34 -0500 (EST) +Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103]) + by mailhub-auth-2.mit.edu (8.13.8/8.9.2) with ESMTP id qBFK4WjI014730; + Sat, 15 Dec 2012 15:04:32 -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 qBFK4Sjj025683 + (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT); + Sat, 15 Dec 2012 15:04:31 -0500 (EST) +Received: from amthrax by drake.dyndns.org with local (Exim 4.77) + (envelope-from ) + id 1TjxyG-0007sV-LN; Sat, 15 Dec 2012 15:04:28 -0500 +From: Austin Clements +To: notmuch@notmuchmail.org +Subject: [PATCH v2 3/7] emacs: Factor out synchronous notmuch JSON invocations +Date: Sat, 15 Dec 2012 15:04:16 -0500 +Message-Id: <1355601860-30121-4-git-send-email-amdragon@mit.edu> +X-Mailer: git-send-email 1.7.10.4 +In-Reply-To: <1355601860-30121-1-git-send-email-amdragon@mit.edu> +References: <1355601860-30121-1-git-send-email-amdragon@mit.edu> +X-Brightmail-Tracker: + H4sIAAAAAAAAA+NgFjrOIsWRmVeSWpSXmKPExsUixG6nonvp+pkAg4VTVSxWz+WxuH5zJrPF + m5XzWB2YPXbOusvucfjrQhaPZ6tuMQcwR3HZpKTmZJalFunbJXBlXNp3h6ngjXjFm689jA2M + C4S7GDk5JARMJE63drBD2GISF+6tZ+ti5OIQEtjHKLHz/yJ2CGcDo8TMpxeYIZxHTBIHWh5C + lc1llNi2YTczSD+bgIbEtv3LGUFsEQFpiZ13Z7OC2MwCcRJbpvwHiwsL+Ek8efcfLM4ioCpx + sf8xG4jNK+Ag0bt0EQvEHYoS3c8mgMU5BRwlJk7exQRiCwHV3F4wh2kCI/8CRoZVjLIpuVW6 + uYmZOcWpybrFyYl5ealFusZ6uZkleqkppZsYQeHFKcm3g/HrQaVDjAIcjEo8vDsiTgcIsSaW + FVfmHmKU5GBSEuXNuHwmQIgvKT+lMiOxOCO+qDQntfgQowQHs5IIb9J8oBxvSmJlVWpRPkxK + moNFSZz3SspNfyGB9MSS1OzU1ILUIpisDAeHkgSvEDCOhASLUtNTK9Iyc0oQ0kwcnCDDeYCG + c4DU8BYXJOYWZ6ZD5E8xKkqJ89qBJARAEhmleXC9sPh/xSgO9Iow74drQFU8wNQB1/0KaDAT + 0ODlNmCDSxIRUlINjJGM/OVnPvvqMM1vWMx266j/jyu8payR0x94Cpk/2dM4N6ZP+mBenOcC + s3s51SIsmr7zfstI+Cd4xD7XPlVjsaDRZAnPvPmegTMMP8zUEeFhMN1wX+fX/iVr2loO+i1w + 3nLS6tb16fNkuqMeHVcMyJXfEvz36KP5WpuCG/8v37REM9rOIrs1R4mlOCPRUIu5qDgRAO2H + aUzaAgAA +Cc: tomi.ollila@iki.fi +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: Sat, 15 Dec 2012 20:04:38 -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 f757ce7..f534770 100644 +--- a/emacs/notmuch-lib.el ++++ b/emacs/notmuch-lib.el +@@ -371,6 +371,20 @@ contents of ERR-FILE will be included in the error message." + ;; Mimic `process-lines' + (error "%s exited with status %s" (car command) exit-status)))) + ++(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 +