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?
Asked
Active
Viewed 7,251 times
5

Name
- 7,689
- 4
- 38
- 84
-
1The function `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 function `eshell` over the `.emacs` or `init.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 for `shell` 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
2 Answers
9
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)))

wasamasa
- 21,803
- 1
- 65
- 97
5
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
.

Dan
- 32,584
- 6
- 98
- 168
-
-
@Name: you could probably adapt this code to write some advice for `shell`. – Dan Jun 30 '15 at 20:26