os.texi 85.3 KB
Newer Older
Glenn Morris's avatar
Glenn Morris committed
1 2
@c -*-texinfo-*-
@c This is part of the GNU Emacs Lisp Reference Manual.
3
@c Copyright (C) 1990-1995, 1998-1999, 2001-2012
Glenn Morris's avatar
Glenn Morris committed
4
@c   Free Software Foundation, Inc.
Glenn Morris's avatar
Glenn Morris committed
5
@c See the file elisp.texi for copying conditions.
6
@setfilename ../../info/os
Tom Tromey's avatar
Tom Tromey committed
7
@node System Interface, Packaging, Display, Top
Glenn Morris's avatar
Glenn Morris committed
8 9 10
@chapter Operating System Interface

  This chapter is about starting and getting out of Emacs, access to
Glenn Morris's avatar
Glenn Morris committed
11
values in the operating system environment, and terminal input, output.
Glenn Morris's avatar
Glenn Morris committed
12

13 14 15
  @xref{Building Emacs}, for related information.  @xref{Display}, for
additional operating system status information pertaining to the
terminal and the screen.
Glenn Morris's avatar
Glenn Morris committed
16 17 18 19 20 21

@menu
* Starting Up::         Customizing Emacs startup processing.
* Getting Out::         How exiting works (permanent or temporary).
* System Environment::  Distinguish the name and kind of system.
* User Identification:: Finding the name and user id of the user.
Glenn Morris's avatar
Glenn Morris committed
22
* Time of Day::         Getting the current time.
23
* Time Conversion::     Converting a time from numeric form to
24
                          calendrical data and vice versa.
Glenn Morris's avatar
Glenn Morris committed
25 26 27 28
* Time Parsing::        Converting a time from numeric form to text
                          and vice versa.
* Processor Run Time::  Getting the run time used by Emacs.
* Time Calculations::   Adding, subtracting, comparing times, etc.
Glenn Morris's avatar
Glenn Morris committed
29
* Timers::              Setting a timer to call a function at a certain time.
Glenn Morris's avatar
Glenn Morris committed
30 31 32 33 34
* Idle Timers::         Setting a timer to call a function when Emacs has
                          been idle for a certain length of time.
* Terminal Input::      Accessing and recording terminal input.
* Terminal Output::     Controlling and recording terminal output.
* Sound Output::        Playing sounds on the computer's speaker.
35
* X11 Keysyms::         Operating on key symbols for X Windows.
Glenn Morris's avatar
Glenn Morris committed
36 37
* Batch Mode::          Running Emacs without terminal interaction.
* Session Management::  Saving and restoring state with X Session Management.
38
* Dynamic Libraries::   On-demand loading of support libraries.
Glenn Morris's avatar
Glenn Morris committed
39 40 41 42 43 44 45 46 47 48
@end menu

@node Starting Up
@section Starting Up Emacs

  This section describes what Emacs does when it is started, and how you
can customize these actions.

@menu
* Startup Summary::         Sequence of actions Emacs performs at startup.
49
* Init File::               Details on reading the init file.
Glenn Morris's avatar
Glenn Morris committed
50 51 52 53 54 55 56 57 58 59 60
* Terminal-Specific::       How the terminal-specific Lisp file is read.
* Command-Line Arguments::  How command-line arguments are processed,
                              and how you can customize them.
@end menu

@node Startup Summary
@subsection Summary: Sequence of Actions at Startup
@cindex initialization of Emacs
@cindex startup of Emacs
@cindex @file{startup.el}

61
  When Emacs is started up, it performs the following operations
Glenn Morris's avatar
Glenn Morris committed
62
(see @code{normal-top-level} in @file{startup.el}):
Glenn Morris's avatar
Glenn Morris committed
63 64 65 66

@enumerate
@item
It adds subdirectories to @code{load-path}, by running the file named
67 68 69 70
@file{subdirs.el} in each directory in the list.  Normally, this file
adds the directory's subdirectories to the list, and those are scanned
in their turn.  The files @file{subdirs.el} are normally generated
automatically when Emacs is installed.
Glenn Morris's avatar
Glenn Morris committed
71

Glenn Morris's avatar
Glenn Morris committed
72 73 74 75 76 77 78 79 80
@item
It registers input methods by loading any @file{leim-list.el} file
found in the @code{load-path}.

@c It removes PWD from the environment if it is not accurate.
@c It abbreviates default-directory.

@c Now normal-top-level calls command-line.

81
@vindex before-init-time
Glenn Morris's avatar
Glenn Morris committed
82
@item
83
It sets the variable @code{before-init-time} to the value of
84
@code{current-time} (@pxref{Time of Day}).  It also sets
85 86
@code{after-init-time} to @code{nil}, which signals to Lisp programs
that Emacs is being initialized.
Glenn Morris's avatar
Glenn Morris committed
87

Glenn Morris's avatar
Glenn Morris committed
88 89 90 91 92 93 94 95
@c set-locale-environment
@item
It sets the language environment and the terminal coding system,
if requested by environment variables such as @code{LANG}.

@item
It does some basic parsing of the command-line arguments.

96 97
@vindex initial-window-system@r{, and startup}
@vindex window-system-initialization-alist
Glenn Morris's avatar
Glenn Morris committed
98
@item
Glenn Morris's avatar
Glenn Morris committed
99 100 101 102 103 104 105 106 107
If not running in batch mode, it initializes the window system that
the variable @code{initial-window-system} specifies (@pxref{Window
Systems, initial-window-system}).  The initialization function for
each supported window system is specified by
@code{window-system-initialization-alist}.  If the value
of @code{initial-window-system} is @var{windowsystem}, then the
appropriate initialization function is defined in the file
@file{term/@var{windowsystem}-win.el}.  This file should have been
compiled into the Emacs executable when it was built.
108 109

@item
Glenn Morris's avatar
Glenn Morris committed
110
It runs the normal hook @code{before-init-hook}.
Glenn Morris's avatar
Glenn Morris committed
111 112

@item
Glenn Morris's avatar
Glenn Morris committed
113 114
If appropriate (e.g., not in batch mode or started as a daemon), it
creates a graphical frame.
Glenn Morris's avatar
Glenn Morris committed
115 116

@item
Glenn Morris's avatar
Glenn Morris committed
117 118 119 120
It initializes the initial frame's faces, and sets up the menu bar
and tool bar if needed.  If graphical frames are supported, it sets up
the tool bar even if the current frame is not a graphical one, since a
graphical frame may be created later on.
Glenn Morris's avatar
Glenn Morris committed
121 122

