From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Milan Zimmermann Newsgroups: gmane.emacs.bugs Subject: bug#59612: 29.0.50; Eshell: The behavior of conditionals depends on whitespace Date: Sun, 27 Nov 2022 00:07:40 -0500 Message-ID: References: <8fec9d79-4118-eaa5-b762-c57f11f41aef@gmail.com> <7f19f7fa-6573-23de-e0b9-81683dd3b61c@gmail.com> Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="0000000000000cac3a05ee6cbe3b" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="39981"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 59612@debbugs.gnu.org To: Jim Porter Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sun Nov 27 06:09:21 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 1oz9up-000ABU-BJ for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 27 Nov 2022 06:09:19 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oz9uc-00014y-0Y; Sun, 27 Nov 2022 00:09:06 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oz9uZ-00014l-De for bug-gnu-emacs@gnu.org; Sun, 27 Nov 2022 00:09:03 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oz9uZ-0001bo-4l for bug-gnu-emacs@gnu.org; Sun, 27 Nov 2022 00:09:03 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1oz9uX-0003Vt-U7 for bug-gnu-emacs@gnu.org; Sun, 27 Nov 2022 00:09:01 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Milan Zimmermann Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 27 Nov 2022 05:09:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 59612 X-GNU-PR-Package: emacs Original-Received: via spool by 59612-submit@debbugs.gnu.org id=B59612.166952570713494 (code B ref 59612); Sun, 27 Nov 2022 05:09:01 +0000 Original-Received: (at 59612) by debbugs.gnu.org; 27 Nov 2022 05:08:27 +0000 Original-Received: from localhost ([127.0.0.1]:41825 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oz9ty-0003Va-Hf for submit@debbugs.gnu.org; Sun, 27 Nov 2022 00:08:27 -0500 Original-Received: from mail-vs1-f44.google.com ([209.85.217.44]:37643) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oz9tt-0003VT-Iw for 59612@debbugs.gnu.org; Sun, 27 Nov 2022 00:08:24 -0500 Original-Received: by mail-vs1-f44.google.com with SMTP id 124so7697290vsv.4 for <59612@debbugs.gnu.org>; Sat, 26 Nov 2022 21:08:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=VjxBdGGQrXVqYqkE9otC90DsjvrzEpg5XxhbN/jBU8o=; b=aVvNkxlb9DT439/Mgdu5MfQMxqRLeKxXjU+ni9rSrg7d337G5K32pEr9y1m8NbbBrc q0vjMTecjLd1xFBVRySoDBFT0I8uyDGfsYhurYZgVj8GGedB23ae6yJlTFPxygkpaO5K Ag4qKS+/t5Yi6IvgsEaKt05wwpKkF94/W6nivM9KBCLHnTm4jZSkkyEfp4BodqCXqkwK IWoD6GWlemUZmH5z6ZQSnMCdOKUAFaSmNdQCD0QZZs7T38yuVhS6L2G1OHit9x/tdgXX sGRlNV6vCY5VIp6XLFsjfN9D4kowgmAwWMg0QFE/c33isbbvSMjAz2aPrxrEgkXgdsdE saMg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=VjxBdGGQrXVqYqkE9otC90DsjvrzEpg5XxhbN/jBU8o=; b=TaOh3CNJw5zZjOfHruvvplE7fGvbC/y5CNo6ZwoZAiDxt9n2ZkI5DUmnbNBiS95rIl 8GWuXrwTSi+D2FnSPJ+yQH5ua0G5e8GXzWg7LZMJdMUZg+sFjnzorbxrpaNXvpbSs7Ng ke9l3WMmoc9zq2bbAfGTuKkBZ0A98fgcDcXH8268lVQc/Dgh97MxcWhWD/Q29sJBpBob 9V/toCTlKGDX78mCkMabxStb9HgCiuEK8gz2M0h0NLWRWsowSV8EdnVpr1E9iXIELwWE FHm6MihLabhFe1qZBywT/HpcAecb0OhWV4cWcGgg9N4MGi6k86UfhSHhhbUMbtEx/Rbt djnw== X-Gm-Message-State: ANoB5plXAbPzkuKcUnjz0hHJrej50k3TdQI77DCniXRlsgQyKJVPEGSg W+MYQ1qvIYn15tpg1mFwf1iEEcapF7FPN7Qx3Q4= X-Google-Smtp-Source: AA0mqf70+uoGVXO2JHHHv3vAnJmxgBspzg1ji7MK6ZI4IYkB5BWz2JqlmQD30WWD11k291MtRT1rSBWZsw8j0fxIC2I= X-Received: by 2002:a05:6102:f9a:b0:3b0:8bc4:1600 with SMTP id e26-20020a0561020f9a00b003b08bc41600mr3945018vsv.4.1669525695931; Sat, 26 Nov 2022 21:08:15 -0800 (PST) In-Reply-To: <7f19f7fa-6573-23de-e0b9-81683dd3b61c@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-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:249165 Archived-At: --0000000000000cac3a05ee6cbe3b Content-Type: text/plain; charset="UTF-8" These are all great ideas (implementing else on if as a kind of joining commands, adding eshell-functions, adding ability to invoke Eshell commands/functions from the elisp blocks). Thanks for sharing the details. I would love to offer help to dig into some of it, but I need to restrain myself from overpromising. In the meantime, I will continue to report bugs or things that do not feel right, hope that is ok. (I decided this third time to use eshell as my main shell at least for personal projects will succeed at least in a limited way.) On Sat, Nov 26, 2022 at 10:13 PM Jim Porter wrote: > On 11/26/2022 6:16 PM, Milan Zimmermann wrote: > > Jim, thanks for the follow-up. Please feel free to close this. > > I think it would be reasonable to leave this open to track adding > support for some kind of "command re-joining" logic that things like > if/else forms could use. Then something like this would just work: > > if { condition } > { true-case } > else > { false-case } > > At a high level, I'm thinking something like this: > > 1. Enhance 'eshell-rewrite-if-command' to support "if"/"else if"/"else" > forms. > > 2. Add some top-level command-rewriting logic that lets you join > multiple separate commands back into one. I think Eshell splits the > commands up line-by-line pretty early in the process, so re-joining them > later might be the least-invasive way to do this. It'll take some > further diagnosis though. > > > Yes, I agree. From the way of thinking "whitespace should not matter" it > > is a surprising behavior though. > > Yeah, it's a strange result, and possibly a sign that the syntax for > Eshell conditionals wasn't the ideal way to do things. But it is what it > is now, and hopefully there are ways to make it less surprising without > making a major incompatible change to syntax. > > > BTW, a slightly related question if I may: A further diversion of > > lisp-iness, I do not suppose there is a way to do a "return"? In bash, > > the ability to "return" from sourced bash scripts or functions allows us > > to deal with errors at the beginning, then process the main logic. > > I think this is related to a TODO in the Eshell manual to add a > Bash-like "function" command, which would let you write whole functions > in Eshell command form. I've also thought about the idea of adding > syntax in Eshell so you can write stuff in Lisp forms but then go back > out to writing command forms. Something like: > > (defun some-function () > (do-stuff) > ($ "echo $foobar") ;; Invoke an Eshell command. > ) > > That might be tricky to get all the plumbing working though. > --0000000000000cac3a05ee6cbe3b Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
3D""These are all = great ideas (implementing else on if as a kind of joining commands, adding = eshell-functions, adding ability to invoke Eshell commands/functions from t= he elisp blocks).

