Subject: bug#71386: 29.1; Frame is auto-deleted even when it has multiple tabs

From: martin rudalics <[email-masked]>
Date: Fri, 4 Apr 2025 09:43:21 +0200

> Looks right to restrict it to the selected frame.
 > (I don't know if this should be installed since
 > it only gives an unexpected result in one minor test.)

Hmmm...  When the frame is deleted or not the selected one, we should
try to select the one that contains the window that was selected before
calling 'display-buffer'.  When the frame is not deleted and is the
already selected one, I think we should keep it alone.  Patch attached.

martin

diff --git a/lisp/window.el b/lisp/window.el
index d1d869a83b8..cdd6b932502 100644
--- a/lisp/window.el
+++ b/lisp/window.el
@@ -5335,13 +5335,19 @@ quit-restore-window-no-switch
   :version "31.1"
   :group 'windows)
 
-(defun window--quit-restore-select-window (window)
+(defun window--quit-restore-select-window (window &optional frame)
   "Select WINDOW after having quit another one.
 Do not select an inactive minibuffer window."
   (when (and (window-live-p window)
              (or (not (window-minibuffer-p window))
                  (minibuffer-window-active-p window)))
-    (select-window window)))
+    ;; If WINDOW is not on the selected frame, don't switch to
+    ;; another frame.
+    (unless (and (eq frame (selected-frame))
+		 (not (eq frame (window-frame window))))
+      (setq frame (window-frame window))
+      (set-frame-selected-window frame window)
+      (select-frame-set-input-focus frame))))
 
 (defun quit-restore-window (&optional window bury-or-kill)
   "Quit WINDOW and deal with its buffer.
@@ -5400,6 +5406,7 @@ quit-restore-window
                           (unless (eq (car buf) buffer)
                             (throw 'prev-buffer (car buf))))))
          (dedicated (window-dedicated-p window))
+	 (frame (window-frame window))
 	 quad entry reset-prev)
     (cond
      ;; First try to delete dedicated windows that are not side windows.
@@ -5407,7 +5414,7 @@ quit-restore-window
            (window--delete
 	    window 'dedicated (memq bury-or-kill '(kill killing))))
       ;; If the previously selected window is still alive, select it.
-      (window--quit-restore-select-window quit-restore-2))
+      (window--quit-restore-select-window quit-restore-2 frame))
      ((and (not prev-buffer)
 	   (or (memq (nth 1 quit-restore) '(frame tab))
 	       (and (eq (nth 1 quit-restore) 'window)
@@ -5419,7 +5426,7 @@ quit-restore-window
 	   ;; Delete WINDOW if possible.
 	   (window--delete window nil (eq bury-or-kill 'kill)))
       ;; If the previously selected window is still alive, select it.
-      (window--quit-restore-select-window quit-restore-2))
+      (window--quit-restore-select-window quit-restore-2 frame))
      ((and (or (and quit-restore-window-no-switch (not prev-buffer))
 	       ;; Ignore first of the previous buffers if
 	       ;; 'quit-restore-window-no-switch' says so.
@@ -5429,7 +5436,7 @@ quit-restore-window
 	   (window--delete
 	    window nil (memq bury-or-kill '(kill killing))))
       ;; If the previously selected window is still alive, select it.
-      (window--quit-restore-select-window quit-restore-2))
+      (window--quit-restore-select-window quit-restore-2 frame))
      ((or (and (listp (setq quad (nth 1 quit-restore-prev)))
 	       (buffer-live-p (car quad))
 	       (eq (nth 3 quit-restore-prev) buffer)