Add arch taglines
[bpt/emacs.git] / lispref / os.texi
index 41d07aa..a92f550 100644 (file)
@@ -1,7 +1,7 @@
 @c -*-texinfo-*-
 @c This is part of the GNU Emacs Lisp Reference Manual.
 @c Copyright (C) 1990, 1991, 1992, 1993, 1994, 1995, 1998, 1999
-@c   Free Software Foundation, Inc. 
+@c   Free Software Foundation, Inc.
 @c See the file elisp.texi for copying conditions.
 @setfilename ../info/os
 @node System Interface, Antinews, Calendar, Top
@@ -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
@@ -88,13 +90,13 @@ It loads the library @file{site-start}, unless the option
 @file{site-start.el}.
 @cindex @file{site-start.el}
 
-@item 
+@item
 It loads your init file (usually @file{~/.emacs}), unless @samp{-q},
 @samp{-no-init-file}, or @samp{-batch} was specified on the command line.
 The @samp{-u} option can specify another user whose home directory
 should be used instead of @file{~}.
 
-@item 
+@item
 It loads the library @file{default}, unless @code{inhibit-default-init}
 is non-@code{nil}.  (This is not done in @samp{-batch} mode or if
 @samp{-q} was specified on the command line.)  The library's file name
@@ -109,7 +111,7 @@ It sets the major mode according to @code{initial-major-mode}, provided
 the buffer @samp{*scratch*} is still current and still in Fundamental
 mode.
 
-@item 
+@item
 It loads the terminal-specific Lisp file, if any, except when in batch
 mode or using a window system.
 
@@ -117,10 +119,10 @@ mode or using a window system.
 It displays the initial echo area message, unless you have suppressed
 that with @code{inhibit-startup-echo-area-message}.
 
-@item 
+@item
 It processes the action arguments from the command line.
 
-@item 
+@item
 It runs @code{emacs-startup-hook} and then @code{term-setup-hook}.
 
 @item
@@ -128,10 +130,10 @@ It calls @code{frame-notice-user-settings}, which modifies the
 parameters of the selected frame according to whatever the init files
 specify.
 
-@item 
+@item
 It runs @code{window-setup-hook}.  @xref{Window Systems}.
 
-@item 
+@item
 It displays copyleft, nonwarranty, and basic use information, provided
 there were no remaining command-line arguments (a few steps above),
 the value of @code{inhibit-startup-message} is @code{nil}, and the
@@ -214,7 +216,7 @@ way you can change it with real effect is to do so before dumping
 Emacs.
 @end defvar
 
-  @xref{Init File Examples,,, emacs, The GNU Emacs Manual}, for
+  @xref{Init Examples,, Init File Examples, emacs, The GNU Emacs Manual}, for
 examples of how to make various commonly desired customizations in your
 @file{.emacs} file.
 
@@ -309,7 +311,7 @@ On MS-DOS, if the environment variable @code{TERM} is not set, Emacs
 uses @samp{internal} as the terminal type.
 @end defvar
 
-@defvar term-setup-hook 
+@defvar term-setup-hook
 This variable is a normal hook that Emacs runs after loading your
 init file, the default initialization file (if any) and the
 terminal-specific Lisp file.
@@ -379,7 +381,7 @@ has the form:
 -@var{option}
 @end example
 
-The elements of the @code{command-switch-alist} look like this: 
+The elements of the @code{command-switch-alist} look like this:
 
 @example
 (@var{option} . @var{handler-function})
@@ -398,8 +400,7 @@ arguments is in @code{command-line-args}.)
 
 The command-line arguments are parsed by the @code{command-line-1}
 function in the @file{startup.el} file.  See also @ref{Command
-Switches, , Command Line Switches and Arguments, emacs, The GNU Emacs
-Manual}.
+Arguments, , Command Line Arguments, emacs, The GNU Emacs Manual}.
 @end defvar
 
 @defvar command-line-args
@@ -483,7 +484,7 @@ additional confirmation from the user.  If any of them returns
 @defvar kill-emacs-hook
 This variable is a normal hook; once @code{save-buffers-kill-emacs} is
 finished with all file saving and confirmation, it runs the functions in
