]> git.eshelyaron.com Git - emacs.git/commitdiff
Fix redirecting Eshell output to symbols in some places
authorJim Porter <jporterbugs@gmail.com>
Thu, 29 Aug 2024 01:53:03 +0000 (18:53 -0700)
committerEshel Yaron <me@eshelyaron.com>
Wed, 4 Sep 2024 07:51:42 +0000 (09:51 +0200)
* lisp/eshell/esh-io.el (eshell-output-object-to-target): Don't require
TARGET to be bound.

* lisp/eshell/em-script.el (eshell-execute-file):
* lisp/eshell/eshell.el (eshell-command): Quote the output/error
targets.

* test/lisp/eshell/em-script-tests.el (eshell-execute-file-output): New
variable.
(em-script-test/execute-file/output-symbol): New test.

* test/lisp/eshell/eshell-tests.el (eshell-command-output): New
variable.
(eshell-test/eshell-command/output-symbol): New test (bug#72857).

(cherry picked from commit e269cf63a67d529740d0ec2382ae7c3a982cd064)

lisp/eshell/em-script.el
lisp/eshell/esh-io.el
lisp/eshell/eshell.el
test/lisp/eshell/em-script-tests.el
test/lisp/eshell/eshell-tests.el

index 8cdaa994cc56b25fc2c1935042015788d231fc44..03d9a88e32e8ff9a581986f76ca176e1b67f5442 100644 (file)
@@ -128,7 +128,7 @@ Comments begin with `#'."
     (with-temp-buffer
       (eshell-mode)
       (eshell-do-eval
-       `(eshell-with-handles (,stdout 'insert ,stderr 'insert)
+       `(eshell-with-handles (',stdout 'insert ',stderr 'insert)
           (let ((eshell-current-subjob-p))
             ,(eshell--source-file file args)))
        t))))
index a6df75e86e941afbadb53d663de7ded4136305c6..0fcba9b14747c25de51bca42e92d1cb960681b23 100644 (file)
@@ -711,7 +711,7 @@ Returns what was actually sent, or nil if nothing was sent.")
 
 (cl-defmethod eshell-output-object-to-target (object (target symbol))
   "Output OBJECT to the value of the symbol TARGET."
-  (if (not (symbol-value target))
+  (if (not (and (boundp target) (symbol-value target)))
       (set target object)
     (setq object (eshell-stringify object))
     (if (not (stringp (symbol-value target)))
index 41e0348f3cdf8fdf7224f23387b50911777a3b8b..fc08734d5f3511a7965909d194840971f0fd76dc 100644 (file)
@@ -354,7 +354,7 @@ buffer is already taken by another running shell command."
          (eshell-non-interactive-p t))
       (eshell-mode)
       (let* ((proc (eshell-eval-command
-                    `(eshell-with-handles (,stdout 'insert ,stderr 'insert)
+                    `(eshell-with-handles (',stdout 'insert ',stderr 'insert)
                        (let ((eshell-current-subjob-p))
                         ,(eshell-parse-command command)))
                     command))
index b9f96fa86db135dc82a975c77c6cfc658748fd23..5e5eb80f215db953ddb78e3807cfd8188f4b2f45 100644 (file)
@@ -33,6 +33,9 @@
          (expand-file-name "eshell-tests-helpers"
                            (file-name-directory (or load-file-name
                                                     default-directory))))
+
+(defvar eshell-execute-file-output)
+
 ;;; Tests:
 
 (ert-deftest em-script-test/source-script ()
         (eshell-execute-file temp-file nil output-file))
       (should (equal (eshell-test-file-string output-file) "moreinitial")))))
 
+(ert-deftest em-script-test/execute-file/output-symbol ()
+  "Test `eshell-execute-file' redirecting to a symbol."
+  (ert-with-temp-file temp-file :text "echo hi\necho bye"
+    (with-temp-eshell-settings
+      (eshell-execute-file temp-file nil 'eshell-execute-file-output))
+    (should (equal eshell-execute-file-output "hibye"))))
+
 (ert-deftest em-script-test/batch-file ()
   "Test running an Eshell script file as a batch script."
   (ert-with-temp-file temp-file
index c84af62fdbd181248fad16b5f6e9bf0f55bad124..e5aeee5123e77888631c10f749823ae7c6db26ef 100644 (file)
@@ -35,6 +35,7 @@
                                                     default-directory))))
 
 (defvar eshell-test-value nil)
+(defvar eshell-command-output)
 
 ;;; Tests:
 
@@ -144,6 +145,11 @@ This test uses a pipeline for the command."
     (eshell-command "echo more" temp-file)
     (should (equal (eshell-test-file-string temp-file) "moreinitial"))))
 
+(ert-deftest eshell-test/eshell-command/output-symbol ()
+  "Test that `eshell-command' can write to a symbol."
+  (eshell-command "echo hi" 'eshell-command-output)
+  (should (equal eshell-command-output "hi")))
+
 (ert-deftest eshell-test/command-running-p ()
   "Modeline should show no command running"
   (with-temp-eshell