Subject: bug#47300: delete-window to select window with same position

From: martin rudalics <[email-masked]>
Date: Thu, 27 May 2021 17:20:51 +0200

+	 (when (and (>= x (nth 0 edges)) (< x (nth 2 edges))
+		    (>= y (nth 1 edges)) (< y (nth 3 edges)))

We have to mention the "<" somewhere.  For two side-by-side windows with
the right window's point at 1, we obviously must avoid the left window's
right edge because the X, Y coordinates set by pos_visible_p are the top
left edge of the character box at that position, i.e., 0, 0.

But OTOH the "<" leaves the right edge of a frame's rightmost window
unhandled and someone might use that function for other purposes.

[...]

It would be a tad more elegant to just save `posn-at-point' here ...

+              (setq posn-at-point-x (+ (nth 0 edges) (car posn-at-point))
+                    posn-at-point-y (+ (nth 1 edges) (cdr posn-at-point))))))
  	;; Actually delete WINDOW.
  	(delete-window-internal window)
  	(window--pixel-to-total frame horizontal)
-	(when (and frame-selected

... and delay extracting its car and cdr until here.

+        (when (and posn-at-point-x posn-at-point-y
+		   (setq window-at-posn-at-point
+			 (window-at-pos posn-at-point-x posn-at-point-y frame)))

I'd still urge you to transfer the `get-mru-window' call here too, that
is, the entire

	  /* Now look whether `get-mru-window' gets us something.  */
	  mru_window = call1 (Qget_mru_window, frame);
	  if (WINDOW_LIVE_P (mru_window)
	      && EQ (XWINDOW (mru_window)->frame, frame))
	    new_selected_window = mru_window;

	  /* If all ended up well, we now promote the mru window.  */
	  if (EQ (FRAME_SELECTED_WINDOW (f), selected_window))
	    Fselect_window (new_selected_window, Qnil);
	  else
	    fset_selected_window (f, new_selected_window);

block, and to include the

         (when (and frame-selected
		   (window-parameter
		    (frame-selected-window frame) 'no-other-window))
	  ;; `delete-window-internal' has selected a window that should
	  ;; not be selected, fix this here.
	  (other-window -1 frame))

so we can avoid selecting a new window up to four times when deleting a
window (the one remaining call in `delete-window-internal' does not
record the window and has to stay there).  It's simply not nice to do
that.

martin