0

Previously, I used GUI Emacs, everything worked perfectly - the desktop was saved and restored as it should be.

I decided to try Emacs in daemon mode. First I made changes to the init.el file:

(custom-set-variables
 '(desktop-load-locked-desktop t) 
 '(desktop-path '("~/.emacs.d/"))
 '(desktop-save-mode t)
 '(save-place-mode t)
 '(tab-bar-mode t))
(add-hook 'server-after-make-frame-hook 'desktop-read)

Then started the server

  Start Init ...
  Loading desktop...done
  Loading saveplace...done
  Wrote /home/mocambo/.emacs.d/.emacs.desktop.lock
  Desktop: 1 frame, 1 buffer restored.
  Starting Emacs daemon.
  Inside after-make-frame-functions
  Not reloading the desktop; already loaded
  Inside server-after-make-frame-hook
  Not reloading the desktop; already loaded
  When done with this frame, type C-x 5 0

EDIT: By adding some debug messages to the init file, it turned out that Emacs loads the desktop earlier than it should.

The culprit may be the (desktop-save-mode t) in the init file. Once set, Emacs calls (desktop-read). How to avoid it? The next time I save the settings, the (desktop-save-mode t ) init file reappears.

Temporary solution:

(custom-set-variables
...
;; '(desktop-save-mode t)
...)
6
  • Is there actually a problem? "When Desktop Save mode is enabled ... The next time Emacs starts, if this mode is active it will restore the desktop." All I'm seeing in your logs is Emacs refraining from doing that more than once.
    – phils
    Jul 17, 2023 at 22:42
  • Calling desktop-read in server-after-make-frame-hook sounds slightly mad, btw. Why would you do that?
    – phils
    Jul 17, 2023 at 22:44
  • If you just want to get rid of the customized user option from your init file, then use M-x customize-option and use the "Revert" button to "erase customizations".
    – phils
    Jul 17, 2023 at 22:47
  • I just want to restore frame from previous desktop session. I have (desktop-save-mode t) setting in init.el. When I start emacsclient -c, it doesnt restore frame. I did as the GNU Emacs manual suggested - calling desktop-read from server-after-make-frame-hook. And this works only when I'll comment out the original (desktop-save-mode t).
    – Herman
    Jul 17, 2023 at 23:04
  • Oh, interesting that it recommends doing that; thanks. I can see the explanation for that in the manual page you linked. So if you erase the customisation for the variable, is everything working the way you want?
    – phils
    Jul 18, 2023 at 0:56

1 Answer 1

1

I looked in the desktop.el file and saw that after-init-hook contains a function where automatic (desktop-read) is called when (desktop-save-mode t) and command-line-args contains a no --no-desktop switch. So, to control (desktop-read) and to restore the desktop in emacs --daemon mode, you have to use the --no-desktop switch. :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.