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 2


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+.


Library 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.

The Bookmark+ doc on Emacs Wiki is very informative if you want to learn more about this package.


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)
                (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)
                (search-ring . 20)
                (shell-command-history . 50)

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."

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 ()
  (if (daemonp)
  • 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
    Commented Sep 26, 2014 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
    Commented Sep 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.
    – Rainer
    Commented Sep 30, 2014 at 9:21
  • @Drew this is exactly what I was looking for - and it works like a charm.
    – Rainer
    Commented Sep 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```?
    – Rainer
    Commented Sep 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)

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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