aboutsummaryrefslogtreecommitdiffstats
path: root/lisp/shell.el
diff options
context:
space:
mode:
authorStefan Monnier2022-05-27 09:14:40 -0400
committerStefan Monnier2022-05-27 09:14:40 -0400
commitf8b2a01a9eea84e374ec65bdfb0ddf31e486d374 (patch)
tree33e3c8e3ea3083e2b05a39eb33241949ff31da33 /lisp/shell.el
parent8399c6a82127f3c6a2e5f781122567d27ae799f8 (diff)
downloademacs-f8b2a01a9eea84e374ec65bdfb0ddf31e486d374.tar.gz
emacs-f8b2a01a9eea84e374ec65bdfb0ddf31e486d374.zip
* lisp/shell.el (shell): Query shell file name from `interactive`
This avoids the use of the brittle `called-interactively-p` and makes it easier to start a shell buffer running another shell than your usual one.
Diffstat (limited to 'lisp/shell.el')
-rw-r--r--lisp/shell.el36
1 files changed, 19 insertions, 17 deletions
diff --git a/lisp/shell.el b/lisp/shell.el
index 4e65fccf9e5..1fcd1a1d1cc 100644
--- a/lisp/shell.el
+++ b/lisp/shell.el
@@ -719,7 +719,7 @@ Sentinels will always get the two parameters PROCESS and EVENT."
719 (insert (format "\nProcess %s %s\n" process event)))))) 719 (insert (format "\nProcess %s %s\n" process event))))))
720 720
721;;;###autoload 721;;;###autoload
722(defun shell (&optional buffer) 722(defun shell (&optional buffer file-name)
723 "Run an inferior shell, with I/O through BUFFER (which defaults to `*shell*'). 723 "Run an inferior shell, with I/O through BUFFER (which defaults to `*shell*').
724Interactively, a prefix arg means to prompt for BUFFER. 724Interactively, a prefix arg means to prompt for BUFFER.
725If `default-directory' is a remote file name, it is also prompted 725If `default-directory' is a remote file name, it is also prompted
@@ -730,6 +730,8 @@ If BUFFER exists and shell process is running, just switch to BUFFER.
730Program used comes from variable `explicit-shell-file-name', 730Program used comes from variable `explicit-shell-file-name',
731 or (if that is nil) from the ESHELL environment variable, 731 or (if that is nil) from the ESHELL environment variable,
732 or (if that is nil) from `shell-file-name'. 732 or (if that is nil) from `shell-file-name'.
733Non-interactively, it can also be specified via the FILE-NAME arg.
734
733If a file `~/.emacs_SHELLNAME' exists, or `~/.emacs.d/init_SHELLNAME.sh', 735If a file `~/.emacs_SHELLNAME' exists, or `~/.emacs.d/init_SHELLNAME.sh',
734it is given as initial input (but this may be lost, due to a timing 736it is given as initial input (but this may be lost, due to a timing
735error, if the shell discards input when it starts up). 737error, if the shell discards input when it starts up).
@@ -771,7 +773,20 @@ Make the shell buffer the current buffer, and return it.
771 (expand-file-name 773 (expand-file-name
772 (read-directory-name 774 (read-directory-name
773 "Default directory: " default-directory default-directory 775 "Default directory: " default-directory default-directory
774 t nil)))))))) 776 t nil))))))
777 ;; On remote hosts, the local `shell-file-name' might be useless.
778 (when (and (file-remote-p default-directory)
779 (null explicit-shell-file-name)
780 (null (getenv "ESHELL")))
781 ;; `expand-file-name' shall not add the MS Windows volume letter
782 ;; (Bug#49229).
783 (replace-regexp-in-string
784 "^[[:alpha:]]:" ""
785 (file-local-name
786 (expand-file-name
787 (read-file-name "Remote shell path: " default-directory
788 shell-file-name t shell-file-name
789 #'file-remote-p)))))))
775 (setq buffer (if (or buffer (not (derived-mode-p 'shell-mode)) 790 (setq buffer (if (or buffer (not (derived-mode-p 'shell-mode))
776 (comint-check-proc (current-buffer))) 791 (comint-check-proc (current-buffer)))
777 (get-buffer-create (or buffer "*shell*")) 792 (get-buffer-create (or buffer "*shell*"))
@@ -782,21 +797,8 @@ Make the shell buffer the current buffer, and return it.
782 (pop-to-buffer buffer display-comint-buffer-action) 797 (pop-to-buffer buffer display-comint-buffer-action)
783 798
784 (with-connection-local-variables 799 (with-connection-local-variables
785 ;; On remote hosts, the local `shell-file-name' might be useless. 800 (when file-name
786 (when (and (file-remote-p default-directory) 801 (setq-local explicit-shell-file-name file-name))
787 (called-interactively-p 'any)
788 (null explicit-shell-file-name)
789 (null (getenv "ESHELL")))
790 ;; `expand-file-name' shall not add the MS Windows volume letter
791 ;; (Bug#49229).
792 (setq-local explicit-shell-file-name
793 (replace-regexp-in-string
794 "^[[:alpha:]]:" ""
795 (file-local-name
796 (expand-file-name
797 (read-file-name "Remote shell path: " default-directory
798 shell-file-name t shell-file-name
799 #'file-remote-p))))))
800 802
801 ;; Rain or shine, BUFFER must be current by now. 803 ;; Rain or shine, BUFFER must be current by now.
802 (unless (comint-check-proc buffer) 804 (unless (comint-check-proc buffer)