From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Sean Whitton Newsgroups: gmane.emacs.bugs Subject: bug#54603: 29.0.50; [PATCH] Eshell's external pipe module interferes with other argument parsing hooks Date: Fri, 01 Apr 2022 14:16:13 -0700 Message-ID: <87fsmwo676.fsf@melete.silentflame.com> References: <70677cd2-f741-16d1-b38f-c39b507cc95e@gmail.com> <871qyij7vx.fsf@melete.silentflame.com> <87bkxliy76.fsf@melete.silentflame.com> <87y20pbuwu.fsf@athena.silentflame.com> <8191b68d-975d-3f84-bb0b-501bdf2edf47@gmail.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="35745"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Emacs/29.0.50 (x86_64-pc-linux-gnu) To: Jim Porter , 54603@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Fri Apr 01 23:17:30 2022 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1naOe8-00092F-G4 for geb-bug-gnu-emacs@m.gmane-mx.org; Fri, 01 Apr 2022 23:17:30 +0200 Original-Received: from localhost ([::1]:57714 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1naOe6-0001yo-W0 for geb-bug-gnu-emacs@m.gmane-mx.org; Fri, 01 Apr 2022 17:17:27 -0400 Original-Received: from eggs.gnu.org ([209.51.188.92]:57570) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1naOdk-0001xn-2b for bug-gnu-emacs@gnu.org; Fri, 01 Apr 2022 17:17:04 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:49861) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1naOdh-0002EJ-Qg for bug-gnu-emacs@gnu.org; Fri, 01 Apr 2022 17:17:03 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1naOdh-0000O7-Mn for bug-gnu-emacs@gnu.org; Fri, 01 Apr 2022 17:17:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Sean Whitton Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 01 Apr 2022 21:17:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 54603 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 54603-submit@debbugs.gnu.org id=B54603.16488477981456 (code B ref 54603); Fri, 01 Apr 2022 21:17:01 +0000 Original-Received: (at 54603) by debbugs.gnu.org; 1 Apr 2022 21:16:38 +0000 Original-Received: from localhost ([127.0.0.1]:43758 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1naOd5-0000NB-Eg for submit@debbugs.gnu.org; Fri, 01 Apr 2022 17:16:38 -0400 Original-Received: from wout1-smtp.messagingengine.com ([64.147.123.24]:51039) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1naOd2-0000Mu-S7 for 54603@debbugs.gnu.org; Fri, 01 Apr 2022 17:16:21 -0400 Original-Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.west.internal (Postfix) with ESMTP id CC02B3200929; Fri, 1 Apr 2022 17:16:14 -0400 (EDT) Original-Received: from mailfrontend1 ([10.202.2.162]) by compute1.internal (MEProxy); Fri, 01 Apr 2022 17:16:15 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=spwhitton.name; h=cc:content-type:date:date:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:sender:subject :subject:to:to; s=fm3; bh=nYr5X5Fow23/+10/RSw5KaPae0UouyM2iAdzaC okgKU=; b=V26wHOBrXhfOrgC6ec6gEnHK8NO0X3jbxg8T/WpFc6yWC/V+8YZCH2 hbML2j0MTSRMXRM2J5eVFkfSEPOM7gnbBcczBqa0rkHUr5/Oa8sCeMh7zGNmk2VE dax3IpN1YLxzRl3MMbcaXeqsFtBpu6PcNB44Uv0zuGWCLRqN4AVVNn3mDrD6r6Ei 5AMRAygjz5utPlgxYTwh2ELayzJAU/60dsLMOBk9L8OuTfhsO3px/yEdPpwm++Oj cKFQ8yu9pkeb/shyfGPvUm+Zayet6nV/cIOc3iopMcTNXMcLRa2bJoCffRB9A5I+ Gp76vHKbe2OxOiiruC8HXAcqeRM/wwzw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:date:date:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:sender:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm3; bh=nYr5X5Fow23/+10/R Sw5KaPae0UouyM2iAdzaCokgKU=; b=HooKpaV6om1BA6rdpDvhU1JcB3N/lO17U UAGigEX9Ugk8pyhsWs4kJfY0b19POdlPufDCz/+hGWWwleU9HoHgOkyWujcABWky b/nO6J8nib0F5PF4ZhmxRXsVcitlY6HYmbzlYTwOMhdN8k+hbVPcoOweBMPoKdli cB5xzTEv+gPrhPsOg3YkhpOlk1WVI6NyC1JcmtW8Ms5MKLAEg9uc/AM24XgxFTDa YpOSGCjlL4cjf/J2YY5jsaEoSx7DGgZ1AZg7Nq44zI5fyFXWc9UTCw9nCMaW8NdH i6PGItw1oQ0NdzwMjfnWsseD9ywdUL4U9pmWL+NJyRIj64RCUOaqA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvvddrudeiiedgudehkecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecunecujfgurhephffvufgjfhgffffkgggtsehmtd dtredtredtnecuhfhrohhmpefuvggrnhcuhghhihhtthhonhcuoehsphifhhhithhtohhn sehsphifhhhithhtohhnrdhnrghmvgeqnecuggftrfgrthhtvghrnhepgfeuueetvdekff egvdevteehjeeitedvuddvffehvefgtedvgffhteetffdvveejnecuvehluhhsthgvrhfu ihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepshhpfihhihhtthhonhesshhpfi hhihhtthhonhdrnhgrmhgv X-ME-Proxy: Original-Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 1 Apr 2022 17:16:14 -0400 (EDT) Original-Received: by melete.silentflame.com (Postfix, from userid 1000) id 43AD67E0C12; Fri, 1 Apr 2022 14:16:13 -0700 (MST) In-Reply-To: <8191b68d-975d-3f84-bb0b-501bdf2edf47@gmail.com> X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:229242 Archived-At: --=-=-= Content-Type: text/plain Hello, On Thu 31 Mar 2022 at 04:31PM -07, Jim Porter wrote: > On 3/31/2022 3:48 PM, Sean Whitton wrote: >> >> I think the error should be caught inside the `or', though? The idea >> would be that if eshell-incomplete is thrown within one of the >> disjuncts, that disjunct should return nil. > > Hmm, that's an interesting thought. Maybe this code could be more > particular about what parse function it calls. Since each of the > function calls here: > > (while (or (eshell-parse-lisp-argument) > (eshell-parse-backslash) > (eshell-parse-double-quote) > (eshell-parse-literal-quote))) > > correspond to a particular token here (earlier in the source): > > (re-search-forward > "\\(?:(\\|#?'\\|\"\\|\\\\\\)" bound t))) > > perhaps it would be better to match the function call to the > corresponding token. Thank you for this suggestion, but I think that findbeg1 is more readable, and actually perhaps more efficient, if we maintain the (while (or ...)) structure. So I would like to install the attached patch to resolve this bug. -- Sean Whitton --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-em-extpipe-Catch-eshell-incomplete-thrown-while-pars.patch >From a66fd4c30779a64e56621d21e589bb35856a57ea Mon Sep 17 00:00:00 2001 From: Sean Whitton Date: Fri, 1 Apr 2022 14:05:07 -0700 Subject: [PATCH] em-extpipe: Catch eshell-incomplete thrown while parsing * lisp/eshell/em-extpipe.el (em-extpipe--or-with-catch): New macro. (eshell-parse-external-pipeline): Use new macro to treat `eshell-incomplete' as a failure of the parse function to move us forward (Bug#54603). Thanks to Jim Porter for the report and for help isolating the problem. * test/lisp/eshell/eshell-tests.el (eshell-test/lisp-command-with-quote): New test for Bug#54603, thanks to Jim Porter . --- lisp/eshell/em-extpipe.el | 22 ++++++++++++++++++---- test/lisp/eshell/eshell-tests.el | 4 ++++ 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/lisp/eshell/em-extpipe.el b/lisp/eshell/em-extpipe.el index eb5b3bfe1d..3db1dea595 100644 --- a/lisp/eshell/em-extpipe.el +++ b/lisp/eshell/em-extpipe.el @@ -49,6 +49,19 @@ eshell-extpipe-initialize (add-hook 'eshell-pre-rewrite-command-hook #'eshell-rewrite-external-pipeline -20 t)) +(defmacro em-extpipe--or-with-catch (&rest disjuncts) + "Evaluate DISJUNCTS like `or' but catch `eshell-incomplete'. + +If `eshell-incomplete' is thrown during the evaluation of a +disjunct, that disjunct yields nil." + (let ((result (gensym))) + `(let (,result) + (or ,@(cl-loop for disjunct in disjuncts collect + `(if (catch 'eshell-incomplete + (ignore (setq ,result ,disjunct))) + nil + ,result)))))) + (defun eshell-parse-external-pipeline () "Parse a pipeline intended for execution by the external shell. @@ -105,10 +118,11 @@ eshell-parse-external-pipeline (if (re-search-forward pat next t) (throw 'found (match-beginning 1)) (goto-char next) - (while (or (eshell-parse-lisp-argument) - (eshell-parse-backslash) - (eshell-parse-double-quote) - (eshell-parse-literal-quote))) + (while (em-extpipe--or-with-catch + (eshell-parse-lisp-argument) + (eshell-parse-backslash) + (eshell-parse-double-quote) + (eshell-parse-literal-quote))) ;; Guard against an infinite loop if none of ;; the parsers moved us forward. (unless (or (> (point) next) (eobp)) diff --git a/test/lisp/eshell/eshell-tests.el b/test/lisp/eshell/eshell-tests.el index e31db07c61..1e303f70e5 100644 --- a/test/lisp/eshell/eshell-tests.el +++ b/test/lisp/eshell/eshell-tests.el @@ -44,6 +44,10 @@ eshell-test/lisp-command "Test `eshell-command-result' with an elisp command." (should (equal (eshell-test-command-result "(+ 1 2)") 3))) +(ert-deftest eshell-test/lisp-command-with-quote () + "Test `eshell-command-result' with an elisp command containing a quote." + (should (equal (eshell-test-command-result "(eq 'foo nil)") nil))) + (ert-deftest eshell-test/for-loop () "Test `eshell-command-result' with a for loop.." (let ((process-environment (cons "foo" process-environment))) -- 2.30.2 --=-=-=--