--- /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 154E3431FBF\r
+ for <notmuch@notmuchmail.org>; Tue, 21 May 2013 11:44:22 -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 EcJRH-eanmG0 for <notmuch@notmuchmail.org>;\r
+ Tue, 21 May 2013 11:44:14 -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 D12CD431FB6\r
+ for <notmuch@notmuchmail.org>; Tue, 21 May 2013 11:44:13 -0700 (PDT)\r
+Received: from guru.guru-group.fi (localhost [IPv6:::1])\r
+ by guru.guru-group.fi (Postfix) with ESMTP id 3082F1002C3;\r
+ Tue, 21 May 2013 21:44:13 +0300 (EEST)\r
+From: Tomi Ollila <tomi.ollila@iki.fi>\r
+To: Mark Walters <markwalters1009@gmail.com>,\r
+ Austin Clements <amdragon@MIT.EDU>, notmuch@notmuchmail.org\r
+Subject: Re: [PATCH 2/5] emacs: Utilities to manage asynchronous notmuch\r
+ processes\r
+In-Reply-To: <87li782yy6.fsf@qmul.ac.uk>\r
+References: <1368851472-5382-1-git-send-email-amdragon@mit.edu>\r
+ <1368851472-5382-3-git-send-email-amdragon@mit.edu>\r
+ <87li782yy6.fsf@qmul.ac.uk>\r
+User-Agent: Notmuch/0.15.2+115~g12cf6af (http://notmuchmail.org) Emacs/24.3.1\r
+ (x86_64-unknown-linux-gnu)\r
+X-Face: HhBM'cA~<r"^Xv\KRN0P{vn'Y"Kd;zg_y3S[4)KSN~s?O\"QPoL\r
+ $[Xv_BD:i/F$WiEWax}R(MPS`^UaptOGD`*/=@\1lKoVa9tnrg0TW?"r7aRtgk[F\r
+ !)g;OY^,BjTbr)Np:%c_o'jj,Z\r
+Date: Tue, 21 May 2013 21:44:12 +0300\r
+Message-ID: <m2txlwkwar.fsf@guru.guru-group.fi>\r
+MIME-Version: 1.0\r
+Content-Type: text/plain; charset=utf-8\r
+Content-Transfer-Encoding: quoted-printable\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: Tue, 21 May 2013 18:44:22 -0000\r
+\r
+On Tue, May 21 2013, Mark Walters <markwalters1009@gmail.com> wrote:\r
+\r
+> Hi\r
+>\r
+> I am working my way through this set.=20\r
+>\r
+> On Sat, 18 May 2013, Austin Clements <amdragon@MIT.EDU> wrote:\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 | 73 +++++++++++++++++++++++++++++++++++++++++++=\r
+++++---\r
+>> 1 file changed, 69 insertions(+), 4 deletions(-)\r
+>>\r
+>> diff --git a/emacs/notmuch-lib.el b/emacs/notmuch-lib.el\r
+>> index 59b1ce3..a543471 100644\r
+>> --- a/emacs/notmuch-lib.el\r
+>> +++ b/emacs/notmuch-lib.el\r
+>> @@ -383,18 +383,21 @@ signaled error. This function does not return."\r
+>> (error "%s" (concat msg (when extra\r
+>> " (see *Notmuch errors* for more details)"))))\r
+>>=20=20\r
+>> -(defun notmuch-check-async-exit-status (proc msg)\r
+>> +(defun notmuch-check-async-exit-status (proc msg &optional command err-=\r
+file)\r
+>> "If PROC exited abnormally, pop up an error buffer and signal an erro=\r
+r.\r
+>>=20=20\r
+>> This is a wrapper around `notmuch-check-exit-status' for\r
+>> asynchronous process sentinels. PROC and MSG must be the\r
+>> -arguments passed to the sentinel."\r
+>> +arguments passed to the sentinel. COMMAND and ERR-FILE, if\r
+>> +provided, are passed to `notmuch-check-exit-status'. If COMMAND\r
+>> +is not provided, it is taken from `process-command'."\r
+>> (let ((exit-status\r
+>> (case (process-status proc)\r
+>> ((exit) (process-exit-status proc))\r
+>> ((signal) msg))))\r
+>> (when exit-status\r
+>> - (notmuch-check-exit-status exit-status (process-command proc)))))\r
+>> + (notmuch-check-exit-status exit-status (or command (process-comma=\r
+nd proc))\r
+>> + nil err-file))))\r
+>>=20=20\r
+>> (defun notmuch-check-exit-status (exit-status command &optional output =\r
+err-file)\r
+>> "If EXIT-STATUS is non-zero, pop up an error buffer and signal an err=\r
+or.\r
+>> @@ -448,7 +451,7 @@ You may need to restart Emacs or upgrade your notmuc=\r
+h package."))\r
+>> ))))\r
+>>=20=20\r
+>> (defun notmuch-call-notmuch-json (&rest args)\r
+>> - "Invoke `notmuch-command' with `args' and return the parsed JSON outp=\r
+ut.\r
+>> + "Invoke `notmuch-command' with ARGS and return the parsed JSON output.\r
+>>=20=20\r
+>> The returned output will represent objects using property lists\r
+>> and arrays as lists. If notmuch exits with a non-zero status,\r
+>\r
+> I think I would prefer that this patch is split here. The stuff above is\r
+> "obviously correct" and could go in independently of the rest.\r
+>=20=20\r
+>> @@ -469,6 +472,68 @@ an error."\r
+>> (json-read)))\r
+>> (delete-file err-file)))))\r
+>>=20=20\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
+>> + (proc (apply #'start-process name buffer\r
+>> + "sh" "-c"\r
+>> + "ERR=3D\"$1\"; shift; exec \"$0\" \"$@\" 2>\"$ERR\""\r
+>> + notmuch-command err-file args)))\r
+>\r
+> I would like some other people to look at this carefully as I won't spot\r
+> errors in quoting or shell side effects or whether PATH is the same as\r
+> emacs would use etc.\r
+\r
+The variable expansion for sell works as desired, but PATH question is\r
+interesting:\r
+\r
+I tried:\r
+\r
+setq exec-path (cons "/bii" exec-path))\r
+(shell-command "echo $PATH")\r
+\r
+and "/bii" was not in the head of the output the shell-command executed\r
+(which is interesting... found this text:\r
+\r
+ The value of =E2=80=9CPATH=E2=80=9D is used by emacs when you are runni=\r
+ng a shell in\r
+ emacs, similar to when you are using a shell in a terminal.\r
+\r
+ The exec-path is used by emacs itself to find programs it needs for its\r
+ features, such as spell checking, file compression, compiling, grep,\r
+ diff, etc.\r
+\r
+ (in http://ergoemacs.org/emacs/emacs_env_var_paths.htm )\r
+\r
+and then:\r
+\r
+ Generally, you should not modify exec-path directly. Instead, ensure that\r
+ your PATH environment variable is set appropriately before starting\r
+ Emacs. Trying to modify exec-path independently of PATH can lead to\r
+ confusing results.=20\r
+\r
+ (in http://www.gnu.org/software/emacs/manual/html_node/elisp/Subprocess-Cr=\r
+eation.html))\r
+\r
+... the --stderr option in the RFC patch I just sent=20\r
+( id:1369161750-12342-1-git-send-email-tomi.ollila@iki.fi ) could solve\r
+quite a few problems here :D\r
+\r
+Tomi\r
+\r