Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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.

share|improve this question
1  
See the answer to this question. –  Tom Jan 29 '12 at 6:51

3 Answers 3

up vote 0 down vote accepted

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.

share|improve this answer

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

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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