How to restore Emacs' windows and buffers from the last session?

The behavior I want is like in web browser that you can restore all the tabs from last session.

link|improve this question

38% accept rate
1  
See the answer to this question. – Tom Jan 29 at 6:51
feedback

2 Answers

Here's some code to do it. For the code to work, you need the "tapestry" Lisp library installed. If you use the VM mailer, you have the library installed already. Otherwise you can download it from here.

Put the following code in your .emacs file. When you want to restore your window and frame setup from your last Emacs session, type M-x load-my-tapestry RET.

(require 'tapestry)

(defvar my-tapestry-file "~/.tapestry")

(defun load-my-tapestry ()
  (interactive)
  (let ((b (find-file-noselect my-tapestry-file)))
    (sit-for 0)
    (set-tapestry (read b))
    (kill-buffer b)))

(defun save-my-tapestry ()
  (interactive)
  (let ((tap (tapestry)))
    (with-temp-buffer
      (let ((standard-output (current-buffer)))
        (setcar tap (make-list (length (car tap)) nil))
        (print tap)
        (write-region (point-min) (point-max) my-tapestry-file)))))

(add-hook 'kill-emacs-hook 'save-my-tapestry)
link|improve this answer
When I do M-x load-my-tapestry RET, I only got (New file) set-tapestry: End of file during parsing in mini-buffer and nothing loaded in the Emacs window. – Problemaniac Jan 29 at 18:03
Run M-x save-my-tapestry once and the process should be bootstrapped. – Kyle Jones Jan 29 at 21:00
Did; then it gaves let: Wrong type argument: listp, config error in mini-buffer now. – Problemaniac Jan 29 at 21:44
Hmmm, there's no config variable in my answer code or in tapestry.el. (setq debug-on-error t) and get a stacktrace. That should indicate where the error is happening. – Kyle Jones Jan 29 at 21:59
Actually when I rerun it, I get set-tapestry: End of file during parsing error again. I opened a Emacs session, opened two frames, and loaded two different files in each of them, then M-x save-my-tapestry, then close it. Reopen Emacs, then do M-x load-my-tapestry RET, it gave set-tapestry: End of file during parsing. – Problemaniac Jan 29 at 22:05
show 3 more comments
feedback

go to your .emacs file and type (desktop-save-mode 1) this will save all current buffers to a "desktop" file, it wont save the actual layout of your frames but you can look into "registers" for that.

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

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