summaryrefslogtreecommitdiff
path: root/lisp/eshell/eshell.el
diff options
context:
space:
mode:
authorJim Porter <jporterbugs@gmail.com>2023-03-30 19:38:30 -0700
committerJim Porter <jporterbugs@gmail.com>2023-04-02 15:05:53 -0700
commit093a360251afdbdc6fe6cf22e72ccbc79fc22e2e (patch)
tree47d527be79f1d352d13b1e5a17955643d7290918 /lisp/eshell/eshell.el
parent267fca267fe858d8a8f34d15de21051e3b6fff41 (diff)
downloademacs-093a360251afdbdc6fe6cf22e72ccbc79fc22e2e.tar.gz
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.
Diffstat (limited to 'lisp/eshell/eshell.el')
-rw-r--r--lisp/eshell/eshell.el34
1 files 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