--- /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 15AE2431FC3\r
+ for <notmuch@notmuchmail.org>; Thu, 30 May 2013 10:14:19 -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 576CL6XWLBfQ for <notmuch@notmuchmail.org>;\r
+ Thu, 30 May 2013 10:14:13 -0700 (PDT)\r
+Received: from dmz-mailsec-scanner-1.mit.edu (dmz-mailsec-scanner-1.mit.edu\r
+ [18.9.25.12])\r
+ by olra.theworths.org (Postfix) with ESMTP id 405B3431FD2\r
+ for <notmuch@notmuchmail.org>; Thu, 30 May 2013 10:13:56 -0700 (PDT)\r
+X-AuditID: 1209190c-b7f566d000004c69-af-51a788d2e626\r
+Received: from mailhub-auth-1.mit.edu ( [18.9.21.35])\r
+ by dmz-mailsec-scanner-1.mit.edu (Symantec Messaging Gateway) with SMTP\r
+ id 9E.95.19561.2D887A15; Thu, 30 May 2013 13:13:54 -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 r4UHDgfo027512; \r
+ Thu, 30 May 2013 13:13:43 -0400\r
+Received: from drake.dyndns.org (c-76-21-105-205.hsd1.ca.comcast.net\r
+ [76.21.105.205]) (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 r4UHDcFC009861\r
+ (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT);\r
+ Thu, 30 May 2013 13:13:41 -0400\r
+Received: from amthrax by drake.dyndns.org with local (Exim 4.77)\r
+ (envelope-from <amdragon@mit.edu>)\r
+ id 1Ui6Py-0005r4-C1; Thu, 30 May 2013 13:13:38 -0400\r
+From: Austin Clements <amdragon@MIT.EDU>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH v2 3/5] emacs: Use async process helper for search\r
+Date: Thu, 30 May 2013 13:13:34 -0400\r
+Message-Id: <1369934016-22308-4-git-send-email-amdragon@mit.edu>\r
+X-Mailer: git-send-email 1.7.10.4\r
+In-Reply-To: <1369934016-22308-1-git-send-email-amdragon@mit.edu>\r
+References: <1369934016-22308-1-git-send-email-amdragon@mit.edu>\r
+X-Brightmail-Tracker:\r
+ H4sIAAAAAAAAA+NgFjrOIsWRmVeSWpSXmKPExsUixCmqrHupY3mgQfNnWYvVc3ksrt+cyWzx\r
+ ZuU8Vgdmj52z7rJ7HP66kMXj2apbzAHMUVw2Kak5mWWpRfp2CVwZd38sZi+YrVxx4dtD1gbG\r
+ 29JdjJwcEgImEvemXmeDsMUkLtxbD2RzcQgJ7GOU2PHkPguEs5FRon3fDKjMaSaJCZNOMUE4\r
+ cxkllj6fxQ7SzyagIbFt/3JGEFtEQFpi593ZrCA2s0CcxJYp/8HiwgJOEq/a/4PtYxFQlZh3\r
+ 7x8LiM0r4CBxZcYrZog7FCW6n00Aq+EUcJTYMfk02BwhoJpLe78yTWDkX8DIsIpRNiW3Sjc3\r
+ MTOnODVZtzg5MS8vtUjXUC83s0QvNaV0EyM4vCR5djC+Oah0iFGAg1GJhzcjaXmgEGtiWXFl\r
+ 7iFGSQ4mJVHe9a1AIb6k/JTKjMTijPii0pzU4kOMEhzMSiK8Bc5AOd6UxMqq1KJ8mJQ0B4uS\r
+ OO/llJv+QgLpiSWp2ampBalFMFkZDg4lCd7r7UCNgkWp6akVaZk5JQhpJg5OkOE8QMMvgNTw\r
+ Fhck5hZnpkPkTzEqSonzrgVJCIAkMkrz4Hph8f+KURzoFWHelSBVPMDUAdf9CmgwE9DgJ9Zg\r
+ g0sSEVJSDYyCdnzJfEp119QyG65PZ/NmZFl+KmLaxTN/ggv+7/q8TJqd9cn59qbzfx0Vnx7c\r
+ E6GzzKD08/+WSQV6Cw//d3Wy73z4/LqSW5zuGS7p6PBpe9Njor9YTEoVNlfeJXy8fdfbfyv4\r
+ +1I+GMxlKv5szdnFvkfl8M4tyxSmT3smGFh3MbJwA/enanUlluKMREMt5qLiRAAB3a2C2gIA AA==\r
+Cc: tomi.ollila@iki.fi\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: Thu, 30 May 2013 17:14:19 -0000\r
+\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
+- (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
+-- \r
+1.7.10.4\r
+\r