What is the difference between pop-to-buffer-same-window and switch-to-buffer?

switch-to-buffer-other-window is basically an alias for pop-to-buffer, so I'm surprised that pop-to-buffer-same-window is not basically an alias for switch-to-buffer.

  • 2
    Please look at the doc-string for each function at issue and edit your question if you still have any questions regarding the differences between each function. M-x describe-function or C-h f. If you are really curious, then use M-x find-function to visit the source-code. In addition, please look at the doc-strings for the other functions mentioned in the question -- including the one that you believe is an alias.
    – lawlist
    Oct 11, 2016 at 6:03
  • I've looked at the doc-string and source code, thanks. If I'd figured it out from that, I wouldn't have posted the question. And yes, I know switch-to-buffer-other-window not a real "alias" for pop-to-buffer, just a thin wrapper--that's why I said "basically". Oct 11, 2016 at 6:32
  • 2
    Please specify just what is unclear to you, after having read the doc, as specifically as possible.
    – Drew
    Oct 11, 2016 at 15:07
  • 1
    switch-to-buffer opens a buffer in the current window. pop-to-buffer opens a buffer in a different window. switch-to-buffer-other-window is a thin wrapper around ("alias" for) pop-to-buffer. So why isn't pop-to-buffer-same-window similarly a thin wrapper around ("alias" for) switch-to-buffer? Oct 12, 2016 at 6:34

1 Answer 1


The difference is that pop-to-buffer-same-window doesn't insist as much about using the same window.

Historically, switch-to-buffer has been used for 2 purposes:

  • change which buffer is shown in the selected window.
  • display the specified buffer.

In many cases you can do both at the same time, but in some cases you have to choose between the two (e.g. when the selected-window is a minibuffer window). switch-to-buffer cares more about the first, while pop-to-buffer-same-window cares more about the second.

Personally I recommend you stay away from switch-to-buffer in Elisp code (in 99% of the cases where I see switch-to-buffer in Elisp code, the code will misbehave when used with my config). Better use pop-to-buffer-same-window or use set-window-buffer depending on your specific needs.


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.