2000 |
|
|
2001 |
@node Session Management |
@node Session Management |
2002 |
@section Session Management |
@section Session Management |
2003 |
@cindex session management |
@cindex session manager |
|
@cindex X session management protocol |
|
2004 |
|
|
2005 |
X has defined the X Session Management Protocol to handle start and |
Emacs supports the X Session Management Protocol for suspension and |
2006 |
restart of applications. There is one session manager who has the |
restart of applications. In the X Window System, a program called the |
2007 |
responsibility to keep track of the applications that are running |
@dfn{session manager} has the responsibility to keep track of the |
2008 |
when the window system shuts down, so the session manager later can |
applications that are running. During shutdown, the session manager |
2009 |
restart them. |
asks applications to save their state, and delays the actual shutdown |
2010 |
|
until they respond. An application can also cancel the shutdown. |
2011 |
Before the session manager shuts down the window system it informs |
|
2012 |
applications that they should save their state. When the applications |
When the session manager restarts a suspended session, it directs |
2013 |
are restarted, the applications will restore their state. |
these applications to individually reload their saved state. It does |
2014 |
|
this by specifying a special command-line argument that says what |
2015 |
|
saved session to restore. For Emacs, this argument is @samp{--smid |
2016 |
|
@var{session}}. |
2017 |
|
|
2018 |
@defvar emacs-save-session-functions |
@defvar emacs-save-session-functions |
2019 |
@tindex emacs-save-session-functions |
@tindex emacs-save-session-functions |
2020 |
Emacs supports saving state by using a hook called |
Emacs supports saving state by using a hook called |
2021 |
@code{emacs-save-session-functions}. Each function in this hook is |
@code{emacs-save-session-functions}. Each function in this hook is |
2022 |
called when the session manager tells Emacs that the window system is |
called when the session manager tells Emacs that the window system is |
2023 |
shutting down. The functions are called with the current buffer set to |
shutting down. The functions are called with the current buffer set |
2024 |
a temporary buffer. Functions can use @code{insert} to add lisp code |
to a temporary buffer. Each functions can use @code{insert} to add |
2025 |
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 |
2026 |
loaded when Emacs is restarted. |
file that Emacs will load in order to restart the saved session. |
2027 |
|
|
2028 |
If a function in @code{emacs-save-session-functions} returns non-nil |
If a function in @code{emacs-save-session-functions} returns |
2029 |
Emacs will inform the session manager that the window system shutdown |
non-@code{nil}, Emacs tells the session manager to cancel the |
2030 |
shall be cancelled. |
shutdown. |
2031 |
@end defvar |
@end defvar |
2032 |
|
|
2033 |
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 |
2034 |
is restarted by the session manager. |
Emacs is restarted by the session manager. |
2035 |
|
|
2036 |
@example |
@example |
2037 |
@group |
@group |
2040 |
|
|
2041 |
@group |
@group |
2042 |
(defun save-yourself-test () |
(defun save-yourself-test () |
2043 |
(progn |
(insert "(save-excursion |
2044 |
(insert |
(switch-to-buffer \"*scratch*\") |
2045 |
"(save-excursion |
(insert \"I am restored\"))") |
2046 |
(switch-to-buffer \"*scratch*\") |
nil) |
|
(insert \"I am restored\"))") |
|
|
@result{} nil)) |
|
2047 |
@end group |
@end group |
2048 |
@end example |
@end example |