--- /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 16556431FDC\r
+ for <notmuch@notmuchmail.org>; Fri, 31 May 2013 16:41:42 -0700 (PDT)\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 TvA6BpPkSq3m for <notmuch@notmuchmail.org>;\r
+ Fri, 31 May 2013 16:41:34 -0700 (PDT)\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 5DB2D431FBD\r
+ for <notmuch@notmuchmail.org>; Fri, 31 May 2013 16:41:34 -0700 (PDT)\r
+X-AuditID: 12074424-b7f8c6d0000028c4-f7-51a9352db106\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 61.C0.10436.D2539A15; Fri, 31 May 2013 19:41:33 -0400 (EDT)\r
+Received: from outgoing.mit.edu (outgoing-auth-1.mit.edu [18.9.28.11])\r
+ by mailhub-auth-1.mit.edu (8.13.8/8.9.2) with ESMTP id r4VNfW3G004129; \r
+ Fri, 31 May 2013 19:41:33 -0400\r
+Received: from awakening.csail.mit.edu (awakening.csail.mit.edu [18.26.4.91])\r
+ (authenticated bits=0)\r
+ (User authenticated as amdragon@ATHENA.MIT.EDU)\r
+ by outgoing.mit.edu (8.13.8/8.12.4) with ESMTP id r4VNfVhc004485\r
+ (version=TLSv1/SSLv3 cipher=DHE-RSA-AES128-SHA bits=128 verify=NOT);\r
+ Fri, 31 May 2013 19:41:32 -0400\r
+Received: from amthrax by awakening.csail.mit.edu with local (Exim 4.80)\r
+ (envelope-from <amdragon@mit.edu>)\r
+ id 1UiYws-0005Ve-VV; Fri, 31 May 2013 19:41:31 -0400\r
+From: Austin Clements <amdragon@MIT.EDU>\r
+To: Tomi Ollila <tomi.ollila@iki.fi>, notmuch@notmuchmail.org\r
+Subject: Re: [PATCH v2 2/5] emacs: Utilities to manage asynchronous notmuch\r
+ processes\r
+In-Reply-To: <m24ndjas8o.fsf@guru.guru-group.fi>\r
+References: <1369934016-22308-1-git-send-email-amdragon@mit.edu>\r
+ <1369934016-22308-3-git-send-email-amdragon@mit.edu>\r
+ <m24ndjas8o.fsf@guru.guru-group.fi>\r
+User-Agent: Notmuch/0.15.2+133~gf9ff9fd (http://notmuchmail.org) Emacs/23.4.1\r
+ (i486-pc-linux-gnu)\r
+Date: Fri, 31 May 2013 19:41:30 -0400\r
+Message-ID: <87zjvahg45.fsf@awakening.csail.mit.edu>\r
+MIME-Version: 1.0\r
+Content-Type: text/plain; charset=us-ascii\r
+X-Brightmail-Tracker:\r
+ H4sIAAAAAAAAA+NgFnrAIsWRmVeSWpSXmKPExsUixCmqrKtrujLQ4OdHG4vrN2cyW7xZOY/V\r
+ gcnj8NeFLB7PVt1iDmCK4rJJSc3JLEst0rdL4Mq41p5WcESkYuqMTywNjMsFuhg5OSQETCTu\r
+ HNrPAmGLSVy4t54NxBYS2Mco0b5JrouRC8jeyCgxd28jE4RzmkliwaHTUM4SRonWh7PBWtgE\r
+ NCS27V/OCGKLCNhKXFlykhXEFhYIlVj96zk7iM0pYCDxcN1FFojmmYwS+9asAXI4OEQFEiUW\r
+ 7I4BqWERUJW49Okp2Em8QOd93NnKDmELSpyc+QQsziygJXHj30umCYwCs5CkZiFJLWBkWsUo\r
+ m5JbpZubmJlTnJqsW5ycmJeXWqRrrpebWaKXmlK6iREUkOwuKjsYmw8pHWIU4GBU4uE1WLEi\r
+ UIg1say4MvcQoyQHk5Iob67JykAhvqT8lMqMxOKM+KLSnNTiQ4wSHMxKIrz5c4DKeVMSK6tS\r
+ i/JhUtIcLErivNdTbvoLCaQnlqRmp6YWpBbBZGU4OJQkeDtAhgoWpaanVqRl5pQgpJk4OEGG\r
+ 8wANXwFSw1tckJhbnJkOkT/FqCglzjsPJCEAksgozYPrhSWMV4ziQK8I82aCVPEAkw1c9yug\r
+ wUxAg59YLwcZXJKIkJJqYIz4Mqci/M7j370hOVkXVzKsmfH176Ipt3K2z55zU+/fFzO1GdoP\r
+ 3YVO6qbeV53XWl+jd2v9+vu/ZLI7GNlnsheffBxUtvZh9uxrX8PbvOesqO+5KnHm2vHSqFWn\r
+ llzfON9qnXGH/KXw/T9mHTDdf63kCt+UvC05WZPq1/o8XvHuUsIbpwvhH8IClFiKMxINtZiL\r
+ ihMBCyqXDfMCAAA=\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: Fri, 31 May 2013 23:41:42 -0000\r
+\r
+On Fri, 31 May 2013, Tomi Ollila <tomi.ollila@iki.fi> wrote:\r
+> Austin Clements <amdragon@MIT.EDU> writes:\r
+>\r
+>> This provides a new notmuch-lib utility to start an asynchronous\r
+>> notmuch process that handles redirecting of stderr and checking of the\r
+>> exit status. This is similar to `notmuch-call-notmuch-json', but for\r
+>> asynchronous processes (and it leaves output processing to the\r
+>> caller).\r
+>> ---\r
+>> emacs/notmuch-lib.el | 77 +++++++++++++++++++++++++++++++++++++++++++++++---\r
+>\r
+> ...\r
+>\r
+>> +(defun notmuch-start-notmuch (name buffer sentinel &rest args)\r
+>> + "Start and return an asynchronous notmuch command.\r
+>> +\r
+>> +This starts and returns an asynchronous process running\r
+>> +`notmuch-command' with ARGS. The exit status is checked via\r
+>> +`notmuch-check-async-exit-status'. Output written to stderr is\r
+>> +redirected and displayed when the process exits (even if the\r
+>> +process exits successfully). NAME and BUFFER are the same as in\r
+>> +`start-process'. SENTINEL is a process sentinel function to call\r
+>> +when the process exits, or nil for none. The caller must *not*\r
+>> +invoke `set-process-sentinel' directly on the returned process,\r
+>> +as that will interfere with the handling of stderr and the exit\r
+>> +status."\r
+>> +\r
+>> + ;; There is no way (as of Emacs 24.3) to capture stdout and stderr\r
+>> + ;; separately for asynchronous processes, or even to redirect stderr\r
+>> + ;; to a file, so we use a trivial shell wrapper to send stderr to a\r
+>> + ;; temporary file and clean things up in the sentinel.\r
+>> + (let* ((err-file (make-temp-file "nmerr"))\r
+>> + ;; Use a pipe\r
+>> + (process-connection-type nil)\r
+>> + ;; Find notmuch using Emacs' `exec-path'\r
+>> + (command (or (executable-find notmuch-command)\r
+>> + (error "command not found: %s" notmuch-command)))\r
+>> + (proc (apply #'start-process name buffer\r
+>> + "sh" "-c"\r
+>\r
+> I'd suggest "/bin/sh".\r
+\r
+Done.\r
+\r
+>> + "ERR=\"$1\"; shift; exec \"$0\" \"$@\" 2>\"$ERR\""\r
+>\r
+> An alternative to the above ...\r
+>\r
+> "exec 2>\"$1\"; shift; exec \"$0\" \"$@\""\r
+>\r
+> ... which one is better is a matter of quar^H^H^H^H^H taste :D\r
+\r
+I like it. Done.\r
+\r
+> Everything else in this patch series looks good to me (as far as\r
+> I understood -- test passed and works as expected).\r
+>\r
+>\r
+> Tomi\r
+>\r
+>> + command err-file args)))\r
+>> + (process-put proc 'err-file err-file)\r
+>> + (process-put proc 'sub-sentinel sentinel)\r
+>> + (process-put proc 'real-command (cons notmuch-command args))\r
+>> + (set-process-sentinel proc #'notmuch-start-notmuch-sentinel)\r
+>> + proc))\r
+>> +\r