aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJim Porter2024-08-28 19:12:29 -0700
committerJim Porter2024-08-28 19:14:30 -0700
commitb6f4ffcc106fdbc21dfea45c75fdc4f217d8f201 (patch)
tree08693bf3b13a8dbe871183d053541b579ffa72a8
parente269cf63a67d529740d0ec2382ae7c3a982cd064 (diff)
downloademacs-b6f4ffcc106fdbc21dfea45c75fdc4f217d8f201.tar.gz
emacs-b6f4ffcc106fdbc21dfea45c75fdc4f217d8f201.zip
Support "/dev/null" as a target when creating Eshell handles
Previously, you could only use this when setting the handle afterwards. * lisp/eshell/esh-io.el (eshell-set-output-handle): Don't catch 'eshell-null-device' here... (eshell-get-target): ... catch it here. * test/lisp/eshell/eshell-tests.el (eshell-test/eshell-command/output-dev-null): New test (bug#72857).
-rw-r--r--lisp/eshell/esh-io.el21
-rw-r--r--test/lisp/eshell/eshell-tests.el8
2 files changed, 19 insertions, 10 deletions
diff --git a/lisp/eshell/esh-io.el b/lisp/eshell/esh-io.el
index 0fcba9b1474..feb4bf8959f 100644
--- a/lisp/eshell/esh-io.el
+++ b/lisp/eshell/esh-io.el
@@ -429,11 +429,10 @@ current list of targets."
429 (when defaultp 429 (when defaultp
430 (cl-decf (cdar handle)) 430 (cl-decf (cdar handle))
431 (setcar handle (cons nil 1))) 431 (setcar handle (cons nil 1)))
432 (catch 'eshell-null-device 432 (let ((current (caar handle))
433 (let ((current (caar handle)) 433 (where (eshell-get-target target mode)))
434 (where (eshell-get-target target mode))) 434 (when (and where (not (member where current)))
435 (unless (member where current) 435 (setcar (car handle) (append current (list where)))))
436 (setcar (car handle) (append current (list where))))))
437 (setcar (cdr handle) nil)))) 436 (setcar (cdr handle) nil))))
438 437
439(defun eshell-copy-output-handle (index index-to-copy &optional handles) 438(defun eshell-copy-output-handle (index index-to-copy &optional handles)
@@ -609,11 +608,13 @@ return an `eshell-generic-target' instance; otherwise, return a
609marker for a file named TARGET." 608marker for a file named TARGET."
610 (setq mode (or mode 'insert)) 609 (setq mode (or mode 'insert))
611 (if-let ((redir (assoc raw-target eshell-virtual-targets))) 610 (if-let ((redir (assoc raw-target eshell-virtual-targets)))
612 (let ((target (if (nth 2 redir) 611 (let (target)
613 (funcall (nth 1 redir) mode) 612 (catch 'eshell-null-device
614 (nth 1 redir)))) 613 (setq target (if (nth 2 redir)
615 (unless (eshell-generic-target-p target) 614 (funcall (nth 1 redir) mode)
616 (setq target (eshell-function-target-create target))) 615 (nth 1 redir)))
616 (unless (eshell-generic-target-p target)
617 (setq target (eshell-function-target-create target))))
617 target) 618 target)
618 (let ((exists (get-file-buffer raw-target)) 619 (let ((exists (get-file-buffer raw-target))
619 (buf (find-file-noselect raw-target t))) 620 (buf (find-file-noselect raw-target t)))
diff --git a/test/lisp/eshell/eshell-tests.el b/test/lisp/eshell/eshell-tests.el
index e5aeee5123e..50a748cd56e 100644
--- a/test/lisp/eshell/eshell-tests.el
+++ b/test/lisp/eshell/eshell-tests.el
@@ -150,6 +150,14 @@ This test uses a pipeline for the command."
150 (eshell-command "echo hi" 'eshell-command-output) 150 (eshell-command "echo hi" 'eshell-command-output)
151 (should (equal eshell-command-output "hi"))) 151 (should (equal eshell-command-output "hi")))
152 152
153(ert-deftest eshell-test/eshell-command/output-dev-null ()
154 "Test that the `eshell-command' function handles /dev/null properly."
155 (ert-with-temp-directory eshell-directory-name
156 (let ((eshell-history-file-name nil))
157 (with-temp-buffer
158 (eshell-command "echo hi" "/dev/null")
159 (should (equal (buffer-string) ""))))))
160
153(ert-deftest eshell-test/command-running-p () 161(ert-deftest eshell-test/command-running-p ()
154 "Modeline should show no command running" 162 "Modeline should show no command running"
155 (with-temp-eshell 163 (with-temp-eshell