Commit f8e7eebe authored by Richard M. Stallman's avatar Richard M. Stallman
Browse files

Clean up session manager node.

parent 8a5782b5
...@@ -2000,36 +2000,38 @@ This variable is non-@code{nil} when Emacs is running in batch mode. ...@@ -2000,36 +2000,38 @@ This variable is non-@code{nil} when Emacs is running in batch mode.
@node Session Management @node Session Management
@section Session Management @section Session Management
@cindex session management @cindex session manager
@cindex X session management protocol
X has defined the X Session Management Protocol to handle start and Emacs supports the X Session Management Protocol for suspension and
restart of applications. There is one session manager who has the restart of applications. In the X Window System, a program called the
responsibility to keep track of the applications that are running @dfn{session manager} has the responsibility to keep track of the
when the window system shuts down, so the session manager later can applications that are running. During shutdown, the session manager
restart them. asks applications to save their state, and delays the actual shutdown
until they respond. An application can also cancel the shutdown.
Before the session manager shuts down the window system it informs When the session manager restarts a suspended session, it directs
applications that they should save their state. When the applications these applications to individually reload their saved state. It does
are restarted, the applications will restore their state. this by specifying a special command-line argument that says what
saved session to restore. For Emacs, this argument is @samp{--smid
@var{session}}.
@defvar emacs-save-session-functions @defvar emacs-save-session-functions
@tindex emacs-save-session-functions @tindex emacs-save-session-functions
Emacs supports saving state by using a hook called Emacs supports saving state by using a hook called
@code{emacs-save-session-functions}. Each function in this hook is @code{emacs-save-session-functions}. Each function in this hook is
called when the session manager tells Emacs that the window system is called when the session manager tells Emacs that the window system is
shutting down. The functions are called with the current buffer set to shutting down. The functions are called with the current buffer set
a temporary buffer. Functions can use @code{insert} to add lisp code to a temporary buffer. Each functions can use @code{insert} to add
to this buffer. The buffer will then be saved in a lisp file that is Lisp code to this buffer. At the end, Emacs saves the buffer in a
loaded when Emacs is restarted. file that Emacs will load in order to restart the saved session.
If a function in @code{emacs-save-session-functions} returns non-nil If a function in @code{emacs-save-session-functions} returns
Emacs will inform the session manager that the window system shutdown non-@code{nil}, Emacs tells the session manager to cancel the
shall be cancelled. shutdown.
@end defvar @end defvar
Here is an example that just inserts some text into *scratch* when Emacs Here is an example that just inserts some text into *scratch* when
is restarted by the session manager. Emacs is restarted by the session manager.
@example @example
@group @group
...@@ -2038,11 +2040,9 @@ is restarted by the session manager. ...@@ -2038,11 +2040,9 @@ is restarted by the session manager.
@group @group
(defun save-yourself-test () (defun save-yourself-test ()
(progn (insert "(save-excursion
(insert (switch-to-buffer \"*scratch*\")
"(save-excursion (insert \"I am restored\"))")
(switch-to-buffer \"*scratch*\") nil)
(insert \"I am restored\"))")
@result{} nil))
@end group @end group
@end example @end example
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment