desktop

Homepage: https://www.gnu.org/software/emacs

Author: Morten Welinder

Summary

Save partial status of Emacs when killed

Commentary

Save the Desktop, i.e.,
	- some global variables
	- the list of buffers with associated files.  For each buffer also
		- the major mode
		- the default directory
		- the point
		- the mark & mark-active
		- buffer-read-only
		- some local variables
	- frame and window configuration

To use this, use customize to turn on desktop-save-mode or add the
following line somewhere in your init file:

	(desktop-save-mode 1)

For further usage information, look at the section
(info "(emacs)Saving Emacs Sessions") in the GNU Emacs Manual.

When the desktop module is loaded, the function `desktop-kill' is
added to the `kill-emacs-hook'.  This function is responsible for
saving the desktop when Emacs is killed.  Furthermore an anonymous
function is added to the `after-init-hook'.  This function is
responsible for loading the desktop when Emacs is started.

Special handling.
-----------------
Variables `desktop-buffer-mode-handlers' and `desktop-minor-mode-handlers'
are supplied to handle special major and minor modes respectively.
`desktop-buffer-mode-handlers' is an alist of major mode specific functions
to restore a desktop buffer.  Elements must have the form

   (MAJOR-MODE . RESTORE-BUFFER-FUNCTION).

Functions listed are called by `desktop-create-buffer' when `desktop-read'
evaluates the desktop file.  Buffers with a major mode not specified here,
are restored by the default handler `desktop-restore-file-buffer'.
`desktop-minor-mode-handlers' is an alist of functions to restore
non-standard minor modes.  Elements must have the form

   (MINOR-MODE . RESTORE-FUNCTION).

Functions are called by `desktop-create-buffer' to restore minor modes.
Minor modes not specified here, are restored by the standard minor mode
function.  If you write a module that defines a major or minor mode that
needs a special handler, then place code like

   (defun foo-restore-desktop-buffer
   ...
   (add-to-list 'desktop-buffer-mode-handlers
                '(foo-mode . foo-restore-desktop-buffer))

or

   (defun bar-desktop-restore
   ...
   (add-to-list 'desktop-minor-mode-handlers
                '(bar-mode . bar-desktop-restore))

in the module itself.  The mode function must either be autoloaded,
or of the form "foobar-mode" and defined in library "foobar", so that
desktop can guess how to load its definition.
See the docstrings of `desktop-buffer-mode-handlers' and
`desktop-minor-mode-handlers' for more info.

Minor modes.
------------
Conventional minor modes (see node "Minor Mode Conventions" in the elisp
manual) are handled in the following way:
When `desktop-save' saves the state of a buffer to the desktop file, it
saves as `desktop-minor-modes' the list of names of those variables in
`minor-mode-alist' that have a non-nil value.
When `desktop-create' restores the buffer, each of the symbols in
`desktop-minor-modes' is called as function with parameter 1.
The variables `desktop-minor-mode-table' and `desktop-minor-mode-handlers'
are used to handle non-conventional minor modes.  `desktop-save' uses
`desktop-minor-mode-table' to map minor mode variables to minor mode
functions before writing `desktop-minor-modes'.  If a minor mode has a
variable name that is different form its function name, an entry

   (NAME RESTORE-FUNCTION)

should be added to `desktop-minor-mode-table'.  If a minor mode should not
be restored, RESTORE-FUNCTION should be set to nil.  `desktop-create' uses
`desktop-minor-mode-handlers' to lookup minor modes that needs a restore
function different from the usual minor mode function.
---------------------------------------------------------------------------

By the way: don't use desktop.el to customize Emacs -- the file .emacs
in your home directory is used for that.  Saving global default values
for buffers is an example of misuse.

PLEASE NOTE: The kill ring can be saved as specified by the variable
`desktop-globals-to-save' (by default it isn't).  This may result in saving
things you did not mean to keep.  Use M-x desktop-clear RET.

Thanks to  hetrick@phys.uva.nl (Jim Hetrick)      for useful ideas.
           avk@rtsg.mot.com (Andrew V. Klein)     for a dired tip.
           chris@tecc.co.uk (Chris Boucher)       for a mark tip.
           f89-kam@nada.kth.se (Klas Mellbourn)   for a mh-e tip.
           kifer@cs.stonybrook.edu (M. Kifer)     for a bug hunt.
           treese@lcs.mit.edu (Win Treese)        for ange-ftp tips.
           pot@cnuce.cnr.it (Francesco Potortì)  for misc. tips.
---------------------------------------------------------------------------
TODO:

Recognize more minor modes.
Save mark rings.

Dependencies

Reverse dependencies