--- /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 F3069431FC9\r
+ for <notmuch@notmuchmail.org>; Sat, 18 May 2013 13:14:14 -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 jbNE9OOKbllV for <notmuch@notmuchmail.org>;\r
+ Sat, 18 May 2013 13:14:04 -0700 (PDT)\r
+Received: from dmz-mailsec-scanner-4.mit.edu (DMZ-MAILSEC-SCANNER-4.MIT.EDU\r
+ [18.9.25.15])\r
+ by olra.theworths.org (Postfix) with ESMTP id 598D2431FC2\r
+ for <notmuch@notmuchmail.org>; Sat, 18 May 2013 13:14:03 -0700 (PDT)\r
+X-AuditID: 1209190f-b7f256d000005616-cd-5197e1095c86\r
+Received: from mailhub-auth-4.mit.edu ( [18.7.62.39])\r
+ by dmz-mailsec-scanner-4.mit.edu (Symantec Messaging Gateway) with SMTP\r
+ id AB.E5.22038.901E7915; Sat, 18 May 2013 16:14:01 -0400 (EDT)\r
+Received: from outgoing.mit.edu (OUTGOING-AUTH-1.MIT.EDU [18.9.28.11])\r
+ by mailhub-auth-4.mit.edu (8.13.8/8.9.2) with ESMTP id r4IKDxqS006974; \r
+ Sat, 18 May 2013 16:14:00 -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 r4IKDvPK021199\r
+ (version=TLSv1/SSLv3 cipher=DHE-RSA-AES128-SHA bits=128 verify=NOT);\r
+ Sat, 18 May 2013 16:13:58 -0400\r
+Received: from amthrax by awakening.csail.mit.edu with local (Exim 4.80)\r
+ (envelope-from <amdragon@MIT.EDU>)\r
+ id 1UdnVt-0002qF-4P; Sat, 18 May 2013 16:13:57 -0400\r
+Date: Sat, 18 May 2013 16:13:57 -0400\r
+From: Austin Clements <amdragon@MIT.EDU>\r
+To: Mark Walters <markwalters1009@gmail.com>\r
+Subject: Re: [PATCH 3/5] emacs: Use async process helper for search\r
+Message-ID: <20130518201356.GC5999@mit.edu>\r
+References: <1368851472-5382-1-git-send-email-amdragon@mit.edu>\r
+ <1368851472-5382-4-git-send-email-amdragon@mit.edu>\r
+ <87d2sopxnm.fsf@qmul.ac.uk>\r
+MIME-Version: 1.0\r
+Content-Type: text/plain; charset=us-ascii\r
+Content-Disposition: inline\r
+In-Reply-To: <87d2sopxnm.fsf@qmul.ac.uk>\r
+User-Agent: Mutt/1.5.21 (2010-09-15)\r
+X-Brightmail-Tracker:\r
+ H4sIAAAAAAAAA+NgFmpmleLIzCtJLcpLzFFi42IRYrdT1+V8OD3Q4EcXh8XquTwW12/OZHZg\r
+ 8tg56y67x7NVt5gDmKK4bFJSczLLUov07RK4Mha93MNc0K9XMX2xZQPjVOUuRk4OCQETiclf\r
+ X7JB2GISF+6tB7K5OIQE9jFKPN38mwnC2cgoceTvFVYI5zSTxOGmP1CZJYwSm7vXsoD0swio\r
+ Skxc/54VxGYT0JDYtn85I4gtIqAjcfvQAnYQm1lAWuLb72YmEFtYwFmiZcJ8sBpeAW2J7qkL\r
+ oDZMZpR49fY2M0RCUOLkzCcsEM1aEjf+vQRq5gAbtPwfB0iYE2jXmuc/wH4QFVCRmHJyG9sE\r
+ RqFZSLpnIemehdC9gJF5FaNsSm6Vbm5iZk5xarJucXJiXl5qka6JXm5miV5qSukmRlBYc0ry\r
+ 72D8dlDpEKMAB6MSD+9H12mBQqyJZcWVuYcYJTmYlER5m25PDxTiS8pPqcxILM6ILyrNSS0+\r
+ xCjBwawkwtsaBpTjTUmsrEotyodJSXOwKInzXk256S8kkJ5YkpqdmlqQWgSTleHgUJLgtXsA\r
+ 1ChYlJqeWpGWmVOCkGbi4AQZzgM0PAmkhre4IDG3ODMdIn+KUVFKnDcAJCEAksgozYPrhaWd\r
+ V4ziQK8I88aAVPEAUxZc9yugwUxAg1mvTQUZXJKIkJJqYOTv/+yw2bvv2tzKWx9Lmraw1Uwx\r
+ Yi053+q42n6rpkjCaY/Hy9keRWX/OhD30bGiNLIgT6k3/cYldpVpeqHTuabyhicp/4x94vta\r
+ aufa5y67Z0y5mlGt5uX0eVdYRcftg9fLtIKnP0m93VdUvdn82eG9d7asFDe50bX5xNFE9TaO\r
+ +CaH+xJJL5VYijMSDbWYi4oTAX5jlRMWAwAA\r
+Cc: notmuch@notmuchmail.org\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, 18 May 2013 20:14:15 -0000\r
+\r
+Quoth Mark Walters on May 18 at 8:14 am:\r
+> \r
+> I have only very briefly looked at this: it seems to not quite apply to\r
+> master (one fix up see below)\r
+> \r
+> Also, as far as I can see condition-case-unless-debug (used in patch\r
+> 2/5) is emacs 24 only.\r
+\r
+Indeed. I'll just use condition-case in v2 (unless we want to\r
+introduce a compatibility macro).\r
+\r
+I really wish the Emacs documentation included what version functions\r
+were introduced in. I couldn't even *find* a copy of the non-latest\r
+documentation; I wound up downloading a tarball of Emacs 23 and\r
+building the documentation myself.\r
+\r
+> Best wishes\r
+> \r
+> Mark\r
+> \r
+> On Sat, 18 May 2013, Austin Clements <amdragon@MIT.EDU> wrote:\r
+> > Previously, search started the async notmuch process directly. Now,\r
+> > it uses `notmuch-start-notmuch'. This simplifies the process sentinel\r
+> > a bit and means that we no longer have to worry about errors\r
+> > interleaved with the JSON output.\r
+> >\r
+> > We also update the tests of Emacs error handling, since the error\r
+> > output is now separated from the search results buffer.\r
+> > ---\r
+> > emacs/notmuch.el | 19 +++++--------------\r
+> > test/emacs | 36 ++++++++++++++++++++++++++++++++----\r
+> > 2 files changed, 37 insertions(+), 18 deletions(-)\r
+> >\r
+> > diff --git a/emacs/notmuch.el b/emacs/notmuch.el\r
+> > index 4c1a6ca..b8d9c44 100644\r
+> > --- a/emacs/notmuch.el\r
+> > +++ b/emacs/notmuch.el\r
+> > @@ -653,15 +653,8 @@ of the result."\r
+> > ;; For version mismatch, there's no point in\r
+> > ;; showing the search buffer\r
+> > (when (or (= exit-status 20) (= exit-status 21))\r
+> > - (kill-buffer))\r
+> > - (condition-case err\r
+> > - (notmuch-check-async-exit-status proc msg)\r
+> > - ;; Suppress the error signal since strange\r
+> > - ;; things happen if a sentinel signals. Mimic\r
+> > - ;; the top-level's handling of error messages.\r
+> > - (error\r
+> > - (message "%s" (error-message-string err))\r
+> \r
+> This line is \r
+> (message "%s" (second err))\r
+> in master.\r
+\r
+Sorry, I thought these patches were independent from the ones I'd sent\r
+earlier, but obviously not. It should apply now that David has\r
+applied the other patch.\r
+\r
+> > - (throw 'return nil)))\r
+> > + (kill-buffer)\r
+> > + (throw 'return nil))\r
+> > (if (and atbob\r
+> > (not (string= notmuch-search-target-thread "found")))\r
+> > (set 'never-found-target-thread t)))))\r
+> > @@ -938,10 +931,9 @@ Other optional parameters are used as follows:\r
+> > (erase-buffer)\r
+> > (goto-char (point-min))\r
+> > (save-excursion\r
+> > - (let ((proc (start-process\r
+> > - "notmuch-search" buffer\r
+> > - notmuch-command "search"\r
+> > - "--format=json" "--format-version=1"\r
+> > + (let ((proc (notmuch-start-notmuch\r
+> > + "notmuch-search" buffer #'notmuch-search-process-sentinel\r
+> > + "search" "--format=json" "--format-version=1"\r
+> > (if oldest-first\r
+> > "--sort=oldest-first"\r
+> > "--sort=newest-first")\r
+> > @@ -951,7 +943,6 @@ Other optional parameters are used as follows:\r
+> > ;; should be called no matter how the process dies.\r
+> > (parse-buf (generate-new-buffer " *notmuch search parse*")))\r
+> > (process-put proc 'parse-buf parse-buf)\r
+> > - (set-process-sentinel proc 'notmuch-search-process-sentinel)\r
+> > (set-process-filter proc 'notmuch-search-process-filter)\r
+> > (set-process-query-on-exit-flag proc nil))))\r
+> > (run-hooks 'notmuch-search-hook)))\r
+> > diff --git a/test/emacs b/test/emacs\r
+> > index f033bdf..d38ae8c 100755\r
+> > --- a/test/emacs\r
+> > +++ b/test/emacs\r
+> > @@ -853,11 +853,10 @@ test_expect_success "Rendering HTML mail with images" \\r
+> > 'cat OUTPUT && grep -q smiley OUTPUT'\r
+> > \r
+> > \r
+> > -test_begin_subtest "Search handles subprocess errors"\r
+> > +test_begin_subtest "Search handles subprocess error exit codes"\r
+> > cat > notmuch_fail <<EOF\r
+> > #!/bin/sh\r
+> > echo This is output\r
+> > -echo This is an error >&2\r
+> > exit 1\r
+> > EOF\r
+> > chmod a+x notmuch_fail\r
+> > @@ -874,8 +873,6 @@ sed -i -e 's/^\[.*\]$/[XXX]/' ERROR\r
+> > test_expect_equal "$(cat OUTPUT; echo ---; cat MESSAGES; echo ---; cat ERROR)" "\\r
+> > Error: Unexpected output from notmuch search:\r
+> > This is output\r
+> > -Error: Unexpected output from notmuch search:\r
+> > -This is an error\r
+> > End of search results.\r
+> > ---\r
+> > $PWD/notmuch_fail exited with status 1 (see *Notmuch errors* for more details)\r
+> > @@ -885,4 +882,35 @@ $PWD/notmuch_fail exited with status 1\r
+> > command: $PWD/notmuch_fail search --format\=json --format-version\=1 --sort\=newest-first tag\:inbox\r
+> > exit status: 1"\r
+> > \r
+> > +test_begin_subtest "Search handles subprocess warnings"\r
+> > +cat > notmuch_fail <<EOF\r
+> > +#!/bin/sh\r
+> > +echo This is output\r
+> > +echo This is a warning >&2\r
+> > +echo This is another warning >&2\r
+> > +exit 0\r
+> > +EOF\r
+> > +chmod a+x notmuch_fail\r
+> > +test_emacs "(let ((notmuch-command \"$PWD/notmuch_fail\"))\r
+> > + (with-current-buffer \"*Messages*\" (erase-buffer))\r
+> > + (with-current-buffer \"*Notmuch errors*\" (erase-buffer))\r
+> > + (notmuch-search \"tag:inbox\")\r
+> > + (notmuch-test-wait)\r
+> > + (with-current-buffer \"*Messages*\"\r
+> > + (test-output \"MESSAGES\"))\r
+> > + (with-current-buffer \"*Notmuch errors*\"\r
+> > + (test-output \"ERROR\"))\r
+> > + (test-output))"\r
+> > +sed -i -e 's/^\[.*\]$/[XXX]/' ERROR\r
+> > +test_expect_equal "$(cat OUTPUT; echo ---; cat MESSAGES; echo ---; cat ERROR)" "\\r
+> > +Error: Unexpected output from notmuch search:\r
+> > +This is output\r
+> > +End of search results.\r
+> > +---\r
+> > +This is a warning (see *Notmuch errors* for more details)\r
+> > +---\r
+> > +[XXX]\r
+> > +This is a warning\r
+> > +This is another warning"\r
+> > +\r
+> > test_done\r