@item
Glenn Morris's avatar
Glenn Morris committed
123 124 125 126 127 128 129 130
It use @code{custom-reevaluate-setting} to re-initialize the members
of the list @code{custom-delayed-init-variables}.  These are any
pre-loaded user options whose default value depends on the run-time,
rather than build-time, context.
@xref{Building Emacs, custom-initialize-delay}.

@c @item
@c It registers the colors available for tty frames.
131 132

@item
133 134
It loads the library @file{site-start}, if it exists.  This is not
done if the options @samp{-Q} or @samp{--no-site-file} were specified.
Glenn Morris's avatar
Glenn Morris committed
135 136 137
@cindex @file{site-start.el}

@item
138 139 140 141
It loads your init file (@pxref{Init File}).  This is not done if the
options @samp{-q}, @samp{-Q}, or @samp{--batch} were specified.  If
the @samp{-u} option was specified, Emacs looks for the init file in
that user's home directory instead.
Glenn Morris's avatar
Glenn Morris committed
142 143

@item
144 145 146
It loads the library @file{default}, if it exists.  This is not done
if @code{inhibit-default-init} is non-@code{nil}, nor if the options
@samp{-q}, @samp{-Q}, or @samp{--batch} were specified.
Glenn Morris's avatar
Glenn Morris committed
147 148
@cindex @file{default.el}

149 150
@item
It loads your abbrevs from the file specified by
151 152 153
@code{abbrev-file-name}, if that file exists and can be read
(@pxref{Abbrev Files, abbrev-file-name}).  This is not done if the
option @samp{--batch} was specified.
154

Chong Yidong's avatar
Chong Yidong committed
155 156 157 158 159
@item
If @code{package-enable-at-startup} is non-@code{nil}, it calls the
function @code{package-initialize} to activate any optional Emacs Lisp
package that has been installed.  @xref{Packaging Basics}.

160 161
@vindex after-init-time
@item
162 163 164 165
It sets the variable @code{after-init-time} to the value of
@code{current-time}.  This variable was set to @code{nil} earlier;
setting it to the current time signals that the initialization phase
is over, and, together with @code{before-init-time}, provides the
166 167
measurement of how long it took.

Glenn Morris's avatar
Glenn Morris committed
168 169 170 171
@item
It runs the normal hook @code{after-init-hook}.

@item
172 173 174
If the buffer @samp{*scratch*} exists and is still in Fundamental mode
(as it should be by default), it sets its major mode according to
@code{initial-major-mode}.
Glenn Morris's avatar
Glenn Morris committed
175 176

@item
177
If started on a text terminal, it loads the terminal-specific
178 179 180
Lisp library, which is specified by the variable
@code{term-file-prefix} (@pxref{Terminal-Specific}).  This is not done
in @code{--batch} mode, nor if @code{term-file-prefix} is @code{nil}.
Glenn Morris's avatar
Glenn Morris committed
181

Glenn Morris's avatar
Glenn Morris committed
182 183
@c Now command-line calls command-line-1.

Glenn Morris's avatar
Glenn Morris committed
184 185 186 187 188
@item
It displays the initial echo area message, unless you have suppressed
that with @code{inhibit-startup-echo-area-message}.

@item
Glenn Morris's avatar
Glenn Morris committed
189
It processes any command-line options that were not handled earlier.
Glenn Morris's avatar
Glenn Morris committed
190

Glenn Morris's avatar
Glenn Morris committed
191 192
@c This next one is back in command-line, but the remaining bits of
@c command-line-1 are not done if noninteractive.
193 194 195 196 197 198 199 200
@item
It now exits if the option @code{--batch} was specified.

@item
If @code{initial-buffer-choice} is a string, it visits the file with
that name.  Furthermore, if the @samp{*scratch*} buffer exists and is
empty, it inserts @code{initial-scratch-message} into that buffer.

Glenn Morris's avatar
Glenn Morris committed
201 202 203 204 205 206 207 208 209
@c To make things nice and confusing, the next three items can be
@c called from two places.  If displaying a startup screen, they are
@c called in command-line-1 before the startup screen is shown.
@c inhibit-startup-hooks is then set and window-setup-hook set to nil.
@c If not displaying a startup screen, they are are called in
@c normal-top-level.
@c FIXME?  So it seems they can be called before or after the
@c daemon/session restore step?

Glenn Morris's avatar
Glenn Morris committed
210 211 212 213 214 215 216 217 218 219 220
@item
It runs @code{emacs-startup-hook} and then @code{term-setup-hook}.

@item
It calls @code{frame-notice-user-settings}, which modifies the
parameters of the selected frame according to whatever the init files
specify.

@item
It runs @code{window-setup-hook}.  @xref{Window Systems}.

221
@item
222 223 224 225 226
It displays the @dfn{startup screen}, which is a special buffer that
contains information about copyleft and basic Emacs usage.  This is
not done if @code{initial-buffer-choice} or
@code{inhibit-startup-screen} are @code{nil}, nor if the
@samp{--no-splash} or @samp{-Q} command-line options were specified.
227

Glenn Morris's avatar
Glenn Morris committed
228 229 230 231 232 233 234 235 236 237 238 239
@c End of command-line-1.

@c Back to command-line from command-line-1.

@c This is the point at which we actually exit in batch mode, but the
@c last few bits of command-line-1 are not done in batch mode.

@item
If the option @code{--daemon} was specified, it calls
@code{server-start} and detaches from the controlling terminal.
@xref{Emacs Server,,, emacs, The GNU Emacs Manual}.

240 241 242
@item
If started by the X session manager, it calls
@code{emacs-session-restore} passing it as argument the ID of the
243
previous session.  @xref{Session Management}.
Glenn Morris's avatar
Glenn Morris committed
244 245 246 247 248

@c End of command-line.

@c Back to normal-top-level from command-line.

Glenn Morris's avatar
Glenn Morris committed
249 250
@end enumerate

251 252 253
@noindent
The following options affect some aspects of the startup sequence.

254
@defopt inhibit-startup-screen
255 256 257
This variable, if non-@code{nil}, inhibits the startup screen.  In
that case, Emacs typically displays the @samp{*scratch*} buffer; but
see @code{initial-buffer-choice}, below.
Glenn Morris's avatar
Glenn Morris committed
258

259 260 261
Do not set this variable in the init file of a new user, or in a way
that affects more than one user, as that would prevent new users from
receiving information about copyleft and basic Emacs usage.
262

