Subject: Re: bug#32825: 27.0.50; Deterministic window management

From: martin rudalics <[email-masked]>
Date: Fri, 09 Nov 2018 13:51:32 +0100

> There are only two places where debugger-previous-window is set - both
 > in `debug': in the first, the value is set when the debugger pops up, to
 > the window that has been chosen to display it.  In the second place,
 > it's reset to nil when the debugger "won't be back".
 >
 > So, when the value is a (live) window, it should be respected.  I didn't
 > follow your discussion very attentively, but I'm not sure how the
 > debugger-previous-window variable is concerned in what you discussed
 > recently.  AFAIK its only use is to remember the window while a debugger
 > session is still active.

You're right - FWIW this is the same bug I proposed to fix earlier
with the patch I reattach now.  Juri, you never tried it, I suppose?

martin
--- a/lisp/emacs-lisp/debug.el
+++ b/lisp/emacs-lisp/debug.el
@@ -101,7 +101,10 @@ debugger-old-buffer
   "This is the buffer that was current when the debugger was entered.")
 
 (defvar debugger-previous-window nil
-  "This is the window last showing the debugger buffer.")
+  "The last debugger window from the same session.")
+
+(defvar debugger-pre-previous-window nil
+  "The last debugger window from the previous session.")
 
 (defvar debugger-previous-window-height nil
   "The last recorded height of `debugger-previous-window'.")
@@ -240,10 +243,16 @@ debug
 	       debugger-buffer
 	       `((display-buffer-reuse-window
 		  display-buffer-in-previous-window)
-		 . (,(when (and (window-live-p debugger-previous-window)
-				(frame-visible-p
-				 (window-frame debugger-previous-window)))
-		       `(previous-window . ,debugger-previous-window)))))
+		 . (,(cond
+                      ((and (window-live-p debugger-previous-window)
+			    (frame-visible-p
+			     (window-frame debugger-previous-window)))
+		       `(previous-window . ,debugger-previous-window))
+                      ((and (window-live-p debugger-pre-previous-window)
+                            (eq (window-frame debugger-pre-previous-window)
+                                (selected-frame)))
+		       `(previous-window . ,debugger-pre-previous-window)))
+                    (inhibit-same-window . t))))
 	      (setq debugger-window (selected-window))
 	      (if (eq debugger-previous-window debugger-window)
 		  (when debugger-jumping-flag
@@ -297,7 +306,9 @@ debug
 		(quit-restore-window debugger-window debugger-bury-or-kill)
 		;; Restore current buffer (Bug#12502).
 		(set-buffer debugger-old-buffer)))
-            ;; Forget debugger window, it won't be back (Bug#17882).
+            ;; Forget debugger window, it won't be back (Bug#17882)
+            ;; unless it's on the selected frame (Bug#32825).
+            (setq debugger-pre-previous-window debugger-previous-window)
             (setq debugger-previous-window nil))
           ;; Restore previous state of debugger-buffer in case we were
           ;; in a recursive invocation of the debugger, otherwise just