I would like to use DeskTop for basic project management, i.e. opening a set of buffers and restore histories depending on the project I am working on. Is this possible, i.e. having one desktop file in a project directory and how can I achieve this?
2 Answers
I needed to manage the desktop files just like you; have a separate desktop file for each project and save buffers, Emacs variables, etc independently for each.
I was able to achieve that using a package called bookmark+
.
bookmark+
Library Bookmark+ manages different types of bookmarks, one of those is Desktop Bookmarks.
After installing the package,
- You need to have
(require 'bookmark+)
in yourinit.el
- To create a bookmark for each project, set up the buffers you'd like for each project and do
M-x bmkp-set-desktop-bookmark
or C-x p K. That will ask you where you want to save the desktop file and you can choose to save it in that project's folder. - Once you have set the desktop bookmarks for all projects, you can jump to different bookmarks using
M-x bmkp-desktop-jump
or C-x j K.
The Bookmark+ doc on Emacs Wiki is very informative if you want to learn more about this package.
desktop.el
In addition to that, I have the following to set up the desktop
package where I can choose what all I want to save per desktop
(desktop-save-mode 1)
;; Source: https://github.com/purcell/emacs.d/blob/master/lisp/init-sessions.el
; save a bunch of variables to the desktop file
;; for lists specify the len of the maximal saved data also
(setq desktop-globals-to-save
(append '((comint-input-ring . 50)
(compile-history . 30)
desktop-missing-file-warning
(dired-regexp-history . 20)
(extended-command-history . 30)
(face-name-history . 20)
(file-name-history . 100)
(grep-find-history . 30)
(grep-history . 30)
(ido-buffer-history . 100)
(ido-last-directory-list . 100)
(ido-work-directory-list . 100)
(ido-work-file-list . 100)
(magit-read-rev-history . 50)
(minibuffer-history . 50)
(org-clock-history . 50)
(org-refile-history . 50)
(org-tags-history . 50)
(query-replace-history . 60)
(read-expression-history . 60)
(regexp-history . 60)
(regexp-search-ring . 20)
register-alist
(search-ring . 20)
(shell-command-history . 50)
tags-file-name
tags-table-list)))
Saving project-specific desktops when quitting emacs
I find it useful to bind the below function to C-x C-c so that the desktops get saved automatically when I quit emacs.
(defun save-desktop-save-buffers-kill-emacs ()
"Save buffers and current desktop every time when quitting emacs."
(interactive)
(desktop-save-in-desktop-dir)
(save-buffers-kill-emacs))
At times, I wouldn't want to save the desktop when quitting emacs. For those occasions, I use this other function and have bound that to C-x M-c.
;; Kill emacs when running in daemon mode or not
;; Source: http://lists.gnu.org/archive/html/emacs-devel/2011-11/msg00348.html
(defun tv-stop-emacs ()
(interactive)
(if (daemonp)
(save-buffers-kill-emacs)
(save-buffers-kill-terminal)))
-
Thanks - that looks VERY promising. I found the combination of bookmarks+ and DeskTop before, but could not find a concise way of doing it. This sounds great. I'll try it out latest Mondays!– RainerSep 26, 2014 at 18:51
-
1Note that, unlike the case for the vanilla Emacs desktop commands, Bookmark+ desktop bookmarks are intended for switching among multiple desktops. IOW, you can have multiple desktop files. And your desktop files can be anywhere. They need not be in different directories. Vanilla desktop use presumes that you have only one desktop file per directory.– DrewSep 26, 2014 at 22:47
-
@kaushalmodi Thanks - brilliant. And now I have a lot to read about bookmark+ - but it does exactly want I want.– RainerSep 30, 2014 at 9:21
-
@Drew this is exactly what I was looking for - and it works like a charm.– RainerSep 30, 2014 at 9:21
-
@kaushalmodi I assume that you are using your exit function to be able to quit emacs without saving the desktop - or is there a difference, when wanting to always save the desktop, to using the variable
desktop-eve
to ``ask-if-new```?– RainerSep 30, 2014 at 9:46
I tend to use the following setup to save and load/read the desktop file from the local directory of the respective projects:
(require 'desktop)
(setq desktop-path (list "./"))
(desktop-save-mode 1)
(desktop-read)
This is not without issues as switching projects via e.g., projectile or other project management utilities does not load any desktop files but one can utilize the projectile-after-switch-project-hook
function to call a private function to do the needful