--- /dev/null
+Return-Path: <tomi.ollila@iki.fi>\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 C2373431FC3\r
+ for <notmuch@notmuchmail.org>; Fri, 31 May 2013 12:01:38 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: 0\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none]\r
+ 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 gEkoRqbrF3uz for <notmuch@notmuchmail.org>;\r
+ Fri, 31 May 2013 12:01:32 -0700 (PDT)\r
+Received: from guru.guru-group.fi (guru.guru-group.fi [46.183.73.34])\r
+ by olra.theworths.org (Postfix) with ESMTP id 82573431FBD\r
+ for <notmuch@notmuchmail.org>; Fri, 31 May 2013 12:01:32 -0700 (PDT)\r
+Received: from guru.guru-group.fi (localhost [IPv6:::1])\r
+ by guru.guru-group.fi (Postfix) with ESMTP id 2E935100093;\r
+ Fri, 31 May 2013 22:01:28 +0300 (EEST)\r
+From: Tomi Ollila <tomi.ollila@iki.fi>\r
+To: Austin Clements <amdragon@MIT.EDU>, notmuch@notmuchmail.org\r
+Subject: Re: [PATCH v2 2/5] emacs: Utilities to manage asynchronous notmuch\r
+ processes\r
+In-Reply-To: <1369934016-22308-3-git-send-email-amdragon@mit.edu>\r
+References: <1369934016-22308-1-git-send-email-amdragon@mit.edu>\r
+ <1369934016-22308-3-git-send-email-amdragon@mit.edu>\r
+User-Agent: Notmuch/0.15.2+115~g12cf6af (http://notmuchmail.org) Emacs/24.3.1\r
+ (x86_64-unknown-linux-gnu)\r
+Date: Fri, 31 May 2013 22:01:27 +0300\r
+Message-ID: <m24ndjas8o.fsf@guru.guru-group.fi>\r
+MIME-Version: 1.0\r
+Content-Type: text/plain\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 19:01:38 -0000\r
+\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
+\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
+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