On 11.09.2023, at 20:45, Alan Third <alan@idiocy.org> wrote:

> On Mon, Sep 11, 2023 at 06:16:19PM +0100, Christian Tanzer wrote:
> ...
> In the mean time, I might have an idea how to mitigate the issue.

Yup. That worked.

I defined one hook added to desktop-save-hook and another one added to
desktop-after-read-hook. The idea is to have no iconified frames in
the .emacs.desktop, so ::

+ the hook running before desktop-save makes all iconified frames
  visible and sets a frame-parameter to mark the frame is iconified

    (defun lse-frame:desktop-before-save:deiconify-frames ()
      "desktop-save-hook: de-iconify all frames that are iconified"
      (dolist (frame (frame-list))
        (when (eq (frame-parameter frame 'visibility) 'icon)
          (set-frame-parameter frame 'lse-iconified t)
          (make-frame-visible frame)
        )
      )
    )

+ the hook running after desktop-read iconifies all frames marked by
  the desktop-save-hook

    (defun lse-frame:desktop-after-read:iconify-frames ()
      "desktop-after-read-hook: iconify all frames that were de-iconified
    before desktop-save"
      (dolist (frame (frame-list))
        (when (frame-parameter frame 'lse-iconified)
          (set-frame-parameter frame 'lse-iconified nil)
          (iconify-frame frame)
        )
      )
    )

A fringe benefit of this is that position and size of iconified frames
are preserved better.

An .emacs.desktop that crashed will work after being changed from
`(visibility . icon)` to `(visibility . t) (lse-iconified . t)`.

So I can upgrade from Emacs 27 to Emacs 28.2.

Emacs 29.1 is still out because of bug=65840.

Cheers,

--
Christian Tanzer