[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
master 093a360251a 2/2: Use the 'interactive' spec to set arguments for
From: |
Jim Porter |
Subject: |
master 093a360251a 2/2: Use the 'interactive' spec to set arguments for 'eshell-command' |
Date: |
Sun, 2 Apr 2023 18:06:46 -0400 (EDT) |
branch: master
commit 093a360251afdbdc6fe6cf22e72ccbc79fc22e2e
Author: Jim Porter <jporterbugs@gmail.com>
Commit: Jim Porter <jporterbugs@gmail.com>
Use the 'interactive' spec to set arguments for 'eshell-command'
* lisp/eshell/eshell.el (eshell-read-command): New function...
(eshell-command): ... use it. Additionally, require the COMMAND
argument, and rename ARG to TO-CURRENT-BUFFER.
---
lisp/eshell/eshell.el | 34 ++++++++++++++++++----------------
1 file changed, 18 insertions(+), 16 deletions(-)
diff --git a/lisp/eshell/eshell.el b/lisp/eshell/eshell.el
index b71f283bf9f..15fc2ae6310 100644
--- a/lisp/eshell/eshell.el
+++ b/lisp/eshell/eshell.el
@@ -272,26 +272,28 @@ information on Eshell, see Info node `(eshell)Top'."
(declare-function eshell-add-input-to-history "em-hist" (input))
-;;;###autoload
-(defun eshell-command (&optional command arg)
- "Execute the Eshell command string COMMAND.
-With prefix ARG, insert output into the current buffer at point."
- (interactive)
- (unless arg
- (setq arg current-prefix-arg))
- (let ((eshell-non-interactive-p t))
+(defun eshell-read-command (&optional prompt)
+ "Read an Eshell command from the minibuffer, prompting with PROMPT."
+ (let ((prompt (or prompt "Emacs shell command: "))
+ (eshell-non-interactive-p t))
;; Enable `eshell-mode' only in this minibuffer.
(minibuffer-with-setup-hook (lambda ()
(eshell-mode)
(eshell-command-mode +1))
- (unless command
- (setq command (read-from-minibuffer "Emacs shell command: "))
- (if (eshell-using-module 'eshell-hist)
- (eshell-add-input-to-history command)))))
- (unless command
- (error "No command specified!"))
+ (let ((command (read-from-minibuffer prompt)))
+ (when (eshell-using-module 'eshell-hist)
+ (eshell-add-input-to-history command))
+ command))))
+
+;;;###autoload
+(defun eshell-command (command &optional to-current-buffer)
+ "Execute the Eshell command string COMMAND.
+If TO-CURRENT-BUFFER is non-nil (interactively, with the prefix
+argument), then insert output into the current buffer at point."
+ (interactive (list (eshell-read-command)
+ current-prefix-arg))
(save-excursion
- (let ((stdout (if arg (current-buffer) t))
+ (let ((stdout (if to-current-buffer (current-buffer) t))
(buf (set-buffer (generate-new-buffer " *eshell cmd*")))
(eshell-non-interactive-p t))
(eshell-mode)
@@ -319,7 +321,7 @@ With prefix ARG, insert output into the current buffer at
point."
(while (and (bolp) (not (bobp)))
(delete-char -1)))
(cl-assert (and buf (buffer-live-p buf)))
- (unless arg
+ (unless to-current-buffer
(let ((len (if (not intr) 2
(count-lines (point-min) (point-max)))))
(cond