diff options
| -rw-r--r-- | lisp/eshell/eshell.el | 34 |
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'." | |||
| 272 | 272 | ||
| 273 | (declare-function eshell-add-input-to-history "em-hist" (input)) | 273 | (declare-function eshell-add-input-to-history "em-hist" (input)) |
| 274 | 274 | ||
| 275 | ;;;###autoload | 275 | (defun eshell-read-command (&optional prompt) |
| 276 | (defun eshell-command (&optional command arg) | 276 | "Read an Eshell command from the minibuffer, prompting with PROMPT." |
| 277 | "Execute the Eshell command string COMMAND. | 277 | (let ((prompt (or prompt "Emacs shell command: ")) |
| 278 | With prefix ARG, insert output into the current buffer at point." | 278 | (eshell-non-interactive-p t)) |
| 279 | (interactive) | ||
| 280 | (unless arg | ||
| 281 | (setq arg current-prefix-arg)) | ||
| 282 | (let ((eshell-non-interactive-p t)) | ||
| 283 | ;; Enable `eshell-mode' only in this minibuffer. | 279 | ;; Enable `eshell-mode' only in this minibuffer. |
| 284 | (minibuffer-with-setup-hook (lambda () | 280 | (minibuffer-with-setup-hook (lambda () |
| 285 | (eshell-mode) | 281 | (eshell-mode) |
| 286 | (eshell-command-mode +1)) | 282 | (eshell-command-mode +1)) |
| 287 | (unless command | 283 | (let ((command (read-from-minibuffer prompt))) |
| 288 | (setq command (read-from-minibuffer "Emacs shell command: ")) | 284 | (when (eshell-using-module 'eshell-hist) |
| 289 | (if (eshell-using-module 'eshell-hist) | 285 | (eshell-add-input-to-history command)) |
| 290 | (eshell-add-input-to-history command))))) | 286 | command)))) |
| 291 | (unless command | 287 | |
| 292 | (error "No command specified!")) | 288 | ;;;###autoload |
| 289 | (defun eshell-command (command &optional to-current-buffer) | ||
| 290 | "Execute the Eshell command string COMMAND. | ||
| 291 | If TO-CURRENT-BUFFER is non-nil (interactively, with the prefix | ||
| 292 | argument), then insert output into the current buffer at point." | ||
| 293 | (interactive (list (eshell-read-command) | ||
| 294 | current-prefix-arg)) | ||
| 293 | (save-excursion | 295 | (save-excursion |
| 294 | (let ((stdout (if arg (current-buffer) t)) | 296 | (let ((stdout (if to-current-buffer (current-buffer) t)) |
| 295 | (buf (set-buffer (generate-new-buffer " *eshell cmd*"))) | 297 | (buf (set-buffer (generate-new-buffer " *eshell cmd*"))) |
| 296 | (eshell-non-interactive-p t)) | 298 | (eshell-non-interactive-p t)) |
| 297 | (eshell-mode) | 299 | (eshell-mode) |
| @@ -319,7 +321,7 @@ With prefix ARG, insert output into the current buffer at point." | |||
| 319 | (while (and (bolp) (not (bobp))) | 321 | (while (and (bolp) (not (bobp))) |
| 320 | (delete-char -1))) | 322 | (delete-char -1))) |
| 321 | (cl-assert (and buf (buffer-live-p buf))) | 323 | (cl-assert (and buf (buffer-live-p buf))) |
| 322 | (unless arg | 324 | (unless to-current-buffer |
| 323 | (let ((len (if (not intr) 2 | 325 | (let ((len (if (not intr) 2 |
| 324 | (count-lines (point-min) (point-max))))) | 326 | (count-lines (point-min) (point-max))))) |
| 325 | (cond | 327 | (cond |