bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#57129: 29.0.50; Improve behavior of conditionals in Eshell


From: Jim Porter
Subject: bug#57129: 29.0.50; Improve behavior of conditionals in Eshell
Date: Wed, 10 Aug 2022 19:46:41 -0700

Here are some patches to fix this.

The first patch adds tests/documentation for the current state so that the subsequent patches are clearer. It also improves 'eshell-close-handles' so that you can set the exit status elsewhere, which makes some of the code simpler.

The second patch fixes the use of variables in conditionals (e.g. if statements, while loops). The only non-test code change here is that 'eshell-structure-basic-command' needed to be taught that forms beginning with 'eshell-escape-arg' should be treated as data, much like 'eshell-convert'.

The third patch fixes the behavior of the '$?' and '$$' variables to match the manual: '$$' is t when an external command succeeds, and '$?' is 1 when a Lisp command signals an error. I also added a new feature that '$?' is 2 when an actual Lisp *form* returns nil. This lets you use Lisp forms as conditionals in Eshell much like you would in regular Lisp. However, it doesn't apply to the command syntax, even if it runs Lisp code:

  ~ $ (zerop 1); echo $?
  2
  ~ $ zerop 1; echo $?
  0

That's because Eshell prints the return value of Lisp commands (unless it's nil), so a Lisp command that wants to silently succeed would return nil. For example, the Lisp version of 'cat' returns nil. We want that to have an exit status of 0. However, when writing it as a Lisp form with parentheses, I think it makes more sense that nil is treated as false for conditionals. The overall goal is so that this prints hi:

  cat foo.txt && echo hi

And that this doesn't:

  (zerop 1) && echo hi

For people who don't like this behavior, they can customize the new 'eshell-lisp-form-nil-is-failure' variable.

Attachment: 0001-Only-set-Eshell-execution-result-metavariables-when-.patch
Description: Text document

Attachment: 0002-Allow-using-dollar-expansions-in-Eshell-conditionals.patch
Description: Text document

Attachment: 0003-Make-and-variables-more-consistent-in-Eshell.patch
Description: Text document


reply via email to

[Prev in Thread] Current Thread [Next in Thread]