Desktop.el

From WikEmacs
Revision as of 12:49, 30 August 2014 by Elvince (talk | contribs) (desktop.el)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search
Desktop
Description save and restore the state of Emacs accross sessions
Author name of author
Maintainer name of maintainer
Source no link provided
Part of Emacs yes

Use the desktop library to save the state of Emacs from one session to another. Once you save the Emacs desktop (the buffers, their file names, major modes, buffer positions, and so on) then subsequent Emacs sessions reload the saved desktop.

Save and restore sessions manually

You can save the desktop manually with the command M-x desktop-save, and you can load a saved one with M-x desktop-read.

Save and restore sessions automatically

You can also enable automatic saving of the desktop when you exit Emacs, and automatic restoration of the last saved desktop when Emacs starts: add this line in your init file:

    (desktop-save-mode 1)

If you turn on desktop-save-mode in your init file, then when Emacs starts, it looks for a saved desktop in the current directory. (More precisely, it looks in the directories specified by desktop-path, and uses the first desktop it finds.) Thus, you can have separate saved desktops in different directories, and the starting directory determines which one Emacs reloads. You can save the current desktop and reload one saved in another directory by typing M-x desktop-change-dir. Typing M-x desktop-revert reverts to the desktop previously reloaded.

Restore big sessions smoothly

By default, all the buffers in the desktop are restored at one go. However, this may be slow if there are a lot of buffers in the desktop. You can specify the maximum number of buffers to restore immediately with the variable desktop-restore-eager; the remaining buffers are restored “lazily”, when Emacs is idle.

Tips

Clear the desktop

Type M-x desktop-clear to empty the Emacs desktop. This kills all buffers except for internal ones, and clears the global variables listed in desktop-globals-to-clear. If you want this to preserve certain buffers, customize the variable desktop-clear-preserve-buffers-regexp, whose value is a regular expression matching the names of buffers not to kill.

See also

Savehist: save minibuffer history

savehist, to save minibuffer history from one session to another.