From 47cda4ecacb981fef811a46875fa5b089acc9689 Mon Sep 17 00:00:00 2001 From: Jim Porter Date: Sun, 20 Jul 2025 16:41:51 -0700 Subject: [PATCH] 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. --- lisp/eshell/esh-cmd.el | 3 ++- test/lisp/eshell/esh-cmd-tests.el | 5 +++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lisp/eshell/esh-cmd.el b/lisp/eshell/esh-cmd.el index 0f506c7664a..5292acb964a 100644 --- a/lisp/eshell/esh-cmd.el +++ b/lisp/eshell/esh-cmd.el @@ -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))) diff --git a/test/lisp/eshell/esh-cmd-tests.el b/test/lisp/eshell/esh-cmd-tests.el index 1d03becb9d9..fd7df7e1d81 100644 --- a/test/lisp/eshell/esh-cmd-tests.el +++ b/test/lisp/eshell/esh-cmd-tests.el @@ -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))