Correct the explanation of glyphs and glyph table.
[bpt/emacs.git] / lispref / os.texi
index f9afd45..a6ca1a7 100644 (file)
@@ -23,13 +23,15 @@ pertaining to the terminal and the screen.
 * Time of Day::                Getting the current time.
 * Time Conversion::     Converting a time from numeric form to a string, or
                           to calendrical data (or vice versa).
+* Time Calculations::   Adding, subtracting, comparing times, etc.
 * Timers::             Setting a timer to call a function at a certain time.
 * Terminal Input::      Recording terminal input for debugging.
 * Terminal Output::     Recording terminal output for debugging.
 * Sound Output::        Playing sounds on the computer's speaker.
-* Special Keysyms::     Defining system-specific key symbols for X windows.
+* X11 Keysyms::         Operating on key symbols for X Windows
 * Flow Control::        How to turn output flow control on or off.
 * Batch Mode::          Running Emacs without terminal interaction.
+* Session Management::  Saving and restoring state with X Session Management.
 @end menu
 
 @node Starting Up
@@ -505,7 +507,7 @@ subprocess of Emacs.  Then you would exit the shell to return to Emacs.
 may not have a parent that can resume it again, and in any case you can
 give input to some other job such as a shell merely by moving to a
 different window.  Therefore, suspending is not allowed when Emacs is using
-a window system (X Windows or MS Windows).
+a window system (X or MS Windows).
 
 @defun suspend-emacs string
 This function stops Emacs and returns control to the superior process.
@@ -710,7 +712,7 @@ SHELL=/bin/csh
 HOME=/user/lewis
 @end group
 @end example
-@end defun
+@end deffn
 
 @c Emacs 19 feature
 @deffn Command setenv variable value
@@ -738,6 +740,10 @@ process-environment
     "HOME=/user/lewis")
 @end group
 @end smallexample
+
+If @code{process-environment} contains ``duplicate'' elements that
+specify the same environment variable, the first of these elements
+specifies the variable, and the other ``duplicates'' are ignored.
 @end defvar
 
 @defvar path-separator
@@ -995,6 +1001,18 @@ integers.  Thus, you can use times obtained from @code{current-time}
 (see above) and from @code{file-attributes} (@pxref{File Attributes}).
 @end defun
 
+@defun float-time &optional time-value
+This function returns the current time as a floating-point number of
+seconds since the epoch.  The argument @var{time-value}, if given,
+specifies a time to convert instead of the current time.  The argument
+should have the same form as for @code{current-time-string} (see
+above), and it also accepts the output of @code{current-time} and
+@code{file-attributes}.
+
+@emph{Warning}: Since the result is floating point, it may not be
+exact.  Do not use this function if precise time stamps are required.
+@end defun
+
 @node Time Conversion
 @section Time Conversion
 
@@ -1016,6 +1034,11 @@ the number of years since the year 1 B.C., and do not skip zero as
 traditional Gregorian years do; for example, the year number @minus{}37
 represents the Gregorian year 38 B.C@.
 
+@defun date-to-time string
+This function parses the time-string @var{string} and returns the
+corresponding time value.
+@end defun
+
 @defun format-time-string format-string &optional time universal
 This function converts @var{time} (or the current time, if @var{time} is
 omitted) to a string according to @var{format-string}.  The argument
@@ -1130,6 +1153,12 @@ returns the resulting string, @code{format-time-string} decodes the
 string using that same coding system.
 @end defun
 
+@defun seconds-to-time seconds
+This function converts @var{seconds}, a floating point number of
+seconds since the epoch, to a time value and returns that.  To perform
+the inverse conversion, use @code{float-time}.
+@end defun
+
 @defun decode-time time
 This function converts a time value into calendrical information.  The
 return value is a list of nine elements, as follows:
@@ -1201,6 +1230,45 @@ The operating system puts limits on the range of possible time values;
 if you try to encode a time that is out of range, an error results.
 @end defun
 
+@node Time Calculations
+@section Time Calculations
+
+  These functions perform calendrical computations using time values
+(the kind of list that @code{current-time} returns).
+
+@defun time-less-p t1 t2
+This returns @code{t} if time value @var{t1} is less than time value
+@var{t2}.
+@end defun
+
+@defun time-subtract t1 t2
+This returns the time difference @var{t1} @minus{} @var{t2} between
+two time values, in the same format as a time value.
+@end defun
+
+@defun time-add t1 t2
+This returns the sum of two time values, one of which ought to
+represent a time difference rather than a point in time.
+Here is how to add a number of seconds to a time value:
+
+@example
+(time-add @var{time} (seconds-to-time @var{seconds}))
+@end example
+@end defun
+
+@defun time-to-days time
+This function returns the number of days between the beginning of year
+1 and @var{time}.
+@end defun
+
+@defun time-to-day-in-year time
+This returns the day number within the year corresponding to @var{time}.
+@end defun
+
+@defun date-leap-year-p year
+This function returns @code{t} if @var{year} is a leap year.
+@end defun
+
 @node Timers
 @section Timers for Delayed Execution
 @cindex timer
