GNU bug report logs -
#57129
29.0.50; Improve behavior of conditionals in Eshell
Previous Next
Reported by: Jim Porter <jporterbugs <at> gmail.com>
Date: Thu, 11 Aug 2022 02:44:02 UTC
Severity: normal
Found in version 29.0.50
Done: Jim Porter <jporterbugs <at> gmail.com>
Bug is archived. No further changes may be made.
Full log
Message #8 received at 57129 <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
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.
[0001-Only-set-Eshell-execution-result-metavariables-when-.patch (text/plain, attachment)]
[0002-Allow-using-dollar-expansions-in-Eshell-conditionals.patch (text/plain, attachment)]
[0003-Make-and-variables-more-consistent-in-Eshell.patch (text/plain, attachment)]
This bug report was last modified 2 years and 129 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.