On 11 December 2007 00:42, Reuben Thomas <rrt@sc3d.org> wrote:
On Tue, 11 Dec 2007, Juri Linkov wrote:

This is how other modes work: when you want a configuration change to
take effect, you should disable and re-enable this mode.

Fair enough, then.

[Some time passed]

I have just revisited this. Nothing much seems to have changed in desktop.el in the mean time.

I have gathered together what was agreed on earlier in the thread, and implemented it:

(defun desktop-save-in-desktop-dir (&optional dirname)
  "Save the desktop in directory `desktop-dirname'."
  (interactive
   (list (or desktop-dirname
             (read-directory-name "Directory to save desktop file in: "))))
  (when (and (null dirname) desktop-dirname)
    (setq dirname desktop-dirname))
  (when dirname
    (desktop-save dirname)
    (when (called-interactively-p 'interactive)
        (message "Desktop saved in %s" (abbreviate-file-name dirname)))))

(defun desktop-owner-save-in-desktop-dir ()
  "Save the desktop if we are its owner."
  (if (eq (desktop-owner) (emacs-pid))
      (desktop-save-in-desktop-dir)))

(define-minor-mode desktop-save-mode
  "Toggle desktop saving (Desktop Save mode).
With a prefix argument ARG, enable Desktop Save mode if ARG is
positive, and disable it otherwise.  If called from Lisp, enable
the mode if ARG is omitted or nil.

If Desktop Save mode is enabled, the state of Emacs is saved from
one session to another.  See variable `desktop-save' and function
`desktop-read' for details."
  :global t
  :group 'desktop
  (if desktop-save-mode
      (if desktop-auto-save
          (add-hook 'auto-save-hook 'desktop-owner-save-in-desktop-dir))
    (remove-hook 'auto-save-hook 'desktop-owner-save-in-desktop-dir)))

Remaining issues:

1. Here I have added the function desktop-owner-save-in-desktop-dir which only saves the desktop if the current process owns it.

2. There was some discussion over whether by default we should use a separate timer or auto-save-hook. For now I've used the latter.

3. It was desired to save the desktop only when it changed. Juri Linkov previously said "This is easy to do once we will decide what auto-saving method to use", so, since I don't know how to do it anyway, and since the auto-saving method is not yet decided, I didn't implement that yet.

I've been happily using essentially the above code (mostly Juri's, with a handful of lines by me) since this thread went quiet over five years ago.

--
http://rrt.sc3d.org