7

I have many elscreen tabs(frames?) that are horizontally and vertically split. I'd like to be able to save the current buffers, windows layout in each frame, and the frames themselves.

In short, I'd like to be able to close emacs and re-open with relatively the same state as when I closed it.

(I think I got the terminology right)

deadghost
  • 5,017
  • 3
  • 34
  • 46
  • 1
    Have you tried using a snapshot developer build of Emacs and the built-in `desktop.el` to see how close that gets you to where you want to be? I'd start with that and then adjust elscreen thereafter if necessary. Your horizontal / vertical splits are called `windows`. The `frame` is what holds all the `windows` and can be minimized or maximized. My understanding is that the developer build of Emacs has some extra gizmos for restoring `windows`, which is not yet available in the stable public release. – lawlist Mar 17 '14 at 03:22

1 Answers1

6

Here's what I have in my .emacs exactly for that purpose (sources inline):

auto-save and restore elscreen sessions

;; http://stackoverflow.com/questions/803812/emacs-reopen-buffers-from-last-session-on-startup
(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.")

auto save elscreen on exit:

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

auto restore elscreen on startup:

(defun elscreen-restore ()
    "Restore the elscreen tab configuration."
    (interactive)
    (if (desktop-read)
        (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)
Ehvince
  • 17,274
  • 7
  • 58
  • 79