4

I would like to use a standard desktop save file when using Emacs as a server (with Emacsclient) and use no desktop save file (or optionally, another desktop save file) when running a regular Emacs instance (no server-start command).

Is it possible to use a fixed desktop save directory name with desktop-save-mode?

If I use:

(desktop-save-mode 1)

I have no direct control over where the desktop is saved (though, I think it is saved in ~/.emacs.d/.emacs.desktop).

I tried to add the following to my Emacs init file:

(require 'desktop)
(defvar my-desktop-dir "~/emacs-server")
(when (file-exists-p (desktop-full-file-name my-desktop-dir))
  (desktop-read my-desktop-dir))
(add-hook 'kill-emacs-hook (lambda () (desktop-save my-desktop-dir))))

while this seems to work, I am not sure if desktop auto save will be enabled.. From the manual :

When desktop-save-mode is active and the desktop file exists, Emacs auto-saves it every desktop-auto-save-timeout seconds, if that is non-nil and non-zero.

so in order to make desktop-save-mode active, I have to run (desktop-save-mode 1) in my init file. The problem is that this command then will revert to the desktop stored in ~/.emacs.d, which is not desired.

Håkon Hægland
  • 3,608
  • 1
  • 20
  • 51

2 Answers2

4

Using (setq desktop-path (list my-desktop-dir)) before calling (desktop-save-mode 1) seems to solve the issue:

(require 'desktop)
(setq desktop-path (list "~/emacs-server"))
(desktop-save-mode 1)

Note: You will now get a question Save desktop? (y or n) when killing Emacs server and this is the first time you save the desktop..

Håkon Hægland
  • 3,608
  • 1
  • 20
  • 51
1

You should use desktop-change-dir to instruct emacs to load the desktop file at a given location, and remember it for auto-save later.

(desktop-change-dir "~/emacs-server")
(desktop-save-mode 1)
François Févotte
  • 5,917
  • 1
  • 24
  • 37