17

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:

  • Managing sessions by name
  • Saving tabs, screens, frames etc..

I'm trying to use Emacs because it has got really good features but a good session manager is important to my workflow.


Related:

Community
  • 1
  • 1
sid3k
  • 225
  • 3
  • 8

5 Answers5

35

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

scottfrazer
  • 17,079
  • 4
  • 51
  • 49
5

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.

Community
  • 1
  • 1
viam0Zah
  • 25,949
  • 8
  • 77
  • 100
  • I already tried desktop.el (as I said 4 times), it does not support saving sessions by names. – sid3k May 11 '09 at 13:13
  • @Török Gábor: He claims to have tried the choice list therein, and is asking for a very particular feature. The formulation of the question was marginal, and the tone passive-aggressive, but the question seems to be unique. – dmckee --- ex-moderator kitten May 11 '09 at 17:00
  • @dmckee: yes, the comment to my answer clarified it, that's why I tried to point out then that Emacs Desktop handles multiple sessions, it just doesn't separate them by names but directories. – viam0Zah May 11 '09 at 19:10
  • possibly worth noting that `desktop-path` defaults changed in 24.3, causing confusing with older documentation. https://www.emacswiki.org/emacs/DesktopMultipleSaveFiles – pestophagous Jun 24 '19 at 20:34
2

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.

sadesyllas
  • 101
  • 1
  • 4
2

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.

Drew
  • 29,895
  • 7
  • 74
  • 104
0

Try Emacs desktop. Go here

Nifle
  • 11,745
  • 10
  • 75
  • 100
  • 1
    I already tried desktop.el (as I said 4 times), it does not support saving sessions by names. – sid3k May 11 '09 at 13:13
  • 4
    Where did you say you used desktop.el? – Nifle May 11 '09 at 13:42
  • 1
    "I tried all of the sessionmanager plugins for emacs that is written in the wiki but I saw that most useful of them doesn't save frames, doesn't use session names and all of them have really bad names." – sid3k May 11 '09 at 14:01