Is there a command that allows me to have my cursor switch windows to a specified buffer? Something that looks like
(switch-to-specific-window-command "buffer-name")
Is there a command that allows me to have my cursor switch windows to a specified buffer? Something that looks like
(switch-to-specific-window-command "buffer-name")
Command 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
.
Command 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)))