Subject: bug#54190: 29.0.50; [PATCH] Incorrect/missing documentation for some Eshell "$" syntaxes

From: Jim Porter <[email-masked]>
Date: Thu, 3 Mar 2022 21:55:41 -0800

On 3/1/2022 5:10 AM, Eli Zaretskii wrote:
> Thanks, installed on the emacs-28 branch.  (But the markup in the
> manual part was wrong; see my followup changes.)

Thanks for fixing that up.

> Fine with me.  It's up to you whether to close this bug or leave it
> open until a better solution is found for master.

After a bit of looking at the `eshell-do-eval' implementation, I 
realized that there's a better solution that's very simple. See the 
attached patch. It's simple enough that it might be fine for Emacs 28, 
but the existing change on the 28 branch is probably a bit safer, since 
that change was just a partial revert. I'm not aware of anything that 
could be broken by this new patch, but you never know...

This doesn't do anything more elaborate like using generator.el's 
machinery here; while (I think) that would be nice to have eventually, 
we can address that in a separate bug, since it'd be a pretty big 
change. We could probably close this bug after this new patch merges.
From 48387e827cd8d550e9627df7256fd3f1a9705a26 Mon Sep 17 00:00:00 2001
From: Jim Porter <[email-masked]>
Date: Thu, 3 Mar 2022 21:46:11 -0800
Subject: [PATCH] Fix Eshell's '$<command>' forms in a better way

* lisp/eshell/esh-cmd.el (eshell-do-eval): Handle 'lambda' forms.
* lisp/eshell/esh-var.el (eshell-parse-variable-ref): Remove
workaround from commit 9e257ae (bug#54190).
---
 lisp/eshell/esh-cmd.el | 2 +-
 lisp/eshell/esh-var.el | 8 ++------
 2 files changed, 3 insertions(+), 7 deletions(-)

diff --git a/lisp/eshell/esh-cmd.el b/lisp/eshell/esh-cmd.el
index 04b54d9d79..484888ec47 100644
--- a/lisp/eshell/esh-cmd.el
+++ b/lisp/eshell/esh-cmd.el
@@ -1077,7 +1077,7 @@ eshell-do-eval
   (cond
    ((not (listp form))
     (list 'quote (eval form)))
-   ((memq (car form) '(quote function))
+   ((memq (car form) '(quote function lambda))
     form)
    (t
     ;; skip past the call to `eshell-do-eval'
diff --git a/lisp/eshell/esh-var.el b/lisp/eshell/esh-var.el
index af89e35f55..092f9f87a4 100644
--- a/lisp/eshell/esh-var.el
+++ b/lisp/eshell/esh-var.el
@@ -458,12 +458,8 @@ eshell-parse-variable-ref
                        (eshell-parse-command cmd)))
                    (ignore
                     (nconc eshell-this-command-hook
-                           ;; Quote this lambda; it will be evaluated
-                           ;; by `eshell-do-eval', which requires very
-                           ;; particular forms in order to work
-                           ;; properly.  See bug#54190.
-                           (list (function (lambda ()
-                                   (delete-file ,temp))))))
+                           (list (lambda ()
+                                   (delete-file ,temp)))))
                    (quote ,temp)))
             (goto-char (1+ end)))))))
    ((eq (char-after) ?\()
-- 
2.25.1