Commit c8804c4f authored by Martin Rudalics's avatar Martin Rudalics

(Fget_buffer, Fbury_buffer, switch_to_buffer_1):

Rename arg "buffer" to "buffer_or_name".
(Fkill_buffer): Rename arg "buffer" to "buffer_or_name" and make
it optional.
(no_switch_window): Remove since the return value is not used.
(Fswitch_to_buffer):  Rename arg "buffer" to "buffer_or_name".
Consider window as dedicated when Fwindow_dedicated_p returns a
non-nil value.
parent 3645358a
...@@ -266,17 +266,18 @@ assoc_ignore_text_properties (key, list) ...@@ -266,17 +266,18 @@ assoc_ignore_text_properties (key, list)
} }
DEFUN ("get-buffer", Fget_buffer, Sget_buffer, 1, 1, 0, DEFUN ("get-buffer", Fget_buffer, Sget_buffer, 1, 1, 0,
doc: /* Return the buffer named NAME (a string). doc: /* Return the buffer named BUFFER-OR-NAME.
If there is no live buffer named NAME, return nil. BUFFER-OR-NAME must be either a string or a buffer. If BUFFER-OR-NAME
NAME may also be a buffer; if so, the value is that buffer. */) is a string and there is no buffer with that name, return nil. If
(name) BUFFER-OR-NAME is a buffer, return it as given. */)
register Lisp_Object name; (buffer_or_name)
register Lisp_Object buffer_or_name;
{ {
if (BUFFERP (name)) if (BUFFERP (buffer_or_name))
return name; return buffer_or_name;
CHECK_STRING (name); CHECK_STRING (buffer_or_name);
return Fcdr (assoc_ignore_text_properties (name, Vbuffer_alist)); return Fcdr (assoc_ignore_text_properties (buffer_or_name, Vbuffer_alist));
} }
DEFUN ("get-file-buffer", Fget_file_buffer, Sget_file_buffer, 1, 1, 0, DEFUN ("get-file-buffer", Fget_file_buffer, Sget_file_buffer, 1, 1, 0,
...@@ -1382,38 +1383,39 @@ Hook to be run (by `run-hooks', which see) when a buffer is killed.\n\ ...@@ -1382,38 +1383,39 @@ Hook to be run (by `run-hooks', which see) when a buffer is killed.\n\
The buffer being killed will be current while the hook is running.\n\ The buffer being killed will be current while the hook is running.\n\
See `kill-buffer'." See `kill-buffer'."
*/ */
DEFUN ("kill-buffer", Fkill_buffer, Skill_buffer, 1, 1, "bKill buffer: ", DEFUN ("kill-buffer", Fkill_buffer, Skill_buffer, 0, 1, "bKill buffer: ",
doc: /* Kill the buffer BUFFER. doc: /* Kill buffer BUFFER-OR-NAME.
The argument may be a buffer or the name of a buffer. The argument may be a buffer or the name of an existing buffer.
With a nil argument, kill the current buffer. Argument nil or omitted means kill the current buffer. Return t if the
buffer is actually killed, nil otherwise.
Value is t if the buffer is actually killed, nil otherwise.
This function calls `replace-buffer-in-windows' for cleaning up all
The functions in `kill-buffer-query-functions' are called with BUFFER as windows currently displaying the buffer to be killed. The functions in
the current buffer. If any of them returns nil, the buffer is not killed. `kill-buffer-query-functions' are called with the buffer to be killed as
the current buffer. If any of them returns nil, the buffer is not
The hook `kill-buffer-hook' is run before the buffer is actually killed. killed. The hook `kill-buffer-hook' is run before the buffer is
The buffer being killed will be current while the hook is running. actually killed. The buffer being killed will be current while the hook
is running.
Any processes that have this buffer as the `process-buffer' are killed Any processes that have this buffer as the `process-buffer' are killed
with SIGHUP. */) with SIGHUP. */)
(buffer) (buffer_or_name)
Lisp_Object buffer; Lisp_Object buffer_or_name;
{ {
Lisp_Object buf; Lisp_Object buffer;
register struct buffer *b; register struct buffer *b;
register Lisp_Object tem; register Lisp_Object tem;
register struct Lisp_Marker *m; register struct Lisp_Marker *m;
struct gcpro gcpro1; struct gcpro gcpro1;
if (NILP (buffer)) if (NILP (buffer_or_name))
buf = Fcurrent_buffer (); buffer = Fcurrent_buffer ();
else else
buf = Fget_buffer (buffer); buffer = Fget_buffer (buffer_or_name);
if (NILP (buf)) if (NILP (buffer))
nsberror (buffer); nsberror (buffer_or_name);
b = XBUFFER (buf); b = XBUFFER (buffer);
/* Avoid trouble for buffer already dead. */ /* Avoid trouble for buffer already dead. */
if (NILP (b->name)) if (NILP (b->name))
...@@ -1423,7 +1425,7 @@ with SIGHUP. */) ...@@ -1423,7 +1425,7 @@ with SIGHUP. */)
if (INTERACTIVE && !NILP (b->filename) if (INTERACTIVE && !NILP (b->filename)
&& BUF_MODIFF (b) > BUF_SAVE_MODIFF (b)) && BUF_MODIFF (b) > BUF_SAVE_MODIFF (b))
{ {
GCPRO1 (buf); GCPRO1 (buffer);
tem = do_yes_or_no_p (format2 ("Buffer %s modified; kill anyway? ", tem = do_yes_or_no_p (format2 ("Buffer %s modified; kill anyway? ",
b->name, make_number (0))); b->name, make_number (0)));
UNGCPRO; UNGCPRO;
...@@ -1456,7 +1458,7 @@ with SIGHUP. */) ...@@ -1456,7 +1458,7 @@ with SIGHUP. */)
since anything can happen within do_yes_or_no_p. */ since anything can happen within do_yes_or_no_p. */
/* Don't kill the minibuffer now current. */ /* Don't kill the minibuffer now current. */
if (EQ (buf, XWINDOW (minibuf_window)->buffer)) if (EQ (buffer, XWINDOW (minibuf_window)->buffer))
return Qnil; return Qnil;
if (NILP (b->name)) if (NILP (b->name))
...@@ -1469,16 +1471,16 @@ with SIGHUP. */) ...@@ -1469,16 +1471,16 @@ with SIGHUP. */)
{ {
struct buffer *other; struct buffer *other;
GCPRO1 (buf); GCPRO1 (buffer);
for (other = all_buffers; other; other = other->next) for (other = all_buffers; other; other = other->next)
/* all_buffers contains dead buffers too; /* all_buffers contains dead buffers too;
don't re-kill them. */ don't re-kill them. */
if (other->base_buffer == b && !NILP (other->name)) if (other->base_buffer == b && !NILP (other->name))
{ {
Lisp_Object buf; Lisp_Object buffer;
XSETBUFFER (buf, other); XSETBUFFER (buffer, other);
Fkill_buffer (buf); Fkill_buffer (buffer);
} }
UNGCPRO; UNGCPRO;
...@@ -1489,7 +1491,7 @@ with SIGHUP. */) ...@@ -1489,7 +1491,7 @@ with SIGHUP. */)
and give up if so. */ and give up if so. */
if (b == current_buffer) if (b == current_buffer)
{ {
tem = Fother_buffer (buf, Qnil, Qnil); tem = Fother_buffer (buffer, Qnil, Qnil);
Fset_buffer (tem); Fset_buffer (tem);
if (b == current_buffer) if (b == current_buffer)
return Qnil; return Qnil;
...@@ -1500,8 +1502,8 @@ with SIGHUP. */) ...@@ -1500,8 +1502,8 @@ with SIGHUP. */)
XSETBUFFER (tem, current_buffer); XSETBUFFER (tem, current_buffer);
if (EQ (tem, XWINDOW (minibuf_window)->buffer)) if (EQ (tem, XWINDOW (minibuf_window)->buffer))
{ {
tem = Fother_buffer (buf, Qnil, Qnil); tem = Fother_buffer (buffer, Qnil, Qnil);
if (EQ (buf, tem)) if (EQ (buffer, tem))
return Qnil; return Qnil;
} }
...@@ -1512,8 +1514,8 @@ with SIGHUP. */) ...@@ -1512,8 +1514,8 @@ with SIGHUP. */)
unlock_buffer (b); unlock_buffer (b);
#endif /* CLASH_DETECTION */ #endif /* CLASH_DETECTION */
GCPRO1 (buf); GCPRO1 (buffer);
kill_buffer_processes (buf); kill_buffer_processes (buffer);
UNGCPRO; UNGCPRO;
/* Killing buffer processes may run sentinels which may /* Killing buffer processes may run sentinels which may
...@@ -1526,9 +1528,9 @@ with SIGHUP. */) ...@@ -1526,9 +1528,9 @@ with SIGHUP. */)
tem = Vinhibit_quit; tem = Vinhibit_quit;
Vinhibit_quit = Qt; Vinhibit_quit = Qt;
replace_buffer_in_all_windows (buf); replace_buffer_in_all_windows (buffer);
Vbuffer_alist = Fdelq (Frassq (buf, Vbuffer_alist), Vbuffer_alist); Vbuffer_alist = Fdelq (Frassq (buffer, Vbuffer_alist), Vbuffer_alist);
frames_discard_buffer (buf); frames_discard_buffer (buffer);
Vinhibit_quit = tem; Vinhibit_quit = tem;
/* Delete any auto-save file, if we saved it in this session. /* Delete any auto-save file, if we saved it in this session.
...@@ -1723,96 +1725,82 @@ the current buffer's major mode. */) ...@@ -1723,96 +1725,82 @@ the current buffer's major mode. */)
return unbind_to (count, Qnil); return unbind_to (count, Qnil);
} }
/* If switching buffers in WINDOW would be an error, return
a C string saying what the error would be. */
char *
no_switch_window (window)
Lisp_Object window;
{
Lisp_Object tem;
if (EQ (minibuf_window, window))
return "Cannot switch buffers in minibuffer window";
tem = Fwindow_dedicated_p (window);
if (EQ (tem, Qt))
return "Cannot switch buffers in a dedicated window";
return NULL;
}
/* Switch to buffer BUFFER in the selected window. /* Switch to buffer BUFFER in the selected window.
If NORECORD is non-nil, don't call record_buffer. */ If NORECORD is non-nil, don't call record_buffer. */
Lisp_Object Lisp_Object
switch_to_buffer_1 (buffer, norecord) switch_to_buffer_1 (buffer_or_name, norecord)
Lisp_Object buffer, norecord; Lisp_Object buffer_or_name, norecord;
{ {
register Lisp_Object buf; register Lisp_Object buffer;
if (NILP (buffer)) if (NILP (buffer_or_name))
buf = Fother_buffer (Fcurrent_buffer (), Qnil, Qnil); buffer = Fother_buffer (Fcurrent_buffer (), Qnil, Qnil);
else else
{ {
buf = Fget_buffer (buffer); buffer = Fget_buffer (buffer_or_name);
if (NILP (buf)) if (NILP (buffer))
{ {
buf = Fget_buffer_create (buffer); buffer = Fget_buffer_create (buffer_or_name);
Fset_buffer_major_mode (buf); Fset_buffer_major_mode (buffer);
} }
} }
Fset_buffer (buf); Fset_buffer (buffer);
if (NILP (norecord)) if (NILP (norecord))
record_buffer (buf); record_buffer (buffer);
Fset_window_buffer (EQ (selected_window, minibuf_window) Fset_window_buffer (EQ (selected_window, minibuf_window)
? Fnext_window (minibuf_window, Qnil, Qnil) ? Fnext_window (minibuf_window, Qnil, Qnil)
: selected_window, : selected_window,
buf, Qnil); buffer, Qnil);
return buf; return buffer;
} }
DEFUN ("switch-to-buffer", Fswitch_to_buffer, Sswitch_to_buffer, 1, 2, DEFUN ("switch-to-buffer", Fswitch_to_buffer, Sswitch_to_buffer, 1, 2,
"(list (read-buffer-to-switch \"Switch to buffer: \"))", "(list (read-buffer-to-switch \"Switch to buffer: \"))",
doc: /* Select buffer BUFFER in the current window. doc: /* Make BUFFER-OR-NAME current and display it in the selected window.
If BUFFER does not identify an existing buffer, BUFFER-OR-NAME may be a buffer, a string, or nil. If BUFFER-OR-NAME is
nil, then this function chooses a buffer using `other-buffer'. If
BUFFER-OR-NAME is a string and does not identify an existing buffer,
then this function creates a buffer with that name. then this function creates a buffer with that name.
When called from Lisp, BUFFER may be a buffer, a string \(a buffer name), Optional second arg NORECORD non-nil means do not put this buffer at the
or nil. If BUFFER is nil, then this function chooses a buffer front of the list of recently selected ones. This function returns the
using `other-buffer'. buffer it switched to as a Lisp object.
Optional second arg NORECORD non-nil means
do not put this buffer at the front of the list of recently selected ones. If the selected window is the minibuffer window or dedicated to its
This function returns the buffer it switched to. buffer, use `pop-to-buffer' for displaying the buffer.
WARNING: This is NOT the way to work on another buffer temporarily WARNING: This is NOT the way to work on another buffer temporarily
within a Lisp program! Use `set-buffer' instead. That avoids messing with within a Lisp program! Use `set-buffer' instead. That avoids messing
the window-buffer correspondences. */) with the window-buffer correspondences. */)
(buffer, norecord) (buffer_or_name, norecord)
Lisp_Object buffer, norecord; Lisp_Object buffer_or_name, norecord;
{ {
char *err; char *err;
if (EQ (buffer, Fwindow_buffer (selected_window))) if (EQ (buffer_or_name, Fwindow_buffer (selected_window)))
{ {
/* Basically a NOP. Avoid signalling an error in the case where /* Basically a NOP. Avoid signalling an error in the case where
the selected window is dedicated, or a minibuffer. */ the selected window is dedicated, or a minibuffer. */
/* But do put this buffer at the front of the buffer list, /* But do put this buffer at the front of the buffer list, unless
unless that has been inhibited. Note that even if that has been inhibited. Note that even if BUFFER-OR-NAME is
BUFFER is at the front of the main buffer-list already, at the front of the main buffer-list already, we still want to
we still want to move it to the front of the frame's buffer list. */ move it to the front of the frame's buffer list. */
if (NILP (norecord)) if (NILP (norecord))
record_buffer (buffer); record_buffer (buffer_or_name);
return Fset_buffer (buffer); return Fset_buffer (buffer_or_name);
} }
err = no_switch_window (selected_window); if (EQ (minibuf_window, selected_window)
if (err) || !NILP (Fwindow_dedicated_p (selected_window)))
/* If can't display in current window, let pop-to-buffer /* We can't use the selected window so let `pop-to-buffer' try some
try some other window. */ other window. */
return call3 (intern ("pop-to-buffer"), buffer, Qnil, norecord); return call3 (intern ("pop-to-buffer"), buffer_or_name, Qnil, norecord);
else
return switch_to_buffer_1 (buffer, norecord); return switch_to_buffer_1 (buffer_or_name, norecord);
} }
DEFUN ("current-buffer", Fcurrent_buffer, Scurrent_buffer, 0, 0, 0, DEFUN ("current-buffer", Fcurrent_buffer, Scurrent_buffer, 0, 0, 0,
...@@ -2010,23 +1998,23 @@ set_buffer_temp (b) ...@@ -2010,23 +1998,23 @@ set_buffer_temp (b)
} }
DEFUN ("set-buffer", Fset_buffer, Sset_buffer, 1, 1, 0, DEFUN ("set-buffer", Fset_buffer, Sset_buffer, 1, 1, 0,
doc: /* Make the buffer BUFFER current for editing operations. doc: /* Make buffer BUFFER-OR-NAME current for editing operations.
BUFFER may be a buffer or the name of an existing buffer. BUFFER-OR-NAME may be a buffer or the name of an existing buffer. See
See also `save-excursion' when you want to make a buffer current temporarily. also `save-excursion' when you want to make a buffer current
This function does not display the buffer, so its effect ends temporarily. This function does not display the buffer, so its effect
when the current command terminates. ends when the current command terminates. Use `switch-to-buffer' or
Use `switch-to-buffer' or `pop-to-buffer' to switch buffers permanently. */) `pop-to-buffer' to switch buffers permanently. */)
(buffer) (buffer_or_name)
register Lisp_Object buffer; register Lisp_Object buffer_or_name;
{ {
register Lisp_Object buf; register Lisp_Object buffer;
buf = Fget_buffer (buffer); buffer = Fget_buffer (buffer_or_name);
if (NILP (buf)) if (NILP (buffer))
nsberror (buffer); nsberror (buffer_or_name);
if (NILP (XBUFFER (buf)->name)) if (NILP (XBUFFER (buffer)->name))
error ("Selecting deleted buffer"); error ("Selecting deleted buffer");
set_buffer_internal (XBUFFER (buf)); set_buffer_internal (XBUFFER (buffer));
return buf; return buffer;
} }
/* Set the current buffer to BUFFER provided it is alive. */ /* Set the current buffer to BUFFER provided it is alive. */
...@@ -2052,18 +2040,21 @@ DEFUN ("barf-if-buffer-read-only", Fbarf_if_buffer_read_only, ...@@ -2052,18 +2040,21 @@ DEFUN ("barf-if-buffer-read-only", Fbarf_if_buffer_read_only,
} }
DEFUN ("bury-buffer", Fbury_buffer, Sbury_buffer, 0, 1, "", DEFUN ("bury-buffer", Fbury_buffer, Sbury_buffer, 0, 1, "",
doc: /* Put BUFFER at the end of the list of all buffers. doc: /* Put BUFFER-OR-NAME at the end of the list of all buffers.
There it is the least likely candidate for `other-buffer' to return; There it is the least likely candidate for `other-buffer' to return;
thus, the least likely buffer for \\[switch-to-buffer] to select by default. thus, the least likely buffer for \\[switch-to-buffer] to select by
You can specify a buffer name as BUFFER, or an actual buffer object. default.
If BUFFER is nil or omitted, bury the current buffer.
Also, if BUFFER is nil or omitted, remove the current buffer from the The argument may be a buffer name or an actual buffer object. If
selected window if it is displayed there. */) BUFFER-OR-NAME is nil or omitted, bury the current buffer and remove it
(buffer) from the selected window if it is displayed there. */)
register Lisp_Object buffer; (buffer_or_name)
register Lisp_Object buffer_or_name;
{ {
Lisp_Object buffer;
/* Figure out what buffer we're going to bury. */ /* Figure out what buffer we're going to bury. */
if (NILP (buffer)) if (NILP (buffer_or_name))
{ {
Lisp_Object tem; Lisp_Object tem;
XSETBUFFER (buffer, current_buffer); XSETBUFFER (buffer, current_buffer);
...@@ -2082,12 +2073,9 @@ selected window if it is displayed there. */) ...@@ -2082,12 +2073,9 @@ selected window if it is displayed there. */)
} }
else else
{ {
Lisp_Object buf1; buffer = Fget_buffer (buffer_or_name);
if (NILP (buffer))
buf1 = Fget_buffer (buffer); nsberror (buffer_or_name);
if (NILP (buf1))
nsberror (buffer);
buffer = buf1;
} }
/* Move buffer to the end of the buffer list. Do nothing if the /* Move buffer to the end of the buffer list. Do nothing if the
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment