Emacs: Restore Opened Files, Windows Config

By Xah Lee. Date: . Last updated: .

emacs has desktop-save-mode. When on, it save and restore all previously opened files in last emacs session, and also previous windows configuration (size, position, etc.)

Put this in your Emacs Init File:

;; save/restore opened files and windows config
(desktop-save-mode 1) ; 0 for off

Starting Emacs Without Opening Last Session's Files

To start emacs without opening last session's files, start it by:

emacs --no-desktop

This is useful because sometimes you have a corrupted desktop file.

Desktop File Path Location

By default, the temp file used by emacs to store your “desktop” status is at ~/.emacs.d/.emacs.desktop.

The desktop file path is controlled by the variable desktop-dirname and desktop-base-file-name.

Alt+x describe-variable, type “desktop-”, then press Tab, to see all desktop mode's variables.

Alt+x customize-group type “desktop”, to set preferences. [see Emacs: M-x customize Tutorial]

desktop-save-mode Changes in Emacs 24.4

In emacs 24.4 (year 2014) new variable desktop-save. Default is t. When t, desktop are automatically saved when you quit. [see Emacs 24.4 Features (released 2014-10)]

In emacs 24.4: new variable desktop-auto-save-timeout. Default value is 30 (seconds). It specifies the time interval to periodically save “desktop”. Before, it saves only when you quit emacs.

In emacs 24.4: New variable desktop-restore-frames. Default value is t. When t, save and restore the frame and window configuration.

More options for restoring windows, see: desktop-restore-in-current-display, desktop-restore-reuses-frames, desktop-restore-forces-onscreen

Alt+x describe-variable to see a variable's value and documentation.

Emacs, Restore Things


Emacs Init

Init Basics

Keys

Font

Text Editing

Completion

File

Restore Things

Backup/AutoSave

Line

Appearance

Misc

Advanced Init Tips

packages