From: Austin Clements Date: Sat, 1 Jun 2013 00:40:05 +0000 (+2000) Subject: [PATCH v3 3/6] emacs: Use async process helper for search X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=587c0c20648dd0512c7a73afbc32303599d6d7ac;p=notmuch-archives.git [PATCH v3 3/6] emacs: Use async process helper for search --- diff --git a/a8/445bc22d263fda9bdb60d28d775655516df88f b/a8/445bc22d263fda9bdb60d28d775655516df88f new file mode 100644 index 000000000..70fa53310 --- /dev/null +++ b/a8/445bc22d263fda9bdb60d28d775655516df88f @@ -0,0 +1,194 @@ +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 2F5A4429E40 + for ; Fri, 31 May 2013 17:40:30 -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 du3bUaL87RbX for ; + Fri, 31 May 2013 17:40:23 -0700 (PDT) +Received: from dmz-mailsec-scanner-8.mit.edu (dmz-mailsec-scanner-8.mit.edu + [18.7.68.37]) + by olra.theworths.org (Postfix) with ESMTP id 47DF4429E27 + for ; Fri, 31 May 2013 17:40:17 -0700 (PDT) +X-AuditID: 12074425-b7f986d00000082c-e9-51a942ee8c97 +Received: from mailhub-auth-1.mit.edu ( [18.9.21.35]) + by dmz-mailsec-scanner-8.mit.edu (Symantec Messaging Gateway) with SMTP + id D4.F3.02092.EE249A15; Fri, 31 May 2013 20:40:14 -0400 (EDT) +Received: from outgoing.mit.edu (outgoing-auth-1.mit.edu [18.9.28.11]) + by mailhub-auth-1.mit.edu (8.13.8/8.9.2) with ESMTP id r510eDCU008172; + Fri, 31 May 2013 20:40:13 -0400 +Received: from drake.dyndns.org (c-76-21-105-205.hsd1.ca.comcast.net + [76.21.105.205]) (authenticated bits=0) + (User authenticated as amdragon@ATHENA.MIT.EDU) + by outgoing.mit.edu (8.13.8/8.12.4) with ESMTP id r510eAIl020943 + (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT); + Fri, 31 May 2013 20:40:12 -0400 +Received: from amthrax by drake.dyndns.org with local (Exim 4.77) + (envelope-from ) + id 1UiZrd-0003QT-FN; Fri, 31 May 2013 20:40:09 -0400 +From: Austin Clements +To: notmuch@notmuchmail.org +Subject: [PATCH v3 3/6] emacs: Use async process helper for search +Date: Fri, 31 May 2013 20:40:05 -0400 +Message-Id: <1370047208-12785-4-git-send-email-amdragon@mit.edu> +X-Mailer: git-send-email 1.7.10.4 +In-Reply-To: <1370047208-12785-1-git-send-email-amdragon@mit.edu> +References: <1370047208-12785-1-git-send-email-amdragon@mit.edu> +X-Brightmail-Tracker: + H4sIAAAAAAAAA+NgFjrGIsWRmVeSWpSXmKPExsUixCmqrPvOaWWgwfEX1har5/JYXL85k9ni + zcp5rA7MHjtn3WX3OPx1IYvHs1W3mAOYo7hsUlJzMstSi/TtErgy7v5YzF4wW7niwreHrA2M + t6W7GDk5JARMJL5+7mKHsMUkLtxbz9bFyMUhJLCPUeLPtCdgCSGBjYwSr2Y4QCROM0ksuviJ + CcKZyyhxYvMXJpAqNgENiW37lzOC2CIC0hI7785mBbGZBeIktkz5DxYXFnCSuLBvIjOIzSKg + KnGquwXM5hVwkHg0ZTorxBmKEt3PJrCB2JwCjhLnr/5jhrjCQeLxiZPMExj5FzAyrGKUTcmt + 0s1NzMwpTk3WLU5OzMtLLdK10MvNLNFLTSndxAgKLnYX1R2MEw4pHWIU4GBU4uE1WLEiUIg1 + say4MvcQoyQHk5Io72zHlYFCfEn5KZUZicUZ8UWlOanFhxglOJiVRHjz5wCV86YkVlalFuXD + pKQ5WJTEeW+k3PQXEkhPLEnNTk0tSC2CycpwcChJ8L4EGSpYlJqeWpGWmVOCkGbi4AQZzgM0 + /BxIDW9xQWJucWY6RP4Uo6KUOC8/MH6FBEASGaV5cL2w6H/FKA70ijDvBZB2HmDigOt+BTSY + CWjwE+vlIINLEhFSUg2MzoJHK5TtNb88WJkzY8fduVyaKXtWJIjuYFqQkMfnNjFSboOWpd2B + 6mmWDv0umy++WHz7uHe71w+bgldMtcvZC26yi7BeP3lv+r47Xabvf6Ru7VZ9/sT1zKLJqdMf + bQi03bmpb8nLwF0VCxP93rUmuZje2212tSetPaCtS9WeKW3RwwWZ6YcVlViKMxINtZiLihMB + ZQWsL9kCAAA= +Cc: tomi.ollila@iki.fi +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, 01 Jun 2013 00:40:30 -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 +