Subject: Re: bug#36894: Stability issues in frameset sorting

From: Juri Linkov <[email-masked]>
Date: Tue, 06 Aug 2019 00:17:32 +0300

> Currently frameset sorting is not stable.  It changes the sorting order of equal
> minibuffer-owning frames.  On closer inspection it becomes clear that
> frameset--mini parameters are messed up in 'frameset--minibufferless-last-p'.
> This patch should fix it:

Pushed to master.

Now one problem still remains: the desktop file doesn't restore the
selected frame, i.e. after restoring frames from the desktop file,
the selected frame is not the same as was before saving the desktop.
This patch ensures that the previously selected frame is restored last,
thus becoming selected again:

diff --git a/lisp/frameset.el b/lisp/frameset.el
index a8b16706c2..8e69bfb499 100644
--- a/lisp/frameset.el
+++ b/lisp/frameset.el
@@ -1104,7 +1106,9 @@ frameset--minibufferless-last-p
 Internal use only."
   (pcase-let ((`(,hasmini1 . ,id-def1) (cdr (assq 'frameset--mini (car state1))))
 	      (`(,hasmini2 . ,id-def2) (cdr (assq 'frameset--mini (car state2)))))
-    (cond ((eq id-def1 t) t)
+    (cond ((and (eq hasmini1 t) (eq hasmini2 t) (eq (cdr (assq 'last-focus-update (car state1))) t)) nil)
+          ((and (eq hasmini1 t) (eq hasmini2 t) (eq (cdr (assq 'last-focus-update (car state2))) t)) t)
+          ((eq id-def1 t) t)
 	  ((eq id-def2 t) nil)
 	  ((not (eq hasmini1 hasmini2)) (eq hasmini1 t))
 	  ((eq hasmini1 nil) (or id-def1 id-def2))