--- /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 2F5A4429E40\r
+ for <notmuch@notmuchmail.org>; Fri, 31 May 2013 17:40:30 -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 du3bUaL87RbX for <notmuch@notmuchmail.org>;\r
+ Fri, 31 May 2013 17:40:23 -0700 (PDT)\r
+Received: from dmz-mailsec-scanner-8.mit.edu (dmz-mailsec-scanner-8.mit.edu\r
+ [18.7.68.37])\r
+ by olra.theworths.org (Postfix) with ESMTP id 47DF4429E27\r
+ for <notmuch@notmuchmail.org>; Fri, 31 May 2013 17:40:17 -0700 (PDT)\r
+X-AuditID: 12074425-b7f986d00000082c-e9-51a942ee8c97\r
+Received: from mailhub-auth-1.mit.edu ( [18.9.21.35])\r
+ by dmz-mailsec-scanner-8.mit.edu (Symantec Messaging Gateway) with SMTP\r
+ id D4.F3.02092.EE249A15; Fri, 31 May 2013 20:40:14 -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 r510eDCU008172; \r
+ Fri, 31 May 2013 20:40:13 -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 r510eAIl020943\r
+ (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT);\r
+ Fri, 31 May 2013 20:40:12 -0400\r
+Received: from amthrax by drake.dyndns.org with local (Exim 4.77)\r
+ (envelope-from <amdragon@mit.edu>)\r
+ id 1UiZrd-0003QT-FN; Fri, 31 May 2013 20:40:09 -0400\r
+From: Austin Clements <amdragon@MIT.EDU>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH v3 3/6] emacs: Use async process helper for search\r
+Date: Fri, 31 May 2013 20:40:05 -0400\r
+Message-Id: <1370047208-12785-4-git-send-email-amdragon@mit.edu>\r
+X-Mailer: git-send-email 1.7.10.4\r
+In-Reply-To: <1370047208-12785-1-git-send-email-amdragon@mit.edu>\r
+References: <1370047208-12785-1-git-send-email-amdragon@mit.edu>\r
+X-Brightmail-Tracker:\r
+ H4sIAAAAAAAAA+NgFjrGIsWRmVeSWpSXmKPExsUixCmqrPvOaWWgwfEX1har5/JYXL85k9ni\r
+ zcp5rA7MHjtn3WX3OPx1IYvHs1W3mAOYo7hsUlJzMstSi/TtErgy7v5YzF4wW7niwreHrA2M\r
+ t6W7GDk5JARMJL5+7mKHsMUkLtxbz9bFyMUhJLCPUeLPtCdgCSGBjYwSr2Y4QCROM0ksuviJ\r
+ CcKZyyhxYvMXJpAqNgENiW37lzOC2CIC0hI7785mBbGZBeIktkz5DxYXFnCSuLBvIjOIzSKg\r
+ KnGquwXM5hVwkHg0ZTorxBmKEt3PJrCB2JwCjhLnr/5jhrjCQeLxiZPMExj5FzAyrGKUTcmt\r
+ 0s1NzMwpTk3WLU5OzMtLLdK10MvNLNFLTSndxAgKLnYX1R2MEw4pHWIU4GBU4uE1WLEiUIg1\r
+ say4MvcQoyQHk5Io72zHlYFCfEn5KZUZicUZ8UWlOanFhxglOJiVRHjz5wCV86YkVlalFuXD\r
+ pKQ5WJTEeW+k3PQXEkhPLEnNTk0tSC2CycpwcChJ8L4EGSpYlJqeWpGWmVOCkGbi4AQZzgM0\r
+ /BxIDW9xQWJucWY6RP4Uo6KUOC8/MH6FBEASGaV5cL2w6H/FKA70ijDvBZB2HmDigOt+BTSY\r
+ CWjwE+vlIINLEhFSUg2MzoJHK5TtNb88WJkzY8fduVyaKXtWJIjuYFqQkMfnNjFSboOWpd2B\r
+ 6mmWDv0umy++WHz7uHe71w+bgldMtcvZC26yi7BeP3lv+r47Xabvf6Ru7VZ9/sT1zKLJqdMf\r
+ bQi03bmpb8nLwF0VCxP93rUmuZje2212tSetPaCtS9WeKW3RwwWZ6YcVlViKMxINtZiLihMB\r
+ ZQWsL9kCAAA=\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: Sat, 01 Jun 2013 00:40:30 -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