[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

14. Save Partial Status of Emacs When Killed

Save the Desktop, i.e.,

To use this, first put these two lines at the bottom of your initialization file (the later the better):

 
  (desktop-load-default)
  (desktop-read)

Between these two lines you may wish to add something that updates the variables desktop-globals-to-save and/or desktop-locals-to-save. If for instance you want to save the local variable foobar for every buffer in which it is local, you could add the line

 
  (setq desktop-locals-to-save (cons 'foobar desktop-locals-to-save))

To avoid saving excessive amounts of data you may also wish to add something like the following

 
  (add-hook 'kill-emacs-hook
            '(lambda ()
               (desktop-truncate search-ring 3)
               (desktop-truncate regexp-search-ring 3)))

which will make sure that no more than three search items are saved. You must place this line after the (desktop-load-default) line. See also the variable desktop-save-hook.

Start Emacs in the root directory of your "project". The desktop saver is inactive by default. You activate it by typing M-x desktop-save RET. When you exit the next time the above data will be saved. This ensures that all the files you were editing will be reloaded the next time you start Emacs from the same directory and that points will be set where you left them. If you save a desktop file in your home directory it will act as a default desktop when you start Emacs from a directory that doesn’t have its own. I never do this, but you may want to.

Some words on minor modes: Most minor modes are controlled by buffer-local variables, which have a standard save / restore mechanism. To handle all minor modes, we take the following approach: (1) check whether the variable name from minor-mode-alist is also a function; and (2) use translation table desktop-minor-mode-table in the case where the two names are not the same.

By the way: don’t use ‘desktop.el’ to customize Emacs – the standard XEmacs initialization file 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.

To configure this package, type:

 
  M-x customize-group RET desktop RET

[ << ] [ >> ]           [Top] [Contents] [Index] [ ? ]

This document was generated by Aidan Kehoe on December 27, 2016 using texi2html 1.82.