263 264
@vindex inhibit-startup-message
@vindex inhibit-splash-screen
265 266 267 268 269 270
@code{inhibit-startup-message} and @code{inhibit-splash-screen} are
aliases for this variable.
@end defopt

@defopt initial-buffer-choice
This variable, if non-@code{nil}, determines a file or buffer for
271 272 273 274 275 276 277
Emacs to display after starting up, instead of the startup screen.
@ignore
@c I do not think this should be mentioned.  AFAICS it is just a dodge
@c around inhibit-startup-screen not being settable on a site-wide basis.
If its value is @code{t}, Emacs displays the @samp{*scratch*} buffer. 
@end ignore
If its value is a string, that specifies the name of a file for Emacs to
278
visit.
Glenn Morris's avatar
Glenn Morris committed
279 280 281 282 283 284 285 286 287 288 289 290 291 292
@end defopt

@defopt inhibit-startup-echo-area-message
This variable controls the display of the startup echo area message.
You can suppress the startup echo area message by adding text with this
form to your init file:

@example
(setq inhibit-startup-echo-area-message
      "@var{your-login-name}")
@end example

Emacs explicitly checks for an expression as shown above in your init
file; your login name must appear in the expression as a Lisp string
293
constant.  You can also use the Custom interface.  Other methods of setting
Glenn Morris's avatar
Glenn Morris committed
294
@code{inhibit-startup-echo-area-message} to the same value do not
295 296 297 298
inhibit the startup message.  This way, you can easily inhibit the
message for yourself if you wish, but thoughtless copying of your init
file will not inhibit the message for someone else.
@end defopt
Glenn Morris's avatar
Glenn Morris committed
299

300 301 302 303
@defopt initial-scratch-message
This variable, if non-@code{nil}, should be a string, which is
inserted into the @samp{*scratch*} buffer when Emacs starts up.  If it
is @code{nil}, the @samp{*scratch*} buffer is empty.
Glenn Morris's avatar
Glenn Morris committed
304 305
@end defopt

306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333
@noindent
The following command-line options affect some aspects of the startup
sequence.  @xref{Initial Options,,, emacs, The GNU Emacs Manual}.

@table @code
@item --no-splash
Do not display a splash screen.

@item --batch
Run without an interactive terminal.  @xref{Batch Mode}.

@item --daemon
Do not initialize any display; just start a server in the background.

@item --no-init-file
@itemx -Q
Do not load either the init file, or the @file{default} library.

@item --no-site-file
Do not load the @file{site-start} library.

@item --quick
@itemx -Q
Equivalent to @samp{-q --no-site-file --no-splash}.
@c and --no-site-lisp, but let's not mention that here.
@end table


Glenn Morris's avatar
Glenn Morris committed
334
@node Init File
Chong Yidong's avatar
Chong Yidong committed
335
@subsection The Init File
Glenn Morris's avatar
Glenn Morris committed
336 337
@cindex init file
@cindex @file{.emacs}
Chong Yidong's avatar
Chong Yidong committed
338
@cindex @file{init.el}
Glenn Morris's avatar
Glenn Morris committed
339 340

  When you start Emacs, it normally attempts to load your @dfn{init
341 342
file}.  This is either a file named @file{.emacs} or @file{.emacs.el}
in your home directory, or a file named @file{init.el} in a
Glenn Morris's avatar
Glenn Morris committed
343 344 345
subdirectory named @file{.emacs.d} in your home directory.
@ignore
Whichever place you use, you can also compile the file (@pxref{Byte
346 347
Compilation}); then the actual file loaded will be @file{.emacs.elc}
or @file{init.elc}.
Glenn Morris's avatar
Glenn Morris committed
348
@end ignore
Glenn Morris's avatar
Glenn Morris committed
349 350 351 352 353 354 355 356 357 358 359 360 361 362

  The command-line switches @samp{-q}, @samp{-Q}, and @samp{-u}
control whether and where to find the init file; @samp{-q} (and the
stronger @samp{-Q}) says not to load an init file, while @samp{-u
@var{user}} says to load @var{user}'s init file instead of yours.
@xref{Entering Emacs,,, emacs, The GNU Emacs Manual}.  If neither
option is specified, Emacs uses the @code{LOGNAME} environment
variable, or the @code{USER} (most systems) or @code{USERNAME} (MS
systems) variable, to find your home directory and thus your init
file; this way, even if you have su'd, Emacs still loads your own init
file.  If those environment variables are absent, though, Emacs uses
your user-id to find your home directory.

@cindex default init file
Chong Yidong's avatar
Chong Yidong committed
363 364 365 366 367 368 369
  An Emacs installation may have a @dfn{default init file}, which is a
Lisp library named @file{default.el}.  Emacs finds this file through
the standard search path for libraries (@pxref{How Programs Do
Loading}).  The Emacs distribution does not come with this file; it is
intended for local customizations.  If the default init file exists,
it is loaded whenever you start Emacs, except in batch mode or if
@samp{-q} (or @samp{-Q}) is specified.  But your own personal init
Glenn Morris's avatar
Glenn Morris committed
370 371 372 373 374 375 376 377
file, if any, is loaded first; if it sets @code{inhibit-default-init}
to a non-@code{nil} value, then Emacs does not subsequently load the
@file{default.el} file.

  Another file for site-customization is @file{site-start.el}.  Emacs
loads this @emph{before} the user's init file.  You can inhibit the
loading of this file with the option @samp{--no-site-file}.

378
@defopt site-run-file
Glenn Morris's avatar
Glenn Morris committed
379 380 381 382
This variable specifies the site-customization file to load before the
user's init file.  Its normal value is @code{"site-start"}.  The only
way you can change it with real effect is to do so before dumping
Emacs.
383
@end defopt
Glenn Morris's avatar
Glenn Morris committed
384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438

  @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.

@defopt inhibit-default-init
This variable prevents Emacs from loading the default initialization
library file for your session of Emacs.  If its value is non-@code{nil},
then the default library is not loaded.  The default value is
@code{nil}.
@end defopt

