I have read the page in Emacs wiki which contains a list of session manager plugins. But after trying all of these, I am still not happy with any of them.
By comparison, the VIM session manager saves and loads sessions by name, which is one of the most important features for me.
In particular, I want a session manager for Emacs that:
I'm trying to use Emacs because it has got really good features but a good session manager is important to my workflow.
Related:
Since you don't like the base functionality of desktop.el, throw some elisp around it:
(defvar my-desktop-session-dir
(concat (getenv "HOME") "/.emacs.d/desktop-sessions/")
"*Directory to save desktop sessions in")
(defvar my-desktop-session-name-hist nil
"Desktop session name history")
(defun my-desktop-save (&optional name)
"Save desktop with a name."
(interactive)
(unless name
(setq name (my-desktop-get-session-name "Save session as: ")))
(make-directory (concat my-desktop-session-dir name) t)
(desktop-save (concat my-desktop-session-dir name) t))
(defun my-desktop-read (&optional name)
"Read desktop with a name."
(interactive)
(unless name
(setq name (my-desktop-get-session-name "Load session: ")))
(desktop-read (concat my-desktop-session-dir name)))
(defun my-desktop-get-session-name (prompt)
(completing-read prompt (and (file-exists-p my-desktop-session-dir)
(directory-files my-desktop-session-dir))
nil nil nil my-desktop-session-name-hist))
EDIT:
Getting some votes, so add niceties like completing-read and history
Already answered:
Explaining your requirements in detail allow us to provide a more specific solution for you.
Edit
Desktop mode allows you to have more than one sessions—saved desktops are not name but directory based.
From chapter Saving Emacs Sessions:
You can save the current desktop and reload one saved in another directory by typing
M-x desktop-change-dir.
Furthermore, desktop-path
variable allows you to define a list of directories to search for the saved desktops.
Edit 2
The Elisp code snippet sent by scottfrazer allows you to name your session, as in the background it translates the name to the proper directory name for Desktop mode.
Use different desktops by bookmarking them. Simple, quick to use -- hit a key and presto, different desktop. You can even cycle among them if you like.
Use C-x p K (by default) to set a desktop bookmark. You are prompted for the desktop file location and the bookmark name to use.
Use C-x j K (by default) to jump to a bookmarked desktop. You are prompted for the bookmark name (with completion).
You need Bookmark+ to do this.
For the buffers/tabs storing/restoring parts of the question: I use elscreen and the way I manage storing/restoring the desktop session and the elscreen tab configuration is the following code in my .emacs file (the names used are self-explanatory and if the storing/restoring functions should not be executed every time emacs starts just comment out the lines with "(push #'elscreen-store kill-emacs-hook)" and "(elscreen-restore)"):
(defvar emacs-configuration-directory
"~/.emacs.d/"
"The directory where the emacs configuration files are stored.")
(defvar elscreen-tab-configuration-store-filename
(concat emacs-configuration-directory ".elscreen")
"The file where the elscreen tab configuration is stored.")
(defun elscreen-store ()
"Store the elscreen tab configuration."
(interactive)
(if (desktop-save emacs-configuration-directory)
(with-temp-file elscreen-tab-configuration-store-filename
(insert (prin1-to-string (elscreen-get-screen-to-name-alist))))))
(push #'elscreen-store kill-emacs-hook)
(defun elscreen-restore ()
"Restore the elscreen tab configuration."
(interactive)
(if (eq (type-of (desktop-read)) 'symbol)
(let ((screens (reverse
(read
(with-temp-buffer
(insert-file-contents elscreen-tab-configuration-store-filename)
(buffer-string))))))
(while screens
(setq screen (car (car screens)))
(setq buffers (split-string (cdr (car screens)) ":"))
(if (eq screen 0)
(switch-to-buffer (car buffers))
(elscreen-find-and-goto-by-buffer (car buffers) t t))
(while (cdr buffers)
(switch-to-buffer-other-window (car (cdr buffers)))
(setq buffers (cdr buffers)))
(setq screens (cdr screens))))))
(elscreen-restore)
EDIT:
I changed the "if (desktop-read)", in elscreen-restore, to "if (eq (type-of (desktop-read)) 'symbol)" because, if emacs is killed instead of being closed in the usual way, the .emacs.desktop.lock file is not deleted. Thus, if for any reason the desktop session cannot be restored, the return value of "(desktop-read)" is a "string", explaining the error, and not "nil", so the "if" does not fail as it should.
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