]> git.eshelyaron.com Git - emacs.git/commitdiff
Don't switch to another frame if window is not on the selected frame.
authorJuri Linkov <juri@linkov.net>
Thu, 17 Apr 2025 18:21:29 +0000 (21:21 +0300)
committerEshel Yaron <me@eshelyaron.com>
Fri, 18 Apr 2025 06:46:56 +0000 (08:46 +0200)
* lisp/window.el (window--quit-restore-select-window):
Add optional arg 'frame'.  Don't switch to another frame
if window is not on the selected frame (bug#71386).
(quit-restore-window): Provide the 'frame' arg
to 'window--quit-restore-select-window' calls.
Patch by martin rudalics <rudalics@gmx.at>.

* test/lisp/tab-bar-tests.el (tab-bar-tests-quit-restore-window):
No need to reselect the frame after 'quit-window'.

(cherry picked from commit 9f4347e00c02c3aa436118425a0cda2bc7f69d51)

lisp/window.el
test/lisp/tab-bar-tests.el

index 0e89b490aece6851cb8ecba0d9afc3575ae3c2de..052547de7df79b9c5ff86c1f280b2c1966f77464 100644 (file)
@@ -5278,13 +5278,19 @@ the window has never shown before."
   :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.
@@ -5343,6 +5349,7 @@ elsewhere.  This value is used by `quit-windows-on'."
                           (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.
@@ -5350,7 +5357,7 @@ elsewhere.  This value is used by `quit-windows-on'."
            (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)
@@ -5362,7 +5369,7 @@ elsewhere.  This value is used by `quit-windows-on'."
           ;; 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.
@@ -5372,7 +5379,7 @@ elsewhere.  This value is used by `quit-windows-on'."
           (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)
index 3f9ee3aa4b71dff6926f6d6064a149a7d6b3ecf9..33ec580b450cbfc3228aa5ef6f7ef059c4fcaba9 100644 (file)
@@ -89,9 +89,6 @@
       (should (eq (length (window-list)) 2))
       (should (equal (buffer-name) "*info*"))
       (quit-window)
-      ;; 'quit-window' unexpectedly selects the original frame,
-      ;; so move back to the created frame
-      (select-frame (car (frame-list)))
       (should (eq (length (window-list)) 1))
       (should (eq (length (frame-list)) 2))
       (should (equal (buffer-name) "*Messages*"))
@@ -99,7 +96,7 @@
       (should (eq (length (frame-list)) 2))
       ;; Delete the created frame afterwards because with tty frames
       ;; the output of 'message' is bound to the original frame
-      (delete-frame))
+      (delete-frame (car (frame-list))))
 
     ;; 2.1. 'quit-restore-window' should close the tab
     ;; from initial window (bug#59862)