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.


3 Answers 3


In addition to automatically restoring your last Emacs session state, you can also save any number of session states and restore them on demand in any other session, any number of times. IOW, you can easily switch among different desktops.

The easiest way to do this is to load library Bookmark+ and use key C-x r K to save the current session state as a desktop bookmark. You can then restore any desktop bookmark in any session using key C-x j K.


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.


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 ()
  (let ((b (find-file-noselect my-tapestry-file)))
    (sit-for 0)
    (set-tapestry (read b))
    (kill-buffer b)))

(defun save-my-tapestry ()
  (let ((tap (tapestry)))
      (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)
  • 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.
    – qazwsx
    Jan 29, 2012 at 18:03
  • Run M-x save-my-tapestry once and the process should be bootstrapped.
    – Kyle Jones
    Jan 29, 2012 at 21:00
  • Did; then it gaves let: Wrong type argument: listp, config error in mini-buffer now.
    – qazwsx
    Jan 29, 2012 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, 2012 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.
    – qazwsx
    Jan 29, 2012 at 22:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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