Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Some emacs desktop-save questions: how to change it to save in ~/.emacs.d/.emacs.desktop

I have this set in my init.el

(desktop-save-mode 1)

This works great, only I was wondering:

  • how can I change it to save the .emacs.desktop files into ~/.emacs.d instead of ~/

  • how can I stop it from asking me if I want to save (only occurs the first time I close emacs after a reboot, from then on it assumes yes, which is what I always want to happen)

like image 223
tobeannounced Avatar asked Dec 18 '10 08:12

tobeannounced


2 Answers

I use the following, which works for me:

;; Automatically save and restore sessions
(setq desktop-dirname             "~/.emacs.d/desktop/"
      desktop-base-file-name      "emacs.desktop"
      desktop-base-lock-name      "lock"
      desktop-path                (list desktop-dirname)
      desktop-save                t
      desktop-files-not-to-save   "^$" ;reload tramp paths
      desktop-load-locked-desktop nil
      desktop-auto-save-timeout   30)
(desktop-save-mode 1)

Well, I actually set (desktop-save-mode 0) and then use M-x my-desktop to kick things off:

(defun my-desktop ()
  "Load the desktop and enable autosaving"
  (interactive)
  (let ((desktop-load-locked-desktop "ask"))
    (desktop-read)
    (desktop-save-mode 1)))

But that's because my session is frequently in excess of 100 files, mostly via tramp, and so I prefer to make loading it a manual task, and not clobber the desktop file otherwise :)

I recommend checking out the Emacs Wiki: http://www.emacswiki.org/emacs/DeskTop

There are some useful enhancements to the default functionality. In particular, I recommend adding some method of auto-saving your desktop mid-session, as it's really annoying if your system crashes when Emacs has been running for several days, and your desktop hasn't been saved in the interim.

Since Emacs 24.4 the desktop file is auto-saved periodically by default. See the desktop-auto-save-timeout variable (which I've also added to the block above). Thanks to GDP2 and Dexter Morgan for their comments on this.

like image 168
phils Avatar answered Nov 17 '22 22:11

phils


how can I change it to save the .emacs.desktop files into ~/.emacs.d instead of ~/

Customize desktop-dirname variable.

how can I stop it from asking me if I want to save

Customize desktop-save variable.

like image 36
jfs Avatar answered Nov 17 '22 22:11

jfs