Allow writing a lambda function as a command in Eshell

* lisp/eshell/esh-cmd.el (eshell-lisp-command): Don't try to call a
literal lambda.

* test/lisp/eshell/esh-cmd-tests.el (esh-cmd-test/literal-lambda): New
test.
This commit is contained in:
Jim Porter 2025-07-20 16:41:51 -07:00
parent b72dcebdab
commit 47cda4ecac
2 changed files with 7 additions and 1 deletions

View file

@ -1584,7 +1584,8 @@ a string naming a Lisp function."
(eshell-set-exit-info 0))
(setq eshell-last-arguments args)
(let* ((eshell-ensure-newline-p t)
(command-form-p (functionp object))
(command-form-p (and (functionp object)
(symbolp object)))
result)
(if command-form-p
(let ((numeric (not (get object 'eshell-no-numeric-conversions)))

View file

@ -60,6 +60,11 @@ Test that trailing arguments outside the S-expression are
ignored. e.g. \"(+ 1 2) 3\" => 3"
(eshell-command-result-equal "(+ 1 2) 3" 3))
(ert-deftest esh-cmd-test/literal-lambda ()
"Test that a lambda isn't immediately invoked."
(eshell-command-result-equal "(lambda (i) (+ i 1))"
(eval '(lambda (i) (+ i 1)))))
(ert-deftest esh-cmd-test/subcommand ()
"Test invocation with a simple subcommand."
(eshell-command-result-equal "{+ 1 2}" 3))