Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Restore Emacs Session/Desktop

Tags:

emacs

I've been searching for how to restore an emacs session, with no luck. I'm looking to restore all previously open buffers, some of which might contain erc, shells, directory listings, files, etc.

Every time I open emacs, I spend a considerable amount of time arranging my buffers; splitting them into rows and columns, opening a shell, arranging irc channels. It takes a while to get onto work.

I've tried adding the following to my init.el

(desktop-save-mode 1)

And then using M-x desktop-save. This only seems to restore files that are open, not shells or anything else running within buffers.

I've also checked the following questions:

  • Session management in emacs using Desktop library
  • Emacs session / projects / window management
  • Emacs: reopen buffers from last session on startup?

And read through:

  • DeskTop and EmacsSession at emacsWiki.org

Here's a screenshot example of my emacs session.

A simple answer would be to just focus on real work :P

like image 802
Patrick McLaren Avatar asked Apr 24 '10 08:04

Patrick McLaren


People also ask

How do I save a session in Emacs?

The first time you save the state of the Emacs session, you must do it manually, with the command M-x desktop-save . Once you have done that, exiting Emacs will save the state again--not only the present Emacs session, but also subsequent sessions.

How do I save and exit Emacs?

To enter Emacs, type emacs at the shell prompt. When you want to leave Emacs for a short time, type a C-z and Emacs will be suspended. To get back into Emacs, type %emacs at the shell prompt. To quit Emacs permanently, type C-x C-c.

What is the command to save all open files stored in the buffer and exit Emacs?

Emacs allows you to save the contents to the current buffers by hitting the keys Ctrl + x followed by Ctrl + s.

What is the Search command in Emacs?

Simple Searches Emacs also offers a simple, or nonincremental, search. To use a more straightforward search, type C-s RETURN or select Search from the Search menu. Type the search string, press RETURN, and Emacs begins the search. Simply press C-s again to repeat the search.


2 Answers

I'd suggest a simple solution - create a function that sets up your preferred layout. For example I like to have some IRC channels in the second half of my screen in separate windows, so that I may have a look at them from time to time, while coding for instance in another window. So I've written some simple code to take care of the window splitting and arrange my buffers as I wish:

;; show some buffers
(defun show-some-buffers (buffer-list)
  (split-window-horizontally)
  (other-window 1)
  (dolist (buffer buffer-list)
    (split-window-vertically)
    (switch-to-buffer (get-buffer buffer))
    (other-window 1))
  ;; at the end we have one extra window we need to delete
  (delete-window)
  (balance-windows))

;; show some erc buffers
(defun show-erc-buffers ()
  (interactive)
  (show-some-buffers '("#emacs" "#clojure")))

The code is fairly simple and features no error checking, but it will give you a hint about what I mean.

You might want to consider using registers as well to store some window configurations.

like image 55
Bozhidar Batsov Avatar answered Sep 19 '22 12:09

Bozhidar Batsov


As you've found, desktop.el and session.el are a good start, but they don't restore the window layouts.

However, using revive.el you can save/restore arbitrary window configurations, which are remembered between restarts.

Also check out these hints relating to window layouts, which cover winner-mode and the trick of saving window configurations into registers.

like image 37
sanityinc Avatar answered Sep 19 '22 12:09

sanityinc