123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474 |
- (eval-when-compile
- (require 'cl)
- (require 'esh-util))
- (require 'esh-util)
- (require 'esh-mode)
- (defgroup eshell nil
- "A command shell implemented entirely in Emacs Lisp.
- It invokes no external processes beyond those requested by the
- user, and is intended to be a functional replacement for command
- shells such as bash, zsh, rc, 4dos."
- :tag "The Emacs shell"
- :link '(info-link "(eshell)Top")
- :version "21.1"
- :group 'applications)
- (defalias 'eshell-defgroup 'defgroup)
- (defvar eshell-buffer-name)
- (defsubst eshell-add-to-window-buffer-names ()
- "Add `eshell-buffer-name' to `same-window-buffer-names'."
- (add-to-list 'same-window-buffer-names eshell-buffer-name))
- (defsubst eshell-remove-from-window-buffer-names ()
- "Remove `eshell-buffer-name' from `same-window-buffer-names'."
- (setq same-window-buffer-names
- (delete eshell-buffer-name same-window-buffer-names)))
- (defcustom eshell-load-hook nil
- "A hook run once Eshell has been loaded."
- :type 'hook
- :group 'eshell)
- (defcustom eshell-unload-hook
- '(eshell-remove-from-window-buffer-names
- eshell-unload-all-modules)
- "A hook run when Eshell is unloaded from memory."
- :type 'hook
- :group 'eshell)
- (defcustom eshell-buffer-name "*eshell*"
- "The basename used for Eshell buffers."
- :set (lambda (symbol value)
-
- (if (boundp 'eshell-buffer-name)
- (eshell-remove-from-window-buffer-names))
- (set symbol value)
-
- (eshell-add-to-window-buffer-names)
- value)
- :type 'string
- :group 'eshell)
- (defcustom eshell-directory-name
- (locate-user-emacs-file "eshell/" ".eshell/")
- "The directory where Eshell control files should be kept."
- :type 'directory
- :group 'eshell)
- (defun eshell (&optional arg)
- "Create an interactive Eshell buffer.
- The buffer used for Eshell sessions is determined by the value of
- `eshell-buffer-name'. If there is already an Eshell session active in
- that buffer, Emacs will simply switch to it. Otherwise, a new session
- will begin. A numeric prefix arg (as in `C-u 42 M-x eshell RET')
- switches to the session with that number, creating it if necessary. A
- nonnumeric prefix arg means to create a new session. Returns the
- buffer selected (or created)."
- (interactive "P")
- (assert eshell-buffer-name)
- (let ((buf (cond ((numberp arg)
- (get-buffer-create (format "%s<%d>"
- eshell-buffer-name
- arg)))
- (arg
- (generate-new-buffer eshell-buffer-name))
- (t
- (get-buffer-create eshell-buffer-name)))))
-
-
-
-
-
- (assert (and buf (buffer-live-p buf)))
- (pop-to-buffer buf)
- (unless (eq major-mode 'eshell-mode)
- (eshell-mode))
- buf))
- (defun eshell-return-exits-minibuffer ()
- (define-key eshell-mode-map [(control ?g)] 'abort-recursive-edit)
- (define-key eshell-mode-map [return] 'exit-minibuffer)
- (define-key eshell-mode-map [(control ?m)] 'exit-minibuffer)
- (define-key eshell-mode-map [(control ?j)] 'exit-minibuffer)
- (define-key eshell-mode-map [(meta return)] 'exit-minibuffer)
- (define-key eshell-mode-map [(meta control ?m)] 'exit-minibuffer))
- (defvar eshell-non-interactive-p nil
- "A variable which is non-nil when Eshell is not running interactively.
- Modules should use this variable so that they don't clutter
- non-interactive sessions, such as when using `eshell-command'.")
- (defun eshell-command (&optional command arg)
- "Execute the Eshell command string COMMAND.
- With prefix ARG, insert output into the current buffer at point."
- (interactive)
- (require 'esh-cmd)
- (unless arg
- (setq arg current-prefix-arg))
- (let ((eshell-non-interactive-p t))
-
- (minibuffer-with-setup-hook #'(lambda ()
- (eshell-mode)
- (eshell-return-exits-minibuffer))
- (unless command
- (setq command (read-from-minibuffer "Emacs shell command: "))
- (eshell-add-input-to-history command))))
- (unless command
- (error "No command specified!"))
-
-
-
-
-
- (if arg
- (setq command
- (concat command
- (format " >>> #<buffer %s>"
- (buffer-name (current-buffer))))))
- (save-excursion
- (let ((buf (set-buffer (generate-new-buffer " *eshell cmd*")))
- (eshell-non-interactive-p t))
- (eshell-mode)
- (let* ((proc (eshell-eval-command
- (list 'eshell-commands
- (eshell-parse-command command))))
- intr
- (bufname (if (and proc (listp proc))
- "*EShell Async Command Output*"
- (setq intr t)
- "*EShell Command Output*")))
- (if (buffer-live-p (get-buffer bufname))
- (kill-buffer bufname))
- (rename-buffer bufname)
-
-
-
- (when intr
- (if (eshell-interactive-process)
- (eshell-wait-for-process (eshell-interactive-process)))
- (assert (not (eshell-interactive-process)))
- (goto-char (point-max))
- (while (and (bolp) (not (bobp)))
- (delete-char -1)))
- (assert (and buf (buffer-live-p buf)))
- (unless arg
- (let ((len (if (not intr) 2
- (count-lines (point-min) (point-max)))))
- (cond
- ((= len 0)
- (message "(There was no command output)")
- (kill-buffer buf))
- ((= len 1)
- (message "%s" (buffer-string))
- (kill-buffer buf))
- (t
- (save-selected-window
- (select-window (display-buffer buf))
- (goto-char (point-min))
-
-
-
- (and intr temp-buffer-resize-mode
- (resize-temp-buffer-window)))))))))))
- (defun eshell-command-result (command &optional status-var)
- "Execute the given Eshell COMMAND, and return the result.
- The result might be any Lisp object.
- If STATUS-VAR is a symbol, it will be set to the exit status of the
- command. This is the only way to determine whether the value returned
- corresponding to a successful execution."
-
- (if (not command)
- (ignore
- (if (and status-var (symbolp status-var))
- (set status-var 0)))
- (with-temp-buffer
- (let ((eshell-non-interactive-p t))
- (eshell-mode)
- (let ((result (eshell-do-eval
- (list 'eshell-commands
- (list 'eshell-command-to-value
- (eshell-parse-command command))) t)))
- (assert (eq (car result) 'quote))
- (if (and status-var (symbolp status-var))
- (set status-var eshell-last-command-status))
- (cadr result))))))
- (define-obsolete-function-alias 'eshell-report-bug 'report-emacs-bug "23.1")
- (defun eshell-unload-all-modules ()
- "Unload all modules that were loaded by Eshell, if possible.
- If the user has require'd in any of the modules, or customized a
- variable with a :require tag (such as `eshell-prefer-to-shell'), it
- will be impossible to unload Eshell completely without restarting
- Emacs."
-
-
- (when (fboundp 'eshell-subgroups)
- (dolist (module (eshell-subgroups 'eshell))
-
-
-
-
- (if (featurep module)
- (ignore-errors
- (message "Unloading %s..." (symbol-name module))
- (unload-feature module)
- (message "Unloading %s...done" (symbol-name module)))))
- (message "Unloading eshell...done")))
- (run-hooks 'eshell-load-hook)
- (provide 'eshell)
|