Emacs: Save/Restore Opened Files, Windows Configuration: desktop-mode

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, …)

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. (you can also delete it)

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.

Call describe-variable, type “desktop-”, then press Tab ⇥, to see all desktop mode's variables.

Call 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: new variable desktop-save. Default is t. When t, desktop are automatically saved when you quit.

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

Call describe-variable to see a variable's value and documentation.

Like it? Buy Xah Emacs Tutorial. Thanks.

or, buy something from Best Keyboard for Emacs