By M-x eshell
or M-x shell
Emacs opens a shell
or an eshell
in the current window.
How to open this shell
or eshell
in a new window?
Here's a simple command to open a shell
in a new window:
(defun shell-other-window ()
"Open a `shell' in a new window."
(interactive)
(let ((buf (shell)))
(switch-to-buffer (other-buffer buf))
(switch-to-buffer-other-window buf)))
Edit: If you want shell
to open in a new frame rather than new window, replace switch-to-buffer-other-window
with switch-to-buffer-other-frame
.
-
-
@Name: you could probably adapt this code to write some advice for
shell
. – Dan♦ Jun 30 '15 at 20:26
The canonical way of altering the display behaviour for a buffer is to customize display-buffer-alist
:
(setq display-buffer-alist '(("\\`\\*e?shell" display-buffer-pop-up-window)))
(setq display-buffer-alist '(("\\`\\*e?shell" display-buffer-pop-up-frame)))
It's a bit easier with my shackle package though:
(setq shackle-rules '(("\\`\\*e?shell" :regexp t :popup t)))
(setq shackle-rules '(("\\`\\*e?shell" :regexp t :frame t)))
eshell
is only 15 lines of actual code (excluding the doc-string). In my opinion, there is no need to advice or write a fixer function. Instead, just copy the functioneshell
over the.emacs
orinit.el
file and call it something new -- e.g.,eshell-other-window
-- change(pop-to-buffer-same-window buf)
to(switch-to-buffer-other-window buf)
. Creating a new function forshell
can be done much the same way -- it doesn't really matter that it's a few more lines long, because you will only be changing one line of code and changing the name of the function itself. – lawlist Jun 30 '15 at 21:59