Subject: bug#6400: I want to stay with a sibling window

From: Lennart Borgman <[email-masked]>
Date: Fri, 11 Jun 2010 10:27:14 +0200

A small patch to make the selected window one of the siblings when the
selected window is deleted.

I do not understand the code so I am not sure this is correct. Martin?
=== modified file 'src/window.c'
--- trunk/src/window.c	2010-06-07 18:28:02 +0000
+++ patched/src/window.c	2010-06-11 08:17:43 +0000
@@ -1563,6 +1563,7 @@
   register struct window *p;
   register struct window *par;
   struct frame *f;
+  int did_select = 0;
 
   /* Because this function is called by other C code on non-leaf
      windows, the CHECK_LIVE_WINDOW macro would choke inappropriately,
@@ -1628,7 +1629,10 @@
 	   delete the selected window on any other frame, we shouldn't do
 	   anything but set the frame's selected_window slot.  */
 	if (EQ (FRAME_SELECTED_WINDOW (f), selected_window))
-	  Fselect_window (swindow, Qnil);
+          {
+            Fselect_window (swindow, Qnil);
+            did_select = 1;
+          }
 	else
 	  FRAME_SELECTED_WINDOW (f) = swindow;
       }
@@ -1758,6 +1762,10 @@
   /* Adjust glyph matrices. */
   adjust_glyphs (f);
   UNBLOCK_INPUT;
+
+  if (did_select)
+    if (!NILP (sib))
+      Fselect_window (sib, Qnil);
 }

@@ -3765,7 +3773,7 @@
       window = display_buffer (buf, Qnil, Qnil);
 
       if (!EQ (XWINDOW (window)->frame, selected_frame))
-	Fmake_frame_visible (WINDOW_FRAME (XWINDOW (window)));
+	Fmake_frame_visible (WINDOW_FRAME (XWINDOW (window)), Qnil);
       Vminibuf_scroll_window = window;
       w = XWINDOW (window);
       XSETFASTINT (w->hscroll, 0);