--- /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 01800431FB6\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 GAr4StNIX5xb for <notmuch@notmuchmail.org>;\r
+ Fri, 14 Dec 2012 21:15:29 -0800 (PST)\r
+Received: from dmz-mailsec-scanner-7.mit.edu (DMZ-MAILSEC-SCANNER-7.MIT.EDU\r
+ [18.7.68.36])\r
+ by olra.theworths.org (Postfix) with ESMTP id 82C21431FC2\r
+ for <notmuch@notmuchmail.org>; Fri, 14 Dec 2012 21:15:28 -0800 (PST)\r
+X-AuditID: 12074424-b7fe06d0000008f0-f7-50cc076fb88c\r
+Received: from mailhub-auth-1.mit.edu ( [18.9.21.35])\r
+ by dmz-mailsec-scanner-7.mit.edu (Symantec Messaging Gateway) with SMTP\r
+ id 3B.38.02288.F670CC05; 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-1.mit.edu (8.13.8/8.9.2) with ESMTP id qBF5FQ1F021590; \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 qBF5FOGp011443\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-0002kJ-3a; Sat, 15 Dec 2012 00:15:24 -0500\r
+From: Austin Clements <amdragon@MIT.EDU>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH 1/7] emacs: Centralize notmuch command error handling\r
+Date: Sat, 15 Dec 2012 00:15:07 -0500\r
+Message-Id: <1355548513-10085-2-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+NgFtrDIsWRmVeSWpSXmKPExsUixCmqrFvAfibA4M07VovVc3ksrt+cyezA\r
+ 5LFz1l12j2erbjEHMEVx2aSk5mSWpRbp2yVwZczoX8ZYMEWsYs2aSawNjPsEuxg5OSQETCSO\r
+ /ulghbDFJC7cW8/WxcjFISSwj1HiSP88dghnA6PE2ud/mECqhAQeMUlc6fCFSMxllDjZspQN\r
+ JMEmoCGxbf9yRhBbREBaYufd2WBjmQUcJT7vXwRWIyzgKnHx5CVmEJtFQFVi6ct+MJtXwAGo\r
+ /hM7xBmKEt3PJoDVcwL1Lvt4jgVisYPE2Vd3WScw8i9gZFjFKJuSW6Wbm5iZU5yarFucnJiX\r
+ l1qka66Xm1mil5pSuokRFEjsLio7GJsPKR1iFOBgVOLh3RFxOkCINbGsuDL3EKMkB5OSKO8t\r
+ hjMBQnxJ+SmVGYnFGfFFpTmpxYcYJTiYlUR4xbYAlfOmJFZWpRblw6SkOViUxHmvp9z0FxJI\r
+ TyxJzU5NLUgtgsnKcHAoSfCyswENFSxKTU+tSMvMKUFIM3FwggznARp+lhWohre4IDG3ODMd\r
+ In+KUVFKnPcJSEIAJJFRmgfXC4v0V4ziQK8I8z4CqeIBJgm47ldAg5mABsddOg4yuCQRISXV\r
+ wNj+ZX2U2YdFQj2RjowGrdXJSpYvwqbPmc6l7FurczP3QGP1l01y1lYLA6bNO7dS+KzTg3/u\r
+ YZWSvKlh8vz7Tr9Livd3ZjqhO22KSHqDfcq8xC3yCUebhPmdb1k31753lL0m2jD1lJjF9DCD\r
+ Iymv36nXH3mus7XaZePZtX7bdx3+F2WywTZfUImlOCPRUIu5qDgRAM/mKkPPAgAA\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:30 -0000\r
+\r
+This provides library functions for unified handling of errors from\r
+the notmuch CLI. Follow-up patches will convert some scattered error\r
+handling to use this and add error handling where we currently ignore\r
+errors.\r
+---\r
+ emacs/notmuch-lib.el | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++\r
+ 1 file changed, 53 insertions(+)\r
+\r
+diff --git a/emacs/notmuch-lib.el b/emacs/notmuch-lib.el\r
+index 9c4ee71..851098f 100644\r
+--- a/emacs/notmuch-lib.el\r
++++ b/emacs/notmuch-lib.el\r
+@@ -316,6 +316,59 @@ string), a property list of face attributes, or a list of these."\r
+ (put-text-property pos next 'face (cons face cur))\r
+ (setq pos next)))))\r
+ \r
++(defun notmuch-pop-up-error (msg)\r
++ "Pop up an error buffer displaying MSG.\r
++\r
++This will accumulate error messages in the errors buffer until\r
++the user dismisses it."\r
++\r
++ (let ((buf (get-buffer-create "*Notmuch errors*")))\r
++ (with-current-buffer buf\r
++ (view-mode-enter nil #'kill-buffer)\r
++ (let ((inhibit-read-only t))\r
++ (insert msg)\r
++ (unless (bolp)\r
++ (insert "\n"))\r
++ (goto-char (point-min))))\r
++ (pop-to-buffer buf)))\r
++\r
++(defun notmuch-check-exit-status (exit-status command &optional output err-file)\r
++ "If EXIT-STATUS is non-zero, pop up an error buffer and signal an error.\r
++\r
++If EXIT-STATUS is non-zero, pop up a notmuch error buffer\r
++describing the error and signal an Elisp error. EXIT-STATUS must\r
++be a number indicating the exit status code of a process or a\r
++string describing the signal that terminated the process (such as\r
++returned by `call-process'). COMMAND must be a list giving the\r
++command and its arguments. OUTPUT, if provided, is a string\r
++giving the output of command. ERR-FILE, if provided, is the name\r
++of a file containing the error output of command. OUTPUT and the\r
++contents of ERR-FILE will be included in the error message."\r
++\r
++ ;; This is implemented as a cond to make it easy to expand.\r
++ (cond\r
++ ((eq exit-status 0) t)\r
++ (t\r
++ (notmuch-pop-up-error\r
++ (concat\r
++ (format "Error invoking notmuch. %s exited with %s%s.\n"\r
++ (mapconcat #'identity command " ")\r
++ ;; Signal strings look like "Terminated", hence the\r
++ ;; colon.\r
++ (if (integerp exit-status) "status " "signal: ")\r
++ exit-status)\r
++ (when err-file\r
++ (concat "Error:\n"\r
++ (with-temp-buffer\r
++ (insert-file-contents err-file)\r
++ (if (eobp)\r
++ "(no error output)\n"\r
++ (buffer-string)))))\r
++ (when (and output (not (equal output "")))\r
++ (format "Output:\n%s" output))))\r
++ ;; Mimic `process-lines'\r
++ (error "%s exited with status %s" (car command) exit-status))))\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
+-- \r
+1.7.10.4\r
+\r