(Feval): Put check for interrupt_input_block in #if 0.
[bpt/emacs.git] / lispref / os.texi
CommitLineData
73804d4b
RS
1@c -*-texinfo-*-
2@c This is part of the GNU Emacs Lisp Reference Manual.
fd897522
GM
3@c Copyright (C) 1990, 1991, 1992, 1993, 1994, 1995, 1998, 1999
4@c Free Software Foundation, Inc.
73804d4b
RS
5@c See the file elisp.texi for copying conditions.
6@setfilename ../info/os
513331d3 7@node System Interface, Antinews, Calendar, Top
73804d4b
RS
8@chapter Operating System Interface
9
10 This chapter is about starting and getting out of Emacs, access to
78608595 11values in the operating system environment, and terminal input, output,
73804d4b
RS
12and flow control.
13
14 @xref{Building Emacs}, for related information. See also
15@ref{Display}, for additional operating system status information
16pertaining to the terminal and the screen.
17
18@menu
8241495d 19* Starting Up:: Customizing Emacs startup processing.
73804d4b
RS
20* Getting Out:: How exiting works (permanent or temporary).
21* System Environment:: Distinguish the name and kind of system.
22* User Identification:: Finding the name and user id of the user.
23* Time of Day:: Getting the current time.
22697dac
KH
24* Time Conversion:: Converting a time from numeric form to a string, or
25 to calendrical data (or vice versa).
73804d4b
RS
26* Timers:: Setting a timer to call a function at a certain time.
27* Terminal Input:: Recording terminal input for debugging.
28* Terminal Output:: Recording terminal output for debugging.
8241495d 29* Sound Output:: Playing sounds on the computer's speaker.
73804d4b
RS
30* Special Keysyms:: Defining system-specific key symbols for X windows.
31* Flow Control:: How to turn output flow control on or off.
32* Batch Mode:: Running Emacs without terminal interaction.
33@end menu
34
35@node Starting Up
36@section Starting Up Emacs
37
38 This section describes what Emacs does when it is started, and how you
39can customize these actions.
40
41@menu
8241495d 42* Startup Summary:: Sequence of actions Emacs performs at startup.
73804d4b
RS
43* Init File:: Details on reading the init file (@file{.emacs}).
44* Terminal-Specific:: How the terminal-specific Lisp file is read.
8241495d 45* Command-Line Arguments:: How command-line arguments are processed,
73804d4b
RS
46 and how you can customize them.
47@end menu
48
8241495d
RS
49@node Startup Summary
50@subsection Summary: Sequence of Actions at Startup
73804d4b 51@cindex initialization
8241495d 52@cindex startup of Emacs
73804d4b
RS
53@cindex @file{startup.el}
54
55 The order of operations performed (in @file{startup.el}) by Emacs when
56it is started up is as follows:
57
58@enumerate
a9f0a989 59@item
5858d11f
RS
60It adds subdirectories to @code{load-path}, by running the file named
61@file{subdirs.el} in each directory in the list. Normally this file
62adds the directory's subdirectories to the list, and these will be
63scanned in their turn. The files @file{subdirs.el} are normally
64generated automatically by Emacs installation.
a9f0a989
RS
65
66@item
67It sets the language environment and the terminal coding system,
68if requested by environment variables such as @code{LANG}.
69
73804d4b
RS
70@item
71It loads the initialization library for the window system, if you are
72using a window system. This library's name is
73@file{term/@var{windowsystem}-win.el}.
74
bfe721d1
KH
75@item
76It processes the initial options. (Some of them are handled
77even earlier than this.)
78
73804d4b 79@item
969fe9b5 80It initializes the window frame and faces, if appropriate.
73804d4b
RS
81
82@item
83It runs the normal hook @code{before-init-hook}.
84
85@item
86It loads the library @file{site-start}, unless the option
87@samp{-no-site-file} was specified. The library's file name is usually
88@file{site-start.el}.
89@cindex @file{site-start.el}
90
91@item
3f705836
GM
92It loads your init file (usually @file{~/.emacs}), unless @samp{-q},
93@samp{-no-init-file}, or @samp{-batch} was specified on the command line.
94The @samp{-u} option can specify another user whose home directory
95should be used instead of @file{~}.
73804d4b
RS
96
97@item
969fe9b5 98It loads the library @file{default}, unless @code{inhibit-default-init}
73804d4b 99is non-@code{nil}. (This is not done in @samp{-batch} mode or if
78608595
RS
100@samp{-q} was specified on the command line.) The library's file name
101is usually @file{default.el}.
73804d4b
RS
102@cindex @file{default.el}
103
104@item
105It runs the normal hook @code{after-init-hook}.
106
107@item
108It sets the major mode according to @code{initial-major-mode}, provided
109the buffer @samp{*scratch*} is still current and still in Fundamental
110mode.
111
112@item
113It loads the terminal-specific Lisp file, if any, except when in batch
114mode or using a window system.
115
116@item
117It displays the initial echo area message, unless you have suppressed
118that with @code{inhibit-startup-echo-area-message}.
119
120@item
bfe721d1 121It processes the action arguments from the command line.
73804d4b
RS
122
123@item
7ba6d818 124It runs @code{emacs-startup-hook} and then @code{term-setup-hook}.
73804d4b
RS
125
126@item
127It calls @code{frame-notice-user-settings}, which modifies the
128parameters of the selected frame according to whatever the init files
129specify.
130
131@item
132It runs @code{window-setup-hook}. @xref{Window Systems}.
133
134@item
78608595 135It displays copyleft, nonwarranty, and basic use information, provided
8241495d 136there were no remaining command-line arguments (a few steps above),
f9f59935
RS
137the value of @code{inhibit-startup-message} is @code{nil}, and the
138buffer is still empty.
73804d4b
RS
139@end enumerate
140
141@defopt inhibit-startup-message
142This variable inhibits the initial startup messages (the nonwarranty,
143etc.). If it is non-@code{nil}, then the messages are not printed.
144
145This variable exists so you can set it in your personal init file, once
146you are familiar with the contents of the startup message. Do not set
147this variable in the init file of a new user, or in a way that affects
148more than one user, because that would prevent new users from receiving
149the information they are supposed to see.
150@end defopt
151
152@defopt inhibit-startup-echo-area-message
153This variable controls the display of the startup echo area message.
154You can suppress the startup echo area message by adding text with this
a40d4712 155form to your init file:
73804d4b
RS
156
157@example
158(setq inhibit-startup-echo-area-message
159 "@var{your-login-name}")
160@end example
161
a40d4712
PR
162Emacs explicitly checks for an expression as shown above in your init
163file; your login name must appear in the expression as a Lisp string
164constant. Other methods of setting
a9f0a989
RS
165@code{inhibit-startup-echo-area-message} to the same value do not
166inhibit the startup message.
73804d4b
RS
167
168This way, you can easily inhibit the message for yourself if you wish,
a40d4712
PR
169but thoughtless copying of your init file will not inhibit the message
170for someone else.
73804d4b
RS
171@end defopt
172
173@node Init File
a40d4712 174@subsection The Init File, @file{.emacs}
73804d4b
RS
175@cindex init file
176@cindex @file{.emacs}
177
a40d4712
PR
178 When you start Emacs, it normally attempts to load your @dfn{init
179file}, a file in your home directory. Its normal name is @file{.emacs},
180but you can alternatively call it @file{.emacs.el}, which enables you to
181byte-compile it (@pxref{Byte Compilation}); then the actual file loaded
182will be @file{.emacs.elc}.
183
184 The command-line switches @samp{-q} and @samp{-u} control whether and
185where to find the init file; @samp{-q} says not to load an init file,
186and @samp{-u @var{user}} says to load @var{user}'s init file instead of
187yours. @xref{Entering Emacs,,, emacs, The GNU Emacs Manual}. If
188neither option is specified, Emacs uses the @code{LOGNAME} environment
189variable, or the @code{USER} (most systems) or @code{USERNAME} (MS
190systems) variable, to find your home directory and thus your init file;
191this way, even if you have su'd, Emacs still loads your own init file.
192If those environment variables are absent, though, Emacs uses your
193user-id to find your home directory.
73804d4b
RS
194
195@cindex default init file
196 A site may have a @dfn{default init file}, which is the library named
197@file{default.el}. Emacs finds the @file{default.el} file through the
198standard search path for libraries (@pxref{How Programs Do Loading}).
199The Emacs distribution does not come with this file; sites may provide
200one for local customizations. If the default init file exists, it is
201loaded whenever you start Emacs, except in batch mode or if @samp{-q} is
202specified. But your own personal init file, if any, is loaded first; if
203it sets @code{inhibit-default-init} to a non-@code{nil} value, then
204Emacs does not subsequently load the @file{default.el} file.
205
206 Another file for site-customization is @file{site-start.el}. Emacs
207loads this @emph{before} the user's init file. You can inhibit the
208loading of this file with the option @samp{-no-site-file}.
209
bfe721d1 210@defvar site-run-file
ebc6903b
RS
211This variable specifies the site-customization file to load before the
212user's init file. Its normal value is @code{"site-start"}. The only
213way you can change it with real effect is to do so before dumping
214Emacs.
bfe721d1
KH
215@end defvar
216
a890e1b0 217 @xref{Init File Examples,,, emacs, The GNU Emacs Manual}, for
73804d4b
RS
218examples of how to make various commonly desired customizations in your
219@file{.emacs} file.
220
221@defopt inhibit-default-init
222This variable prevents Emacs from loading the default initialization
223library file for your session of Emacs. If its value is non-@code{nil},
224then the default library is not loaded. The default value is
225@code{nil}.
226@end defopt
227
228@defvar before-init-hook
1911e6e5 229This normal hook is run, once, just before loading all the init files
a9f0a989 230(the user's init file, @file{default.el}, and/or @file{site-start.el}).
1911e6e5 231(The only way to change it with real effect is before dumping Emacs.)
a9f0a989
RS
232@end defvar
233
234@defvar after-init-hook
1911e6e5 235This normal hook is run, once, just after loading all the init files
a9f0a989 236(the user's init file, @file{default.el}, and/or @file{site-start.el}),
7ba6d818
RS
237before loading the terminal-specific library and processing the
238command-line arguments.
239@end defvar
240
241@defvar emacs-startup-hook
242@tindex emacs-startup-hook
243This normal hook is run, once, just after handling the command line
244arguments, just before @code{term-setup-hook}.
245@end defvar
246
247@defvar user-init-file
248@tindex user-init-file
249This variable holds the file name of the user's init file. If the
250actual init file loaded is a compiled file, such as @file{.emacs.elc},
251the value refers to the corresponding source file.
73804d4b
RS
252@end defvar
253
254@node Terminal-Specific
255@subsection Terminal-Specific Initialization
256@cindex terminal-specific initialization
257
258 Each terminal type can have its own Lisp library that Emacs loads when
a9f0a989
RS
259run on that type of terminal. The library's name is constructed by
260concatenating the value of the variable @code{term-file-prefix} and the
8241495d
RS
261terminal type (specified by the environment variable @code{TERM}).
262Normally, @code{term-file-prefix} has the value
a9f0a989
RS
263@code{"term/"}; changing this is not recommended. Emacs finds the file
264in the normal manner, by searching the @code{load-path} directories, and
265trying the @samp{.elc} and @samp{.el} suffixes.
73804d4b
RS
266
267 The usual function of a terminal-specific library is to enable special
268keys to send sequences that Emacs can recognize. It may also need to
269set or add to @code{function-key-map} if the Termcap entry does not
270specify all the terminal's function keys. @xref{Terminal Input}.
271
272@cindex Termcap
273 When the name of the terminal type contains a hyphen, only the part of
274the name before the first hyphen is significant in choosing the library
275name. Thus, terminal types @samp{aaa-48} and @samp{aaa-30-rv} both use
276the @file{term/aaa} library. If necessary, the library can evaluate
277@code{(getenv "TERM")} to find the full name of the terminal
278type.@refill
279
a40d4712 280 Your init file can prevent the loading of the
73804d4b
RS
281terminal-specific library by setting the variable
282@code{term-file-prefix} to @code{nil}. This feature is useful when
283experimenting with your own peculiar customizations.
284
285 You can also arrange to override some of the actions of the
286terminal-specific library by setting the variable
287@code{term-setup-hook}. This is a normal hook which Emacs runs using
288@code{run-hooks} at the end of Emacs initialization, after loading both
a40d4712 289your init file and any terminal-specific libraries. You can
73804d4b
RS
290use this variable to define initializations for terminals that do not
291have their own libraries. @xref{Hooks}.
292
293@defvar term-file-prefix
294@cindex @code{TERM} environment variable
295If the @code{term-file-prefix} variable is non-@code{nil}, Emacs loads
296a terminal-specific initialization file as follows:
297
298@example
299(load (concat term-file-prefix (getenv "TERM")))
300@end example
301
302@noindent
303You may set the @code{term-file-prefix} variable to @code{nil} in your
a40d4712 304init file if you do not wish to load the
73804d4b 305terminal-initialization file. To do this, put the following in
a40d4712 306your init file: @code{(setq term-file-prefix nil)}.
8241495d
RS
307
308On MS-DOS, if the environment variable @code{TERM} is not set, Emacs
309uses @samp{internal} as the terminal type.
73804d4b
RS
310@end defvar
311
312@defvar term-setup-hook
78608595 313This variable is a normal hook that Emacs runs after loading your
a40d4712 314init file, the default initialization file (if any) and the
73804d4b
RS
315terminal-specific Lisp file.
316
317You can use @code{term-setup-hook} to override the definitions made by a
318terminal-specific file.
319@end defvar
320
321 See @code{window-setup-hook} in @ref{Window Systems}, for a related
322feature.
323
8241495d
RS
324@node Command-Line Arguments
325@subsection Command-Line Arguments
326@cindex command-line arguments
73804d4b 327
8241495d 328 You can use command-line arguments to request various actions when you
73804d4b
RS
329start Emacs. Since you do not need to start Emacs more than once per
330day, and will often leave your Emacs session running longer than that,
8241495d 331command-line arguments are hardly ever used. As a practical matter, it
73804d4b
RS
332is best to avoid making the habit of using them, since this habit would
333encourage you to kill and restart Emacs unnecessarily often. These
334options exist for two reasons: to be compatible with other editors (for
335invocation by other programs) and to enable shell scripts to run
336specific Lisp programs.
337
8241495d 338 This section describes how Emacs processes command-line arguments,
73804d4b
RS
339and how you can customize them.
340
341@ignore
342 (Note that some other editors require you to start afresh each time
343you want to edit a file. With this kind of editor, you will probably
8241495d 344specify the file as a command-line argument. The recommended way to
73804d4b
RS
345use GNU Emacs is to start it only once, just after you log in, and do
346all your editing in the same Emacs process. Each time you want to edit
347a different file, you visit it with the existing Emacs, which eventually
348comes to have many files in it ready for editing. Usually you do not
349kill the Emacs until you are about to log out.)
350@end ignore
351
352@defun command-line
78608595 353This function parses the command line that Emacs was called with,
a40d4712 354processes it, loads the user's init file and displays the
78608595 355startup messages.
73804d4b
RS
356@end defun
357
358@defvar command-line-processed
359The value of this variable is @code{t} once the command line has been
360processed.
361
362If you redump Emacs by calling @code{dump-emacs}, you may wish to set
363this variable to @code{nil} first in order to cause the new dumped Emacs
8241495d 364to process its new command-line arguments.
73804d4b
RS
365@end defvar
366
367@defvar command-switch-alist
368@cindex switches on command line
369@cindex options on command line
8241495d 370@cindex command-line options
73804d4b
RS
371The value of this variable is an alist of user-defined command-line
372options and associated handler functions. This variable exists so you
373can add elements to it.
374
8241495d
RS
375A @dfn{command-line option} is an argument on the command line, which
376has the form:
73804d4b
RS
377
378@example
379-@var{option}
380@end example
381
382The elements of the @code{command-switch-alist} look like this:
383
384@example
385(@var{option} . @var{handler-function})
386@end example
387
8241495d
RS
388The @sc{car}, @var{option}, is a string, the name of a command-line
389option (not including the initial hyphen). The @var{handler-function}
390is called to handle @var{option}, and receives the option name as its
391sole argument.
73804d4b
RS
392
393In some cases, the option is followed in the command line by an
394argument. In these cases, the @var{handler-function} can find all the
395remaining command-line arguments in the variable
396@code{command-line-args-left}. (The entire list of command-line
397arguments is in @code{command-line-args}.)
398
8241495d 399The command-line arguments are parsed by the @code{command-line-1}
73804d4b
RS
400function in the @file{startup.el} file. See also @ref{Command
401Switches, , Command Line Switches and Arguments, emacs, The GNU Emacs
402Manual}.
403@end defvar
404
405@defvar command-line-args
8241495d 406The value of this variable is the list of command-line arguments passed
73804d4b
RS
407to Emacs.
408@end defvar
409
410@defvar command-line-functions
411This variable's value is a list of functions for handling an
412unrecognized command-line argument. Each time the next argument to be
413processed has no special meaning, the functions in this list are called,
78608595 414in order of appearance, until one of them returns a non-@code{nil}
73804d4b
RS
415value.
416
417These functions are called with no arguments. They can access the
418command-line argument under consideration through the variable
f9f59935
RS
419@code{argi}, which is bound temporarily at this point. The remaining
420arguments (not including the current one) are in the variable
421@code{command-line-args-left}.
73804d4b
RS
422
423When a function recognizes and processes the argument in @code{argi}, it
424should return a non-@code{nil} value to say it has dealt with that
425argument. If it has also dealt with some of the following arguments, it
426can indicate that by deleting them from @code{command-line-args-left}.
427
428If all of these functions return @code{nil}, then the argument is used
429as a file name to visit.
430@end defvar
431
432@node Getting Out
433@section Getting Out of Emacs
434@cindex exiting Emacs
435
436 There are two ways to get out of Emacs: you can kill the Emacs job,
437which exits permanently, or you can suspend it, which permits you to
438reenter the Emacs process later. As a practical matter, you seldom kill
439Emacs---only when you are about to log out. Suspending is much more
440common.
441
442@menu
443* Killing Emacs:: Exiting Emacs irreversibly.
444* Suspending Emacs:: Exiting Emacs reversibly.
445@end menu
446
447@node Killing Emacs
448@comment node-name, next, previous, up
449@subsection Killing Emacs
450@cindex killing Emacs
451
452 Killing Emacs means ending the execution of the Emacs process. The
453parent process normally resumes control. The low-level primitive for
454killing Emacs is @code{kill-emacs}.
455
456@defun kill-emacs &optional exit-data
457This function exits the Emacs process and kills it.
458
459If @var{exit-data} is an integer, then it is used as the exit status
460of the Emacs process. (This is useful primarily in batch operation; see
461@ref{Batch Mode}.)
462
463If @var{exit-data} is a string, its contents are stuffed into the
464terminal input buffer so that the shell (or whatever program next reads
465input) can read them.
466@end defun
467
468 All the information in the Emacs process, aside from files that have
8241495d
RS
469been saved, is lost when the Emacs process is killed. Because killing
470Emacs inadvertently can lose a lot of work, Emacs queries for
471confirmation before actually terminating if you have buffers that need
472saving or subprocesses that are running. This is done in the function
73804d4b
RS
473@code{save-buffers-kill-emacs}.
474
475@defvar kill-emacs-query-functions
476After asking the standard questions, @code{save-buffers-kill-emacs}
f9f59935 477calls the functions in the list @code{kill-emacs-query-functions}, in
73804d4b
RS
478order of appearance, with no arguments. These functions can ask for
479additional confirmation from the user. If any of them returns
48bad490 480@code{nil}, Emacs is not killed.
73804d4b
RS
481@end defvar
482
483@defvar kill-emacs-hook
484This variable is a normal hook; once @code{save-buffers-kill-emacs} is
485finished with all file saving and confirmation, it runs the functions in
486this hook.
487@end defvar
488
489@node Suspending Emacs
490@subsection Suspending Emacs
491@cindex suspending Emacs
492
493 @dfn{Suspending Emacs} means stopping Emacs temporarily and returning
494control to its superior process, which is usually the shell. This
495allows you to resume editing later in the same Emacs process, with the
496same buffers, the same kill ring, the same undo history, and so on. To
497resume Emacs, use the appropriate command in the parent shell---most
498likely @code{fg}.
499
500 Some operating systems do not support suspension of jobs; on these
501systems, ``suspension'' actually creates a new shell temporarily as a
502subprocess of Emacs. Then you would exit the shell to return to Emacs.
503
969fe9b5
RS
504 Suspension is not useful with window systems, because the Emacs job
505may not have a parent that can resume it again, and in any case you can
506give input to some other job such as a shell merely by moving to a
507different window. Therefore, suspending is not allowed when Emacs is using
8241495d 508a window system (X Windows or MS Windows).
73804d4b
RS
509
510@defun suspend-emacs string
511This function stops Emacs and returns control to the superior process.
512If and when the superior process resumes Emacs, @code{suspend-emacs}
513returns @code{nil} to its caller in Lisp.
514
515If @var{string} is non-@code{nil}, its characters are sent to be read
516as terminal input by Emacs's superior shell. The characters in
517@var{string} are not echoed by the superior shell; only the results
518appear.
519
520Before suspending, @code{suspend-emacs} runs the normal hook
969fe9b5 521@code{suspend-hook}.
73804d4b 522
78608595 523After the user resumes Emacs, @code{suspend-emacs} runs the normal hook
73804d4b
RS
524@code{suspend-resume-hook}. @xref{Hooks}.
525
526The next redisplay after resumption will redraw the entire screen,
527unless the variable @code{no-redraw-on-reenter} is non-@code{nil}
528(@pxref{Refresh Screen}).
529
530In the following example, note that @samp{pwd} is not echoed after
531Emacs is suspended. But it is read and executed by the shell.
532
533@smallexample
534@group
535(suspend-emacs)
536 @result{} nil
537@end group
538
539@group
540(add-hook 'suspend-hook
541 (function (lambda ()
542 (or (y-or-n-p
543 "Really suspend? ")
544 (error "Suspend cancelled")))))
545 @result{} (lambda nil
546 (or (y-or-n-p "Really suspend? ")
547 (error "Suspend cancelled")))
548@end group
549@group
550(add-hook 'suspend-resume-hook
551 (function (lambda () (message "Resumed!"))))
552 @result{} (lambda nil (message "Resumed!"))
553@end group
554@group
555(suspend-emacs "pwd")
556 @result{} nil
557@end group
558@group
559---------- Buffer: Minibuffer ----------
560Really suspend? @kbd{y}
561---------- Buffer: Minibuffer ----------
562@end group
563
564@group
565---------- Parent Shell ----------
566lewis@@slug[23] % /user/lewis/manual
567lewis@@slug[24] % fg
568@end group
569
570@group
571---------- Echo Area ----------
572Resumed!
573@end group
574@end smallexample
575@end defun
576
577@defvar suspend-hook
8241495d 578This variable is a normal hook that Emacs runs before suspending.
73804d4b
RS
579@end defvar
580
581@defvar suspend-resume-hook
8241495d
RS
582This variable is a normal hook that Emacs runs on resuming
583after a suspension.
73804d4b
RS
584@end defvar
585
586@node System Environment
587@section Operating System Environment
588@cindex operating system environment
589
590 Emacs provides access to variables in the operating system environment
591through various functions. These variables include the name of the
592system, the user's @sc{uid}, and so on.
593
969fe9b5
RS
594@defvar system-configuration
595This variable holds the GNU configuration name for the hardware/software
596configuration of your system, as a string. The convenient way to test
597parts of this string is with @code{string-match}.
598@end defvar
599
73804d4b 600@defvar system-type
bfe721d1
KH
601The value of this variable is a symbol indicating the type of operating
602system Emacs is operating on. Here is a table of the possible values:
73804d4b
RS
603
604@table @code
1911e6e5
RS
605@item alpha-vms
606VMS on the Alpha.
607
73804d4b
RS
608@item aix-v3
609AIX.
610
611@item berkeley-unix
612Berkeley BSD.
613
bfe721d1
KH
614@item dgux
615Data General DGUX operating system.
616
617@item gnu
969fe9b5 618the GNU system (using the GNU kernel, which consists of the HURD and Mach).
0c124126
RS
619
620@item gnu/linux
969fe9b5
RS
621A GNU/Linux system---that is, a variant GNU system, using the Linux
622kernel. (These systems are the ones people often call ``Linux,'' but
623actually Linux is just the kernel, not the whole system.)
bfe721d1 624
73804d4b 625@item hpux
bfe721d1 626Hewlett-Packard HPUX operating system.
73804d4b
RS
627
628@item irix
629Silicon Graphics Irix system.
630
bfe721d1 631@item ms-dos
8241495d
RS
632Microsoft MS-DOS ``operating system.'' Emacs compiled with DJGPP for
633MS-DOS binds @code{system-type} to @code{ms-dos} even when you run it on
634MS-Windows.
bfe721d1
KH
635
636@item next-mach
637NeXT Mach-based system.
6705a2a6 638
73804d4b
RS
639@item rtu
640Masscomp RTU, UCB universe.
641
642@item unisoft-unix
643UniSoft UniPlus.
644
645@item usg-unix-v
646AT&T System V.
647
648@item vax-vms
649VAX VMS.
650
bfe721d1 651@item windows-nt
8241495d
RS
652Microsoft windows NT. The same executable supports Windows 9X, but the
653value of @code{system-type} is @code{windows-nt} in either case.
bfe721d1 654
73804d4b
RS
655@item xenix
656SCO Xenix 386.
657@end table
658
659We do not wish to add new symbols to make finer distinctions unless it
660is absolutely necessary! In fact, we hope to eliminate some of these
661alternatives in the future. We recommend using
662@code{system-configuration} to distinguish between different operating
663systems.
664@end defvar
665
73804d4b
RS
666@defun system-name
667This function returns the name of the machine you are running on.
668@example
669(system-name)
a9f0a989 670 @result{} "www.gnu.org"
73804d4b
RS
671@end example
672@end defun
673
22697dac
KH
674 The symbol @code{system-name} is a variable as well as a function. In
675fact, the function returns whatever value the variable
676@code{system-name} currently holds. Thus, you can set the variable
677@code{system-name} in case Emacs is confused about the name of your
678system. The variable is also useful for constructing frame titles
679(@pxref{Frame Titles}).
680
681@defvar mail-host-address
682If this variable is non-@code{nil}, it is used instead of
683@code{system-name} for purposes of generating email addresses. For
684example, it is used when constructing the default value of
685@code{user-mail-address}. @xref{User Identification}. (Since this is
686done when Emacs starts up, the value actually used is the one saved when
687Emacs was dumped. @xref{Building Emacs}.)
688@end defvar
689
73804d4b
RS
690@defun getenv var
691@cindex environment variable access
692This function returns the value of the environment variable @var{var},
693as a string. Within Emacs, the environment variable values are kept in
694the Lisp variable @code{process-environment}.
695
696@example
697@group
698(getenv "USER")
699 @result{} "lewis"
700@end group
701
702@group
703lewis@@slug[10] % printenv
704PATH=.:/user/lewis/bin:/usr/bin:/usr/local/bin
705USER=lewis
706@end group
707@group
708TERM=ibmapa16
709SHELL=/bin/csh
710HOME=/user/lewis
711@end group
712@end example
713@end defun
714
715@c Emacs 19 feature
716@deffn Command setenv variable value
717This command sets the value of the environment variable named
718@var{variable} to @var{value}. Both arguments should be strings. This
719function works by modifying @code{process-environment}; binding that
720variable with @code{let} is also reasonable practice.
721@end deffn
722
723@defvar process-environment
724This variable is a list of strings, each describing one environment
725variable. The functions @code{getenv} and @code{setenv} work by means
726of this variable.
727
728@smallexample
729@group
730process-environment
731@result{} ("l=/usr/stanford/lib/gnuemacs/lisp"
732 "PATH=.:/user/lewis/bin:/usr/class:/nfsusr/local/bin"
733 "USER=lewis"
734@end group
735@group
736 "TERM=ibmapa16"
737 "SHELL=/bin/csh"
738 "HOME=/user/lewis")
739@end group
740@end smallexample
741@end defvar
742
bfe721d1
KH
743@defvar path-separator
744This variable holds a string which says which character separates
745directories in a search path (as found in an environment variable). Its
746value is @code{":"} for Unix and GNU systems, and @code{";"} for MS-DOS
8241495d 747and MS-Windows.
bfe721d1
KH
748@end defvar
749
5557b83b
RS
750@defun parse-colon-path path
751@tindex parse-colon-path
752This function takes a search path string such as would be the value of
753the @code{PATH} environment variable, and splits it at the separators,
754returning a list of directory names. @code{nil} in this list stands for
755``use the current directory.'' Although the function's name says
756``colon,'' it actually uses the value of @code{path-separator}.
757
758@example
759(parse-colon-path ":/foo:/bar")
760 @result{} (nil "/foo/" "/bar/")
761@end example
762@end defun
763
a890e1b0
RS
764@defvar invocation-name
765This variable holds the program name under which Emacs was invoked. The
766value is a string, and does not include a directory name.
767@end defvar
768
769@defvar invocation-directory
770This variable holds the directory from which the Emacs executable was
771invoked, or perhaps @code{nil} if that directory cannot be determined.
772@end defvar
773
774@defvar installation-directory
775If non-@code{nil}, this is a directory within which to look for the
776@file{lib-src} and @file{etc} subdirectories. This is non-@code{nil}
777when Emacs can't find those directories in their standard installed
78608595
RS
778locations, but can find them in a directory related somehow to the one
779containing the Emacs executable.
a890e1b0
RS
780@end defvar
781
a9f0a989 782@defun load-average &optional use-float
1911e6e5
RS
783This function returns the current 1-minute, 5-minute, and 15-minute load
784averages, in a list.
a9f0a989
RS
785
786By default, the values are integers that are 100 times the system load
787averages, which indicate the average number of processes trying to run.
788If @var{use-float} is non-@code{nil}, then they are returned
1911e6e5 789as floating point numbers and without multiplying by 100.
73804d4b
RS
790
791@example
792@group
793(load-average)
794 @result{} (169 48 36)
795@end group
a9f0a989
RS
796@group
797(load-average t)
798 @result{} (1.69 0.48 0.36)
799@end group
73804d4b
RS
800
801@group
802lewis@@rocky[5] % uptime
803 11:55am up 1 day, 19:37, 3 users,
804 load average: 1.69, 0.48, 0.36
805@end group
806@end example
807@end defun
808
809@defun emacs-pid
810This function returns the process @sc{id} of the Emacs process.
811@end defun
812
f9f59935
RS
813@defvar tty-erase-char
814This variable holds the erase character that was selected
815in the system's terminal driver, before Emacs was started.
816@end defvar
817
73804d4b
RS
818@defun setprv privilege-name &optional setp getprv
819This function sets or resets a VMS privilege. (It does not exist on
8241495d
RS
820other systems.) The first argument is the privilege name, as a string.
821The second argument, @var{setp}, is @code{t} or @code{nil}, indicating
822whether the privilege is to be turned on or off. Its default is
823@code{nil}. The function returns @code{t} if successful, @code{nil}
824otherwise.
73804d4b
RS
825
826 If the third argument, @var{getprv}, is non-@code{nil}, @code{setprv}
827does not change the privilege, but returns @code{t} or @code{nil}
828indicating whether the privilege is currently enabled.
829@end defun
830
831@node User Identification
832@section User Identification
833
f9f59935
RS
834@defvar init-file-user
835This variable says which user's init files should be used by Emacs---or
8241495d 836@code{nil} if none. The value reflects command-line options such as
f9f59935
RS
837@samp{-q} or @samp{-u @var{user}}.
838
839Lisp packages that load files of customizations, or any other sort of
840user profile, should obey this variable in deciding where to find it.
841They should load the profile of the user name found in this variable.
842If @code{init-file-user} is @code{nil}, meaning that the @samp{-q}
843option was used, then Lisp packages should not load any customization
844files or user profile.
845@end defvar
846
22697dac
KH
847@defvar user-mail-address
848This holds the nominal email address of the user who is using Emacs.
485dbcf2
RS
849Emacs normally sets this variable to a default value after reading your
850init files, but not if you have already set it. So you can set the
a40d4712 851variable to some other value in your init file if you do not
485dbcf2 852want to use the default value.
22697dac
KH
853@end defvar
854
855@defun user-login-name &optional uid
856If you don't specify @var{uid}, this function returns the name under
857which the user is logged in. If the environment variable @code{LOGNAME}
858is set, that value is used. Otherwise, if the environment variable
859@code{USER} is set, that value is used. Otherwise, the value is based
860on the effective @sc{uid}, not the real @sc{uid}.
861
862If you specify @var{uid}, the value is the user name that corresponds
863to @var{uid} (which should be an integer).
73804d4b
RS
864
865@example
866@group
867(user-login-name)
868 @result{} "lewis"
869@end group
870@end example
871@end defun
872
873@defun user-real-login-name
874This function returns the user name corresponding to Emacs's real
875@sc{uid}. This ignores the effective @sc{uid} and ignores the
876environment variables @code{LOGNAME} and @code{USER}.
877@end defun
878
f9f59935
RS
879@defun user-full-name &optional uid
880This function returns the full name of the logged-in user---or the value
8241495d 881of the environment variable @code{NAME}, if that is set.
73804d4b 882
8241495d 883@c "Bil" is the correct spelling.
73804d4b
RS
884@example
885@group
886(user-full-name)
887 @result{} "Bil Lewis"
888@end group
889@end example
f9f59935 890
52f51621
KH
891If the Emacs job's user-id does not correspond to any known user (and
892provided @code{NAME} is not set), the value is @code{"unknown"}.
893
894If @var{uid} is non-@code{nil}, then it should be an integer (a user-id)
895or a string (a login name). Then @code{user-full-name} returns the full
896name corresponding to that user-id or login name. If you specify a
897user-id or login name that isn't defined, it returns @code{nil}.
73804d4b
RS
898@end defun
899
22697dac
KH
900@vindex user-full-name
901@vindex user-real-login-name
902@vindex user-login-name
903 The symbols @code{user-login-name}, @code{user-real-login-name} and
904@code{user-full-name} are variables as well as functions. The functions
905return the same values that the variables hold. These variables allow
906you to ``fake out'' Emacs by telling the functions what to return. The
907variables are also useful for constructing frame titles (@pxref{Frame
908Titles}).
909
73804d4b
RS
910@defun user-real-uid
911This function returns the real @sc{uid} of the user.
912
913@example
914@group
915(user-real-uid)
916 @result{} 19
917@end group
918@end example
919@end defun
920
921@defun user-uid
922This function returns the effective @sc{uid} of the user.
923@end defun
924
925@node Time of Day
926@section Time of Day
927
928 This section explains how to determine the current time and the time
929zone.
930
931@defun current-time-string &optional time-value
a9f0a989 932This function returns the current time and date as a human-readable
73804d4b
RS
933string. The format of the string is unvarying; the number of characters
934used for each part is always the same, so you can reliably use
bfe721d1
KH
935@code{substring} to extract pieces of it. It is wise to count the
936characters from the beginning of the string rather than from the end, as
f9f59935 937additional information may some day be added at the end.
73804d4b
RS
938
939@c Emacs 19 feature
940The argument @var{time-value}, if given, specifies a time to format
bfe721d1
KH
941instead of the current time. The argument should be a list whose first
942two elements are integers. Thus, you can use times obtained from
943@code{current-time} (see below) and from @code{file-attributes}
944(@pxref{File Attributes}).
73804d4b
RS
945
946@example
947@group
948(current-time-string)
949 @result{} "Wed Oct 14 22:21:05 1987"
950@end group
951@end example
952@end defun
953
954@c Emacs 19 feature
955@defun current-time
956This function returns the system's time value as a list of three
957integers: @code{(@var{high} @var{low} @var{microsec})}. The integers
958@var{high} and @var{low} combine to give the number of seconds since
8241495d 9590:00 January 1, 1970 (local time), which is
37680279 960@ifnottex
73804d4b 961@var{high} * 2**16 + @var{low}.
37680279 962@end ifnottex
73804d4b 963@tex
78608595 964$high*2^{16}+low$.
73804d4b
RS
965@end tex
966
967The third element, @var{microsec}, gives the microseconds since the
8241495d
RS
968start of the current second (or 0 for systems that return time with
969the resolution of only one second).
73804d4b
RS
970
971The first two elements can be compared with file time values such as you
972get with the function @code{file-attributes}. @xref{File Attributes}.
973@end defun
974
975@c Emacs 19 feature
976@defun current-time-zone &optional time-value
977This function returns a list describing the time zone that the user is
978in.
979
980The value has the form @code{(@var{offset} @var{name})}. Here
981@var{offset} is an integer giving the number of seconds ahead of UTC
982(east of Greenwich). A negative value means west of Greenwich. The
8241495d 983second element, @var{name}, is a string giving the name of the time
73804d4b
RS
984zone. Both elements change when daylight savings time begins or ends;
985if the user has specified a time zone that does not use a seasonal time
986adjustment, then the value is constant through time.
987
988If the operating system doesn't supply all the information necessary to
989compute the value, both elements of the list are @code{nil}.
990
991The argument @var{time-value}, if given, specifies a time to analyze
992instead of the current time. The argument should be a cons cell
993containing two integers, or a list whose first two elements are
994integers. Thus, you can use times obtained from @code{current-time}
22697dac
KH
995(see above) and from @code{file-attributes} (@pxref{File Attributes}).
996@end defun
997
998@node Time Conversion
999@section Time Conversion
1000
1001 These functions convert time values (lists of two or three integers)
1002to strings or to calendrical information. There is also a function to
1003convert calendrical information to a time value. You can get time
1004values from the functions @code{current-time} (@pxref{Time of Day}) and
1005@code{file-attributes} (@pxref{File Attributes}).
1006
cfbaa90c
RS
1007Many operating systems are limited to time values that contain 32 bits
1008of information; these systems typically handle only the times from
10091901-12-13 20:45:52 UTC through 2038-01-19 03:14:07 UTC. However, some
1010operating systems have larger time values, and can represent times far
1011in the past or future.
1012
1013Time conversion functions always use the Gregorian calendar, even for
1014dates before the Gregorian calendar was introduced. Year numbers count
1015the number of years since the year 1 B.C., and do not skip zero as
969fe9b5 1016traditional Gregorian years do; for example, the year number @minus{}37
cfbaa90c
RS
1017represents the Gregorian year 38 B.C@.
1018
3f705836
GM
1019@defun format-time-string format-string &optional time universal
1020This function converts @var{time} (or the current time, if @var{time} is
1021omitted) to a string according to @var{format-string}. The argument
1022@var{format-string} may contain @samp{%}-sequences which say to
1023substitute parts of the time. Here is a table of what the
1024@samp{%}-sequences mean:
22697dac
KH
1025
1026@table @samp
1027@item %a
1028This stands for the abbreviated name of the day of week.
1029@item %A
1030This stands for the full name of the day of week.
1031@item %b
1032This stands for the abbreviated name of the month.
1033@item %B
1034This stands for the full name of the month.
1035@item %c
1036This is a synonym for @samp{%x %X}.
1037@item %C
bfe721d1
KH
1038This has a locale-specific meaning. In the default locale (named C), it
1039is equivalent to @samp{%A, %B %e, %Y}.
22697dac
KH
1040@item %d
1041This stands for the day of month, zero-padded.
1042@item %D
1043This is a synonym for @samp{%m/%d/%y}.
1044@item %e
1045This stands for the day of month, blank-padded.
1046@item %h
1047This is a synonym for @samp{%b}.
1048@item %H
1049This stands for the hour (00-23).
1050@item %I
8241495d 1051This stands for the hour (01-12).
22697dac
KH
1052@item %j
1053This stands for the day of the year (001-366).
1054@item %k
1055This stands for the hour (0-23), blank padded.
1056@item %l
1057This stands for the hour (1-12), blank padded.
1058@item %m
1059This stands for the month (01-12).
1060@item %M
1061This stands for the minute (00-59).
1062@item %n
1063This stands for a newline.
1064@item %p
1065This stands for @samp{AM} or @samp{PM}, as appropriate.
1066@item %r
1067This is a synonym for @samp{%I:%M:%S %p}.
1068@item %R
1069This is a synonym for @samp{%H:%M}.
1070@item %S
8241495d 1071This stands for the seconds (00-59).
22697dac
KH
1072@item %t
1073This stands for a tab character.
1074@item %T
1075This is a synonym for @samp{%H:%M:%S}.
1076@item %U
1077This stands for the week of the year (01-52), assuming that weeks
1078start on Sunday.
1079@item %w
1080This stands for the numeric day of week (0-6). Sunday is day 0.
1081@item %W
1082This stands for the week of the year (01-52), assuming that weeks
1083start on Monday.
1084@item %x
969fe9b5
RS
1085This has a locale-specific meaning. In the default locale (named
1086@samp{C}), it is equivalent to @samp{%D}.
22697dac 1087@item %X
969fe9b5
RS
1088This has a locale-specific meaning. In the default locale (named
1089@samp{C}), it is equivalent to @samp{%T}.
22697dac
KH
1090@item %y
1091This stands for the year without century (00-99).
1092@item %Y
1093This stands for the year with century.
1094@item %Z
1095This stands for the time zone abbreviation.
1096@end table
f9f59935
RS
1097
1098You can also specify the field width and type of padding for any of
969fe9b5
RS
1099these @samp{%}-sequences. This works as in @code{printf}: you write
1100the field width as digits in the middle of a @samp{%}-sequences. If you
a9f0a989
RS
1101start the field width with @samp{0}, it means to pad with zeros. If you
1102start the field width with @samp{_}, it means to pad with spaces.
f9f59935
RS
1103
1104For example, @samp{%S} specifies the number of seconds since the minute;
1105@samp{%03S} means to pad this with zeros to 3 positions, @samp{%_3S} to
1106pad with spaces to 3 positions. Plain @samp{%3S} pads with zeros,
1107because that is how @samp{%S} normally pads to two positions.
3f705836
GM
1108
1109The characters @samp{E} and @samp{O} act as modifiers when used between
1110@samp{%} and one of the letters in the table above. @samp{E} specifies
79ddc9c9
GM
1111using the current locale's ``alternative'' version of the date and time.
1112In a Japanese locale, for example, @code{%Ex} might yield a date format
1113based on the Japanese Emperors' reigns. @samp{E} is allowed in
1114@samp{%Ec}, @samp{%EC}, @samp{%Ex}, @samp{%EX}, @samp{%Ey}, and
1115@samp{%EY}.
1116
1117@samp{O} means to use the current locale's ``alternative''
1118representation of numbers, instead of the ordinary decimal digits. This
1119is allowed with most letters, all the ones that output numbers.
3f705836
GM
1120
1121If @var{universal} is non-@code{nil}, that means to describe the time as
1122Universal Time; @code{nil} means describe it using what Emacs believes
1123is the local time zone (see @code{current-time-zone}).
2468d0c0
DL
1124
1125This function uses the C library function @code{strftime} to do most of
1126the work. In order to communicate with that function, it first encodes
1127its argument using the coding system specified by
1128@code{locale-coding-system} (@pxref{Locales}); after @code{strftime}
1129returns the resulting string, @code{format-time-string} decodes the
1130string using that same coding system.
22697dac
KH
1131@end defun
1132
1133@defun decode-time time
bfe721d1
KH
1134This function converts a time value into calendrical information. The
1135return value is a list of nine elements, as follows:
22697dac
KH
1136
1137@example
1138(@var{seconds} @var{minutes} @var{hour} @var{day} @var{month} @var{year} @var{dow} @var{dst} @var{zone})
1139@end example
1140
1141Here is what the elements mean:
1142
1143@table @var
8241495d 1144@item seconds
22697dac 1145The number of seconds past the minute, as an integer between 0 and 59.
8241495d 1146@item minutes
22697dac
KH
1147The number of minutes past the hour, as an integer between 0 and 59.
1148@item hour
1149The hour of the day, as an integer between 0 and 23.
1150@item day
1151The day of the month, as an integer between 1 and 31.
1152@item month
1153The month of the year, as an integer between 1 and 12.
1154@item year
1155The year, an integer typically greater than 1900.
1156@item dow
1157The day of week, as an integer between 0 and 6, where 0 stands for
1158Sunday.
1159@item dst
1160@code{t} if daylight savings time is effect, otherwise @code{nil}.
1161@item zone
bfe721d1
KH
1162An integer indicating the time zone, as the number of seconds east of
1163Greenwich.
22697dac
KH
1164@end table
1165
969fe9b5
RS
1166@strong{Common Lisp Note:} Common Lisp has different meanings for
1167@var{dow} and @var{zone}.
22697dac
KH
1168@end defun
1169
d59b6ae6 1170@defun encode-time seconds minutes hour day month year &optional zone
22697dac 1171This function is the inverse of @code{decode-time}. It converts seven
bfe721d1
KH
1172items of calendrical data into a time value. For the meanings of the
1173arguments, see the table above under @code{decode-time}.
22697dac 1174
8241495d 1175Year numbers less than 100 are not treated specially. If you want them
4f939ab8
RS
1176to stand for years above 1900, or years above 2000, you must alter them
1177yourself before you call @code{encode-time}.
22697dac
KH
1178
1179The optional argument @var{zone} defaults to the current time zone and
1180its daylight savings time rules. If specified, it can be either a list
f9f59935
RS
1181(as you would get from @code{current-time-zone}), a string as in the
1182@code{TZ} environment variable, or an integer (as you would get from
1183@code{decode-time}). The specified zone is used without any further
1184alteration for daylight savings time.
0c124126
RS
1185
1186If you pass more than seven arguments to @code{encode-time}, the first
1187six are used as @var{seconds} through @var{year}, the last argument is
1188used as @var{zone}, and the arguments in between are ignored. This
1189feature makes it possible to use the elements of a list returned by
1190@code{decode-time} as the arguments to @code{encode-time}, like this:
1191
1192@example
1193(apply 'encode-time (decode-time @dots{}))
1194@end example
f9f59935
RS
1195
1196You can perform simple date arithmetic by using out-of-range values for
8241495d 1197the @var{seconds}, @var{minutes}, @var{hour}, @var{day}, and @var{month}
f9f59935 1198arguments; for example, day 0 means the day preceding the given month.
a9f0a989
RS
1199
1200The operating system puts limits on the range of possible time values;
1201if you try to encode a time that is out of range, an error results.
73804d4b
RS
1202@end defun
1203
1204@node Timers
bfe721d1 1205@section Timers for Delayed Execution
0c124126 1206@cindex timer
73804d4b 1207
0c124126
RS
1208 You can set up a @dfn{timer} to call a function at a specified future time or
1209after a certain length of idleness.
1210
969fe9b5 1211 Emacs cannot run timers at any arbitrary point in a Lisp program; it
0c124126
RS
1212can run them only when Emacs could accept output from a subprocess:
1213namely, while waiting or inside certain primitive functions such as
1911e6e5 1214@code{sit-for} or @code{read-event} which @emph{can} wait. Therefore, a
0c124126
RS
1215timer's execution may be delayed if Emacs is busy. However, the time of
1216execution is very precise if Emacs is idle.
73804d4b
RS
1217
1218@defun run-at-time time repeat function &rest args
1219This function arranges to call @var{function} with arguments @var{args}
1220at time @var{time}. The argument @var{function} is a function to call
1221later, and @var{args} are the arguments to give it when it is called.
1222The time @var{time} is specified as a string.
1223
1911e6e5
RS
1224Absolute times may be specified in a wide variety of formats; this
1225function tries to accept all the commonly used date formats. Valid
1226formats include these two,
a9f0a989
RS
1227
1228@example
1229@var{year}-@var{month}-@var{day} @var{hour}:@var{min}:@var{sec} @var{timezone}
1230
1231@var{hour}:@var{min}:@var{sec} @var{timezone} @var{month}/@var{day}/@var{year}
1232@end example
1233
1234@noindent
1235where in both examples all fields are numbers; the format that
1236@code{current-time-string} returns is also allowed, and many others
1237as well.
73804d4b
RS
1238
1239To specify a relative time, use numbers followed by units.
1240For example:
1241
1242@table @samp
1243@item 1 min
1244denotes 1 minute from now.
1245@item 1 min 5 sec
1246denotes 65 seconds from now.
1247@item 1 min 2 sec 3 hour 4 day 5 week 6 fortnight 7 month 8 year
1248denotes exactly 103 months, 123 days, and 10862 seconds from now.
1249@end table
1250
8241495d
RS
1251For relative time values, Emacs considers a month to be exactly thirty
1252days, and a year to be exactly 365.25 days.
1253
0c124126
RS
1254If @var{time} is a number (integer or floating point), that specifies a
1255relative time measured in seconds.
73804d4b
RS
1256
1257The argument @var{repeat} specifies how often to repeat the call. If
1258@var{repeat} is @code{nil}, there are no repetitions; @var{function} is
0c124126 1259called just once, at @var{time}. If @var{repeat} is a number, it
f9f59935
RS
1260specifies a repetition period measured in seconds.
1261
1262In most cases, @var{repeat} has no effect on when @emph{first} call
1263takes place---@var{time} alone specifies that. There is one exception:
1264if @var{time} is @code{t}, then the timer runs whenever the time is a
1265multiple of @var{repeat} seconds after the epoch. This is useful for
1266functions like @code{display-time}.
78608595
RS
1267
1268The function @code{run-at-time} returns a timer value that identifies
1269the particular scheduled future action. You can use this value to call
0c124126
RS
1270@code{cancel-timer} (see below).
1271@end defun
1272
1273@defmac with-timeout (seconds timeout-forms@dots{}) body@dots{}
1274Execute @var{body}, but give up after @var{seconds} seconds. If
1275@var{body} finishes before the time is up, @code{with-timeout} returns
1276the value of the last form in @var{body}. If, however, the execution of
1277@var{body} is cut short by the timeout, then @code{with-timeout}
1278executes all the @var{timeout-forms} and returns the value of the last
1279of them.
1280
a9f0a989 1281This macro works by setting a timer to run after @var{seconds} seconds. If
0c124126
RS
1282@var{body} finishes before that time, it cancels the timer. If the
1283timer actually runs, it terminates execution of @var{body}, then
1284executes @var{timeout-forms}.
1285
1286Since timers can run within a Lisp program only when the program calls a
1287primitive that can wait, @code{with-timeout} cannot stop executing
1288@var{body} while it is in the midst of a computation---only when it
1289calls one of those primitives. So use @code{with-timeout} only with a
1290@var{body} that waits for input, not one that does a long computation.
1291@end defmac
1292
1293 The function @code{y-or-n-p-with-timeout} provides a simple way to use
1294a timer to avoid waiting too long for an answer. @xref{Yes-or-No
1295Queries}.
1296
1297@defun run-with-idle-timer secs repeat function &rest args
1298Set up a timer which runs when Emacs has been idle for @var{secs}
1299seconds. The value of @var{secs} may be an integer or a floating point
1300number.
1301
1302If @var{repeat} is @code{nil}, the timer runs just once, the first time
1303Emacs remains idle for a long enough time. More often @var{repeat} is
1304non-@code{nil}, which means to run the timer @emph{each time} Emacs
1305remains idle for @var{secs} seconds.
1306
1307The function @code{run-with-idle-timer} returns a timer value which you
1308can use in calling @code{cancel-timer} (see below).
73804d4b
RS
1309@end defun
1310
0c124126
RS
1311@cindex idleness
1312 Emacs becomes ``idle'' when it starts waiting for user input, and it
1313remains idle until the user provides some input. If a timer is set for
1314five seconds of idleness, it runs approximately five seconds after Emacs
8241495d
RS
1315first becomes idle. Even if @var{repeat} is non-@code{nil}, this timer
1316will not run again as long as Emacs remains idle, because the duration
1317of idleness will continue to increase and will not go down to five
1318seconds again.
0c124126
RS
1319
1320 Emacs can do various things while idle: garbage collect, autosave or
969fe9b5
RS
1321handle data from a subprocess. But these interludes during idleness do
1322not interfere with idle timers, because they do not reset the clock of
1323idleness to zero. An idle timer set for 600 seconds will run when ten
1324minutes have elapsed since the last user command was finished, even if
1325subprocess output has been accepted thousands of times within those ten
8241495d 1326minutes, and even if there have been garbage collections and autosaves.
0c124126
RS
1327
1328 When the user supplies input, Emacs becomes non-idle while executing the
1329input. Then it becomes idle again, and all the idle timers that are
1330set up to repeat will subsequently run another time, one by one.
1331
73804d4b
RS
1332@defun cancel-timer timer
1333Cancel the requested action for @var{timer}, which should be a value
0c124126
RS
1334previously returned by @code{run-at-time} or @code{run-with-idle-timer}.
1335This cancels the effect of that call to @code{run-at-time}; the arrival
1336of the specified time will not cause anything special to happen.
73804d4b
RS
1337@end defun
1338
1339@node Terminal Input
1340@section Terminal Input
1341@cindex terminal input
1342
1343 This section describes functions and variables for recording or
1344manipulating terminal input. See @ref{Display}, for related
1345functions.
1346
1347@menu
1348* Input Modes:: Options for how input is processed.
1349* Translating Input:: Low level conversion of some characters or events
1350 into others.
1351* Recording Input:: Saving histories of recent or all input events.
1352@end menu
1353
1354@node Input Modes
1355@subsection Input Modes
1356@cindex input modes
1357@cindex terminal input modes
1358
1359@defun set-input-mode interrupt flow meta quit-char
1360This function sets the mode for reading keyboard input. If
1361@var{interrupt} is non-null, then Emacs uses input interrupts. If it is
969fe9b5 1362@code{nil}, then it uses @sc{cbreak} mode. The default setting is
8241495d 1363system-dependent. Some systems always use @sc{cbreak} mode regardless
969fe9b5 1364of what is specified.
73804d4b 1365
969fe9b5
RS
1366When Emacs communicates directly with X, it ignores this argument and
1367uses interrupts if that is the way it knows how to communicate.
73804d4b 1368
969fe9b5
RS
1369If @var{flow} is non-@code{nil}, then Emacs uses @sc{xon/xoff}
1370(@kbd{C-q}, @kbd{C-s}) flow control for output to the terminal. This
1371has no effect except in @sc{cbreak} mode. @xref{Flow Control}.
73804d4b
RS
1372
1373@c Emacs 19 feature
1374The argument @var{meta} controls support for input character codes
1375above 127. If @var{meta} is @code{t}, Emacs converts characters with
1376the 8th bit set into Meta characters. If @var{meta} is @code{nil},
1377Emacs disregards the 8th bit; this is necessary when the terminal uses
1378it as a parity bit. If @var{meta} is neither @code{t} nor @code{nil},
1379Emacs uses all 8 bits of input unchanged. This is good for terminals
969fe9b5 1380that use 8-bit character sets.
73804d4b
RS
1381
1382@c Emacs 19 feature
1383If @var{quit-char} is non-@code{nil}, it specifies the character to
1384use for quitting. Normally this character is @kbd{C-g}.
1385@xref{Quitting}.
1386@end defun
1387
1388The @code{current-input-mode} function returns the input mode settings
1389Emacs is currently using.
1390
1391@c Emacs 19 feature
1392@defun current-input-mode
8241495d 1393This function returns the current mode for reading keyboard input. It
73804d4b
RS
1394returns a list, corresponding to the arguments of @code{set-input-mode},
1395of the form @code{(@var{interrupt} @var{flow} @var{meta} @var{quit})} in
1396which:
1397@table @var
1398@item interrupt
1399is non-@code{nil} when Emacs is using interrupt-driven input. If
1400@code{nil}, Emacs is using @sc{cbreak} mode.
1401@item flow
1402is non-@code{nil} if Emacs uses @sc{xon/xoff} (@kbd{C-q}, @kbd{C-s})
a9f0a989
RS
1403flow control for output to the terminal. This value is meaningful only
1404when @var{interrupt} is @code{nil}.
73804d4b 1405@item meta
bfe721d1 1406is @code{t} if Emacs treats the eighth bit of input characters as
73804d4b
RS
1407the meta bit; @code{nil} means Emacs clears the eighth bit of every
1408input character; any other value means Emacs uses all eight bits as the
1409basic character code.
1410@item quit
1411is the character Emacs currently uses for quitting, usually @kbd{C-g}.
1412@end table
1413@end defun
1414
73804d4b
RS
1415@node Translating Input
1416@subsection Translating Input Events
1417@cindex translating input events
1418
0c124126
RS
1419 This section describes features for translating input events into
1420other input events before they become part of key sequences. These
1421features apply to each event in the order they are described here: each
1422event is first modified according to @code{extra-keyboard-modifiers},
969fe9b5
RS
1423then translated through @code{keyboard-translate-table} (if applicable),
1424and finally decoded with the specified keyboard coding system. If it is
1425being read as part of a key sequence, it is then added to the sequence
1426being read; then subsequences containing it are checked first with
1427@code{function-key-map} and then with @code{key-translation-map}.
73804d4b
RS
1428
1429@c Emacs 19 feature
1430@defvar extra-keyboard-modifiers
1431This variable lets Lisp programs ``press'' the modifier keys on the
1432keyboard. The value is a bit mask:
1433
1434@table @asis
1435@item 1
1436The @key{SHIFT} key.
1437@item 2
1438The @key{LOCK} key.
1439@item 4
1440The @key{CTL} key.
1441@item 8
1442The @key{META} key.
1443@end table
1444
1445Each time the user types a keyboard key, it is altered as if the
1446modifier keys specified in the bit mask were held down.
1447
969fe9b5
RS
1448When using a window system, the program can ``press'' any of the
1449modifier keys in this way. Otherwise, only the @key{CTL} and @key{META}
1450keys can be virtually pressed.
73804d4b
RS
1451@end defvar
1452
1453@defvar keyboard-translate-table
1454This variable is the translate table for keyboard characters. It lets
1455you reshuffle the keys on the keyboard without changing any command
f9f59935 1456bindings. Its value is normally a char-table, or else @code{nil}.
73804d4b 1457
8241495d
RS
1458If @code{keyboard-translate-table} is a char-table
1459(@pxref{Char-Tables}), then each character read from the keyboard is
1460looked up in this char-table. If the value found there is
1461non-@code{nil}, then it is used instead of the actual input character.
73804d4b
RS
1462
1463In the example below, we set @code{keyboard-translate-table} to a
f9f59935
RS
1464char-table. Then we fill it in to swap the characters @kbd{C-s} and
1465@kbd{C-\} and the characters @kbd{C-q} and @kbd{C-^}. Subsequently,
1466typing @kbd{C-\} has all the usual effects of typing @kbd{C-s}, and vice
476a78b9 1467versa. (@xref{Flow Control}, for more information on this subject.)
73804d4b
RS
1468
1469@cindex flow control example
1470@example
1471@group
1472(defun evade-flow-control ()
1473 "Replace C-s with C-\ and C-q with C-^."
1474 (interactive)
1475@end group
1476@group
f9f59935 1477 (setq keyboard-translate-table
a9f0a989 1478 (make-char-table 'keyboard-translate-table nil))
f9f59935
RS
1479@end group
1480@group
1481 ;; @r{Swap @kbd{C-s} and @kbd{C-\}.}
1482 (aset keyboard-translate-table ?\034 ?\^s)
1483 (aset keyboard-translate-table ?\^s ?\034)
73804d4b 1484@end group
73804d4b 1485@group
f9f59935
RS
1486 ;; @r{Swap @kbd{C-q} and @kbd{C-^}.}
1487 (aset keyboard-translate-table ?\036 ?\^q)
1488 (aset keyboard-translate-table ?\^q ?\036))
73804d4b
RS
1489@end group
1490@end example
1491
1492Note that this translation is the first thing that happens to a
1493character after it is read from the terminal. Record-keeping features
1494such as @code{recent-keys} and dribble files record the characters after
1495translation.
1496@end defvar
1497
1498@defun keyboard-translate from to
1499This function modifies @code{keyboard-translate-table} to translate
1500character code @var{from} into character code @var{to}. It creates
f9f59935 1501the keyboard translate table if necessary.
73804d4b
RS
1502@end defun
1503
0c124126
RS
1504 The remaining translation features translate subsequences of key
1505sequences being read. They are implemented in @code{read-key-sequence}
969fe9b5 1506and have no effect on input read with @code{read-event}.
0c124126 1507
73804d4b 1508@defvar function-key-map
f9f59935
RS
1509This variable holds a keymap that describes the character sequences sent
1510by function keys on an ordinary character terminal. This keymap has the
1511same structure as other keymaps, but is used differently: it specifies
1512translations to make while reading key sequences, rather than bindings
1513for key sequences.
73804d4b
RS
1514
1515If @code{function-key-map} ``binds'' a key sequence @var{k} to a vector
1516@var{v}, then when @var{k} appears as a subsequence @emph{anywhere} in a
1517key sequence, it is replaced with the events in @var{v}.
1518
1519For example, VT100 terminals send @kbd{@key{ESC} O P} when the
969fe9b5 1520keypad @key{PF1} key is pressed. Therefore, we want Emacs to translate
73804d4b
RS
1521that sequence of events into the single event @code{pf1}. We accomplish
1522this by ``binding'' @kbd{@key{ESC} O P} to @code{[pf1]} in
1523@code{function-key-map}, when using a VT100.
1524
1525Thus, typing @kbd{C-c @key{PF1}} sends the character sequence @kbd{C-c
1526@key{ESC} O P}; later the function @code{read-key-sequence} translates
1527this back into @kbd{C-c @key{PF1}}, which it returns as the vector
1528@code{[?\C-c pf1]}.
1529
1530Entries in @code{function-key-map} are ignored if they conflict with
1531bindings made in the minor mode, local, or global keymaps. The intent
1532is that the character sequences that function keys send should not have
969fe9b5
RS
1533command bindings in their own right---but if they do, the ordinary
1534bindings take priority.
73804d4b
RS
1535
1536The value of @code{function-key-map} is usually set up automatically
1537according to the terminal's Terminfo or Termcap entry, but sometimes
1538those need help from terminal-specific Lisp files. Emacs comes with
1539terminal-specific files for many common terminals; their main purpose is
1540to make entries in @code{function-key-map} beyond those that can be
1541deduced from Termcap and Terminfo. @xref{Terminal-Specific}.
73804d4b
RS
1542@end defvar
1543
1544@defvar key-translation-map
1545This variable is another keymap used just like @code{function-key-map}
1546to translate input events into other events. It differs from
1547@code{function-key-map} in two ways:
1548
1549@itemize @bullet
1550@item
1551@code{key-translation-map} goes to work after @code{function-key-map} is
1552finished; it receives the results of translation by
1553@code{function-key-map}.
1554
1555@item
0c124126
RS
1556@code{key-translation-map} overrides actual key bindings. For example,
1557if @kbd{C-x f} has a binding in @code{key-translation-map}, that
1558translation takes effect even though @kbd{C-x f} also has a key binding
1559in the global map.
73804d4b
RS
1560@end itemize
1561
1562The intent of @code{key-translation-map} is for users to map one
1563character set to another, including ordinary characters normally bound
1564to @code{self-insert-command}.
1565@end defvar
1566
1567@cindex key translation function
1568You can use @code{function-key-map} or @code{key-translation-map} for
1569more than simple aliases, by using a function, instead of a key
1570sequence, as the ``translation'' of a key. Then this function is called
1571to compute the translation of that key.
1572
1573The key translation function receives one argument, which is the prompt
1574that was specified in @code{read-key-sequence}---or @code{nil} if the
1575key sequence is being read by the editor command loop. In most cases
1576you can ignore the prompt value.
1577
1578If the function reads input itself, it can have the effect of altering
1579the event that follows. For example, here's how to define @kbd{C-c h}
1580to turn the character that follows into a Hyper character:
1581
1582@example
bda144f4 1583@group
73804d4b
RS
1584(defun hyperify (prompt)
1585 (let ((e (read-event)))
1586 (vector (if (numberp e)
f9f59935 1587 (logior (lsh 1 24) e)
73804d4b
RS
1588 (if (memq 'hyper (event-modifiers e))
1589 e
1590 (add-event-modifier "H-" e))))))
1591
1592(defun add-event-modifier (string e)
1593 (let ((symbol (if (symbolp e) e (car e))))
1594 (setq symbol (intern (concat string
1595 (symbol-name symbol))))
bda144f4
MW
1596@end group
1597@group
73804d4b
RS
1598 (if (symbolp e)
1599 symbol
1600 (cons symbol (cdr e)))))
1601
1602(define-key function-key-map "\C-ch" 'hyperify)
bda144f4 1603@end group
73804d4b
RS
1604@end example
1605
969fe9b5
RS
1606Finally, if you have enabled keyboard character set decoding using
1607@code{set-keyboard-coding-system}, decoding is done after the
1608translations listed above. @xref{Specifying Coding Systems}. In future
1609Emacs versions, character set decoding may be done before the other
1610translations.
73804d4b
RS
1611
1612@node Recording Input
1613@subsection Recording Input
1614
1615@defun recent-keys
969fe9b5
RS
1616This function returns a vector containing the last 100 input events from
1617the keyboard or mouse. All input events are included, whether or not
1618they were used as parts of key sequences. Thus, you always get the last
1619100 input events, not counting events generated by keyboard macros.
1620(These are excluded because they are less interesting for debugging; it
78608595 1621should be enough to see the events that invoked the macros.)
73804d4b
RS
1622@end defun
1623
3f705836 1624@deffn Command open-dribble-file filename
73804d4b
RS
1625@cindex dribble file
1626This function opens a @dfn{dribble file} named @var{filename}. When a
1627dribble file is open, each input event from the keyboard or mouse (but
1628not those from keyboard macros) is written in that file. A
1629non-character event is expressed using its printed representation
1630surrounded by @samp{<@dots{}>}.
1631
1632You close the dribble file by calling this function with an argument
1633of @code{nil}.
1634
1635This function is normally used to record the input necessary to
1636trigger an Emacs bug, for the sake of a bug report.
1637
1638@example
1639@group
1640(open-dribble-file "~/dribble")
1641 @result{} nil
1642@end group
1643@end example
1644@end deffn
1645
1646 See also the @code{open-termscript} function (@pxref{Terminal Output}).
1647
1648@node Terminal Output
1649@section Terminal Output
1650@cindex terminal output
1651
8241495d 1652 The terminal output functions send output to the terminal, or keep
73804d4b
RS
1653track of output sent to the terminal. The variable @code{baud-rate}
1654tells you what Emacs thinks is the output speed of the terminal.
1655
1656@defvar baud-rate
1657This variable's value is the output speed of the terminal, as far as
1658Emacs knows. Setting this variable does not change the speed of actual
1659data transmission, but the value is used for calculations such as
1660padding. It also affects decisions about whether to scroll part of the
78608595 1661screen or repaint---even when using a window system. (We designed it
73804d4b
RS
1662this way despite the fact that a window system has no true ``output
1663speed'', to give you a way to tune these decisions.)
1664
1665The value is measured in baud.
1666@end defvar
1667
1668 If you are running across a network, and different parts of the
1669network work at different baud rates, the value returned by Emacs may be
1670different from the value used by your local terminal. Some network
1671protocols communicate the local terminal speed to the remote machine, so
1672that Emacs and other programs can get the proper value, but others do
1673not. If Emacs has the wrong value, it makes decisions that are less
1674than optimal. To fix the problem, set @code{baud-rate}.
1675
1676@defun baud-rate
969fe9b5
RS
1677This obsolete function returns the value of the variable
1678@code{baud-rate}.
73804d4b
RS
1679@end defun
1680
1681@defun send-string-to-terminal string
1682This function sends @var{string} to the terminal without alteration.
1683Control characters in @var{string} have terminal-dependent effects.
1684
1685One use of this function is to define function keys on terminals that
8241495d
RS
1686have downloadable function key definitions. For example, this is how (on
1687certain terminals) to define function key 4 to move forward four
73804d4b
RS
1688characters (by transmitting the characters @kbd{C-u C-f} to the
1689computer):
1690
1691@example
1692@group
1693(send-string-to-terminal "\eF4\^U\^F")
1694 @result{} nil
1695@end group
1696@end example
1697@end defun
1698
1699@deffn Command open-termscript filename
1700@cindex termscript file
1701This function is used to open a @dfn{termscript file} that will record
1702all the characters sent by Emacs to the terminal. It returns
1703@code{nil}. Termscript files are useful for investigating problems
1704where Emacs garbles the screen, problems that are due to incorrect
1705Termcap entries or to undesirable settings of terminal options more
1706often than to actual Emacs bugs. Once you are certain which characters
1707were actually output, you can determine reliably whether they correspond
1708to the Termcap specifications in use.
1709
1710See also @code{open-dribble-file} in @ref{Terminal Input}.
1711
1712@example
1713@group
1714(open-termscript "../junk/termscript")
1715 @result{} nil
1716@end group
1717@end example
1718@end deffn
1719
8241495d
RS
1720@node Sound Output
1721@section Sound Output
1722@cindex sound
1723
1724 To play sound using Emacs, use the function @code{play-sound}. Only
1725certain systems are supported; if you call @code{play-sound} on a system
1726which cannot really do the job, it gives an error. Emacs version 20 and
1727earlier did not support sound at all.
1728
1729 The sound must be stored as a file in RIFF-WAVE format (@samp{.wav})
1730or Sun Audio format (@samp{.au}).
1731
1732@tindex play-sound
1733@defun play-sound sound
1734This function plays a specified sound. The argument, @var{sound}, has
1735the form @code{(sound @var{properties}...)}, where the @var{properties}
1736consist of alternating keywords (particular symbols recognized
1737specially) and values corresponding to them.
1738
1739Here is a table of the keywords that are currently meaningful in
1740@var{sound}, and their meanings:
1741
1742@table @code
1743@item :file @var{file}
1744This specifies the file containing the sound to play.
1745If the file name is not absolute, it is expanded against
1746the directory @code{data-directory}.
1747
8f3efb4e
RS
1748@item :data @var{data}
1749This specifies the sound to play without need to refer to a file. The
1750value, @var{data}, should be a string containing the same bytes as a
1751sound file. We recommend using a unibyte string.
1752
8241495d
RS
1753@item :volume @var{volume}
1754This specifies how loud to play the sound. It should be a number in the
1755range of 0 to 1. The default is to use whatever volume has been
1756specified before.
1757@end table
1758
1759Before actually playing the sound, @code{play-sound}
1760calls the functions in the list @code{play-sound-functions}.
1761Each function is called with one argument, @var{sound}.
1762@end defun
1763
1764@tindex play-sound-functions
1765@defvar play-sound-functions
1766A list of functions to be called before playing a sound. Each function
1767is called with one argument, a property list that describes the sound.
1768@end defvar
1769
73804d4b
RS
1770@node Special Keysyms
1771@section System-Specific X11 Keysyms
1772
1773To define system-specific X11 keysyms, set the variable
1774@code{system-key-alist}.
1775
1776@defvar system-key-alist
1777This variable's value should be an alist with one element for each
8241495d 1778system-specific keysym. Each element has the form @code{(@var{code}
73804d4b 1779. @var{symbol})}, where @var{code} is the numeric keysym code (not
969fe9b5 1780including the ``vendor specific'' bit,
37680279 1781@ifnottex
86494bd5 1782-2**28),
37680279 1783@end ifnottex
969fe9b5 1784@tex
86494bd5 1785$-2^{28}$),
969fe9b5
RS
1786@end tex
1787and @var{symbol} is the name for the function key.
73804d4b 1788
8241495d
RS
1789For example @code{(168 . mute-acute)} defines a system-specific key (used
1790by HP X servers) whose numeric code is
37680279 1791@ifnottex
969fe9b5 1792-2**28
37680279 1793@end ifnottex
969fe9b5
RS
1794@tex
1795$-2^{28}$
1796@end tex
1797+ 168.
73804d4b 1798
969fe9b5
RS
1799It is not crucial to exclude from the alist the keysyms of other X
1800servers; those do no harm, as long as they don't conflict with the ones
1801used by the X server actually in use.
22697dac 1802
1911e6e5 1803The variable is always local to the current terminal, and cannot be
22697dac 1804buffer-local. @xref{Multiple Displays}.
73804d4b
RS
1805@end defvar
1806
1807@node Flow Control
1808@section Flow Control
1809@cindex flow control characters
1810
969fe9b5
RS
1811 This section attempts to answer the question ``Why does Emacs use
1812flow-control characters in its command character set?'' For a second
1813view on this issue, read the comments on flow control in the
73804d4b
RS
1814@file{emacs/INSTALL} file from the distribution; for help with Termcap
1815entries and DEC terminal concentrators, see @file{emacs/etc/TERMS}.
1816
1817@cindex @kbd{C-s}
1818@cindex @kbd{C-q}
1819 At one time, most terminals did not need flow control, and none used
1820@code{C-s} and @kbd{C-q} for flow control. Therefore, the choice of
969fe9b5
RS
1821@kbd{C-s} and @kbd{C-q} as command characters for searching and quoting
1822was natural and uncontroversial. With so many commands needing key
8241495d 1823assignments, of course we assigned meanings to nearly all @sc{ascii}
969fe9b5 1824control characters.
73804d4b
RS
1825
1826 Later, some terminals were introduced which required these characters
1827for flow control. They were not very good terminals for full-screen
969fe9b5
RS
1828editing, so Emacs maintainers ignored them. In later years, flow
1829control with @kbd{C-s} and @kbd{C-q} became widespread among terminals,
1830but by this time it was usually an option. And the majority of Emacs
1831users, who can turn flow control off, did not want to switch to less
1832mnemonic key bindings for the sake of flow control.
73804d4b 1833
969fe9b5 1834 So which usage is ``right''---Emacs's or that of some terminal and
73804d4b
RS
1835concentrator manufacturers? This question has no simple answer.
1836
1837 One reason why we are reluctant to cater to the problems caused by
1838@kbd{C-s} and @kbd{C-q} is that they are gratuitous. There are other
1839techniques (albeit less common in practice) for flow control that
1840preserve transparency of the character stream. Note also that their use
1841for flow control is not an official standard. Interestingly, on the
969fe9b5
RS
1842model 33 teletype with a paper tape punch (around 1970), @kbd{C-s} and
1843@kbd{C-q} were sent by the computer to turn the punch on and off!
73804d4b 1844
969fe9b5
RS
1845 As window systems and PC terminal emulators replace character-only
1846terminals, the flow control problem is gradually disappearing. For the
1847mean time, Emacs provides a convenient way of enabling flow control if
1848you want it: call the function @code{enable-flow-control}.
73804d4b 1849
f9f59935 1850@deffn Command enable-flow-control
73804d4b
RS
1851This function enables use of @kbd{C-s} and @kbd{C-q} for output flow
1852control, and provides the characters @kbd{C-\} and @kbd{C-^} as aliases
1853for them using @code{keyboard-translate-table} (@pxref{Translating Input}).
f9f59935 1854@end deffn
73804d4b
RS
1855
1856You can use the function @code{enable-flow-control-on} in your
a40d4712 1857init file to enable flow control automatically on certain
73804d4b
RS
1858terminal types.
1859
1860@defun enable-flow-control-on &rest termtypes
1861This function enables flow control, and the aliases @kbd{C-\} and @kbd{C-^},
1862if the terminal type is one of @var{termtypes}. For example:
1863
1864@smallexample
1865(enable-flow-control-on "vt200" "vt300" "vt101" "vt131")
1866@end smallexample
1867@end defun
1868
1869 Here is how @code{enable-flow-control} does its job:
1870
1871@enumerate
1872@item
1873@cindex @sc{cbreak}
1874It sets @sc{cbreak} mode for terminal input, and tells the operating
1875system to handle flow control, with @code{(set-input-mode nil t)}.
1876
1877@item
1878It sets up @code{keyboard-translate-table} to translate @kbd{C-\} and
78608595 1879@kbd{C-^} into @kbd{C-s} and @kbd{C-q}. Except at its very
73804d4b
RS
1880lowest level, Emacs never knows that the characters typed were anything
1881but @kbd{C-s} and @kbd{C-q}, so you can in effect type them as @kbd{C-\}
1882and @kbd{C-^} even when they are input for other commands.
1883@xref{Translating Input}.
a890e1b0 1884@end enumerate
73804d4b
RS
1885
1886If the terminal is the source of the flow control characters, then once
1887you enable kernel flow control handling, you probably can make do with
1888less padding than normal for that terminal. You can reduce the amount
1889of padding by customizing the Termcap entry. You can also reduce it by
1890setting @code{baud-rate} to a smaller value so that Emacs uses a smaller
1891speed when calculating the padding needed. @xref{Terminal Output}.
1892
1893@node Batch Mode
1894@section Batch Mode
1895@cindex batch mode
1896@cindex noninteractive use
1897
8241495d 1898 The command-line option @samp{-batch} causes Emacs to run
73804d4b
RS
1899noninteractively. In this mode, Emacs does not read commands from the
1900terminal, it does not alter the terminal modes, and it does not expect
1901to be outputting to an erasable screen. The idea is that you specify
1902Lisp programs to run; when they are finished, Emacs should exit. The
1903way to specify the programs to run is with @samp{-l @var{file}}, which
1904loads the library named @var{file}, and @samp{-f @var{function}}, which
1905calls @var{function} with no arguments.
1906
1907 Any Lisp program output that would normally go to the echo area,
8241495d 1908either using @code{message}, or using @code{prin1}, etc., with @code{t}
bfe721d1 1909as the stream, goes instead to Emacs's standard error descriptor when
73804d4b
RS
1910in batch mode. Thus, Emacs behaves much like a noninteractive
1911application program. (The echo area output that Emacs itself normally
1912generates, such as command echoing, is suppressed entirely.)
1913
1914@defvar noninteractive
1915This variable is non-@code{nil} when Emacs is running in batch mode.
1916@end defvar