12

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?

13

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+, available on Melpa.

bookmark+

bookmark+ manages different types of bookmarks, one of those is Desktop Bookmarks.

After installing the package,

  • You need to have (require 'bookmark+) in your init.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.

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)))

Bookmark Plus' emacs wiki is very informative if you want to learn more about this package.

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! – Rainer Sep 26 '14 at 18:51
  • 1
    Note 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. – Drew Sep 26 '14 at 22:47
  • @kaushalmodi Thanks - brilliant. And now I have a lot to read about bookmark+ - but it does exactly want I want. – Rainer Sep 30 '14 at 9:21
  • @Drew this is exactly what I was looking for - and it works like a charm. – Rainer Sep 30 '14 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```? – Rainer Sep 30 '14 at 9:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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