@defvar before-init-hook
This normal hook is run, once, just before loading all the init files
(the user's init file, @file{default.el}, and/or @file{site-start.el}).
(The only way to change it with real effect is before dumping Emacs.)
@end defvar

@defvar after-init-hook
This normal hook is run, once, just after loading all the init files
(the user's init file, @file{default.el}, and/or @file{site-start.el}),
before loading the terminal-specific library and processing the
command-line action arguments.
@end defvar

@defvar emacs-startup-hook
This normal hook is run, once, just after handling the command line
arguments, just before @code{term-setup-hook}.
@end defvar

@defvar user-init-file
This variable holds the absolute file name of the user's init file.  If the
actual init file loaded is a compiled file, such as @file{.emacs.elc},
the value refers to the corresponding source file.
@end defvar

@defvar user-emacs-directory
This variable holds the name of the @file{.emacs.d} directory.  It is
ordinarily @file{~/.emacs.d}, but differs on some platforms.
@end defvar

@node Terminal-Specific
@subsection Terminal-Specific Initialization
@cindex terminal-specific initialization

  Each terminal type can have its own Lisp library that Emacs loads when
run on that type of terminal.  The library's name is constructed by
concatenating the value of the variable @code{term-file-prefix} and the
terminal type (specified by the environment variable @code{TERM}).
Normally, @code{term-file-prefix} has the value
@code{"term/"}; changing this is not recommended.  Emacs finds the file
in the normal manner, by searching the @code{load-path} directories, and
trying the @samp{.elc} and @samp{.el} suffixes.

@cindex Termcap
Chong Yidong's avatar
Chong Yidong committed
439 440 441 442 443
  The usual role of a terminal-specific library is to enable special
keys to send sequences that Emacs can recognize.  It may also need to
set or add to @code{input-decode-map} if the Termcap or Terminfo entry
does not specify all the terminal's function keys.  @xref{Terminal
Input}.
Glenn Morris's avatar
Glenn Morris committed
444 445 446 447 448

  When the name of the terminal type contains a hyphen, and no library
is found whose name is identical to the terminal's name, Emacs strips
from the terminal's name the last hyphen and everything that follows
it, and tries again.  This process is repeated until Emacs finds a
Chong Yidong's avatar
Chong Yidong committed
449 450 451 452 453 454
matching library, or until there are no more hyphens in the name
(i.g.@: there is no terminal-specific library).  For example, if the
terminal name is @samp{xterm-256color} and there is no
@file{term/xterm-256color.el} library, Emacs tries to load
@file{term/xterm.el}.  If necessary, the terminal library can evaluate
@code{(getenv "TERM")} to find the full name of the terminal type.
Glenn Morris's avatar
Glenn Morris committed
455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470

  Your init file can prevent the loading of the
terminal-specific library by setting the variable
@code{term-file-prefix} to @code{nil}.  This feature is useful when
experimenting with your own peculiar customizations.

  You can also arrange to override some of the actions of the
terminal-specific library by setting the variable
@code{term-setup-hook}.  This is a normal hook which Emacs runs using
@code{run-hooks} at the end of Emacs initialization, after loading both
your init file and any terminal-specific libraries.  You can
use this variable to define initializations for terminals that do not
have their own libraries.  @xref{Hooks}.

@defvar term-file-prefix
@cindex @code{TERM} environment variable
Chong Yidong's avatar
Chong Yidong committed
471 472
If the value of this variable is non-@code{nil}, Emacs loads a
terminal-specific initialization file as follows:
Glenn Morris's avatar
Glenn Morris committed
473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503

@example
(load (concat term-file-prefix (getenv "TERM")))
@end example

@noindent
You may set the @code{term-file-prefix} variable to @code{nil} in your
init file if you do not wish to load the
terminal-initialization file.  To do this, put the following in
your init file: @code{(setq term-file-prefix nil)}.

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
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.

You can use @code{term-setup-hook} to override the definitions made by a
terminal-specific file.
@end defvar

  See @code{window-setup-hook} in @ref{Window Systems}, for a related
feature.

@node Command-Line Arguments
@subsection Command-Line Arguments
@cindex command-line arguments

Chong Yidong's avatar
Chong Yidong committed
504 505 506 507 508 509 510 511
  You can use command-line arguments to request various actions when
you start Emacs.  Command-line arguments should not be commonly used,
since the recommended way of using Emacs is to start it just once,
after logging in, and do all editing in the same Emacs session
(@pxref{Entering Emacs,,, emacs, The GNU Emacs Manual}); nonetheless,
they can be useful when invoking Emacs from session scripts or
debugging Emacs itself.  This section describes how Emacs processes
command-line arguments.
Glenn Morris's avatar
Glenn Morris committed
512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570

@defun command-line
This function parses the command line that Emacs was called with,
processes it, loads the user's init file and displays the
startup messages.
@end defun

@defvar command-line-processed
The value of this variable is @code{t} once the command line has been
processed.

If you redump Emacs by calling @code{dump-emacs}, you may wish to set
this variable to @code{nil} first in order to cause the new dumped Emacs
to process its new command-line arguments.
@end defvar

@defvar command-switch-alist
@cindex switches on command line
@cindex options on command line
@cindex command-line options
The value of this variable is an alist of user-defined command-line
options and associated handler functions.  This variable exists so you
can add elements to it.

A @dfn{command-line option} is an argument on the command line, which
has the form:

@example
-@var{option}
@end example

The elements of the @code{command-switch-alist} look like this:

@example
(@var{option} . @var{handler-function})
@end example

The @sc{car}, @var{option}, is a string, the name of a command-line
option (not including the initial hyphen).  The @var{handler-function}
is called to handle @var{option}, and receives the option name as its
sole argument.

In some cases, the option is followed in the command line by an
argument.  In these cases, the @var{handler-function} can find all the
remaining command-line arguments in the variable
@code{command-line-args-left}.  (The entire list of command-line
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{Emacs
Invocation, , Command Line Arguments for Emacs Invocation, emacs, The
GNU Emacs Manual}.
@end defvar

@defvar command-line-args
The value of this variable is the list of command-line arguments passed
to Emacs.
@end defvar

571
@defvar command-line-args-left
572
@vindex argv
573 574 575 576
The value of this variable is the list of command-line arguments that
have not yet been processed.  @code{argv} is an alias for this.
@end defvar

Glenn Morris's avatar
Glenn Morris committed
577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604
@defvar command-line-functions
This variable's value is a list of functions for handling an
unrecognized command-line argument.  Each time the next argument to be
processed has no special meaning, the functions in this list are called,
in order of appearance, until one of them returns a non-@code{nil}
value.

These functions are called with no arguments.  They can access the
command-line argument under consideration through the variable
@code{argi}, which is bound temporarily at this point.  The remaining
arguments (not including the current one) are in the variable
@code{command-line-args-left}.

When a function recognizes and processes the argument in @code{argi}, it
should return a non-@code{nil} value to say it has dealt with that
argument.  If it has also dealt with some of the following arguments, it
can indicate that by deleting them from @code{command-line-args-left}.

If all of these functions return @code{nil}, then the argument is used
as a file name to visit.
@end defvar

@node Getting Out
@section Getting Out of Emacs
@cindex exiting Emacs

  There are two ways to get out of Emacs: you can kill the Emacs job,
which exits permanently, or you can suspend it, which permits you to
Chong Yidong's avatar
Chong Yidong committed
605
reenter the Emacs process later.
Glenn Morris's avatar
Glenn Morris committed
606 607 608 609 610 611 612 613 614 615 616 617 618 619 620

@menu
* Killing Emacs::        Exiting Emacs irreversibly.
* Suspending Emacs::     Exiting Emacs reversibly.
@end menu

@node Killing Emacs
@comment  node-name,  next,  previous,  up
@subsection Killing Emacs
@cindex killing Emacs

  Killing Emacs means ending the execution of the Emacs process.  The
parent process normally resumes control.  The low-level primitive for
killing Emacs is @code{kill-emacs}.

621
@deffn Command kill-emacs &optional exit-data
622 623
This command calls the hook @code{kill-emacs-hook}, then exits the
Emacs process and kills it.
Glenn Morris's avatar
Glenn Morris committed
624

625 626
If @var{exit-data} is an integer, that is used as the exit status of
the Emacs process.  (This is useful primarily in batch operation; see
Glenn Morris's avatar
Glenn Morris committed
627 628 629 630 631
@ref{Batch Mode}.)

If @var{exit-data} is a string, its contents are stuffed into the
terminal input buffer so that the shell (or whatever program next reads
input) can read them.
632
@end deffn
Glenn Morris's avatar
Glenn Morris committed
633

634 635 636 637 638 639 640 641 642 643 644
@cindex SIGTERM
@cindex SIGHUP
@cindex SIGINT
@cindex operating system signal
  The @code{kill-emacs} function is normally called via the
higher-level command @kbd{C-x C-c}
(@code{save-buffers-kill-terminal}).  @xref{Exiting,,, emacs, The GNU
Emacs Manual}.  It is also called automatically if Emacs receives a
@code{SIGTERM} or @code{SIGHUP} operating system signal (e.g. when the
controlling terminal is disconnected), or if it receives a
@code{SIGINT} signal while running in batch mode (@pxref{Batch Mode}).
Glenn Morris's avatar
Glenn Morris committed
645

646 647 648 649 650 651 652 653
@defvar kill-emacs-hook
This normal hook is run by @code{kill-emacs}, before it kills Emacs.

Because @code{kill-emacs} can be called in situations where user
interaction is impossible (e.g. when the terminal is disconnected),
functions on this hook should not attempt to interact with the user.
If you want to interact with the user when Emacs is shutting down, use
@code{kill-emacs-query-functions}, described below.
Glenn Morris's avatar
Glenn Morris committed
654 655
@end defvar

656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671
  When Emacs is killed, all the information in the Emacs process,
aside from files that have been saved, is lost.  Because killing Emacs
inadvertently can lose a lot of work, the
@code{save-buffers-kill-terminal} command queries for confirmation if
you have buffers that need saving or subprocesses that are running.
It also runs the abnormal hook @code{kill-emacs-query-functions}:

@defvar kill-emacs-query-functions
When @code{save-buffers-kill-terminal} is killing Emacs, it calls the
functions in this hook, after asking the standard questions and before
calling @code{kill-emacs}.  The functions are called in order of
appearance, with no arguments.  Each function can ask for additional
confirmation from the user.  If any of them returns @code{nil},
@code{save-buffers-kill-emacs} does not kill Emacs, and does not run
the remaining functions in this hook.  Calling @code{kill-emacs}
directly does not run this hook.
Glenn Morris's avatar
Glenn Morris committed
672 673 674 675 676 677
@end defvar

@node Suspending Emacs
@subsection Suspending Emacs
@cindex suspending Emacs

678
  On text terminals, it is possible to @dfn{suspend Emacs}, which
679 680 681 682 683 684
means stopping Emacs temporarily and returning control to its superior
process, which is usually the shell.  This allows you to resume
editing later in the same Emacs process, with the same buffers, the
same kill ring, the same undo history, and so on.  To resume Emacs,
use the appropriate command in the parent shell---most likely
@code{fg}.
Glenn Morris's avatar
Glenn Morris committed
685

686 687 688
@cindex controlling terminal
  Suspending works only on a terminal device from which the Emacs
session was started.  We call that device the @dfn{controlling
689 690
terminal} of the session.  Suspending is not allowed if the
controlling terminal is a graphical terminal.
691

Glenn Morris's avatar
Glenn Morris committed
692 693 694 695
  Some operating systems do not support suspension of jobs; on these
systems, ``suspension'' actually creates a new shell temporarily as a
subprocess of Emacs.  Then you would exit the shell to return to Emacs.

696
@deffn Command suspend-emacs &optional string
Glenn Morris's avatar
Glenn Morris committed
697 698 699 700
This function stops Emacs and returns control to the superior process.
If and when the superior process resumes Emacs, @code{suspend-emacs}
returns @code{nil} to its caller in Lisp.

701 702
This function works only on the controlling terminal of the Emacs
session; to relinquish control of other tty devices, use
703
@code{suspend-tty} (see below).  If the Emacs session uses more than
704 705 706
one terminal, you must delete the frames on all the other terminals
before suspending Emacs, or this function signals an error.
@xref{Multiple Terminals}.
707

708 709
If @var{string} is non-@code{nil}, its characters are sent to Emacs's
superior shell, to be read as terminal input.  The characters in
Glenn Morris's avatar
Glenn Morris committed
710 711 712 713
@var{string} are not echoed by the superior shell; only the results
appear.

Before suspending, @code{suspend-emacs} runs the normal hook
714 715 716
@code{suspend-hook}.  After the user resumes Emacs,
@code{suspend-emacs} runs the normal hook @code{suspend-resume-hook}.
@xref{Hooks}.
Glenn Morris's avatar
Glenn Morris committed
717 718

The next redisplay after resumption will redraw the entire screen,
719 720
unless the variable @code{no-redraw-on-reenter} is non-@code{nil}.
@xref{Refresh Screen}.
Glenn Morris's avatar
Glenn Morris committed
721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766

In the following example, note that @samp{pwd} is not echoed after
Emacs is suspended.  But it is read and executed by the shell.

@smallexample
@group
(suspend-emacs)
     @result{} nil
@end group

@group
(add-hook 'suspend-hook
          (function (lambda ()
                      (or (y-or-n-p
                            "Really suspend? ")
                          (error "Suspend canceled")))))
     @result{} (lambda nil
          (or (y-or-n-p "Really suspend? ")
              (error "Suspend canceled")))
@end group
@group
(add-hook 'suspend-resume-hook
          (function (lambda () (message "Resumed!"))))
     @result{} (lambda nil (message "Resumed!"))
@end group
@group
(suspend-emacs "pwd")
     @result{} nil
@end group
@group
---------- Buffer: Minibuffer ----------
Really suspend? @kbd{y}
---------- Buffer: Minibuffer ----------
@end group

@group
---------- Parent Shell ----------
lewis@@slug[23] % /user/lewis/manual
lewis@@slug[24] % fg
@end group

@group
---------- Echo Area ----------
Resumed!
@end group
@end smallexample
767
@end deffn
Glenn Morris's avatar
Glenn Morris committed
768 769 770 771 772 773 774 775 776 777

@defvar suspend-hook
This variable is a normal hook that Emacs runs before suspending.
@end defvar

@defvar suspend-resume-hook
This variable is a normal hook that Emacs runs on resuming
after a suspension.
@end defvar

778 779 780 781
@defun suspend-tty &optional tty
If @var{tty} specifies a terminal device used by Emacs, this function
relinquishes the device and restores it to its prior state.  Frames
that used the device continue to exist, but are not updated and Emacs
782 783 784 785 786 787
doesn't read input from them.  @var{tty} can be a terminal object, a
frame (meaning the terminal for that frame), or @code{nil} (meaning
the terminal for the selected frame).  @xref{Multiple Terminals}.

If @var{tty} is already suspended, this function does nothing.

788
@vindex suspend-tty-functions
789 790
This function runs the hook @code{suspend-tty-functions}, passing the
terminal object as an argument to each function.
791 792 793
@end defun

@defun resume-tty &optional tty
794 795 796 797
This function resumes the previously suspended terminal device
@var{tty}; @var{tty} can be a terminal object, a frame (meaning the
terminal for that frame), or @code{nil} (meaning the terminal for the
selected frame).
798

799
@vindex resume-tty-functions
800 801
This function reopens the terminal device, re-initializes it, and
redraws its with that terminal's selected frame.  It then runs the
802 803
hook @code{resume-tty-functions}, passing the terminal object as an
argument to each function.
804 805 806 807 808 809 810

If the same device is already used by another Emacs terminal, this
function signals an error.
@end defun

@defun controlling-tty-p &optional terminal
This function returns non-@code{nil} if @var{terminal} is the
811 812 813
controlling terminal of the Emacs session; @code{terminal} can be a
terminal object, a frame (meaning the terminal for that frame), or
@code{nil} (meaning the terminal for the selected frame).
814 815 816 817
@end defun

@deffn Command suspend-frame
This command @dfn{suspends} a frame.  For GUI frames, it calls
818 819 820 821
@code{iconify-frame} (@pxref{Visibility of Frames}); for frames on
text terminals, it calls either @code{suspend-emacs} or
@code{suspend-tty}, depending on whether the frame is displayed on the
controlling terminal device or not.
822 823
@end deffn

Glenn Morris's avatar
Glenn Morris committed
824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843
@node System Environment
@section Operating System Environment
@cindex operating system environment

  Emacs provides access to variables in the operating system environment
through various functions.  These variables include the name of the
system, the user's @acronym{UID}, and so on.

@defvar system-configuration
This variable holds the standard GNU configuration name for the
hardware/software configuration of your system, as a string.  The
convenient way to test parts of this string is with
@code{string-match}.
@end defvar

@cindex system type and name
@defvar system-type
The value of this variable is a symbol indicating the type of operating
system Emacs is operating on.  Here is a table of the possible values:

844
@table @code
845 846
@item aix
IBM's AIX.
Glenn Morris's avatar
Glenn Morris committed
847 848

@item berkeley-unix
849
Berkeley BSD and its variants.
Glenn Morris's avatar
Glenn Morris committed
850 851

@item cygwin
852 853 854 855
Cygwin, a Posix layer on top of MS-Windows.

@item darwin
Darwin (Mac OS X).
Glenn Morris's avatar
Glenn Morris committed
856 857

@item gnu
858
The GNU system (using the GNU kernel, which consists of the HURD and Mach).
Glenn Morris's avatar
Glenn Morris committed
859 860 861 862 863 864

@item gnu/linux
A GNU/Linux system---that is, a variant GNU system, using the Linux
kernel.  (These systems are the ones people often call ``Linux,'' but
actually Linux is just the kernel, not the whole system.)

865 866 867
@item gnu/kfreebsd
A GNU (glibc-based) system with a FreeBSD kernel.

Glenn Morris's avatar
Glenn Morris committed
868 869 870 871 872 873 874 875 876 877 878 879
@item hpux
Hewlett-Packard HPUX operating system.

@item irix
Silicon Graphics Irix system.

@item ms-dos
Microsoft MS-DOS ``operating system.''  Emacs compiled with DJGPP for
MS-DOS binds @code{system-type} to @code{ms-dos} even when you run it on
MS-Windows.

@item usg-unix-v
880
AT&T Unix System V.
Glenn Morris's avatar
Glenn Morris committed
881 882

@item windows-nt
883 884 885
Microsoft Windows NT and later.  The same executable supports Windows
9X, but the value of @code{system-type} is @code{windows-nt} in either
case.
Glenn Morris's avatar
Glenn Morris committed
886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910

@end table

We do not wish to add new symbols to make finer distinctions unless it
is absolutely necessary!  In fact, we hope to eliminate some of these
alternatives in the future.  We recommend using
@code{system-configuration} to distinguish between different operating
systems.
@end defvar

@defun system-name
This function returns the name of the machine you are running on.
@example
(system-name)
     @result{} "www.gnu.org"
@end example
@end defun

  The symbol @code{system-name} is a variable as well as a function.  In
fact, the function returns whatever value the variable
@code{system-name} currently holds.  Thus, you can set the variable
@code{system-name} in case Emacs is confused about the name of your
system.  The variable is also useful for constructing frame titles
(@pxref{Frame Titles}).

911
@defopt mail-host-address
Glenn Morris's avatar
Glenn Morris committed
912 913 914 915 916 917
If this variable is non-@code{nil}, it is used instead of
@code{system-name} for purposes of generating email addresses.  For
example, it is used when constructing the default value of
@code{user-mail-address}.  @xref{User Identification}.  (Since this is
done when Emacs starts up, the value actually used is the one saved when
Emacs was dumped.  @xref{Building Emacs}.)
918
@end defopt
Glenn Morris's avatar
Glenn Morris committed
919

920
@deffn Command getenv var &optional frame
Glenn Morris's avatar
Glenn Morris committed
921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989
@cindex environment variable access
This function returns the value of the environment variable @var{var},
as a string.  @var{var} should be a string.  If @var{var} is undefined
in the environment, @code{getenv} returns @code{nil}.  If returns
@samp{""} if @var{var} is set but null.  Within Emacs, the environment
variable values are kept in the Lisp variable @code{process-environment}.

@example
@group
(getenv "USER")
     @result{} "lewis"
@end group

@group
lewis@@slug[10] % printenv
PATH=.:/user/lewis/bin:/usr/bin:/usr/local/bin
USER=lewis
@end group
@group
TERM=ibmapa16
SHELL=/bin/csh
HOME=/user/lewis
@end group
@end example
@end deffn

@c Emacs 19 feature
@deffn Command setenv variable &optional value
This command sets the value of the environment variable named
@var{variable} to @var{value}.  @var{variable} should be a string.
Internally, Emacs Lisp can handle any string.  However, normally
@var{variable} should be a valid shell identifier, that is, a sequence
of letters, digits and underscores, starting with a letter or
underscore.  Otherwise, errors may occur if subprocesses of Emacs try
to access the value of @var{variable}.  If @var{value} is omitted or
@code{nil}, @code{setenv} removes @var{variable} from the environment.
Otherwise, @var{value} should be a string.

@code{setenv} works by modifying @code{process-environment}; binding
that variable with @code{let} is also reasonable practice.

@code{setenv} returns the new value of @var{variable}, or @code{nil}
if it removed @var{variable} from the environment.
@end deffn

@defvar process-environment
This variable is a list of strings, each describing one environment
variable.  The functions @code{getenv} and @code{setenv} work by means
of this variable.

@smallexample
@group
process-environment
@result{} ("l=/usr/stanford/lib/gnuemacs/lisp"
    "PATH=.:/user/lewis/bin:/usr/class:/nfsusr/local/bin"
    "USER=lewis"
@end group
@group
    "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

990 991 992 993 994 995
@defvar initial-environment
This variable holds the list of environment variables Emacs inherited
from its parent process.  It is computed during startup, see
@ref{Startup Summary}.
@end defvar

Glenn Morris's avatar
Glenn Morris committed
996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098
@defvar path-separator
This variable holds a string which says which character separates
directories in a search path (as found in an environment variable).  Its
value is @code{":"} for Unix and GNU systems, and @code{";"} for MS-DOS
and MS-Windows.
@end defvar

@defun parse-colon-path path
This function takes a search path string such as would be the value of
the @code{PATH} environment variable, and splits it at the separators,
returning a list of directory names.  @code{nil} in this list stands for
``use the current directory.''  Although the function's name says
``colon,'' it actually uses the value of @code{path-separator}.

@example
(parse-colon-path ":/foo:/bar")
     @result{} (nil "/foo/" "/bar/")
@end example
@end defun

@defvar invocation-name
This variable holds the program name under which Emacs was invoked.  The
value is a string, and does not include a directory name.
@end defvar

@defvar invocation-directory
This variable holds the directory from which the Emacs executable was
invoked, or perhaps @code{nil} if that directory cannot be determined.
@end defvar

@defvar installation-directory
If non-@code{nil}, this is a directory within which to look for the
@file{lib-src} and @file{etc} subdirectories.  This is non-@code{nil}
when Emacs can't find those directories in their standard installed
locations, but can find them in a directory related somehow to the one
containing the Emacs executable.
@end defvar

@defun load-average &optional use-float
This function returns the current 1-minute, 5-minute, and 15-minute load
averages, in a list.

By default, the values are integers that are 100 times the system load
averages, which indicate the average number of processes trying to run.
If @var{use-float} is non-@code{nil}, then they are returned
as floating point numbers and without multiplying by 100.

If it is impossible to obtain the load average, this function signals
an error.  On some platforms, access to load averages requires
installing Emacs as setuid or setgid so that it can read kernel
information, and that usually isn't advisable.

If the 1-minute load average is available, but the 5- or 15-minute
averages are not, this function returns a shortened list containing
the available averages.

@example
@group
(load-average)
     @result{} (169 48 36)
@end group
@group
(load-average t)
     @result{} (1.69 0.48 0.36)
@end group

@group
lewis@@rocky[5] % uptime
 11:55am  up 1 day, 19:37,  3 users,
 load average: 1.69, 0.48, 0.36
@end group
@end example
@end defun

@defun emacs-pid
This function returns the process @acronym{ID} of the Emacs process,
as an integer.
@end defun

@defvar tty-erase-char
This variable holds the erase character that was selected
in the system's terminal driver, before Emacs was started.
The value is @code{nil} if Emacs is running under a window system.
@end defvar

@node User Identification
@section User Identification
@cindex user identification

@defvar init-file-user
This variable says which user's init files should be used by
Emacs---or @code{nil} if none.  @code{""} stands for the user who
originally logged in.  The value reflects command-line options such as
@samp{-q} or @samp{-u @var{user}}.

Lisp packages that load files of customizations, or any other sort of
user profile, should obey this variable in deciding where to find it.
They should load the profile of the user name found in this variable.
If @code{init-file-user} is @code{nil}, meaning that the @samp{-q}
option was used, then Lisp packages should not load any customization
files or user profile.
@end defvar

1099
@defopt user-mail-address
Glenn Morris's avatar
Glenn Morris committed
1100 1101 1102 1103 1104
This holds the nominal email address of the user who is using Emacs.
Emacs normally sets this variable to a default value after reading your
init files, but not if you have already set it.  So you can set the
variable to some other value in your init file if you do not
want to use the default value.
1105
@end defopt
Glenn Morris's avatar
Glenn Morris committed
1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182

@defun user-login-name &optional uid
If you don't specify @var{uid}, this function returns the name under
which the user is logged in.  If the environment variable @code{LOGNAME}
is set, that value is used.  Otherwise, if the environment variable
@code{USER} is set, that value is used.  Otherwise, the value is based
on the effective @acronym{UID}, not the real @acronym{UID}.

If you specify @var{uid}, the value is the user name that corresponds
to @var{uid} (which should be an integer), or @code{nil} if there is
no such user.

@example
@group
(user-login-name)
     @result{} "lewis"
@end group
@end example
@end defun

@defun user-real-login-name
This function returns the user name corresponding to Emacs's real
@acronym{UID}.  This ignores the effective @acronym{UID} and ignores the
environment variables @code{LOGNAME} and @code{USER}.
@end defun

@defun user-full-name &optional uid
This function returns the full name of the logged-in user---or the value
of the environment variable @code{NAME}, if that is set.

@c "Bil" is the correct spelling.
@example
@group
(user-full-name)
     @result{} "Bil Lewis"
@end group
@end example

If the Emacs job's user-id does not correspond to any known user (and
provided @code{NAME} is not set), the value is @code{"unknown"}.

If @var{uid} is non-@code{nil}, then it should be a number (a user-id)
or a string (a login name).  Then @code{user-full-name} returns the full
name corresponding to that user-id or login name.  If you specify a
user-id or login name that isn't defined, it returns @code{nil}.
@end defun

@vindex user-full-name
@vindex user-real-login-name
@vindex user-login-name
  The symbols @code{user-login-name}, @code{user-real-login-name} and
@code{user-full-name} are variables as well as functions.  The functions
return the same values that the variables hold.  These variables allow
you to ``fake out'' Emacs by telling the functions what to return.  The
variables are also useful for constructing frame titles (@pxref{Frame
Titles}).

@defun user-real-uid
This function returns the real @acronym{UID} of the user.
The value may be a floating point number.

@example
@group
(user-real-uid)
     @result{} 19
@end group
@end example
@end defun

@defun user-uid
This function returns the effective @acronym{UID} of the user.
The value may be a floating point number.
@end defun

@node Time of Day
@section Time of Day

Chong Yidong's avatar
Chong Yidong committed
1183
  This section explains how to determine the current time and time
Glenn Morris's avatar
Glenn Morris committed
1184 1185
zone.

Chong Yidong's avatar
Chong Yidong committed
1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213
@cindex epoch
  Most of these functions represent time as a list of either three
integers, @code{(@var{sec-high} @var{sec-low} @var{microsec})}, or of
two integers, @code{(@var{sec-high} @var{sec-low})}.  The integers
@var{sec-high} and @var{sec-low} give the high and low bits of an
integer number of seconds.  This integer number,
@ifnottex
@var{high} * 2**16 + @var{low},
@end ifnottex
@tex
$high*2^{16}+low$,
@end tex
is the number of seconds from the @dfn{epoch} (0:00 January 1, 1970
UTC) to the specified time.  The third list element @var{microsec}, if
present, gives the number of microseconds from the start of that
second to the specified time.

  The return value of @code{current-time} represents time using three
integers, while the timestamps in the return value of
@code{file-attributes} use two integers (@pxref{Definition of
file-attributes}).  In function arguments, e.g.@: the @var{time-value}
argument to @code{current-time-string}, both two- and three-integer
lists are accepted.  You can convert times from the list
representation into standard human-readable strings using
@code{current-time}, or to other forms using the @code{decode-time}
and @code{format-time-string} functions documented in the following
sections.

Glenn Morris's avatar
Glenn Morris committed
1214 1215
@defun current-time-string &optional time-value
This function returns the current time and date as a human-readable
Chong Yidong's avatar
Chong Yidong committed
1216 1217 1218 1219 1220
string.  The format of the string is unvarying; the number of
characters used for each part is always the same, so you can reliably
use @code{substring} to extract pieces of it.  You should count
characters from the beginning of the string rather than from the end,
as additional information may some day be added at the end.
Glenn Morris's avatar
Glenn Morris committed
1221 1222

The argument @var{time-value}, if given, specifies a time to format
Chong Yidong's avatar
Chong Yidong committed
1223
(represented as a list of integers), instead of the current time.
Glenn Morris's avatar
Glenn Morris committed
1224 1225 1226 1227 1228 1229 1230 1231 1232 1233

@example
@group
(current-time-string)
     @result{} "Wed Oct 14 22:21:05 1987"
@end group
@end example
@end defun

@defun current-time
Chong Yidong's avatar
Chong Yidong committed
1234 1235 1236
This function returns the current time, represented as a list of three
integers @code{(@var{sec-high} @var{sec-low} @var{microsec})}.  On
systems with only one-second time resolutions, @var{microsec} is 0.
Glenn Morris's avatar
Glenn Morris committed
1237 1238
@end defun

1239 1240
@defun float-time &optional time-value
This function returns the current time as a floating-point number of
Chong Yidong's avatar
Chong Yidong committed
1241 1242 1243
seconds since the epoch.  The optional argument @var{time-value}, if
given, specifies a time (represented as a list of integers) to convert
instead of the current time.
1244 1245 1246 1247 1248

@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

Glenn Morris's avatar
Glenn Morris committed
1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263
@defun current-time-zone &optional time-value
This function returns a list describing the time zone that the user is
in.

The value has the form @code{(@var{offset} @var{name})}.  Here
@var{offset} is an integer giving the number of seconds ahead of UTC
(east of Greenwich).  A negative value means west of Greenwich.  The
second element, @var{name}, is a string giving the name of the time
zone.  Both elements change when daylight saving time begins or ends;
if the user has specified a time zone that does not use a seasonal time
adjustment, then the value is constant through time.

If the operating system doesn't supply all the information necessary to
compute the value, the unknown elements of the list are @code{nil}.

Chong Yidong's avatar
Chong Yidong committed
1264 1265
The argument @var{time-value}, if given, specifies a time (represented
as a list of integers) to analyze instead of the current time.
Glenn Morris's avatar
Glenn Morris committed
1266 1267
@end defun

1268 1269 1270 1271 1272
The current time zone is determined by the @samp{TZ} environment
variable.  @xref{System Environment}.  For example, you can tell Emacs
to use universal time with @code{(setenv "TZ" "UTC0")}.  If @samp{TZ}
is not in the environment, Emacs uses a platform-dependent default
time zone.
Glenn Morris's avatar
Glenn Morris committed
1273 1274 1275 1276

@node Time Conversion
@section Time Conversion

Chong Yidong's avatar
Chong Yidong committed
1277 1278 1279
  These functions convert time values (lists of two or three integers,
as explained in the previous section) into calendrical information and
vice versa.
Glenn Morris's avatar
Glenn Morris committed
1280

Chong Yidong's avatar
Chong Yidong committed
1281 1282 1283 1284 1285
  Many 32-bit operating systems are limited to time values containing
32 bits of information; these systems typically handle only the times
from 1901-12-13 20:45:52 UTC through 2038-01-19 03:14:07 UTC.
However, 64-bit and some 32-bit operating systems have larger time
values, and can represent times far in the past or future.
Glenn Morris's avatar
Glenn Morris committed
1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305