From: Austin Clements Date: Sat, 18 May 2013 04:31:10 +0000 (+2000) Subject: [PATCH 3/5] emacs: Use async process helper for search X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=f7088d4ce2eedcc7ee33160199b091f891297a22;p=notmuch-archives.git [PATCH 3/5] emacs: Use async process helper for search --- diff --git a/51/8837137eb7c033f65fda506923d32c46c43703 b/51/8837137eb7c033f65fda506923d32c46c43703 new file mode 100644 index 000000000..bc58b365b --- /dev/null +++ b/51/8837137eb7c033f65fda506923d32c46c43703 @@ -0,0 +1,193 @@ +Return-Path: +X-Original-To: notmuch@notmuchmail.org +Delivered-To: notmuch@notmuchmail.org +Received: from localhost (localhost [127.0.0.1]) + by olra.theworths.org (Postfix) with ESMTP id 54158431FC2 + for ; Fri, 17 May 2013 21:32:21 -0700 (PDT) +X-Virus-Scanned: Debian amavisd-new at olra.theworths.org +X-Spam-Flag: NO +X-Spam-Score: -0.7 +X-Spam-Level: +X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5 + tests=[RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled +Received: from olra.theworths.org ([127.0.0.1]) + by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) + with ESMTP id H5abnrBeF5kz for ; + Fri, 17 May 2013 21:32:15 -0700 (PDT) +Received: from dmz-mailsec-scanner-1.mit.edu (DMZ-MAILSEC-SCANNER-1.MIT.EDU + [18.9.25.12]) + by olra.theworths.org (Postfix) with ESMTP id EE3EA431FC9 + for ; Fri, 17 May 2013 21:32:14 -0700 (PDT) +X-AuditID: 1209190c-b7f566d000004c69-63-5197044e7391 +Received: from mailhub-auth-4.mit.edu ( [18.7.62.39]) + by dmz-mailsec-scanner-1.mit.edu (Symantec Messaging Gateway) with SMTP + id BE.94.19561.E4407915; Sat, 18 May 2013 00:32:14 -0400 (EDT) +Received: from outgoing.mit.edu (OUTGOING-AUTH-1.MIT.EDU [18.9.28.11]) + by mailhub-auth-4.mit.edu (8.13.8/8.9.2) with ESMTP id r4I4WCc1009843; + Sat, 18 May 2013 00:32:13 -0400 +Received: from drake.dyndns.org + (216-15-114-40.c3-0.arl-ubr1.sbo-arl.ma.cable.rcn.com + [216.15.114.40]) (authenticated bits=0) + (User authenticated as amdragon@ATHENA.MIT.EDU) + by outgoing.mit.edu (8.13.8/8.12.4) with ESMTP id r4I4WBLA018834 + (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT); + Sat, 18 May 2013 00:32:12 -0400 +Received: from amthrax by drake.dyndns.org with local (Exim 4.77) + (envelope-from ) + id 1UdYo1-0001Yy-KF; Sat, 18 May 2013 00:31:41 -0400 +From: Austin Clements +To: notmuch@notmuchmail.org +Subject: [PATCH 3/5] emacs: Use async process helper for search +Date: Sat, 18 May 2013 00:31:10 -0400 +Message-Id: <1368851472-5382-4-git-send-email-amdragon@mit.edu> +X-Mailer: git-send-email 1.7.10.4 +In-Reply-To: <1368851472-5382-1-git-send-email-amdragon@mit.edu> +References: <1368851472-5382-1-git-send-email-amdragon@mit.edu> +X-Brightmail-Tracker: + H4sIAAAAAAAAA+NgFtrDIsWRmVeSWpSXmKPExsUixG6nruvHMj3QYOZPOYvVc3ksrt+cyezA + 5LFz1l12j2erbjEHMEVx2aSk5mSWpRbp2yVwZdz9sZi9YLZyxYVvD1kbGG9LdzFyckgImEg8 + fP6LCcIWk7hwbz1bFyMXh5DAPkaJn99bGSGcjYwSd081MoNUCQncYZKYfiofIjGXUeJ2200W + kASbgIbEtv3LGUFsEQFpiZ13Z7OC2MwCjhKf9y9iA7GFBewlLp1uZAexWQRUJXo//gazeYHi + syb9Z4E4Q1Gi+9kEsHpOAQeJw/OPsUEstpfounCTbQIj/wJGhlWMsim5Vbq5iZk5xanJusXJ + iXl5qUW6hnq5mSV6qSmlmxhBgcQpybOD8c1BpUOMAhyMSjy8H1ynBQqxJpYVV+YeYpTkYFIS + 5TX5BxTiS8pPqcxILM6ILyrNSS0+xCjBwawkwvu8GCjHm5JYWZValA+TkuZgURLnvZxy019I + ID2xJDU7NbUgtQgmK8PBoSTBq8s8PVBIsCg1PbUiLTOnBCHNxMEJMpwHaLgVSA1vcUFibnFm + OkT+FKOilDivM0hCACSRUZoH1wuL9FeM4kCvCPNKg1TxAJMEXPcroMFMQINZr00FGVySiJCS + amBk7ggodC95N+dsXeJLvZcTbl0u7t0Vv7XbaLHQy7xnC6el2VpcMd5i+PO7sz2bwDK/B7vd + JfV+ZHz5e/9F6tcGudP2FlIaCSXfTlZcdljq3KPj3HFgLoddZkzBg34HwUTV+pen/y94p6T9 + hPPzzlVblR+fc39mw7F5glnoSfGq8h3ZK60kr95RYinOSDTUYi4qTgQAepkY8M8CAAA= +X-BeenThere: notmuch@notmuchmail.org +X-Mailman-Version: 2.1.13 +Precedence: list +List-Id: "Use and development of the notmuch mail system." + +List-Unsubscribe: , + +List-Archive: +List-Post: +List-Help: +List-Subscribe: , + +X-List-Received-Date: Sat, 18 May 2013 04:32:21 -0000 + +Previously, search started the async notmuch process directly. Now, +it uses `notmuch-start-notmuch'. This simplifies the process sentinel +a bit and means that we no longer have to worry about errors +interleaved with the JSON output. + +We also update the tests of Emacs error handling, since the error +output is now separated from the search results buffer. +--- + emacs/notmuch.el | 19 +++++-------------- + test/emacs | 36 ++++++++++++++++++++++++++++++++---- + 2 files changed, 37 insertions(+), 18 deletions(-) + +diff --git a/emacs/notmuch.el b/emacs/notmuch.el +index 4c1a6ca..b8d9c44 100644 +--- a/emacs/notmuch.el ++++ b/emacs/notmuch.el +@@ -653,15 +653,8 @@ of the result." + ;; For version mismatch, there's no point in + ;; showing the search buffer + (when (or (= exit-status 20) (= exit-status 21)) +- (kill-buffer)) +- (condition-case err +- (notmuch-check-async-exit-status proc msg) +- ;; Suppress the error signal since strange +- ;; things happen if a sentinel signals. Mimic +- ;; the top-level's handling of error messages. +- (error +- (message "%s" (error-message-string err)) +- (throw 'return nil))) ++ (kill-buffer) ++ (throw 'return nil)) + (if (and atbob + (not (string= notmuch-search-target-thread "found"))) + (set 'never-found-target-thread t))))) +@@ -938,10 +931,9 @@ Other optional parameters are used as follows: + (erase-buffer) + (goto-char (point-min)) + (save-excursion +- (let ((proc (start-process +- "notmuch-search" buffer +- notmuch-command "search" +- "--format=json" "--format-version=1" ++ (let ((proc (notmuch-start-notmuch ++ "notmuch-search" buffer #'notmuch-search-process-sentinel ++ "search" "--format=json" "--format-version=1" + (if oldest-first + "--sort=oldest-first" + "--sort=newest-first") +@@ -951,7 +943,6 @@ Other optional parameters are used as follows: + ;; should be called no matter how the process dies. + (parse-buf (generate-new-buffer " *notmuch search parse*"))) + (process-put proc 'parse-buf parse-buf) +- (set-process-sentinel proc 'notmuch-search-process-sentinel) + (set-process-filter proc 'notmuch-search-process-filter) + (set-process-query-on-exit-flag proc nil)))) + (run-hooks 'notmuch-search-hook))) +diff --git a/test/emacs b/test/emacs +index f033bdf..d38ae8c 100755 +--- a/test/emacs ++++ b/test/emacs +@@ -853,11 +853,10 @@ test_expect_success "Rendering HTML mail with images" \ + 'cat OUTPUT && grep -q smiley OUTPUT' + + +-test_begin_subtest "Search handles subprocess errors" ++test_begin_subtest "Search handles subprocess error exit codes" + cat > notmuch_fail <&2 + exit 1 + EOF + chmod a+x notmuch_fail +@@ -874,8 +873,6 @@ sed -i -e 's/^\[.*\]$/[XXX]/' ERROR + test_expect_equal "$(cat OUTPUT; echo ---; cat MESSAGES; echo ---; cat ERROR)" "\ + Error: Unexpected output from notmuch search: + This is output +-Error: Unexpected output from notmuch search: +-This is an error + End of search results. + --- + $PWD/notmuch_fail exited with status 1 (see *Notmuch errors* for more details) +@@ -885,4 +882,35 @@ $PWD/notmuch_fail exited with status 1 + command: $PWD/notmuch_fail search --format\=json --format-version\=1 --sort\=newest-first tag\:inbox + exit status: 1" + ++test_begin_subtest "Search handles subprocess warnings" ++cat > notmuch_fail <&2 ++echo This is another warning >&2 ++exit 0 ++EOF ++chmod a+x notmuch_fail ++test_emacs "(let ((notmuch-command \"$PWD/notmuch_fail\")) ++ (with-current-buffer \"*Messages*\" (erase-buffer)) ++ (with-current-buffer \"*Notmuch errors*\" (erase-buffer)) ++ (notmuch-search \"tag:inbox\") ++ (notmuch-test-wait) ++ (with-current-buffer \"*Messages*\" ++ (test-output \"MESSAGES\")) ++ (with-current-buffer \"*Notmuch errors*\" ++ (test-output \"ERROR\")) ++ (test-output))" ++sed -i -e 's/^\[.*\]$/[XXX]/' ERROR ++test_expect_equal "$(cat OUTPUT; echo ---; cat MESSAGES; echo ---; cat ERROR)" "\ ++Error: Unexpected output from notmuch search: ++This is output ++End of search results. ++--- ++This is a warning (see *Notmuch errors* for more details) ++--- ++[XXX] ++This is a warning ++This is another warning" ++ + test_done +-- +1.7.10.4 +