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.
Super User is a question and answer site for computer enthusiasts and power users. It only takes a minute to sign up.
Sign up to join this communityIn 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 ()
(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)
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.
M-x save-my-tapestry
once and the process should be bootstrapped.
Jan 29, 2012 at 21:00
let: Wrong type argument: listp, config
error in mini-buffer now.
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.
Jan 29, 2012 at 21:59
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
.