comparison lispref/os.texi @ 43829:7e937c00ff00

Clean up session manager node.
author Richard M. Stallman <rms@gnu.org>
date Mon, 11 Mar 2002 09:10:19 +0000
parents 340b4384f4ac
children b77938fad6d0
comparison
equal deleted inserted replaced
43828:0e61ba1b551f 43829:7e937c00ff00
1998 This variable is non-@code{nil} when Emacs is running in batch mode. 1998 This variable is non-@code{nil} when Emacs is running in batch mode.
1999 @end defvar 1999 @end defvar
2000 2000
2001 @node Session Management 2001 @node Session Management
2002 @section Session Management 2002 @section Session Management
2003 @cindex session management 2003 @cindex session manager
2004 @cindex X session management protocol 2004
2005 2005 Emacs supports the X Session Management Protocol for suspension and
2006 X has defined the X Session Management Protocol to handle start and 2006 restart of applications. In the X Window System, a program called the
2007 restart of applications. There is one session manager who has the 2007 @dfn{session manager} has the responsibility to keep track of the
2008 responsibility to keep track of the applications that are running 2008 applications that are running. During shutdown, the session manager
2009 when the window system shuts down, so the session manager later can 2009 asks applications to save their state, and delays the actual shutdown
2010 restart them. 2010 until they respond. An application can also cancel the shutdown.
2011 2011
2012 Before the session manager shuts down the window system it informs 2012 When the session manager restarts a suspended session, it directs
2013 applications that they should save their state. When the applications 2013 these applications to individually reload their saved state. It does
2014 are restarted, the applications will restore their state. 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}}.
2015 2017
2016 @defvar emacs-save-session-functions 2018 @defvar emacs-save-session-functions
2017 @tindex emacs-save-session-functions 2019 @tindex emacs-save-session-functions
2018 Emacs supports saving state by using a hook called 2020 Emacs supports saving state by using a hook called
2019 @code{emacs-save-session-functions}. Each function in this hook is 2021 @code{emacs-save-session-functions}. Each function in this hook is
2020 called when the session manager tells Emacs that the window system is 2022 called when the session manager tells Emacs that the window system is
2021 shutting down. The functions are called with the current buffer set to 2023 shutting down. The functions are called with the current buffer set
2022 a temporary buffer. Functions can use @code{insert} to add lisp code 2024 to a temporary buffer. Each functions can use @code{insert} to add
2023 to this buffer. The buffer will then be saved in a lisp file that is 2025 Lisp code to this buffer. At the end, Emacs saves the buffer in a
2024 loaded when Emacs is restarted. 2026 file that Emacs will load in order to restart the saved session.
2025 2027
2026 If a function in @code{emacs-save-session-functions} returns non-nil 2028 If a function in @code{emacs-save-session-functions} returns
2027 Emacs will inform the session manager that the window system shutdown 2029 non-@code{nil}, Emacs tells the session manager to cancel the
2028 shall be cancelled. 2030 shutdown.
2029 @end defvar 2031 @end defvar
2030 2032
2031 Here is an example that just inserts some text into *scratch* when Emacs 2033 Here is an example that just inserts some text into *scratch* when
2032 is restarted by the session manager. 2034 Emacs is restarted by the session manager.
2033 2035
2034 @example 2036 @example
2035 @group 2037 @group
2036 (add-hook 'emacs-save-session-functions 'save-yourself-test) 2038 (add-hook 'emacs-save-session-functions 'save-yourself-test)
2037 @end group 2039 @end group
2038 2040
2039 @group 2041 @group
2040 (defun save-yourself-test () 2042 (defun save-yourself-test ()
2041 (progn 2043 (insert "(save-excursion
2042 (insert 2044 (switch-to-buffer \"*scratch*\")
2043 "(save-excursion 2045 (insert \"I am restored\"))")
2044 (switch-to-buffer \"*scratch*\") 2046 nil)
2045 (insert \"I am restored\"))") 2047 @end group
2046 @result{} nil)) 2048 @end example
2047 @end group
2048 @end example