[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
master b6f4ffcc106 3/3: Support "/dev/null" as a target when creating Es
From: |
Jim Porter |
Subject: |
master b6f4ffcc106 3/3: Support "/dev/null" as a target when creating Eshell handles |
Date: |
Wed, 28 Aug 2024 22:15:32 -0400 (EDT) |
branch: master
commit b6f4ffcc106fdbc21dfea45c75fdc4f217d8f201
Author: Jim Porter <jporterbugs@gmail.com>
Commit: Jim Porter <jporterbugs@gmail.com>
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).
---
lisp/eshell/esh-io.el | 21 +++++++++++----------
test/lisp/eshell/eshell-tests.el | 8 ++++++++
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."
(when defaultp
(cl-decf (cdar handle))
(setcar handle (cons nil 1)))
- (catch 'eshell-null-device
- (let ((current (caar handle))
- (where (eshell-get-target target mode)))
- (unless (member where current)
- (setcar (car handle) (append current (list where))))))
+ (let ((current (caar handle))
+ (where (eshell-get-target target mode)))
+ (when (and where (not (member where current)))
+ (setcar (car handle) (append current (list where)))))
(setcar (cdr handle) nil))))
(defun eshell-copy-output-handle (index index-to-copy &optional handles)
@@ -609,11 +608,13 @@ return an `eshell-generic-target' instance; otherwise,
return a
marker for a file named TARGET."
(setq mode (or mode 'insert))
(if-let ((redir (assoc raw-target eshell-virtual-targets)))
- (let ((target (if (nth 2 redir)
- (funcall (nth 1 redir) mode)
- (nth 1 redir))))
- (unless (eshell-generic-target-p target)
- (setq target (eshell-function-target-create target)))
+ (let (target)
+ (catch 'eshell-null-device
+ (setq target (if (nth 2 redir)
+ (funcall (nth 1 redir) mode)
+ (nth 1 redir)))
+ (unless (eshell-generic-target-p target)
+ (setq target (eshell-function-target-create target))))
target)
(let ((exists (get-file-buffer raw-target))
(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."
(eshell-command "echo hi" 'eshell-command-output)
(should (equal eshell-command-output "hi")))
+(ert-deftest eshell-test/eshell-command/output-dev-null ()
+ "Test that the `eshell-command' function handles /dev/null properly."
+ (ert-with-temp-directory eshell-directory-name
+ (let ((eshell-history-file-name nil))
+ (with-temp-buffer
+ (eshell-command "echo hi" "/dev/null")
+ (should (equal (buffer-string) ""))))))
+
(ert-deftest eshell-test/command-running-p ()
"Modeline should show no command running"
(with-temp-eshell