Subject: Re: bug#4808: 23.1.50; calc-quit move point to another window

From: martin rudalics <[email-masked]>
Date: Tue, 27 Oct 2009 09:31:10 +0100

>> Lately I have been using a three-window setup for writing in LaTeX and I
 >> have found that calc move point to another window, which I am not sure
 >> is desirable.
 >>
 >> My frame setup is as follows with point in window 1.
 >>
 >>     +------------------+----------+
 >>     |                  |          |
 >>     |                  |     2    |
 >>     |                  |          |
 >>     |                  |          |
 >>     |         1        +----------+
 >>     |                  |          |
 >>     |                  |     3    |
 >>     |                  |          |
 >>     |                  |          |
 >>     +------------------+----------+
 >>
 >> Now `M-x calc' and then quit it with 'q'. You will see point moved to
 >> window 2. This is reproducible with Emacs -q.

I can't reproduce your problem but I haven't built from CVS sources for
quite a while.  The algorithm for selecting a window after deleting the
selected one is contrived and I never understood it completely.
Conceptually, it should select the window "preceding" the deleted one
"in the cyclic ordering of windows".  Only if no preceding window
exists, the window "following" the deleted one "in the cyclic ordering
of windows" should be chosen.  However, since a preceding (previous) and
following (next) window should invariantly exist for any window, this
part of the selection procedure is what I fail to understand.

In your case the window returned by `previous-window' when you are in
the calc window (which here pops up below window 1) should give you the
window that will be selected after the calc window got deleted.  On my
Emacs window 1 gets selected.  Can you tell whether there was a change
in behavior over the past weeks or months?

 > I'm not sure this is a Calc problem; `calc-quit' will (aside from some
 > bookkeeping) delete the calc window and bury the buffer.  If, in the
 > above configuration, you split window 1
 >
 >      +------------------+----------+
 >      |                  |          |
 >      |                  |     2    |
 >      |        1         |          |
 >      |                  |          |
 >      |------------------+----------+
 >      |                  |          |
 >      |        4         |     3    |
 >      |                  |          |
 >      |                  |          |
 >      +------------------+----------+
 >
 > (and have 4 a different buffer, of course),

The buffer identity should not matter.

 > move the cursor from window
 > 1 to window 4, then delete window 4, the cursor will end up in window 2.
 > This seems more like a quirk of deleting windows than anything else.
 > Calc could make efforts to avoid this particular situation, but relying
 > on standard Emacs behavior seems like the best choice.

It's difficult to judge your example since I don't know whether your
first split was horizontally or vertically.  However, iIf window 2 _is_
the window preceding window 4 in the "cyclic ordering of windows" you
essentially get the behavior explained above.

For some reason here I can never get window 2 selected when deleting
window 4 so I'm merely surprised by the behavior of _my_ Emacs ;-)

martin