-this hook.
+this hook.  This hook is not run in batch mode.
 @end defvar
 
 @node Suspending Emacs
@@ -505,7 +506,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.
@@ -611,6 +612,9 @@ AIX.
 @item berkeley-unix
 Berkeley BSD.
 
+@item cygwin
+Cygwin.
+
 @item dgux
 Data General DGUX operating system.
 
@@ -730,14 +734,18 @@ of this variable.
 process-environment
 @result{} ("l=/usr/stanford/lib/gnuemacs/lisp"
     "PATH=.:/user/lewis/bin:/usr/class:/nfsusr/local/bin"
-    "USER=lewis" 
+    "USER=lewis"
 @end group
 @group
-    "TERM=ibmapa16" 
+    "TERM=ibmapa16"
     "SHELL=/bin/csh"
     "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
@@ -909,6 +917,7 @@ Titles}).
 
 @defun user-real-uid
 This function returns the real @sc{uid} of the user.
+The value may be a floating point number.
 
 @example
 @group
@@ -919,7 +928,8 @@ This function returns the real @sc{uid} of the user.
 @end defun
 
 @defun user-uid
-This function returns the effective @sc{uid} of the user.  
+This function returns the effective @sc{uid} of the user.
+The value may be a floating point number.
 @end defun
 
 @node Time of Day
@@ -995,6 +1005,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 +1038,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,9 +1157,16 @@ returns the resulting string, @code{format-time-string} decodes the
 string using that same coding system.
 @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:
+@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 &optional time
+This function converts a time value into calendrical information.  If
+you don't specify @var{time}, it decodes the current time.  The return
+value is a list of nine elements, as follows:
 
 @example
 (@var{seconds} @var{minutes} @var{hour} @var{day} @var{month} @var{year} @var{dow} @var{dst} @var{zone})
@@ -1199,14 +1233,55 @@ arguments; for example, day 0 means the day preceding the given month.
 
 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.
+For instance, years before 1970 do not work on some systems;
+on others, years as early as 1901 do work.
+@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
 
-  You can set up a @dfn{timer} to call a function at a specified future time or
-after a certain length of idleness.
+  You can set up a @dfn{timer} to call a function at a specified
+future time or after a certain length of idleness.
 
   Emacs cannot run timers at any arbitrary point in a Lisp program; it
 can run them only when Emacs could accept output from a subprocess:
@@ -1215,6 +1290,13 @@ namely, while waiting or inside certain primitive functions such as
 timer's execution may be delayed if Emacs is busy.  However, the time of
 execution is very precise if Emacs is idle.
 
+  Emacs binds @code{inhibit-quit} to @code{t} before calling the timer
+function, because quitting out of many timer functions can leave
+things in an inconsistent state.  This is normally unproblematical
+because most timer functions don't do a lot of work.  Indeed, for a
+timer to calls a function that takes substantial time to run is likely
+to be annoying.
+
 @defun run-at-time time repeat function &rest args
 This function arranges to call @var{function} with arguments @var{args}
 at time @var{time}.  The argument @var{function} is a function to call
@@ -1619,6 +1701,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
@@ -1777,8 +1862,8 @@ 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}.
@@ -1787,11 +1872,11 @@ To define system-specific X11 keysyms, set the variable
 This variable's value should be an alist with one element for each
 system-specific keysym.  Each element has the form @code{(@var{code}
 . @var{symbol})}, where @var{code} is the numeric keysym code (not
-including the ``vendor specific'' bit, 
+including the ``vendor specific'' bit,
 @ifnottex
 -2**28),
 @end ifnottex
-@tex 
+@tex
 $-2^{28}$),
 @end tex
 and @var{symbol} is the name for the function key.
@@ -1801,7 +1886,7 @@ by HP X servers) whose numeric code is
 @ifnottex
 -2**28
 @end ifnottex
-@tex 
+@tex
 $-2^{28}$
 @end tex
 + 168.
@@ -1814,6 +1899,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
@@ -1917,10 +2017,65 @@ 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
+
+@ignore
+   arch-tag: 8378814a-30d7-467c-9615-74a80b9988a7
+@end ignore