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?
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
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
- To create a bookmark for each project, set up the buffers you'd like for each project and do
M-x bmkp-set-desktop-bookmarkor 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-jumpor 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) 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)))
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 I'd one can utilize the
projectile-after-switch-project-hook function to call a private function to do the needful