aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJim Porter2024-08-28 18:53:03 -0700
committerJim Porter2024-08-28 18:53:03 -0700
commite269cf63a67d529740d0ec2382ae7c3a982cd064 (patch)
tree268862c96cd206488541f81c502f5a836251fd68
parent5c68545a936ab42df90c8498ca77207a5e6aff1f (diff)
downloademacs-e269cf63a67d529740d0ec2382ae7c3a982cd064.tar.gz
emacs-e269cf63a67d529740d0ec2382ae7c3a982cd064.zip
Fix redirecting Eshell output to symbols in some places
* 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).
-rw-r--r--lisp/eshell/em-script.el2
-rw-r--r--lisp/eshell/esh-io.el2
-rw-r--r--lisp/eshell/eshell.el2
-rw-r--r--test/lisp/eshell/em-script-tests.el10
-rw-r--r--test/lisp/eshell/eshell-tests.el6
5 files changed, 19 insertions, 3 deletions
diff --git a/lisp/eshell/em-script.el b/lisp/eshell/em-script.el
index 8cdaa994cc5..03d9a88e32e 100644
--- a/lisp/eshell/em-script.el
+++ b/lisp/eshell/em-script.el
@@ -128,7 +128,7 @@ Comments begin with `#'."
128 (with-temp-buffer 128 (with-temp-buffer
129 (eshell-mode) 129 (eshell-mode)
130 (eshell-do-eval 130 (eshell-do-eval
131 `(eshell-with-handles (,stdout 'insert ,stderr 'insert) 131 `(eshell-with-handles (',stdout 'insert ',stderr 'insert)
132 (let ((eshell-current-subjob-p)) 132 (let ((eshell-current-subjob-p))
133 ,(eshell--source-file file args))) 133 ,(eshell--source-file file args)))
134 t)))) 134 t))))
diff --git a/lisp/eshell/esh-io.el b/lisp/eshell/esh-io.el
index a6df75e86e9..0fcba9b1474 100644
--- a/lisp/eshell/esh-io.el
+++ b/lisp/eshell/esh-io.el
@@ -711,7 +711,7 @@ Returns what was actually sent, or nil if nothing was sent.")
711 711
712(cl-defmethod eshell-output-object-to-target (object (target symbol)) 712(cl-defmethod eshell-output-object-to-target (object (target symbol))
713 "Output OBJECT to the value of the symbol TARGET." 713 "Output OBJECT to the value of the symbol TARGET."
714 (if (not (symbol-value target)) 714 (if (not (and (boundp target) (symbol-value target)))
715 (set target object) 715 (set target object)
716 (setq object (eshell-stringify object)) 716 (setq object (eshell-stringify object))
717 (if (not (stringp (symbol-value target))) 717 (if (not (stringp (symbol-value target)))
diff --git a/lisp/eshell/eshell.el b/lisp/eshell/eshell.el
index 41e0348f3cd..fc08734d5f3 100644
--- a/lisp/eshell/eshell.el
+++ b/lisp/eshell/eshell.el
@@ -354,7 +354,7 @@ buffer is already taken by another running shell command."
354 (eshell-non-interactive-p t)) 354 (eshell-non-interactive-p t))
355 (eshell-mode) 355 (eshell-mode)
356 (let* ((proc (eshell-eval-command 356 (let* ((proc (eshell-eval-command
357 `(eshell-with-handles (,stdout 'insert ,stderr 'insert) 357 `(eshell-with-handles (',stdout 'insert ',stderr 'insert)
358 (let ((eshell-current-subjob-p)) 358 (let ((eshell-current-subjob-p))
359 ,(eshell-parse-command command))) 359 ,(eshell-parse-command command)))
360 command)) 360 command))
diff --git a/test/lisp/eshell/em-script-tests.el b/test/lisp/eshell/em-script-tests.el
index b9f96fa86db..5e5eb80f215 100644
--- a/test/lisp/eshell/em-script-tests.el
+++ b/test/lisp/eshell/em-script-tests.el
@@ -33,6 +33,9 @@
33 (expand-file-name "eshell-tests-helpers" 33 (expand-file-name "eshell-tests-helpers"
34 (file-name-directory (or load-file-name 34 (file-name-directory (or load-file-name
35 default-directory)))) 35 default-directory))))
36
37(defvar eshell-execute-file-output)
38
36;;; Tests: 39;;; Tests:
37 40
38(ert-deftest em-script-test/source-script () 41(ert-deftest em-script-test/source-script ()
@@ -121,6 +124,13 @@
121 (eshell-execute-file temp-file nil output-file)) 124 (eshell-execute-file temp-file nil output-file))
122 (should (equal (eshell-test-file-string output-file) "moreinitial"))))) 125 (should (equal (eshell-test-file-string output-file) "moreinitial")))))
123 126
127(ert-deftest em-script-test/execute-file/output-symbol ()
128 "Test `eshell-execute-file' redirecting to a symbol."
129 (ert-with-temp-file temp-file :text "echo hi\necho bye"
130 (with-temp-eshell-settings
131 (eshell-execute-file temp-file nil 'eshell-execute-file-output))
132 (should (equal eshell-execute-file-output "hibye"))))
133
124(ert-deftest em-script-test/batch-file () 134(ert-deftest em-script-test/batch-file ()
125 "Test running an Eshell script file as a batch script." 135 "Test running an Eshell script file as a batch script."
126 (ert-with-temp-file temp-file 136 (ert-with-temp-file temp-file
diff --git a/test/lisp/eshell/eshell-tests.el b/test/lisp/eshell/eshell-tests.el
index c84af62fdbd..e5aeee5123e 100644
--- a/test/lisp/eshell/eshell-tests.el
+++ b/test/lisp/eshell/eshell-tests.el
@@ -35,6 +35,7 @@
35 default-directory)))) 35 default-directory))))
36 36
37(defvar eshell-test-value nil) 37(defvar eshell-test-value nil)
38(defvar eshell-command-output)
38 39
39;;; Tests: 40;;; Tests:
40 41
@@ -144,6 +145,11 @@ This test uses a pipeline for the command."
144 (eshell-command "echo more" temp-file) 145 (eshell-command "echo more" temp-file)
145 (should (equal (eshell-test-file-string temp-file) "moreinitial")))) 146 (should (equal (eshell-test-file-string temp-file) "moreinitial"))))
146 147
148(ert-deftest eshell-test/eshell-command/output-symbol ()
149 "Test that `eshell-command' can write to a symbol."
150 (eshell-command "echo hi" 'eshell-command-output)
151 (should (equal eshell-command-output "hi")))
152
147(ert-deftest eshell-test/command-running-p () 153(ert-deftest eshell-test/command-running-p ()
148 "Modeline should show no command running" 154 "Modeline should show no command running"
149 (with-temp-eshell 155 (with-temp-eshell