Is there a command that allows me to have my cursor switch windows to a specified buffer? Something that looks like
Emacs Stack Exchange is a question and answer site for those using, extending or developing Emacs. It only takes a minute to sign up.Sign up to join this community
switch-to-buffer, bound to
C-x b, does what you're looking for. Likewise,
switch-to-buffer-other-window, bound to
C-x 4 b, and
switch-to-buffer-other-frame, bound to
C-x 5 b.
pop-to-buffer also does what you request, slightly differently.
From your comments, it's not clear what you want. The goalposts seem to be moving...
Now you seem to say you want to do nothing if the buffer is already in the
selected-window? In that case,
pop-to-buffer does just what you want, I think. Have you tried it?
Or if you don't want to use
pop-to-buffer, but that is anyway what you want (do nothing if already visiting the buffer in the selected window), then this does that also:
(defun foo (buffer) (interactive "b") (unless (equal (get-buffer buffer) (window-buffer (selected-window))) (switch-to-buffer-other-window buffer)))