Subject: bug#3949: 23.1.50; C-x 0 should go to a sister window if possible

From: martin rudalics <[email-masked]>
Date: Sat, 01 Aug 2009 15:12:28 +0200

>  >    C-x 1
 >  >    C-x 3
 >  >    windmove-right
 >  >    C-x 2
 >  >    windmove-down
 >  >    C-x 0
 >  >
 >  > For me it stops in the left window, not the right as I expect.
 >
 > Looks like a bug indeed.  It behaves this way in the current trunk but
 > doesn't so in my Emacs.  I'll have to look into this.

OK the problem is with the following assignment in delete_window:

	/* Otherwise, try another window for SWINDOW.  */
	swindow = Fnext_window (swindow, Qlambda, Qnil);

This will fail to pick a useful window when deleting the bottom-right
window of a frame.  I use

	/* Otherwise, try another window for SWINDOW.  */
	swindow = Fprevious_window (swindow, Qlambda, Qnil);

which is better for me but fails miserably when deleting the
top-left window of a frame.  So maybe we need something like the
attached patch.  Could you try it?

martin
*** window.c.~1.639.~	2009-07-04 17:09:38.265625000 +0200
--- window.c	2009-08-01 15:06:48.906250000 +0200
***************
*** 1596,1602 ****
  	if (!EQ (window, pwindow))
  	  break;
  	/* Otherwise, try another window for SWINDOW.  */
! 	swindow = Fnext_window (swindow, Qlambda, Qnil);
  
  	/* If we get back to the frame's selected window,
  	   it means there was no acceptable alternative,
--- 1596,1605 ----
  	if (!EQ (window, pwindow))
  	  break;
  	/* Otherwise, try another window for SWINDOW.  */
! 	if (NILP (XWINDOW (swindow)->prev))
! 	  swindow = Fnext_window (swindow, Qlambda, Qnil);
! 	else
! 	  swindow = Fprevious_window (swindow, Qlambda, Qnil);
  
  	/* If we get back to the frame's selected window,
  	   it means there was no acceptable alternative,