From b28afdfd75c9da613f0d6725db2d2916f1d619ff Mon Sep 17 00:00:00 2001 From: Austin Clements Date: Sun, 19 May 2013 16:13:57 +2000 Subject: [PATCH] Re: [PATCH 3/5] emacs: Use async process helper for search --- 8c/664b11e93106fb87793fdb20d61667fed3841c | 226 ++++++++++++++++++++++ 1 file changed, 226 insertions(+) create mode 100644 8c/664b11e93106fb87793fdb20d61667fed3841c diff --git a/8c/664b11e93106fb87793fdb20d61667fed3841c b/8c/664b11e93106fb87793fdb20d61667fed3841c new file mode 100644 index 000000000..d46453310 --- /dev/null +++ b/8c/664b11e93106fb87793fdb20d61667fed3841c @@ -0,0 +1,226 @@ +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 F3069431FC9 + for ; Sat, 18 May 2013 13:14:14 -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 jbNE9OOKbllV for ; + Sat, 18 May 2013 13:14:04 -0700 (PDT) +Received: from dmz-mailsec-scanner-4.mit.edu (DMZ-MAILSEC-SCANNER-4.MIT.EDU + [18.9.25.15]) + by olra.theworths.org (Postfix) with ESMTP id 598D2431FC2 + for ; Sat, 18 May 2013 13:14:03 -0700 (PDT) +X-AuditID: 1209190f-b7f256d000005616-cd-5197e1095c86 +Received: from mailhub-auth-4.mit.edu ( [18.7.62.39]) + by dmz-mailsec-scanner-4.mit.edu (Symantec Messaging Gateway) with SMTP + id AB.E5.22038.901E7915; Sat, 18 May 2013 16:14:01 -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 r4IKDxqS006974; + Sat, 18 May 2013 16:14:00 -0400 +Received: from awakening.csail.mit.edu (awakening.csail.mit.edu [18.26.4.91]) + (authenticated bits=0) + (User authenticated as amdragon@ATHENA.MIT.EDU) + by outgoing.mit.edu (8.13.8/8.12.4) with ESMTP id r4IKDvPK021199 + (version=TLSv1/SSLv3 cipher=DHE-RSA-AES128-SHA bits=128 verify=NOT); + Sat, 18 May 2013 16:13:58 -0400 +Received: from amthrax by awakening.csail.mit.edu with local (Exim 4.80) + (envelope-from ) + id 1UdnVt-0002qF-4P; Sat, 18 May 2013 16:13:57 -0400 +Date: Sat, 18 May 2013 16:13:57 -0400 +From: Austin Clements +To: Mark Walters +Subject: Re: [PATCH 3/5] emacs: Use async process helper for search +Message-ID: <20130518201356.GC5999@mit.edu> +References: <1368851472-5382-1-git-send-email-amdragon@mit.edu> + <1368851472-5382-4-git-send-email-amdragon@mit.edu> + <87d2sopxnm.fsf@qmul.ac.uk> +MIME-Version: 1.0 +Content-Type: text/plain; charset=us-ascii +Content-Disposition: inline +In-Reply-To: <87d2sopxnm.fsf@qmul.ac.uk> +User-Agent: Mutt/1.5.21 (2010-09-15) +X-Brightmail-Tracker: + H4sIAAAAAAAAA+NgFmpmleLIzCtJLcpLzFFi42IRYrdT1+V8OD3Q4EcXh8XquTwW12/OZHZg + 8tg56y67x7NVt5gDmKK4bFJSczLLUov07RK4Mha93MNc0K9XMX2xZQPjVOUuRk4OCQETiclf + X7JB2GISF+6tB7K5OIQE9jFKPN38mwnC2cgoceTvFVYI5zSTxOGmP1CZJYwSm7vXsoD0swio + Skxc/54VxGYT0JDYtn85I4gtIqAjcfvQAnYQm1lAWuLb72YmEFtYwFmiZcJ8sBpeAW2J7qkL + oDZMZpR49fY2M0RCUOLkzCcsEM1aEjf+vQRq5gAbtPwfB0iYE2jXmuc/wH4QFVCRmHJyG9sE + RqFZSLpnIemehdC9gJF5FaNsSm6Vbm5iZk5xarJucXJiXl5qka6JXm5miV5qSukmRlBYc0ry + 72D8dlDpEKMAB6MSD+9H12mBQqyJZcWVuYcYJTmYlER5m25PDxTiS8pPqcxILM6ILyrNSS0+ + xCjBwawkwtsaBpTjTUmsrEotyodJSXOwKInzXk256S8kkJ5YkpqdmlqQWgSTleHgUJLgtXsA + 1ChYlJqeWpGWmVOCkGbi4AQZzgM0PAmkhre4IDG3ODMdIn+KUVFKnDcAJCEAksgozYPrhaWd + V4ziQK8I88aAVPEAUxZc9yugwUxAg1mvTQUZXJKIkJJqYOTv/+yw2bvv2tzKWx9Lmraw1Uwx + Yi053+q42n6rpkjCaY/Hy9keRWX/OhD30bGiNLIgT6k3/cYldpVpeqHTuabyhicp/4x94vta + aufa5y67Z0y5mlGt5uX0eVdYRcftg9fLtIKnP0m93VdUvdn82eG9d7asFDe50bX5xNFE9TaO + +CaH+xJJL5VYijMSDbWYi4oTAX5jlRMWAwAA +Cc: notmuch@notmuchmail.org +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 20:14:15 -0000 + +Quoth Mark Walters on May 18 at 8:14 am: +> +> I have only very briefly looked at this: it seems to not quite apply to +> master (one fix up see below) +> +> Also, as far as I can see condition-case-unless-debug (used in patch +> 2/5) is emacs 24 only. + +Indeed. I'll just use condition-case in v2 (unless we want to +introduce a compatibility macro). + +I really wish the Emacs documentation included what version functions +were introduced in. I couldn't even *find* a copy of the non-latest +documentation; I wound up downloading a tarball of Emacs 23 and +building the documentation myself. + +> Best wishes +> +> Mark +> +> On Sat, 18 May 2013, Austin Clements wrote: +> > 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)) +> +> This line is +> (message "%s" (second err)) +> in master. + +Sorry, I thought these patches were independent from the ones I'd sent +earlier, but obviously not. It should apply now that David has +applied the other patch. + +> > - (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 < > #!/bin/sh +> > echo This is output +> > -echo This is an error >&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 < > +#!/bin/sh +> > +echo This is output +> > +echo This is a warning >&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 -- 2.26.2