[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]


From: Luc Teirlinck
Subject: bury-buffer
Date: Thu, 11 Jul 2002 19:52:07 -0500 (CDT)

There is a problem with bury-buffer.  Its documentation string says
that, with no argument or an argument of nil, it is going to remove
the current buffer from the selected window "if it is displayed
there".  The problem is that it removes any buffer displayed in the
selected window whether current or not.

Just do:

M-: (with-temp-buffer (bury-buffer))

This should not have any effect whatsoever.  It creates a temporary
buffer, makes it current, buries it and kills it, supposedly then
restoring the original current buffer.  This is not what happens. The
original current buffer disappears from the screen.  It did not really
get buried, it is still second in the buffer list after the newly
selected buffer.  All very confusing.

Clearly, (with-temp-buffer (bury-buffer)) is a pretty useless piece of

But the behavior of bury-buffer does cause actual problems, for
instance in ielm.  One often plays around in ielm with a "working
buffer" which is the current buffer during evaluation of forms.
Testing pieces of code involving burying buffers makes the ielm buffer
disappear from the screen, although it is not current when the
(bury-buffer) gets executed.

I tracked the problem down to the C code.  I can program C, but I am
not very familiar with the Emacs C code.

>From the emacs21.2.90 code of buffer.c:   

DEFUN ("bury-buffer", Fbury_buffer, Sbury_buffer, 0, 1, "",
  "Put BUFFER at the end of the list of all buffers.\n\
There it is the least likely candidate for `other-buffer' to
thus, the least likely buffer for \\[switch-to-buffer] to select by
If BUFFER is nil or omitted, bury the current buffer.\n\
Also, if BUFFER is nil or omitted, remove the current buffer from
selected window if it is displayed there.")
     register Lisp_Object buffer;
  /* Figure out what buffer we're going to bury.  */
  if (NILP (buffer))
      XSETBUFFER (buffer, current_buffer);

      /* If we're burying the current buffer, unshow it.  */
      Fswitch_to_buffer (Fother_buffer (buffer, Qnil, Qnil), Qnil);


/* If we're burying the current buffer, unshow it.  */

Immediately following that comment, we need an extra if-statement:

      if (...)
         Fswitch_to_buffer (Fother_buffer (buffer, Qnil, Qnil), Qnil);

where (...) should check whether the current buffer is, in fact,
displayed in the selected window.  Since I am not terribly familiar
with the Emacs C code, I do not know the exact semantics, but this
probably is relatively easy for somebody used to play around with the
Emacs C sources.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]