I usually have 3-4 different projects that I work on at once. So I am trying to figure out how to get emacs to load the desktop from the folder that I open emacs from and also save to that file when I exit from that emacs instance.
All of the docs I have seen either describe how to get emacs to automatically open and save from a default location (which makes multiple desktops impossible), or to manually load and save the desktop to a specific directory (which I am doing now).
Thanks!
Put this to your .emacs:
(setq your-own-path default-directory)
(if (file-exists-p
(concat your-own-path ".emacs.desktop"))
(desktop-read your-own-path))
(add-hook 'kill-emacs-hook
`(lambda ()
(desktop-save ,your-own-path t)))
Upd.: v. 2, ignore on demand.
(setq your-own-path default-directory)
(if (file-exists-p
(concat your-own-path ".emacs.desktop"))
(if (y-or-n-p "Read .emacs.desktop and add hook?")
(progn
(desktop-read your-own-path)
(add-hook 'kill-emacs-hook
`(lambda ()
(desktop-save ,your-own-path t))))))
I have developed a small set of functions to manage multiple desktops: desktop+
You might want to check it out. My workflow is not exactly the same as yours, though:
I always run emacs from the same directory (I run it from a key binding in my window manager), meaning that I can not rely on the starting directory to know which desktop I want to work with
the first time I work on a new project, I call M-xdesktop-create
and provide a name. The desktop is then saved to a central location (under "~/.emacs.d/desktops" by default)
each subsequent time I want to work with a saved desktop, I run M-xdesktop-load
, and am provided with a list of saved sessions in which I can quickly retrieve the name of the desired session.
Sessions are always saved when emacs exits or you load another session.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With