comparison lispref/intro.texi @ 22138:d4ac295a98b3

*** empty log message ***
author Richard M. Stallman <rms@gnu.org>
date Tue, 19 May 1998 03:45:57 +0000
parents 90da2489c498
children 40089afa2b1d
comparison
equal deleted inserted replaced
22137:2b0e6a1e7fb9 22138:d4ac295a98b3
416 files, buffers, displays, subprocesses, and so on. Emacs Lisp is 416 files, buffers, displays, subprocesses, and so on. Emacs Lisp is
417 closely integrated with the editing facilities; thus, editing commands 417 closely integrated with the editing facilities; thus, editing commands
418 are functions that can also conveniently be called from Lisp programs, 418 are functions that can also conveniently be called from Lisp programs,
419 and parameters for customization are ordinary Lisp variables. 419 and parameters for customization are ordinary Lisp variables.
420 420
421 This manual describes Emacs Lisp, presuming considerable familiarity 421 This manual attempts to be a full description of Emacs Lisp. For a
422 with the use of Emacs for editing. (See @cite{The GNU Emacs Manual} 422 beginner's introduction to Emacs Lisp, see @cite{An Introduction to
423 for this basic information.) Generally speaking, the earlier chapters 423 Emacs Lisp Programming}, by Bob Chassell, also published by the Free
424 describe features of Emacs Lisp that have counterparts in many 424 Software Foundation. This manual presumes considerable familiarity with
425 programming languages, and later chapters describe features that are 425 the use of Emacs for editing; see @cite{The GNU Emacs Manual} for this
426 peculiar to Emacs Lisp or relate specifically to editing. 426 basic information.
427
428 Generally speaking, the earlier chapters describe features of Emacs
429 Lisp that have counterparts in many programming languages, and later
430 chapters describe features that are peculiar to Emacs Lisp or relate
431 specifically to editing.
427 432
428 This is edition 2.5. 433 This is edition 2.5.
429 434
430 @menu 435 @menu
431 * Caveats:: Flaws and a request for help. 436 * Caveats:: Flaws and a request for help.
432 * Lisp History:: Emacs Lisp is descended from Maclisp. 437 * Lisp History:: Emacs Lisp is descended from Maclisp.
433 * Conventions:: How the manual is formatted. 438 * Conventions:: How the manual is formatted.
439 * Version Info:: Which Emacs version is running?
434 * Acknowledgements:: The authors, editors, and sponsors of this manual. 440 * Acknowledgements:: The authors, editors, and sponsors of this manual.
435 @end menu 441 @end menu
436 442
437 @node Caveats 443 @node Caveats
438 @section Caveats 444 @section Caveats
472 @end ifinfo 478 @end ifinfo
473 479
474 Please mail comments and corrections to 480 Please mail comments and corrections to
475 481
476 @example 482 @example
477 bug-lisp-manual@@prep.ai.mit.edu 483 bug-lisp-manual@@gnu.org
478 @end example 484 @end example
479 485
480 @noindent 486 @noindent
481 We let mail to this list accumulate unread until someone decides to 487 We let mail to this list accumulate unread until someone decides to
482 apply the corrections. Months, and sometimes years, go by between 488 apply the corrections. Months, and sometimes years, go by between
483 updates. So please attach no significance to the lack of a reply---your 489 updates. So please attach no significance to the lack of a reply---your
484 mail @emph{will} be acted on in due time. If you want to contact the 490 mail @emph{will} be acted on in due time. If you want to contact the
485 Emacs maintainers more quickly, send mail to 491 Emacs maintainers more quickly, send mail to
486 @code{bug-gnu-emacs@@prep.ai.mit.edu}. 492 @code{bug-gnu-emacs@@gnu.org}.
487 493
488 @display 494 @display
489 --Bil Lewis, Dan LaLiberte, Richard Stallman 495 --Bil Lewis, Dan LaLiberte, Richard Stallman
490 @end display 496 @end display
491 497
492 @node Lisp History 498 @node Lisp History
493 @section Lisp History 499 @section Lisp History
494 @cindex Lisp history 500 @cindex Lisp history
495 501
496 Lisp (LISt Processing language) was first developed in the late 1950's 502 Lisp (LISt Processing language) was first developed in the late 1950s
497 at the Massachusetts Institute of Technology for research in artificial 503 at the Massachusetts Institute of Technology for research in artificial
498 intelligence. The great power of the Lisp language makes it superior 504 intelligence. The great power of the Lisp language makes it ideal
499 for other purposes as well, such as writing editing commands. 505 for other purposes as well, such as writing editing commands.
500 506
501 @cindex Maclisp 507 @cindex Maclisp
502 @cindex Common Lisp 508 @cindex Common Lisp
503 Dozens of Lisp implementations have been built over the years, each 509 Dozens of Lisp implementations have been built over the years, each
504 with its own idiosyncrasies. Many of them were inspired by Maclisp, 510 with its own idiosyncrasies. Many of them were inspired by Maclisp,
505 which was written in the 1960's at MIT's Project MAC. Eventually the 511 which was written in the 1960s at MIT's Project MAC. Eventually the
506 implementors of the descendants of Maclisp came together and developed a 512 implementors of the descendants of Maclisp came together and developed a
507 standard for Lisp systems, called Common Lisp. In the mean time, Gerry 513 standard for Lisp systems, called Common Lisp. In the meantime, Gerry
508 Sussman and Guy Steele at MIT developed a simplified but very powerful 514 Sussman and Guy Steele at MIT developed a simplified but very powerful
509 dialect of Lisp, called Scheme. 515 dialect of Lisp, called Scheme.
510 516
511 GNU Emacs Lisp is largely inspired by Maclisp, and a little by Common 517 GNU Emacs Lisp is largely inspired by Maclisp, and a little by Common
512 Lisp. If you know Common Lisp, you will notice many similarities. 518 Lisp. If you know Common Lisp, you will notice many similarities.
513 However, many of the features of Common Lisp have been omitted or 519 However, many features of Common Lisp have been omitted or
514 simplified in order to reduce the memory requirements of GNU Emacs. 520 simplified in order to reduce the memory requirements of GNU Emacs.
515 Sometimes the simplifications are so drastic that a Common Lisp user 521 Sometimes the simplifications are so drastic that a Common Lisp user
516 might be very confused. We will occasionally point out how GNU Emacs 522 might be very confused. We will occasionally point out how GNU Emacs
517 Lisp differs from Common Lisp. If you don't know Common Lisp, don't 523 Lisp differs from Common Lisp. If you don't know Common Lisp, don't
518 worry about it; this manual is self-contained. 524 worry about it; this manual is self-contained.
519 525
526 @pindex cl
527 A certain amount of Common Lisp emulation is available via the
528 @file{cl} library @xref{Top,, Common Lisp Extension, cl, Common Lisp
529 Extensions}.
530
520 Emacs Lisp is not at all influenced by Scheme; but the GNU project has 531 Emacs Lisp is not at all influenced by Scheme; but the GNU project has
521 an implementation of Scheme, called Guile. We use Guile for 532 an implementation of Scheme, called Guile. We use Guile in all new GNU
522 extensibility in all new GNU software that calls for extensibility. 533 software that calls for extensibility.
523 534
524 @node Conventions 535 @node Conventions
525 @section Conventions 536 @section Conventions
526 537
527 This section explains the notational conventions that are used in this 538 This section explains the notational conventions that are used in this
529 540
530 @menu 541 @menu
531 * Some Terms:: Explanation of terms we use in this manual. 542 * Some Terms:: Explanation of terms we use in this manual.
532 * nil and t:: How the symbols @code{nil} and @code{t} are used. 543 * nil and t:: How the symbols @code{nil} and @code{t} are used.
533 * Evaluation Notation:: The format we use for examples of evaluation. 544 * Evaluation Notation:: The format we use for examples of evaluation.
534 * Printing Notation:: The format we use for examples that print output. 545 * Printing Notation:: The format we use when examples print text.
535 * Error Messages:: The format we use for examples of errors. 546 * Error Messages:: The format we use for examples of errors.
536 * Buffer Text Notation:: The format we use for buffer contents in examples. 547 * Buffer Text Notation:: The format we use for buffer contents in examples.
537 * Format of Descriptions:: Notation for describing functions, variables, etc. 548 * Format of Descriptions:: Notation for describing functions, variables, etc.
538 * Version Info:: Which Emacs version is running?
539 @end menu 549 @end menu
540 550
541 @node Some Terms 551 @node Some Terms
542 @subsection Some Terms 552 @subsection Some Terms
543 553
544 Throughout this manual, the phrases ``the Lisp reader'' and ``the Lisp 554 Throughout this manual, the phrases ``the Lisp reader'' and ``the Lisp
545 printer'' are used to refer to those routines in Lisp that convert 555 printer'' refer to those routines in Lisp that convert textual
546 textual representations of Lisp objects into actual Lisp objects, and vice 556 representations of Lisp objects into actual Lisp objects, and vice
547 versa. @xref{Printed Representation}, for more details. You, the 557 versa. @xref{Printed Representation}, for more details. You, the
548 person reading this manual, are thought of as ``the programmer'' and are 558 person reading this manual, are thought of as ``the programmer'' and are
549 addressed as ``you''. ``The user'' is the person who uses Lisp programs, 559 addressed as ``you''. ``The user'' is the person who uses Lisp
550 including those you write. 560 programs, including those you write.
551 561
552 @cindex fonts 562 @cindex fonts
553 Examples of Lisp code appear in this font or form: @code{(list 1 2 563 Examples of Lisp code appear in this font or form: @code{(list 1 2
554 3)}. Names that represent metasyntactic variables, or arguments to a 564 3)}. Names that represent metasyntactic variables, or arguments to a
555 function being described, appear in this font or form: 565 function being described, appear in this font or form:
588 @cindex true 598 @cindex true
589 In contexts where a truth value is expected, any non-@code{nil} value 599 In contexts where a truth value is expected, any non-@code{nil} value
590 is considered to be @var{true}. However, @code{t} is the preferred way 600 is considered to be @var{true}. However, @code{t} is the preferred way
591 to represent the truth value @var{true}. When you need to choose a 601 to represent the truth value @var{true}. When you need to choose a
592 value which represents @var{true}, and there is no other basis for 602 value which represents @var{true}, and there is no other basis for
593 choosing, use @code{t}. The symbol @code{t} always has value @code{t}. 603 choosing, use @code{t}. The symbol @code{t} always has the value
604 @code{t}.
594 605
595 In Emacs Lisp, @code{nil} and @code{t} are special symbols that always 606 In Emacs Lisp, @code{nil} and @code{t} are special symbols that always
596 evaluate to themselves. This is so that you do not need to quote them 607 evaluate to themselves. This is so that you do not need to quote them
597 to use them as constants in a program. An attempt to change their 608 to use them as constants in a program. An attempt to change their
598 values results in a @code{setting-constant} error. The same is true of 609 values results in a @code{setting-constant} error. The same is true of
616 @noindent 627 @noindent
617 You can read this as ``@code{(car '(1 2))} evaluates to 1''. 628 You can read this as ``@code{(car '(1 2))} evaluates to 1''.
618 629
619 When a form is a macro call, it expands into a new form for Lisp to 630 When a form is a macro call, it expands into a new form for Lisp to
620 evaluate. We show the result of the expansion with 631 evaluate. We show the result of the expansion with
621 @samp{@expansion{}}. We may or may not show the actual result of the 632 @samp{@expansion{}}. We may or may not show the result of the
622 evaluation of the expanded form. 633 evaluation of the expanded form.
623 634
624 @example 635 @example
625 (third '(a b c)) 636 (third '(a b c))
626 @expansion{} (car (cdr (cdr '(a b c)))) 637 @expansion{} (car (cdr (cdr '(a b c))))
739 The appearance of the keyword @code{&optional} in the argument list 750 The appearance of the keyword @code{&optional} in the argument list
740 indicates that the subsequent arguments may be omitted (omitted 751 indicates that the subsequent arguments may be omitted (omitted
741 arguments default to @code{nil}). Do not write @code{&optional} when 752 arguments default to @code{nil}). Do not write @code{&optional} when
742 you call the function. 753 you call the function.
743 754
744 The keyword @code{&rest} (which will always be followed by a single 755 The keyword @code{&rest} (which must be followed by a single argument
745 argument name) indicates that any number of arguments can follow. The value 756 name) indicates that any number of arguments can follow. The single
746 of the single following arguments name will be a list of all these arguments. 757 following argument name will have a value, as a variable, which is a
747 Do not write @code{&rest} when you call the function. 758 list of all these remaining arguments. Do not write @code{&rest} when
759 you call the function.
748 760
749 Here is a description of an imaginary function @code{foo}: 761 Here is a description of an imaginary function @code{foo}:
750 762
751 @defun foo integer1 &optional integer2 &rest integers 763 @defun foo integer1 &optional integer2 &rest integers
752 The function @code{foo} subtracts @var{integer1} from @var{integer2}, 764 The function @code{foo} subtracts @var{integer1} from @var{integer2},
789 (the arguments are not evaluated), but are presented the same way. 801 (the arguments are not evaluated), but are presented the same way.
790 802
791 Special form descriptions use a more complex notation to specify 803 Special form descriptions use a more complex notation to specify
792 optional and repeated arguments because they can break the argument 804 optional and repeated arguments because they can break the argument
793 list down into separate arguments in more complicated ways. 805 list down into separate arguments in more complicated ways.
794 @samp{@code{@r{[}@var{optional-arg}@r{]}}} means that @var{optional-arg} is 806 @samp{@r{[}@var{optional-arg}@r{]}} means that @var{optional-arg} is
795 optional and @samp{@var{repeated-args}@dots{}} stands for zero or more 807 optional and @samp{@var{repeated-args}@dots{}} stands for zero or more
796 arguments. Parentheses are used when several arguments are grouped into 808 arguments. Parentheses are used when several arguments are grouped into
797 additional levels of list structure. Here is an example: 809 additional levels of list structure. Here is an example:
798 810
799 @defspec count-loop (@var{var} [@var{from} @var{to} [@var{inc}]]) @var{body}@dots{} 811 @defspec count-loop (@var{var} [@var{from} @var{to} [@var{inc}]]) @var{body}@dots{}
800 This imaginary special form implements a loop that executes the 812 This imaginary special form implements a loop that executes the
801 @var{body} forms and then increments the variable @var{var} on each 813 @var{body} forms and then increments the variable @var{var} on each
802 iteration. On the first iteration, the variable has the value 814 iteration. On the first iteration, the variable has the value
803 @var{from}; on subsequent iterations, it is incremented by 1 (or by 815 @var{from}; on subsequent iterations, it is incremented by one (or by
804 @var{inc} if that is given). The loop exits before executing @var{body} 816 @var{inc} if that is given). The loop exits before executing @var{body}
805 if @var{var} equals @var{to}. Here is an example: 817 if @var{var} equals @var{to}. Here is an example:
806 818
807 @example 819 @example
808 (count-loop (i 0 10) 820 (count-loop (i 0 10)
809 (prin1 i) (princ " ") 821 (prin1 i) (princ " ")
810 (prin1 (aref vector i)) 822 (prin1 (aref vector i))
811 (terpri)) 823 (terpri))
812 @end example 824 @end example
813 825
814 If @var{from} and @var{to} are omitted, then @var{var} is bound to 826 If @var{from} and @var{to} are omitted, @var{var} is bound to
815 @code{nil} before the loop begins, and the loop exits if @var{var} is 827 @code{nil} before the loop begins, and the loop exits if @var{var} is
816 non-@code{nil} at the beginning of an iteration. Here is an example: 828 non-@code{nil} at the beginning of an iteration. Here is an example:
817 829
818 @example 830 @example
819 (count-loop (done) 831 (count-loop (done)
853 replaced by `User Option'. 865 replaced by `User Option'.
854 866
855 @node Version Info 867 @node Version Info
856 @section Version Information 868 @section Version Information
857 869
858 These functions and variables provide information about which 870 These facilities provide information about which version of Emacs is
859 version of Emacs is in use. 871 in use.
860 872
861 @deffn Command emacs-version 873 @deffn Command emacs-version
862 This function returns a string describing the version of Emacs that is 874 This function returns a string describing the version of Emacs that is
863 running. It is useful to include this string in bug reports. 875 running. It is useful to include this string in bug reports.
864 876
865 @example 877 @smallexample
866 @group 878 @group
867 (emacs-version) 879 (emacs-version)
868 @result{} "GNU Emacs 20.3.5 (i486-pc-linux-gnulibc1, X toolkit) 880 @result{} "GNU Emacs 20.3.5 (i486-pc-linux-gnulibc1, X toolkit)
869 of Sat Feb 14 1998 on psilocin.gnu.org" 881 of Sat Feb 14 1998 on psilocin.gnu.org"
870 @end group 882 @end group
871 @end example 883 @end smallexample
872 884
873 Called interactively, the function prints the same information in the 885 Called interactively, the function prints the same information in the
874 echo area. 886 echo area.
875 @end deffn 887 @end deffn
876 888
877 @defvar emacs-build-time 889 @defvar emacs-build-time
878 The value of this variable is the time at which Emacs was built at the 890 The value of this variable indicates the time at which Emacs was built
879 local site. 891 at the local site. It is a list of three integers, like the value
892 of @code{current-time} (@pxref{Time of Day}).
880 893
881 @example 894 @example
882 @group 895 @group
883 emacs-build-time 896 emacs-build-time
884 @result{} "Tue Jun 6 14:55:57 1995" 897 @result{} (13623 62065 344633)
885 @end group 898 @end group
886 @end example 899 @end example
887 @end defvar 900 @end defvar
888 901
889 @defvar emacs-version 902 @defvar emacs-version
891 string such as @code{"20.3.1"}. The last number in this string is not 904 string such as @code{"20.3.1"}. The last number in this string is not
892 really part of the Emacs release version number; it is incremented each 905 really part of the Emacs release version number; it is incremented each
893 time you build Emacs in any given directory. 906 time you build Emacs in any given directory.
894 @end defvar 907 @end defvar
895 908
896 The following two variables have existed since Emacs version 19.23, 909 The following two variables have existed since Emacs version 19.23:
897 910
898 @defvar emacs-major-version 911 @defvar emacs-major-version
899 The major version number of Emacs, as an integer. For Emacs version 912 The major version number of Emacs, as an integer. For Emacs version
900 20.3, the value is 20. 913 20.3, the value is 20.
901 @end defvar 914 @end defvar