Subject: RE: bug#5405: select-frame losing current-buffer

From: "Drew Adams" <[email-masked]>
Date: Sun, 17 Jan 2010 13:26:40 -0800

> > > The documentation of make-frame says that current-buffer 
> > > continues to selected in the new frame.  The
> > > documentation of select-frame doesn't
> > > say anything about the matter, but one would normally 
> > > expect that the current-buffer should still remain the same.  
...
> > > I presume that the space at the beginning of the buffer name is
> > > a partial cause of this misbehaviour.
> > 
> > This is deliberate behavior dating back about a decade 
> > (frame.c:392). Buffers whose names start with a space are
> > considered "hidden buffers" that should not ordinarily be
> > displayed (e.g. they don't show up in M-x list-buffers either).  
> > I'll update the documentation to mention this.
>
> Thanks very much for the quick response.  But I am not convinced the
> hidden buffer idea explains the behaviour I found.  Before doing
> select-frame, the "hidden buffer" is the current buffer.  For whatever
> reason, the user or the code chose it as the current buffer.  I don't
> believe that the buffer should be forcibly dumped and the focus placed
> on some other random buffer that happens to be around.
> 
> This behaviour was found in maintaining VM which, for some indepdent
> reasons, chose a buffer name with a leading space, and some serious
> buffer corruption resulted from it.  This seems dangerous, undesirable
> behaviour. 
> 
> I have now modified VM to avoid the leading space.  So the issue
> doesn't affect me any more.  But it took me a day's labour to find the
> problem.  I hope there won't be others who will get simiarly burned.

Without speaking directly to what `select-frame'/`make-frame' should do in this
regard, let me say that speaking in terms of "normally expect" (Uday) and
"should not ordinarily" (Yidong) simply begs the question. No such general rule
can answer the question completely for this particular situation.

By _default_, in many common situations, such buffers are hidden or ignored in
some _particular sense_ - for example, as completion candidates. That does not
mean that they must or should be ignored in all contexts, or that users should
not have a way to override a default behavior that ignores them.

The reason for such a general/default/common treatment is more important than
the "rule" itself, as only it provides guidance. The reason is that not ignoring
such buffers can distract or confuse users. Users _typically_ do not need to
consider such buffers - they just get in the way. But the fact that users _can_
consider them if they want (including for completion) speaks to not casting such
a generally helpful rule in concrete.

IOW, the question was raised - for `select-frame'/`make-frame' in particular -
and it is still raised (unanswered). The argument that such buffers must by
definition be ignored is not a valid one. It begs the question to be answered -
both generally, and in this particular case.

Wrt `select-frame'/`make-frame': I'm not sure what the right behavior is. If, as
Uday says, the "hidden" buffer was already chosen then, analogously to
completion when the user explicitly types a pattern that chooses an otherwise
hidden buffer, that choice should probably be respected. If the user types
`foo.log' or ` *foo*' during completion, we don't refuse to give access to that
buffer under the pretext that it is a hidden buffer.

If a program or user has already chosen, then we should probably let it be. But
there might be other considerations for this particular case, which would also
need to be taken into account - dunno. Only attention to the details can help,
not some general rule about a priori hiddenness.