Since a relatively recent laptop re-install, whenever I M-x shell-mode (usually with the default shell buffer already running somewhere), the shell doesn't appear in the currently active window, instead it opens in a different one. Almost entirely always the one I don't want it to open in.

This seems to be new behaviour - my iMac that shares the same .emacs.d doesn't do this.

I can't find any obvious config variable to change this behaviour.

Help :)

  • Is the Emacs version the same?
    – Drew
    Commented Aug 2, 2017 at 2:04
  • This is due to a difference in behavior as of emacs 25.1. See this issue for example.
    – InHarmsWay
    Commented Oct 1, 2017 at 12:49

1 Answer 1


The variable 'display-buffer-alist controls how Emacs chooses the window to display the buffer in.

The value of this option is an alist mapping conditions to display actions. Each condition may be either a regular expression matching a buffer name or a function that takes two arguments: a buffer name and the action argument passed to display-buffer. If the name of the buffer passed to display-buffer either matches a regular expression in this alist or the function specified by a condition returns non-nil, then display-buffer uses the corresponding display action to display the buffer.

I'm not sure why the behavior you're seeing changed, but we can make it open the buffer in the same window in this way:

(add-to-list 'display-buffer-alist
     '("^\\*shell\\*$" . (display-buffer-same-window)))

Other possible functions that can be used to configure these actions can be found here.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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