@@ -1619,6 +1687,9 @@ they were used as parts of key sequences.  Thus, you always get the last
 100 input events, not counting events generated by keyboard macros.
 (These are excluded because they are less interesting for debugging; it
 should be enough to see the events that invoked the macros.)
+
+A call to @code{clear-this-command-keys} (@pxref{Command Loop Info})
+causes this function to return an empty vector immediately afterward.
 @end defun
 
 @deffn Command open-dribble-file filename
@@ -1754,6 +1825,10 @@ sound file.  We recommend using a unibyte string.
 This specifies how loud to play the sound.  It should be a number in the
 range of 0 to 1.  The default is to use whatever volume has been
 specified before.
+
+@item :device @var{device}
+This specifies the system device on which to play the sound, as a
+string.  The default device is system-dependent.
 @end table
 
 Before actually playing the sound, @code{play-sound}
@@ -1761,14 +1836,20 @@ calls the functions in the list @code{play-sound-functions}.
 Each function is called with one argument, @var{sound}.
 @end defun
 
+@defun play-sound-file file &optional volume device
+@tindex play-sound-file
+This function is an alternative interface to playing a sound @var{file}
+specifying an optional @var{volume} and @var{device}.
+@end defun
+
 @tindex play-sound-functions
 @defvar play-sound-functions
 A list of functions to be called before playing a sound.  Each function
 is called with one argument, a property list that describes the sound.
 @end defvar
 
-@node Special Keysyms
-@section System-Specific X11 Keysyms
+@node X11 Keysyms
+@section Operating on X11 Keysyms
 
 To define system-specific X11 keysyms, set the variable
 @code{system-key-alist}.
@@ -1804,6 +1885,21 @@ The variable is always local to the current terminal, and cannot be
 buffer-local.  @xref{Multiple Displays}.
 @end defvar
 
+You can specify which keysyms Emacs should use for the Meta, Alt, Hyper, and Super modifiers by setting these variables:
+
+@defvar x-alt-keysym
+@defvarx x-meta-keysym
+@defvarx x-hyper-keysym
+@defvarx x-super-keysym
+The name of the keysym that should stand for the Alt modifier
+(respectively, for Meta, Hyper, and Super).  For example, here is
+how to swap the Meta and Alt modifiers within Emacs:
+@lisp
+(setq x-alt-keysym 'meta)
+(setq x-meta-keysym 'alt)
+@end lisp
+@end defvar
+
 @node Flow Control
 @section Flow Control
 @cindex flow control characters
@@ -1907,10 +2003,61 @@ calls @var{function} with no arguments.
   Any Lisp program output that would normally go to the echo area,
 either using @code{message}, or using @code{prin1}, etc., with @code{t}
 as the stream, goes instead to Emacs's standard error descriptor when
-in batch mode.  Thus, Emacs behaves much like a noninteractive
+in batch mode.  Similarly, input that would normally come from the
+minibuffer is read from the standard input descriptor.
+Thus, Emacs behaves much like a noninteractive
 application program.  (The echo area output that Emacs itself normally
 generates, such as command echoing, is suppressed entirely.)
 
 @defvar noninteractive
 This variable is non-@code{nil} when Emacs is running in batch mode.
 @end defvar
+
+@node Session Management
+@section Session Management
+@cindex session manager
+
+Emacs supports the X Session Management Protocol for suspension and
+restart of applications.  In the X Window System, a program called the
+@dfn{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 @samp{--smid
+@var{session}}.
+
+@defvar emacs-save-session-functions
+@tindex emacs-save-session-functions
+Emacs supports saving state by using a hook called
+@code{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 the current buffer set
+to a temporary buffer.  Each functions can use @code{insert} to add
+Lisp code to this buffer.  At the end, Emacs saves the buffer in a
+file that Emacs will load in order to restart the saved session.
+
+If a function in @code{emacs-save-session-functions} returns
+non-@code{nil}, Emacs tells the session manager to cancel the
+shutdown.
+@end defvar
+
+Here is an example that just inserts some text into *scratch* when
+Emacs is restarted by the session manager.
+
+@example
+@group
+(add-hook 'emacs-save-session-functions 'save-yourself-test)
+@end group
+
+@group
+(defun save-yourself-test ()
+  (insert "(save-excursion
+  (switch-to-buffer \"*scratch*\")
+  (insert \"I am restored\"))")
+  nil)
+@end group
+@end example