[ < ] [ > ]   [ << ] [Plus haut] [ >> ]         [Top] [Table des matières] [Index] [ ? ]

39.17 Session Management

Emacs supports the X Session Management Protocol for suspension and restart of applications. In the X Window System, a program called the session manager has the responsibility to keep track of the applications that are running. During shutdown, the session manager asks applications to save their state, and delays the actual shutdown until they respond. An application can also cancel the shutdown.

When the session manager restarts a suspended session, it directs these applications to individually reload their saved state. It does this by specifying a special command-line argument that says what saved session to restore. For Emacs, this argument is ‘--smid session’.

Variable: emacs-save-session-functions

Emacs supports saving state by using a hook called emacs-save-session-functions. Each function in this hook is called when the session manager tells Emacs that the window system is shutting down. The functions are called with no arguments and with the current buffer set to a temporary buffer. Each function can use insert to add Lisp code to this buffer. At the end, Emacs saves the buffer in a file that a subsequent Emacs invocation will load in order to restart the saved session.

If a function in emacs-save-session-functions returns non-nil, Emacs tells the session manager to cancel the shutdown.

Here is an example that just inserts some text into ‘*scratch*’ when Emacs is restarted by the session manager.

 
(add-hook 'emacs-save-session-functions 'save-yourself-test)

(defun save-yourself-test ()
  (insert "(save-excursion
  (switch-to-buffer \"*scratch*\")
  (insert \"I am restored\"))")
  nil)

Ce document a été généré par Eric Reinbold le 13 Octobre 2007 en utilisant texi2html 1.78.