Skip to content

Instantly share code, notes, and snippets.

@wfarr
Created November 27, 2008 05:28
Show Gist options
  • Select an option

  • Save wfarr/29689 to your computer and use it in GitHub Desktop.

Select an option

Save wfarr/29689 to your computer and use it in GitHub Desktop.
DEFUN ("switch-to-buffer", Fswitch_to_buffer, Sswitch_to_buffer, 1, 2,
"(list (read-buffer-to-switch \"Switch to buffer: \"))",
doc: /* Make BUFFER-OR-NAME current and display it in selected window.
BUFFER-OR-NAME may be a buffer, a string \(a buffer name), or
nil. Return the buffer switched to.
If BUFFER-OR-NAME is a string and does not identify an existing
buffer, create a new buffer with that name. Interactively, if
`confirm-nonexistent-file-or-buffer' is non-nil, request
confirmation before creating a new buffer. If BUFFER-OR-NAME is
nil, switch to buffer returned by `other-buffer'.
Optional second arg NORECORD non-nil means do not put this buffer
at the front of the list of recently selected ones. This
function returns the buffer it switched to as a Lisp object.
If the selected window is the minibuffer window or dedicated to
its buffer, use `pop-to-buffer' for displaying the buffer.
WARNING: This is NOT the way to work on another buffer temporarily
within a Lisp program! Use `set-buffer' instead. That avoids
messing with the window-buffer correspondences. */)
(buffer_or_name, norecord)
Lisp_Object buffer_or_name, norecord;
{
char *err;
if (EQ (buffer_or_name, Fwindow_buffer (selected_window)))
{
/* Basically a NOP. Avoid signalling an error in the case where
the selected window is dedicated, or a minibuffer. */
/* But do put this buffer at the front of the buffer list, unless
that has been inhibited. Note that even if BUFFER-OR-NAME is
at the front of the main buffer-list already, we still want to
move it to the front of the frame's buffer list. */
if (NILP (norecord))
record_buffer (buffer_or_name);
return Fset_buffer (buffer_or_name);
}
if (EQ (minibuf_window, selected_window)
|| !NILP (Fwindow_dedicated_p (selected_window)))
/* We can't use the selected window so let `pop-to-buffer' try some
other window. */
return call3 (intern ("pop-to-buffer"), buffer_or_name, Qnil, norecord);
else
return switch_to_buffer_1 (buffer_or_name, norecord);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment