File: desktop.el.html
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-query-functions. This function is
responsible for saving the desktop and deleting the desktop lock
file when Emacs is killed. In addition, 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(var)/desktop-save(fun) 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(var)/desktop-save(fun) 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.
Defined variables (44)
desktop-after-read-hook | Normal hook run after a successful ‘desktop-read’. |
desktop-auto-save-timeout | Number of seconds of idle time before auto-saving the desktop. |
desktop-base-file-name | Name of file for Emacs desktop, excluding the directory part. |
desktop-base-lock-name | Name of lock file for Emacs desktop, excluding the directory part. |
desktop-buffer-args-list | List of args for ‘desktop-create-buffer’. |
desktop-buffer-mode-handlers | Alist of major mode specific functions to restore a desktop buffer. |
desktop-buffers-not-to-save | Regexp identifying buffers that are to be excluded from saving. |
desktop-buffers-not-to-save-function | Function identifying buffers that are to be excluded from saving. |
desktop-clear-preserve-buffers | List of buffers that ‘desktop-clear’ should not delete. |
desktop-delay-hook | Hooks run after all buffers are loaded; intended for internal use. |
desktop-dirname | The directory in which the desktop file should be saved. |
desktop-file-checksum | Checksum of the last auto-saved contents of the desktop file. |
desktop-file-modtime | When the desktop file was last modified to the knowledge of this Emacs. |
desktop-file-name-format | Format in which desktop file names should be saved. |
desktop-file-version | Version number of desktop file format. |
desktop-files-not-to-save | Regexp identifying files whose buffers are to be excluded from saving. |
desktop-globals-to-clear | List of global variables that ‘desktop-clear’ will clear. |
desktop-globals-to-save | List of global variables saved by ‘desktop-save’. |
desktop-header | Header to place in Desktop file. |
desktop-io-file-version | The format version of the current desktop file (an integer) or nil. |
desktop-lazy-idle-delay | Idle delay before starting to create buffers. |
desktop-lazy-verbose | Verbose reporting of lazily created buffers. |
desktop-load-locked-desktop | Specifies whether the desktop should be loaded if locked. |
desktop-locals-to-save | List of local variables to save for each buffer. |
desktop-minor-mode-handlers | Alist of functions to restore non-standard minor modes. |
desktop-minor-mode-table | Table mapping minor mode variables to minor mode functions. |
desktop-missing-file-warning | If non-nil, offer to recreate the buffer of a deleted file. |
desktop-modes-not-to-save | List of major modes whose buffers should not be saved. |
desktop-native-file-version | Format version of the current desktop package, an integer. |
desktop-no-desktop-file-hook | Normal hook run when ‘desktop-read’ can’t find a desktop file. |
desktop-not-loaded-hook | Normal hook run when the user declines to reuse a desktop file. |
desktop-path | List of directories to search for the desktop file. |
desktop-restore-eager | Number of buffers to restore immediately. |
desktop-restore-forces-onscreen | If t, restores frames that are fully offscreen onscreen instead. |
desktop-restore-frames | When non-nil, save and restore the frame and window configuration. |
desktop-restore-in-current-display | Controls how restoring of frames treats displays. |
desktop-restore-reuses-frames | If t, restoring frames reuses existing frames. |
desktop-save | Specifies whether the desktop should be saved when it is killed. |
desktop-save-buffer | When non-nil, save buffer status in desktop file. |
desktop-save-hook | Normal hook run before the desktop is saved in a desktop file. |
desktop-save-mode | Non-nil if Desktop-Save mode is enabled. |
desktop-save-mode-hook | Hook run after entering or leaving ‘desktop-save-mode’. |
desktop-saved-frameset | Saved state of all frames. |
desktop-var-serdes-funs | Table of serialization/deserialization functions for variables. |