Subject: Re: bug#9765: 24.0.90; Multiple calls to desktop-read cause problems

From: Lars Ingebrigtsen <[email-masked]>
Date: Mon, 07 Dec 2020 18:54:26 +0100

Ryan Thompson <[email-masked]> writes:

> If a desktop has already been loaded and "desktop-read" is called a
> second time, it will set "desktop-dirname" to nil, which can cause
> problems when trying to save the desktop later. The "desktop-read"
> function checks whether a desktop file is owned before loading it, and
> if the file is owned, it refuses to "steal" the file (assuming
> appropriate options are set) and sets "desktop-dirname" to nil to
> indicate that it does not own the file. This behavior occurs even when
> the owner of the desktop file is the Emacs process itself. Thus, calling
> "desktop-read" once loads the desktop file, and calling "desktop-read" a
> second time effectively abandons it. This behavior can be fixed with the
> following advice, which turns "desktop-read" into a no-op when the
> current Emacs process is already the desktop owner.
>
> (defadvice desktop-read (around avoid-redundant-read activate)
>   "Don't abandon an already-loaded desktop"
>   (if (and (desktop-owner) (= (desktop-owner) (emacs-pid)))
>       (message "Desktop file already loaded. Skipping reload.")
>     ad-do-it))
>
> I'm not sure if this is an appropriate fix, but I think this is the
> correct behavior.

I've now done something similar to what you suggest in Emacs 28.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no