From cff04abb237e3fafc8fa1d8069b23b291903b207 Mon Sep 17 00:00:00 2001 From: Austin Clements Date: Fri, 31 May 2013 13:13:34 +2000 Subject: [PATCH] [PATCH v2 3/5] emacs: Use async process helper for search --- 6a/66b7b6684248b72673bf50685cf0a66c15c26f | 193 ++++++++++++++++++++++ 1 file changed, 193 insertions(+) create mode 100644 6a/66b7b6684248b72673bf50685cf0a66c15c26f diff --git a/6a/66b7b6684248b72673bf50685cf0a66c15c26f b/6a/66b7b6684248b72673bf50685cf0a66c15c26f new file mode 100644 index 000000000..e7c88b7de --- /dev/null +++ b/6a/66b7b6684248b72673bf50685cf0a66c15c26f @@ -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 15AE2431FC3 + for ; Thu, 30 May 2013 10:14:19 -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 576CL6XWLBfQ for ; + Thu, 30 May 2013 10:14:13 -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 405B3431FD2 + for ; Thu, 30 May 2013 10:13:56 -0700 (PDT) +X-AuditID: 1209190c-b7f566d000004c69-af-51a788d2e626 +Received: from mailhub-auth-1.mit.edu ( [18.9.21.35]) + by dmz-mailsec-scanner-1.mit.edu (Symantec Messaging Gateway) with SMTP + id 9E.95.19561.2D887A15; Thu, 30 May 2013 13:13:54 -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 r4UHDgfo027512; + Thu, 30 May 2013 13:13:43 -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 r4UHDcFC009861 + (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT); + Thu, 30 May 2013 13:13:41 -0400 +Received: from amthrax by drake.dyndns.org with local (Exim 4.77) + (envelope-from ) + id 1Ui6Py-0005r4-C1; Thu, 30 May 2013 13:13:38 -0400 +From: Austin Clements +To: notmuch@notmuchmail.org +Subject: [PATCH v2 3/5] emacs: Use async process helper for search +Date: Thu, 30 May 2013 13:13:34 -0400 +Message-Id: <1369934016-22308-4-git-send-email-amdragon@mit.edu> +X-Mailer: git-send-email 1.7.10.4 +In-Reply-To: <1369934016-22308-1-git-send-email-amdragon@mit.edu> +References: <1369934016-22308-1-git-send-email-amdragon@mit.edu> +X-Brightmail-Tracker: + H4sIAAAAAAAAA+NgFjrOIsWRmVeSWpSXmKPExsUixCmqrHupY3mgQfNnWYvVc3ksrt+cyWzx + ZuU8Vgdmj52z7rJ7HP66kMXj2apbzAHMUVw2Kak5mWWpRfp2CVwZd38sZi+YrVxx4dtD1gbG + 29JdjJwcEgImEvemXmeDsMUkLtxbD2RzcQgJ7GOU2PHkPguEs5FRon3fDKjMaSaJCZNOMUE4 + cxkllj6fxQ7SzyagIbFt/3JGEFtEQFpi593ZrCA2s0CcxJYp/8HiwgJOEq/a/4PtYxFQlZh3 + 7x8LiM0r4CBxZcYrZog7FCW6n00Aq+EUcJTYMfk02BwhoJpLe78yTWDkX8DIsIpRNiW3Sjc3 + MTOnODVZtzg5MS8vtUjXUC83s0QvNaV0EyM4vCR5djC+Oah0iFGAg1GJhzcjaXmgEGtiWXFl + 7iFGSQ4mJVHe9a1AIb6k/JTKjMTijPii0pzU4kOMEhzMSiK8Bc5AOd6UxMqq1KJ8mJQ0B4uS + OO/llJv+QgLpiSWp2ampBalFMFkZDg4lCd7r7UCNgkWp6akVaZk5JQhpJg5OkOE8QMMvgNTw + Fhck5hZnpkPkTzEqSonzrgVJCIAkMkrz4Hph8f+KURzoFWHelSBVPMDUAdf9CmgwE9DgJ9Zg + g0sSEVJSDYyCdnzJfEp119QyG65PZ/NmZFl+KmLaxTN/ggv+7/q8TJqd9cn59qbzfx0Vnx7c + E6GzzKD08/+WSQV6Cw//d3Wy73z4/LqSW5zuGS7p6PBpe9Njor9YTEoVNlfeJXy8fdfbfyv4 + +1I+GMxlKv5szdnFvkfl8M4tyxSmT3smGFh3MbJwA/enanUlluKMREMt5qLiRAAB3a2C2gIA AA== +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: Thu, 30 May 2013 17:14:19 -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 + -- 2.26.2