Thanks for sharing the details. = I would love to offer help to dig into some of=C2=A0it, but I need to restr= ain myself from overpromising.

In=C2=A0the meantim= e, I will continue to report bugs or things that do not feel right, hope th= at is ok. (I decided this third time to use eshell as my main shell at leas= t for personal projects will succeed at least in a limited way.)
= =C2=A0


=
On Sat, Nov 26, 2022 at 10:13 PM Jim = Porter <jporterbugs@gmail.com> wrote:
On= 11/26/2022 6:16 PM, Milan Zimmermann wrote:
> Jim, thanks for the follow-up. Please feel free to close this.

I think it would be reasonable to leave this open to track adding
support for some kind of "command re-joining" logic that things l= ike
if/else forms could use. Then something like this would just work:

=C2=A0 =C2=A0if { condition }
=C2=A0 =C2=A0{ true-case }
=C2=A0 =C2=A0else
=C2=A0 =C2=A0{ false-case }

At a high level, I'm thinking something like this:

1. Enhance 'eshell-rewrite-if-command' to support "if"/&q= uot;else if"/"else"
forms.

2. Add some top-level command-rewriting logic that lets you join
multiple separate commands back into one. I think Eshell splits the
commands up line-by-line pretty early in the process, so re-joining them later might be the least-invasive way to do this. It'll take some
further diagnosis though.

> Yes, I agree. From the way of thinking "whitespace should not mat= ter" it
> is a surprising behavior though.

Yeah, it's a strange result, and possibly a sign that the syntax for Eshell conditionals wasn't the ideal way to do things. But it is what i= t
is now, and hopefully there are ways to make it less surprising without making a major incompatible change to syntax.

> BTW, a slightly=C2=A0related question if I may: A further diversion of=
> lisp-iness, I do=C2=A0not suppose=C2=A0there is a way to do a "re= turn"? In bash,
> the ability to "return" from sourced bash scripts or functio= ns allows us
> to deal with errors at the beginning, then process the main logic.

I think this is related to a TODO in the Eshell manual to add a
Bash-like "function" command, which would let you write whole fun= ctions
in Eshell command form. I've also thought about the idea of adding
syntax in Eshell so you can write stuff in Lisp forms but then go back
out to writing command forms. Something like:

=C2=A0 =C2=A0(defun some-function ()
=C2=A0 =C2=A0 =C2=A0(do-stuff)
=C2=A0 =C2=A0 =C2=A0($ "echo $foobar") ;; Invoke an Eshell comman= d.
=C2=A0 =C2=A0 =C2=A0)

That might be tricky to get all the plumbing working though.
--0000000000000cac3a05ee6cbe3b--