master ed2063ba72d 1/8: Allow writing a lambda function as a command in Eshell

Jim Porter <[email protected]>
Newsgroups gmane.emacs.diffs
Message-ID <[email protected]>
branch: master
commit ed2063ba72da6b3ac4f77612876f6e2c535203c3
Author: Jim Porter <[email protected]>
Commit: Jim Porter <[email protected]>

    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))
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.