I have a little issue, not too big but a little annoying.

Suppose I open 3 windows in my Emacs GNU like this:

enter image description here

Once I position myself in any window (the largest one, in this screenshot) and press/type M-x shell, the sub shell opens in the next window, which is in this case the first one.

I wonder why this happens and how to fix it?

  • 1
    The following link demonstrates how to make a shell buffer that does not display in any window by default, and then there are a variety of examples demonstrating how to display the shell buffer with built-in functions and there is also a custom function to display it wherever you want; e.g., above, below, left, right. emacs.stackexchange.com/a/28924/2287 – lawlist Jul 13 '18 at 14:53
  • (I wonder if this question might be a duplicate...) – Drew Jul 13 '18 at 18:00

By default emacs will display the shell buffer in a different window from the selected one. You can override this by using display-buffer-alist to specify different actions based on the buffer name. In this case, setting it to

(setq display-buffer-alist '((".*\\*shell\\*.*" display-buffer-same-window (nil))))

will get you the behaviour you want, although it's probably better to do

M-x customize-variable RET display-buffer-alist RET

There are many options available for how windows are chosen, read

C-h f display-buffer

for the gory details.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.