[PATCH 3/5] emacs: Use async process helper for search
authorAustin Clements <amdragon@MIT.EDU>
Sat, 18 May 2013 04:31:10 +0000 (00:31 +2000)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:54:48 +0000 (09:54 -0800)
51/8837137eb7c033f65fda506923d32c46c43703 [new file with mode: 0644]

diff --git a/51/8837137eb7c033f65fda506923d32c46c43703 b/51/8837137eb7c033f65fda506923d32c46c43703
new file mode 100644 (file)
index 0000000..bc58b36
--- /dev/null
@@ -0,0 +1,193 @@
+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 54158431FC2\r
+       for <notmuch@notmuchmail.org>; Fri, 17 May 2013 21:32:21 -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 H5abnrBeF5kz for <notmuch@notmuchmail.org>;\r
+       Fri, 17 May 2013 21:32:15 -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 EE3EA431FC9\r
+       for <notmuch@notmuchmail.org>; Fri, 17 May 2013 21:32:14 -0700 (PDT)\r
+X-AuditID: 1209190c-b7f566d000004c69-63-5197044e7391\r
+Received: from mailhub-auth-4.mit.edu ( [18.7.62.39])\r
+       by dmz-mailsec-scanner-1.mit.edu (Symantec Messaging Gateway) with SMTP\r
+       id BE.94.19561.E4407915; Sat, 18 May 2013 00:32:14 -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 r4I4WCc1009843; \r
+       Sat, 18 May 2013 00:32:13 -0400\r
+Received: from drake.dyndns.org\r
+       (216-15-114-40.c3-0.arl-ubr1.sbo-arl.ma.cable.rcn.com\r
+       [216.15.114.40]) (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 r4I4WBLA018834\r
+       (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT);\r
+       Sat, 18 May 2013 00:32:12 -0400\r
+Received: from amthrax by drake.dyndns.org with local (Exim 4.77)\r
+       (envelope-from <amdragon@mit.edu>)\r
+       id 1UdYo1-0001Yy-KF; Sat, 18 May 2013 00:31:41 -0400\r
+From: Austin Clements <amdragon@MIT.EDU>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH 3/5] emacs: Use async process helper for search\r
+Date: Sat, 18 May 2013 00:31:10 -0400\r
+Message-Id: <1368851472-5382-4-git-send-email-amdragon@mit.edu>\r
+X-Mailer: git-send-email 1.7.10.4\r
+In-Reply-To: <1368851472-5382-1-git-send-email-amdragon@mit.edu>\r
+References: <1368851472-5382-1-git-send-email-amdragon@mit.edu>\r
+X-Brightmail-Tracker:\r
+ H4sIAAAAAAAAA+NgFtrDIsWRmVeSWpSXmKPExsUixG6nruvHMj3QYOZPOYvVc3ksrt+cyezA\r
+       5LFz1l12j2erbjEHMEVx2aSk5mSWpRbp2yVwZdz9sZi9YLZyxYVvD1kbGG9LdzFyckgImEg8\r
+       fP6LCcIWk7hwbz1bFyMXh5DAPkaJn99bGSGcjYwSd081MoNUCQncYZKYfiofIjGXUeJ2200W\r
+       kASbgIbEtv3LGUFsEQFpiZ13Z7OC2MwCjhKf9y9iA7GFBewlLp1uZAexWQRUJXo//gazeYHi\r
+       syb9Z4E4Q1Gi+9kEsHpOAQeJw/OPsUEstpfounCTbQIj/wJGhlWMsim5Vbq5iZk5xanJusXJ\r
+       iXl5qUW6hnq5mSV6qSmlmxhBgcQpybOD8c1BpUOMAhyMSjy8H1ynBQqxJpYVV+YeYpTkYFIS\r
+       5TX5BxTiS8pPqcxILM6ILyrNSS0+xCjBwawkwvu8GCjHm5JYWZValA+TkuZgURLnvZxy019I\r
+       ID2xJDU7NbUgtQgmK8PBoSTBq8s8PVBIsCg1PbUiLTOnBCHNxMEJMpwHaLgVSA1vcUFibnFm\r
+       OkT+FKOilDivM0hCACSRUZoH1wuL9FeM4kCvCPNKg1TxAJMEXPcroMFMQINZr00FGVySiJCS\r
+       amBk7ggodC95N+dsXeJLvZcTbl0u7t0Vv7XbaLHQy7xnC6el2VpcMd5i+PO7sz2bwDK/B7vd\r
+       JfV+ZHz5e/9F6tcGudP2FlIaCSXfTlZcdljq3KPj3HFgLoddZkzBg34HwUTV+pen/y94p6T9\r
+       hPPzzlVblR+fc39mw7F5glnoSfGq8h3ZK60kr95RYinOSDTUYi4qTgQAepkY8M8CAAA=\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 04:32:21 -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