Sync with Tramp 2.0.44.
[bpt/emacs.git] / lispref / intro.texi
CommitLineData
83ac6b45
RS
1@c -*-texinfo-*-
2@c This is part of the GNU Emacs Lisp Reference Manual.
367b61a1 3@c Copyright (C) 1990, 1991, 1992, 1993, 1994, 2002
177c0ea7 4@c Free Software Foundation, Inc.
83ac6b45
RS
5@c See the file elisp.texi for copying conditions.
6@setfilename ../info/intro
7
892a8f36 8@c Versino of the manual.
367b61a1 9@set VERSION 2.9
892a8f36 10
e4a29e5a 11@node Introduction, Lisp Data Types, Top, Top
83ac6b45 12@comment node-name, next, previous, up
83ac6b45
RS
13@chapter Introduction
14
15 Most of the GNU Emacs text editor is written in the programming
16language called Emacs Lisp. You can write new code in Emacs Lisp and
17install it as an extension to the editor. However, Emacs Lisp is more
18than a mere ``extension language''; it is a full computer programming
19language in its own right. You can use it as you would any other
20programming language.
21
22 Because Emacs Lisp is designed for use in an editor, it has special
23features for scanning and parsing text as well as features for handling
24files, buffers, displays, subprocesses, and so on. Emacs Lisp is
25closely integrated with the editing facilities; thus, editing commands
26are functions that can also conveniently be called from Lisp programs,
27and parameters for customization are ordinary Lisp variables.
28
a9f0a989
RS
29 This manual attempts to be a full description of Emacs Lisp. For a
30beginner's introduction to Emacs Lisp, see @cite{An Introduction to
31Emacs Lisp Programming}, by Bob Chassell, also published by the Free
32Software Foundation. This manual presumes considerable familiarity with
33the use of Emacs for editing; see @cite{The GNU Emacs Manual} for this
34basic information.
35
36 Generally speaking, the earlier chapters describe features of Emacs
37Lisp that have counterparts in many programming languages, and later
38chapters describe features that are peculiar to Emacs Lisp or relate
39specifically to editing.
83ac6b45 40
892a8f36 41 This is edition @value{VERSION}.
83ac6b45
RS
42
43@menu
44* Caveats:: Flaws and a request for help.
45* Lisp History:: Emacs Lisp is descended from Maclisp.
46* Conventions:: How the manual is formatted.
a9f0a989 47* Version Info:: Which Emacs version is running?
83ac6b45
RS
48* Acknowledgements:: The authors, editors, and sponsors of this manual.
49@end menu
50
51@node Caveats
52@section Caveats
30db19b9 53@cindex bugs in this manual
83ac6b45
RS
54
55 This manual has gone through numerous drafts. It is nearly complete
7791402e
RS
56but not flawless. There are a few topics that are not covered, either
57because we consider them secondary (such as most of the individual
58modes) or because they are yet to be written. Because we are not able
59to deal with them completely, we have left out several parts
60intentionally. This includes most information about usage on VMS.
83ac6b45
RS
61
62 The manual should be fully correct in what it does cover, and it is
63therefore open to criticism on anything it says---from specific examples
64and descriptive text, to the ordering of chapters and sections. If
65something is confusing, or you find that you have to look at the sources
66or experiment to learn something not covered in the manual, then perhaps
67the manual should be fixed. Please let us know.
68
69@iftex
a40d4712
PR
70 As you use this manual, we ask that you mark pages with corrections so
71you can later look them up and send them to us. If you think of a simple,
7791402e 72real-life example for a function or group of functions, please make an
83ac6b45
RS
73effort to write it up and send it in. Please reference any comments to
74the chapter name, section name, and function name, as appropriate, since
7791402e
RS
75page numbers and chapter and section numbers will change and we may have
76trouble finding the text you are talking about. Also state the number
77of the edition you are criticizing.
83ac6b45 78@end iftex
37680279 79@ifnottex
83ac6b45
RS
80
81As you use this manual, we ask that you send corrections as soon as you
82find them. If you think of a simple, real life example for a function
83or group of functions, please make an effort to write it up and send it
84in. Please reference any comments to the node name and function or
85variable name, as appropriate. Also state the number of the edition
a40d4712 86you are criticizing.
37680279 87@end ifnottex
83ac6b45 88
5a6f4c95
RS
89@cindex bugs
90@cindex suggestions
83ac6b45
RS
91Please mail comments and corrections to
92
93@example
a9f0a989 94bug-lisp-manual@@gnu.org
83ac6b45
RS
95@end example
96
97@noindent
98We let mail to this list accumulate unread until someone decides to
99apply the corrections. Months, and sometimes years, go by between
100updates. So please attach no significance to the lack of a reply---your
101mail @emph{will} be acted on in due time. If you want to contact the
102Emacs maintainers more quickly, send mail to
a9f0a989 103@code{bug-gnu-emacs@@gnu.org}.
83ac6b45 104
83ac6b45
RS
105@node Lisp History
106@section Lisp History
107@cindex Lisp history
108
a9f0a989 109 Lisp (LISt Processing language) was first developed in the late 1950s
83ac6b45 110at the Massachusetts Institute of Technology for research in artificial
a9f0a989 111intelligence. The great power of the Lisp language makes it ideal
83ac6b45
RS
112for other purposes as well, such as writing editing commands.
113
114@cindex Maclisp
115@cindex Common Lisp
116 Dozens of Lisp implementations have been built over the years, each
117with its own idiosyncrasies. Many of them were inspired by Maclisp,
a9f0a989 118which was written in the 1960s at MIT's Project MAC. Eventually the
7791402e 119implementors of the descendants of Maclisp came together and developed a
a9f0a989 120standard for Lisp systems, called Common Lisp. In the meantime, Gerry
969fe9b5
RS
121Sussman and Guy Steele at MIT developed a simplified but very powerful
122dialect of Lisp, called Scheme.
83ac6b45
RS
123
124 GNU Emacs Lisp is largely inspired by Maclisp, and a little by Common
125Lisp. If you know Common Lisp, you will notice many similarities.
a9f0a989 126However, many features of Common Lisp have been omitted or
83ac6b45
RS
127simplified in order to reduce the memory requirements of GNU Emacs.
128Sometimes the simplifications are so drastic that a Common Lisp user
129might be very confused. We will occasionally point out how GNU Emacs
130Lisp differs from Common Lisp. If you don't know Common Lisp, don't
131worry about it; this manual is self-contained.
132
a9f0a989
RS
133@pindex cl
134 A certain amount of Common Lisp emulation is available via the
0eeca3c1 135@file{cl} library. @inforef{Top, Overview, cl}.
a9f0a989 136
969fe9b5 137 Emacs Lisp is not at all influenced by Scheme; but the GNU project has
a9f0a989
RS
138an implementation of Scheme, called Guile. We use Guile in all new GNU
139software that calls for extensibility.
969fe9b5 140
83ac6b45
RS
141@node Conventions
142@section Conventions
143
144This section explains the notational conventions that are used in this
145manual. You may want to skip this section and refer back to it later.
146
147@menu
148* Some Terms:: Explanation of terms we use in this manual.
149* nil and t:: How the symbols @code{nil} and @code{t} are used.
150* Evaluation Notation:: The format we use for examples of evaluation.
a9f0a989 151* Printing Notation:: The format we use when examples print text.
83ac6b45
RS
152* Error Messages:: The format we use for examples of errors.
153* Buffer Text Notation:: The format we use for buffer contents in examples.
154* Format of Descriptions:: Notation for describing functions, variables, etc.
155@end menu
156
157@node Some Terms
158@subsection Some Terms
159
160 Throughout this manual, the phrases ``the Lisp reader'' and ``the Lisp
a9f0a989
RS
161printer'' refer to those routines in Lisp that convert textual
162representations of Lisp objects into actual Lisp objects, and vice
83ac6b45
RS
163versa. @xref{Printed Representation}, for more details. You, the
164person reading this manual, are thought of as ``the programmer'' and are
a9f0a989
RS
165addressed as ``you''. ``The user'' is the person who uses Lisp
166programs, including those you write.
83ac6b45
RS
167
168@cindex fonts
8241495d
RS
169 Examples of Lisp code are formatted like this: @code{(list 1 2 3)}.
170Names that represent metasyntactic variables, or arguments to a function
171being described, are formatted like this: @var{first-number}.
83ac6b45
RS
172
173@node nil and t
174@subsection @code{nil} and @code{t}
175@cindex @code{nil}, uses of
176@cindex truth value
177@cindex boolean
178@cindex false
179
bfe721d1 180 In Lisp, the symbol @code{nil} has three separate meanings: it
83ac6b45
RS
181is a symbol with the name @samp{nil}; it is the logical truth value
182@var{false}; and it is the empty list---the list of zero elements.
183When used as a variable, @code{nil} always has the value @code{nil}.
184
185 As far as the Lisp reader is concerned, @samp{()} and @samp{nil} are
186identical: they stand for the same object, the symbol @code{nil}. The
187different ways of writing the symbol are intended entirely for human
188readers. After the Lisp reader has read either @samp{()} or @samp{nil},
189there is no way to determine which representation was actually written
190by the programmer.
191
192 In this manual, we use @code{()} when we wish to emphasize that it
193means the empty list, and we use @code{nil} when we wish to emphasize
194that it means the truth value @var{false}. That is a good convention to use
195in Lisp programs also.
196
197@example
198(cons 'foo ()) ; @r{Emphasize the empty list}
199(not nil) ; @r{Emphasize the truth value @var{false}}
200@end example
201
202@cindex @code{t} and truth
203@cindex true
204 In contexts where a truth value is expected, any non-@code{nil} value
205is considered to be @var{true}. However, @code{t} is the preferred way
206to represent the truth value @var{true}. When you need to choose a
207value which represents @var{true}, and there is no other basis for
a9f0a989
RS
208choosing, use @code{t}. The symbol @code{t} always has the value
209@code{t}.
83ac6b45
RS
210
211 In Emacs Lisp, @code{nil} and @code{t} are special symbols that always
212evaluate to themselves. This is so that you do not need to quote them
213to use them as constants in a program. An attempt to change their
969fe9b5
RS
214values results in a @code{setting-constant} error. The same is true of
215any symbol whose name starts with a colon (@samp{:}). @xref{Constant
83ac6b45
RS
216Variables}.
217
218@node Evaluation Notation
219@subsection Evaluation Notation
220@cindex evaluation notation
221@cindex documentation notation
222
223 A Lisp expression that you can evaluate is called a @dfn{form}.
224Evaluating a form always produces a result, which is a Lisp object. In
225the examples in this manual, this is indicated with @samp{@result{}}:
226
227@example
228(car '(1 2))
229 @result{} 1
230@end example
231
232@noindent
233You can read this as ``@code{(car '(1 2))} evaluates to 1''.
234
235 When a form is a macro call, it expands into a new form for Lisp to
236evaluate. We show the result of the expansion with
a9f0a989 237@samp{@expansion{}}. We may or may not show the result of the
83ac6b45
RS
238evaluation of the expanded form.
239
240@example
241(third '(a b c))
242 @expansion{} (car (cdr (cdr '(a b c))))
243 @result{} c
244@end example
245
7791402e 246 Sometimes to help describe one form we show another form that
83ac6b45
RS
247produces identical results. The exact equivalence of two forms is
248indicated with @samp{@equiv{}}.
249
250@example
251(make-sparse-keymap) @equiv{} (list 'keymap)
252@end example
253
254@node Printing Notation
255@subsection Printing Notation
256@cindex printing notation
257
258 Many of the examples in this manual print text when they are
7791402e
RS
259evaluated. If you execute example code in a Lisp Interaction buffer
260(such as the buffer @samp{*scratch*}), the printed text is inserted into
261the buffer. If you execute the example by other means (such as by
262evaluating the function @code{eval-region}), the printed text is
79ddc9c9 263displayed in the echo area.
83ac6b45
RS
264
265 Examples in this manual indicate printed text with @samp{@print{}},
266irrespective of where that text goes. The value returned by evaluating
267the form (here @code{bar}) follows on a separate line.
268
269@example
270@group
271(progn (print 'foo) (print 'bar))
272 @print{} foo
273 @print{} bar
274 @result{} bar
275@end group
276@end example
277
278@node Error Messages
279@subsection Error Messages
280@cindex error message notation
281
282 Some examples signal errors. This normally displays an error message
283in the echo area. We show the error message on a line starting with
284@samp{@error{}}. Note that @samp{@error{}} itself does not appear in
285the echo area.
286
287@example
288(+ 23 'x)
f9f59935 289@error{} Wrong type argument: number-or-marker-p, x
83ac6b45
RS
290@end example
291
292@node Buffer Text Notation
293@subsection Buffer Text Notation
294@cindex buffer text notation
295
8241495d
RS
296 Some examples describe modifications to the contents of a buffer, by
297showing the ``before'' and ``after'' versions of the text. These
298examples show the contents of the buffer in question between two lines
299of dashes containing the buffer name. In addition, @samp{@point{}}
300indicates the location of point. (The symbol for point, of course, is
301not part of the text in the buffer; it indicates the place
302@emph{between} two characters where point is currently located.)
83ac6b45
RS
303
304@example
305---------- Buffer: foo ----------
306This is the @point{}contents of foo.
307---------- Buffer: foo ----------
308
309(insert "changed ")
310 @result{} nil
311---------- Buffer: foo ----------
312This is the changed @point{}contents of foo.
313---------- Buffer: foo ----------
314@end example
315
316@node Format of Descriptions
317@subsection Format of Descriptions
318@cindex description format
319
320 Functions, variables, macros, commands, user options, and special
321forms are described in this manual in a uniform format. The first
322line of a description contains the name of the item followed by its
323arguments, if any.
37680279 324@ifnottex
83ac6b45
RS
325The category---function, variable, or whatever---appears at the
326beginning of the line.
37680279 327@end ifnottex
83ac6b45
RS
328@iftex
329The category---function, variable, or whatever---is printed next to the
330right margin.
331@end iftex
332The description follows on succeeding lines, sometimes with examples.
333
334@menu
335* A Sample Function Description:: A description of an imaginary
336 function, @code{foo}.
337* A Sample Variable Description:: A description of an imaginary
338 variable,
177c0ea7 339 @code{electric-future-map}.
83ac6b45
RS
340@end menu
341
342@node A Sample Function Description
343@subsubsection A Sample Function Description
344@cindex function descriptions
345@cindex command descriptions
346@cindex macro descriptions
347@cindex special form descriptions
348
349 In a function description, the name of the function being described
969fe9b5
RS
350appears first. It is followed on the same line by a list of argument
351names. These names are also used in the body of the description, to
352stand for the values of the arguments.
83ac6b45 353
969fe9b5
RS
354 The appearance of the keyword @code{&optional} in the argument list
355indicates that the subsequent arguments may be omitted (omitted
356arguments default to @code{nil}). Do not write @code{&optional} when
357you call the function.
83ac6b45 358
a9f0a989
RS
359 The keyword @code{&rest} (which must be followed by a single argument
360name) indicates that any number of arguments can follow. The single
361following argument name will have a value, as a variable, which is a
362list of all these remaining arguments. Do not write @code{&rest} when
363you call the function.
83ac6b45
RS
364
365 Here is a description of an imaginary function @code{foo}:
366
367@defun foo integer1 &optional integer2 &rest integers
368The function @code{foo} subtracts @var{integer1} from @var{integer2},
369then adds all the rest of the arguments to the result. If @var{integer2}
370is not supplied, then the number 19 is used by default.
371
372@example
373(foo 1 5 3 9)
374 @result{} 16
375(foo 5)
376 @result{} 14
377@end example
378
7dd3d99f 379@need 1500
83ac6b45
RS
380More generally,
381
382@example
383(foo @var{w} @var{x} @var{y}@dots{})
384@equiv{}
385(+ (- @var{x} @var{w}) @var{y}@dots{})
386@end example
387@end defun
388
969fe9b5 389 Any argument whose name contains the name of a type (e.g.,
83ac6b45
RS
390@var{integer}, @var{integer1} or @var{buffer}) is expected to be of that
391type. A plural of a type (such as @var{buffers}) often means a list of
969fe9b5
RS
392objects of that type. Arguments named @var{object} may be of any type.
393(@xref{Lisp Data Types}, for a list of Emacs object types.) Arguments
394with other sorts of names (e.g., @var{new-file}) are discussed
395specifically in the description of the function. In some sections,
396features common to the arguments of several functions are described at
397the beginning.
83ac6b45
RS
398
399 @xref{Lambda Expressions}, for a more complete description of optional
400and rest arguments.
401
402 Command, macro, and special form descriptions have the same format,
403but the word `Function' is replaced by `Command', `Macro', or `Special
404Form', respectively. Commands are simply functions that may be called
405interactively; macros process their arguments differently from functions
406(the arguments are not evaluated), but are presented the same way.
407
408 Special form descriptions use a more complex notation to specify
969fe9b5 409optional and repeated arguments because they can break the argument
83ac6b45 410list down into separate arguments in more complicated ways.
a9f0a989 411@samp{@r{[}@var{optional-arg}@r{]}} means that @var{optional-arg} is
83ac6b45
RS
412optional and @samp{@var{repeated-args}@dots{}} stands for zero or more
413arguments. Parentheses are used when several arguments are grouped into
414additional levels of list structure. Here is an example:
415
416@defspec count-loop (@var{var} [@var{from} @var{to} [@var{inc}]]) @var{body}@dots{}
417This imaginary special form implements a loop that executes the
418@var{body} forms and then increments the variable @var{var} on each
419iteration. On the first iteration, the variable has the value
a9f0a989 420@var{from}; on subsequent iterations, it is incremented by one (or by
83ac6b45
RS
421@var{inc} if that is given). The loop exits before executing @var{body}
422if @var{var} equals @var{to}. Here is an example:
423
424@example
425(count-loop (i 0 10)
426 (prin1 i) (princ " ")
969fe9b5
RS
427 (prin1 (aref vector i))
428 (terpri))
83ac6b45
RS
429@end example
430
a9f0a989 431If @var{from} and @var{to} are omitted, @var{var} is bound to
83ac6b45
RS
432@code{nil} before the loop begins, and the loop exits if @var{var} is
433non-@code{nil} at the beginning of an iteration. Here is an example:
434
435@example
436(count-loop (done)
437 (if (pending)
438 (fixit)
439 (setq done t)))
440@end example
441
442In this special form, the arguments @var{from} and @var{to} are
443optional, but must both be present or both absent. If they are present,
444@var{inc} may optionally be specified as well. These arguments are
445grouped with the argument @var{var} into a list, to distinguish them
446from @var{body}, which includes all remaining elements of the form.
447@end defspec
448
449@node A Sample Variable Description
450@subsubsection A Sample Variable Description
451@cindex variable descriptions
452@cindex option descriptions
453
454 A @dfn{variable} is a name that can hold a value. Although any
455variable can be set by the user, certain variables that exist
456specifically so that users can change them are called @dfn{user
457options}. Ordinary variables and user options are described using a
458format like that for functions except that there are no arguments.
459
460 Here is a description of the imaginary @code{electric-future-map}
461variable.@refill
462
463@defvar electric-future-map
464The value of this variable is a full keymap used by Electric Command
465Future mode. The functions in this map allow you to edit commands you
466have not yet thought about executing.
467@end defvar
468
469 User option descriptions have the same format, but `Variable' is
470replaced by `User Option'.
471
969fe9b5
RS
472@node Version Info
473@section Version Information
474
a9f0a989
RS
475 These facilities provide information about which version of Emacs is
476in use.
969fe9b5 477
8bbf587d 478@deffn Command emacs-version &optional here
969fe9b5
RS
479This function returns a string describing the version of Emacs that is
480running. It is useful to include this string in bug reports.
481
a9f0a989 482@smallexample
969fe9b5
RS
483@group
484(emacs-version)
485 @result{} "GNU Emacs 20.3.5 (i486-pc-linux-gnulibc1, X toolkit)
486 of Sat Feb 14 1998 on psilocin.gnu.org"
487@end group
a9f0a989 488@end smallexample
969fe9b5 489
8bbf587d
RS
490If @var{here} is non-@code{nil}, it inserts the text in the buffer
491before point, and returns @code{nil}. Called interactively, the
492function prints the same information in the echo area, but giving a
493prefix argument makes @var{here} non-@code{nil}.
969fe9b5
RS
494@end deffn
495
496@defvar emacs-build-time
a9f0a989
RS
497The value of this variable indicates the time at which Emacs was built
498at the local site. It is a list of three integers, like the value
499of @code{current-time} (@pxref{Time of Day}).
969fe9b5
RS
500
501@example
502@group
503emacs-build-time
a9f0a989 504 @result{} (13623 62065 344633)
969fe9b5
RS
505@end group
506@end example
507@end defvar
508
509@defvar emacs-version
510The value of this variable is the version of Emacs being run. It is a
511string such as @code{"20.3.1"}. The last number in this string is not
512really part of the Emacs release version number; it is incremented each
aab28c42 513time you build Emacs in any given directory. A value with four numeric
8241495d
RS
514components, such as @code{"20.3.9.1"}, indicates an unreleased test
515version.
969fe9b5
RS
516@end defvar
517
a9f0a989 518 The following two variables have existed since Emacs version 19.23:
969fe9b5
RS
519
520@defvar emacs-major-version
521The major version number of Emacs, as an integer. For Emacs version
52220.3, the value is 20.
523@end defvar
524
525@defvar emacs-minor-version
526The minor version number of Emacs, as an integer. For Emacs version
52720.3, the value is 3.
528@end defvar
529
83ac6b45
RS
530@node Acknowledgements
531@section Acknowledgements
532
533 This manual was written by Robert Krawitz, Bil Lewis, Dan LaLiberte,
534Richard M. Stallman and Chris Welty, the volunteers of the GNU manual
535group, in an effort extending over several years. Robert J. Chassell
536helped to review and edit the manual, with the support of the Defense
537Advanced Research Projects Agency, ARPA Order 6082, arranged by Warren
a40d4712 538A. Hunt, Jr.@: of Computational Logic, Inc.
83ac6b45
RS
539
540 Corrections were supplied by Karl Berry, Jim Blandy, Bard Bloom,
541Stephane Boucher, David Boyes, Alan Carroll, Richard Davis, Lawrence
542R. Dodd, Peter Doornbosch, David A. Duff, Chris Eich, Beverly
543Erlebacher, David Eckelkamp, Ralf Fassel, Eirik Fuller, Stephen Gildea,
544Bob Glickstein, Eric Hanchrow, George Hartzell, Nathan Hess, Masayuki
545Ida, Dan Jacobson, Jak Kirman, Bob Knighten, Frederick M. Korz, Joe
546Lammens, Glenn M. Lewis, K. Richard Magill, Brian Marick, Roland
547McGrath, Skip Montanaro, John Gardiner Myers, Thomas A. Peterson,
548Francesco Potorti, Friedrich Pukelsheim, Arnold D. Robbins, Raul
a40d4712 549Rockwell, Per Starb@"ack, Shinichirou Sugou, Kimmo Suominen, Edward Tharp,
83ac6b45
RS
550Bill Trost, Rickard Westman, Jean White, Matthew Wilding, Carl Witty,
551Dale Worley, Rusty Wright, and David D. Zuhn.
ab5796a9
MB
552
553@ignore
554 arch-tag: d156593f-82f8-4708-a844-204e48f7f2aa
555@end ignore