home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / gnu / elisp / elisp-2 < prev    next >
Encoding:
GNU Info File  |  1993-05-31  |  44.7 KB  |  990 lines

  1. This is Info file elisp, produced by Makeinfo-1.55 from the input file
  2. elisp.texi.
  3.  
  4.    This is edition 2.0 of the GNU Emacs Lisp Reference Manual, for
  5. Emacs Version 19.
  6.  
  7.    Published by the Free Software Foundation, 675 Massachusetts Avenue,
  8. Cambridge, MA 02139 USA
  9.  
  10.    Copyright (C) 1990, 1991, 1992, 1993 Free Software Foundation, Inc.
  11.  
  12.    Permission is granted to make and distribute verbatim copies of this
  13. manual provided the copyright notice and this permission notice are
  14. preserved on all copies.
  15.  
  16.    Permission is granted to copy and distribute modified versions of
  17. this manual under the conditions for verbatim copying, provided that
  18. the entire resulting derived work is distributed under the terms of a
  19. permission notice identical to this one.
  20.  
  21.    Permission is granted to copy and distribute translations of this
  22. manual into another language, under the above conditions for modified
  23. versions, except that this permission notice may be stated in a
  24. translation approved by the Foundation.
  25.  
  26. 
  27. File: elisp,  Node: Copying,  Next: Introduction,  Prev: Top,  Up: Top
  28.  
  29. GNU GENERAL PUBLIC LICENSE
  30. **************************
  31.  
  32.                          Version 2, June 1991
  33.  
  34.      Copyright (C) 1989, 1991 Free Software Foundation, Inc.
  35.      675 Mass Ave, Cambridge, MA 02139, USA
  36.      
  37.      Everyone is permitted to copy and distribute verbatim copies
  38.      of this license document, but changing it is not allowed.
  39.  
  40. Preamble
  41. ========
  42.  
  43.    The licenses for most software are designed to take away your
  44. freedom to share and change it.  By contrast, the GNU General Public
  45. License is intended to guarantee your freedom to share and change free
  46. software--to make sure the software is free for all its users.  This
  47. General Public License applies to most of the Free Software
  48. Foundation's software and to any other program whose authors commit to
  49. using it.  (Some other Free Software Foundation software is covered by
  50. the GNU Library General Public License instead.)  You can apply it to
  51. your programs, too.
  52.  
  53.    When we speak of free software, we are referring to freedom, not
  54. price.  Our General Public Licenses are designed to make sure that you
  55. have the freedom to distribute copies of free software (and charge for
  56. this service if you wish), that you receive source code or can get it
  57. if you want it, that you can change the software or use pieces of it in
  58. new free programs; and that you know you can do these things.
  59.  
  60.    To protect your rights, we need to make restrictions that forbid
  61. anyone to deny you these rights or to ask you to surrender the rights.
  62. These restrictions translate to certain responsibilities for you if you
  63. distribute copies of the software, or if you modify it.
  64.  
  65.    For example, if you distribute copies of such a program, whether
  66. gratis or for a fee, you must give the recipients all the rights that
  67. you have.  You must make sure that they, too, receive or can get the
  68. source code.  And you must show them these terms so they know their
  69. rights.
  70.  
  71.    We protect your rights with two steps: (1) copyright the software,
  72. and (2) offer you this license which gives you legal permission to copy,
  73. distribute and/or modify the software.
  74.  
  75.    Also, for each author's protection and ours, we want to make certain
  76. that everyone understands that there is no warranty for this free
  77. software.  If the software is modified by someone else and passed on, we
  78. want its recipients to know that what they have is not the original, so
  79. that any problems introduced by others will not reflect on the original
  80. authors' reputations.
  81.  
  82.    Finally, any free program is threatened constantly by software
  83. patents.  We wish to avoid the danger that redistributors of a free
  84. program will individually obtain patent licenses, in effect making the
  85. program proprietary.  To prevent this, we have made it clear that any
  86. patent must be licensed for everyone's free use or not licensed at all.
  87.  
  88.    The precise terms and conditions for copying, distribution and
  89. modification follow.
  90.  
  91.     TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
  92.  
  93.   1. This License applies to any program or other work which contains a
  94.      notice placed by the copyright holder saying it may be distributed
  95.      under the terms of this General Public License.  The "Program",
  96.      below, refers to any such program or work, and a "work based on
  97.      the Program" means either the Program or any derivative work under
  98.      copyright law: that is to say, a work containing the Program or a
  99.      portion of it, either verbatim or with modifications and/or
  100.      translated into another language.  (Hereinafter, translation is
  101.      included without limitation in the term "modification".)  Each
  102.      licensee is addressed as "you".
  103.  
  104.      Activities other than copying, distribution and modification are
  105.      not covered by this License; they are outside its scope.  The act
  106.      of running the Program is not restricted, and the output from the
  107.      Program is covered only if its contents constitute a work based on
  108.      the Program (independent of having been made by running the
  109.      Program).  Whether that is true depends on what the Program does.
  110.  
  111.   2. You may copy and distribute verbatim copies of the Program's
  112.      source code as you receive it, in any medium, provided that you
  113.      conspicuously and appropriately publish on each copy an appropriate
  114.      copyright notice and disclaimer of warranty; keep intact all the
  115.      notices that refer to this License and to the absence of any
  116.      warranty; and give any other recipients of the Program a copy of
  117.      this License along with the Program.
  118.  
  119.      You may charge a fee for the physical act of transferring a copy,
  120.      and you may at your option offer warranty protection in exchange
  121.      for a fee.
  122.  
  123.   3. You may modify your copy or copies of the Program or any portion
  124.      of it, thus forming a work based on the Program, and copy and
  125.      distribute such modifications or work under the terms of Section 1
  126.      above, provided that you also meet all of these conditions:
  127.  
  128.        a. You must cause the modified files to carry prominent notices
  129.           stating that you changed the files and the date of any change.
  130.  
  131.        b. You must cause any work that you distribute or publish, that
  132.           in whole or in part contains or is derived from the Program
  133.           or any part thereof, to be licensed as a whole at no charge
  134.           to all third parties under the terms of this License.
  135.  
  136.        c. If the modified program normally reads commands interactively
  137.           when run, you must cause it, when started running for such
  138.           interactive use in the most ordinary way, to print or display
  139.           an announcement including an appropriate copyright notice and
  140.           a notice that there is no warranty (or else, saying that you
  141.           provide a warranty) and that users may redistribute the
  142.           program under these conditions, and telling the user how to
  143.           view a copy of this License.  (Exception: if the Program
  144.           itself is interactive but does not normally print such an
  145.           announcement, your work based on the Program is not required
  146.           to print an announcement.)
  147.  
  148.      These requirements apply to the modified work as a whole.  If
  149.      identifiable sections of that work are not derived from the
  150.      Program, and can be reasonably considered independent and separate
  151.      works in themselves, then this License, and its terms, do not
  152.      apply to those sections when you distribute them as separate
  153.      works.  But when you distribute the same sections as part of a
  154.      whole which is a work based on the Program, the distribution of
  155.      the whole must be on the terms of this License, whose permissions
  156.      for other licensees extend to the entire whole, and thus to each
  157.      and every part regardless of who wrote it.
  158.  
  159.      Thus, it is not the intent of this section to claim rights or
  160.      contest your rights to work written entirely by you; rather, the
  161.      intent is to exercise the right to control the distribution of
  162.      derivative or collective works based on the Program.
  163.  
  164.      In addition, mere aggregation of another work not based on the
  165.      Program with the Program (or with a work based on the Program) on
  166.      a volume of a storage or distribution medium does not bring the
  167.      other work under the scope of this License.
  168.  
  169.   4. You may copy and distribute the Program (or a work based on it,
  170.      under Section 2) in object code or executable form under the terms
  171.      of Sections 1 and 2 above provided that you also do one of the
  172.      following:
  173.  
  174.        a. Accompany it with the complete corresponding machine-readable
  175.           source code, which must be distributed under the terms of
  176.           Sections 1 and 2 above on a medium customarily used for
  177.           software interchange; or,
  178.  
  179.        b. Accompany it with a written offer, valid for at least three
  180.           years, to give any third party, for a charge no more than your
  181.           cost of physically performing source distribution, a complete
  182.           machine-readable copy of the corresponding source code, to be
  183.           distributed under the terms of Sections 1 and 2 above on a
  184.           medium customarily used for software interchange; or,
  185.  
  186.        c. Accompany it with the information you received as to the offer
  187.           to distribute corresponding source code.  (This alternative is
  188.           allowed only for noncommercial distribution and only if you
  189.           received the program in object code or executable form with
  190.           such an offer, in accord with Subsection b above.)
  191.  
  192.      The source code for a work means the preferred form of the work for
  193.      making modifications to it.  For an executable work, complete
  194.      source code means all the source code for all modules it contains,
  195.      plus any associated interface definition files, plus the scripts
  196.      used to control compilation and installation of the executable.
  197.      However, as a special exception, the source code distributed need
  198.      not include anything that is normally distributed (in either
  199.      source or binary form) with the major components (compiler,
  200.      kernel, and so on) of the operating system on which the executable
  201.      runs, unless that component itself accompanies the executable.
  202.  
  203.      If distribution of executable or object code is made by offering
  204.      access to copy from a designated place, then offering equivalent
  205.      access to copy the source code from the same place counts as
  206.      distribution of the source code, even though third parties are not
  207.      compelled to copy the source along with the object code.
  208.  
  209.   5. You may not copy, modify, sublicense, or distribute the Program
  210.      except as expressly provided under this License.  Any attempt
  211.      otherwise to copy, modify, sublicense or distribute the Program is
  212.      void, and will automatically terminate your rights under this
  213.      License.  However, parties who have received copies, or rights,
  214.      from you under this License will not have their licenses
  215.      terminated so long as such parties remain in full compliance.
  216.  
  217.   6. You are not required to accept this License, since you have not
  218.      signed it.  However, nothing else grants you permission to modify
  219.      or distribute the Program or its derivative works.  These actions
  220.      are prohibited by law if you do not accept this License.
  221.      Therefore, by modifying or distributing the Program (or any work
  222.      based on the Program), you indicate your acceptance of this
  223.      License to do so, and all its terms and conditions for copying,
  224.      distributing or modifying the Program or works based on it.
  225.  
  226.   7. Each time you redistribute the Program (or any work based on the
  227.      Program), the recipient automatically receives a license from the
  228.      original licensor to copy, distribute or modify the Program
  229.      subject to these terms and conditions.  You may not impose any
  230.      further restrictions on the recipients' exercise of the rights
  231.      granted herein.  You are not responsible for enforcing compliance
  232.      by third parties to this License.
  233.  
  234.   8. If, as a consequence of a court judgment or allegation of patent
  235.      infringement or for any other reason (not limited to patent
  236.      issues), conditions are imposed on you (whether by court order,
  237.      agreement or otherwise) that contradict the conditions of this
  238.      License, they do not excuse you from the conditions of this
  239.      License.  If you cannot distribute so as to satisfy simultaneously
  240.      your obligations under this License and any other pertinent
  241.      obligations, then as a consequence you may not distribute the
  242.      Program at all.  For example, if a patent license would not permit
  243.      royalty-free redistribution of the Program by all those who
  244.      receive copies directly or indirectly through you, then the only
  245.      way you could satisfy both it and this License would be to refrain
  246.      entirely from distribution of the Program.
  247.  
  248.      If any portion of this section is held invalid or unenforceable
  249.      under any particular circumstance, the balance of the section is
  250.      intended to apply and the section as a whole is intended to apply
  251.      in other circumstances.
  252.  
  253.      It is not the purpose of this section to induce you to infringe any
  254.      patents or other property right claims or to contest validity of
  255.      any such claims; this section has the sole purpose of protecting
  256.      the integrity of the free software distribution system, which is
  257.      implemented by public license practices.  Many people have made
  258.      generous contributions to the wide range of software distributed
  259.      through that system in reliance on consistent application of that
  260.      system; it is up to the author/donor to decide if he or she is
  261.      willing to distribute software through any other system and a
  262.      licensee cannot impose that choice.
  263.  
  264.      This section is intended to make thoroughly clear what is believed
  265.      to be a consequence of the rest of this License.
  266.  
  267.   9. If the distribution and/or use of the Program is restricted in
  268.      certain countries either by patents or by copyrighted interfaces,
  269.      the original copyright holder who places the Program under this
  270.      License may add an explicit geographical distribution limitation
  271.      excluding those countries, so that distribution is permitted only
  272.      in or among countries not thus excluded.  In such case, this
  273.      License incorporates the limitation as if written in the body of
  274.      this License.
  275.  
  276.  10. The Free Software Foundation may publish revised and/or new
  277.      versions of the General Public License from time to time.  Such
  278.      new versions will be similar in spirit to the present version, but
  279.      may differ in detail to address new problems or concerns.
  280.  
  281.      Each version is given a distinguishing version number.  If the
  282.      Program specifies a version number of this License which applies
  283.      to it and "any later version", you have the option of following
  284.      the terms and conditions either of that version or of any later
  285.      version published by the Free Software Foundation.  If the Program
  286.      does not specify a version number of this License, you may choose
  287.      any version ever published by the Free Software Foundation.
  288.  
  289.  11. If you wish to incorporate parts of the Program into other free
  290.      programs whose distribution conditions are different, write to the
  291.      author to ask for permission.  For software which is copyrighted
  292.      by the Free Software Foundation, write to the Free Software
  293.      Foundation; we sometimes make exceptions for this.  Our decision
  294.      will be guided by the two goals of preserving the free status of
  295.      all derivatives of our free software and of promoting the sharing
  296.      and reuse of software generally.
  297.  
  298.                                 NO WARRANTY
  299.  
  300.  12. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO
  301.      WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE
  302.      LAW.  EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
  303.      HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT
  304.      WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT
  305.      NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  306.      FITNESS FOR A PARTICULAR PURPOSE.  THE ENTIRE RISK AS TO THE
  307.      QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU.  SHOULD THE
  308.      PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY
  309.      SERVICING, REPAIR OR CORRECTION.
  310.  
  311.  13. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN
  312.      WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY
  313.      MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE
  314.      LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL,
  315.      INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR
  316.      INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
  317.      DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU
  318.      OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY
  319.      OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN
  320.      ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
  321.  
  322.                       END OF TERMS AND CONDITIONS
  323.  
  324. How to Apply These Terms to Your New Programs
  325. =============================================
  326.  
  327.    If you develop a new program, and you want it to be of the greatest
  328. possible use to the public, the best way to achieve this is to make it
  329. free software which everyone can redistribute and change under these
  330. terms.
  331.  
  332.    To do so, attach the following notices to the program.  It is safest
  333. to attach them to the start of each source file to most effectively
  334. convey the exclusion of warranty; and each file should have at least
  335. the "copyright" line and a pointer to where the full notice is found.
  336.  
  337.      ONE LINE TO GIVE THE PROGRAM'S NAME AND AN IDEA OF WHAT IT DOES.
  338.      Copyright (C) 19YY  NAME OF AUTHOR
  339.      
  340.      This program is free software; you can redistribute it and/or
  341.      modify it under the terms of the GNU General Public License
  342.      as published by the Free Software Foundation; either version 2
  343.      of the License, or (at your option) any later version.
  344.      
  345.      This program is distributed in the hope that it will be useful,
  346.      but WITHOUT ANY WARRANTY; without even the implied warranty of
  347.      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  348.      GNU General Public License for more details.
  349.      
  350.      You should have received a copy of the GNU General Public License
  351.      along with this program; if not, write to the Free Software
  352.      Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  353.  
  354.    Also add information on how to contact you by electronic and paper
  355. mail.
  356.  
  357.    If the program is interactive, make it output a short notice like
  358. this when it starts in an interactive mode:
  359.  
  360.      Gnomovision version 69, Copyright (C) 19YY NAME OF AUTHOR
  361.      Gnomovision comes with ABSOLUTELY NO WARRANTY; for details
  362.      type `show w'.  This is free software, and you are welcome
  363.      to redistribute it under certain conditions; type `show c'
  364.      for details.
  365.  
  366.    The hypothetical commands `show w' and `show c' should show the
  367. appropriate parts of the General Public License.  Of course, the
  368. commands you use may be called something other than `show w' and `show
  369. c'; they could even be mouse-clicks or menu items--whatever suits your
  370. program.
  371.  
  372.    You should also get your employer (if you work as a programmer) or
  373. your school, if any, to sign a "copyright disclaimer" for the program,
  374. if necessary.  Here is a sample; alter the names:
  375.  
  376.      Yoyodyne, Inc., hereby disclaims all copyright
  377.      interest in the program `Gnomovision'
  378.      (which makes passes at compilers) written
  379.      by James Hacker.
  380.      
  381.      SIGNATURE OF TY COON, 1 April 1989
  382.      Ty Coon, President of Vice
  383.  
  384.    This General Public License does not permit incorporating your
  385. program into proprietary programs.  If your program is a subroutine
  386. library, you may consider it more useful to permit linking proprietary
  387. applications with the library.  If this is what you want to do, use the
  388. GNU Library General Public License instead of this License.
  389.  
  390. 
  391. File: elisp,  Node: Introduction,  Next: Types of Lisp Object,  Prev: Copying,  Up: Top
  392.  
  393. Introduction
  394. ************
  395.  
  396.    Most of the GNU Emacs text editor is written in the programming
  397. language called Emacs Lisp.  You can write new code in Emacs Lisp and
  398. install it as an extension to the editor.  However, Emacs Lisp is more
  399. than a mere "extension language"; it is a full computer programming
  400. language in its own right.  You can use it as you would any other
  401. programming language.
  402.  
  403.    Because Emacs Lisp is designed for use in an editor, it has special
  404. features for scanning and parsing text as well as features for handling
  405. files, buffers, displays, subprocesses, and so on.  Emacs Lisp is
  406. closely integrated with the editing facilities; thus, editing commands
  407. are functions that can also conveniently be called from Lisp programs,
  408. and parameters for customization are ordinary Lisp variables.
  409.  
  410.    This manual describes Emacs Lisp, presuming considerable familiarity
  411. with the use of Emacs for editing.  (See `The GNU Emacs Manual', for
  412. this basic information.)  Generally speaking, the earlier chapters
  413. describe features of Emacs Lisp that have counterparts in many
  414. programming languages, and later chapters describe features that are
  415. peculiar to Emacs Lisp or relate specifically to editing.
  416.  
  417.    This is edition 2.0.
  418.  
  419. * Menu:
  420.  
  421. * Caveats::             Flaws and a request for help.
  422. * Lisp History::        Emacs Lisp is descended from Maclisp.
  423. * Conventions::         How the manual is formatted.
  424. * Acknowledgements::    The authors, editors, and sponsors of this manual.
  425.  
  426. 
  427. File: elisp,  Node: Caveats,  Next: Lisp History,  Prev: Introduction,  Up: Introduction
  428.  
  429. Caveats
  430. =======
  431.  
  432.    This manual has gone through numerous drafts.  It is nearly complete
  433. but not flawless.  There are a few sections which are not included,
  434. either because we consider them secondary (such as most of the
  435. individual modes) or because they are yet to be written.
  436.  
  437.    Because we are not able to deal with them completely, we have left
  438. out several parts intentionally.  This includes most references to VMS
  439. and all information relating Sunview.  (The Free Software Foundation
  440. expends no effort on support for Sunview, since we believe users should
  441. use the free X window system rather than proprietary window systems.)
  442.  
  443.    The manual should be fully correct in what it does cover, and it is
  444. therefore open to criticism on anything it says--from specific examples
  445. and descriptive text, to the ordering of chapters and sections.  If
  446. something is confusing, or you find that you have to look at the sources
  447. or experiment to learn something not covered in the manual, then perhaps
  448. the manual should be fixed.  Please let us know.
  449.  
  450.    As you use this manual, we ask that you send corrections as soon as
  451. you find them.  If you think of a simple, real life example for a
  452. function or group of functions, please make an effort to write it up
  453. and send it in.  Please reference any comments to the node name and
  454. function or variable name, as appropriate.  Also state the number of
  455. the edition which you are criticizing.
  456.  
  457.    Please mail comments and corrections to
  458.      bug-lisp-manual@prep.ai.mit.edu
  459.  
  460.       --Bil Lewis, Dan LaLiberte, Richard Stallman
  461.  
  462. 
  463. File: elisp,  Node: Lisp History,  Next: Conventions,  Prev: Caveats,  Up: Introduction
  464.  
  465. Lisp History
  466. ============
  467.  
  468.    Lisp (LISt Processing language) was first developed in the late 1950s
  469. at the Massachusetts Institute of Technology for research in artificial
  470. intelligence.  The great power of the Lisp language makes it superior
  471. for other purposes as well, such as writing editing commands.
  472.  
  473.    Dozens of Lisp implementations have been built over the years, each
  474. with its own idiosyncrasies.  Many of them were inspired by Maclisp,
  475. which was written in the 1960's at MIT's Project MAC.  Eventually the
  476. implementors of the descendents of Maclisp came together and developed a
  477. standard for Lisp systems, called Common Lisp.
  478.  
  479.    GNU Emacs Lisp is largely inspired by Maclisp, and a little by Common
  480. Lisp.  If you know Common Lisp, you will notice many similarities.
  481. However, many of the features of Common Lisp have been omitted or
  482. simplified in order to reduce the memory requirements of GNU Emacs.
  483. Sometimes the simplifications are so drastic that a Common Lisp user
  484. might be very confused.  We will occasionally point out how GNU Emacs
  485. Lisp differs from Common Lisp.  If you don't know Common Lisp, don't
  486. worry about it; this manual is self-contained.
  487.  
  488. 
  489. File: elisp,  Node: Conventions,  Next: Acknowledgements,  Prev: Lisp History,  Up: Introduction
  490.  
  491. Conventions
  492. ===========
  493.  
  494.    This section explains the notational conventions that are used in
  495. this manual.  You may want to skip this section and refer back to it
  496. later.
  497.  
  498. * Menu:
  499.  
  500. * Some Terms::               Explanation of terms we use in this manual.
  501. * nil and t::                How the symbols `nil' and `t' are used.
  502. * Evaluation Notation::      The format we use for examples of evaluation.
  503. * Printing Notation::        The format we use for examples that print output.
  504. * Error Messages::           The format we use for examples of errors.
  505. * Buffer Text Notation::     The format we use for buffer contents in examples.
  506. * Format of Descriptions::   Notation for describing functions, variables, etc.
  507.  
  508. 
  509. File: elisp,  Node: Some Terms,  Next: nil and t,  Prev: Conventions,  Up: Conventions
  510.  
  511. Some Terms
  512. ----------
  513.  
  514.    Throughout this manual, the phrases "the Lisp reader" and "the Lisp
  515. printer" are used to refer to those routines in Lisp that convert
  516. textual representations of Lisp objects into actual objects, and vice
  517. versa.  *Note Printed Representation::, for more details.  You, the
  518. person reading this manual, are thought of as "the programmer" and are
  519. addressed as "you".  "The user" is the person who uses Lisp programs
  520. including those you write.
  521.  
  522.    Examples of Lisp code appear in this font or form: `(list 1 2 3)'.
  523. Names that represent arguments or metasyntactic variables appear in
  524. this font or form: FIRST-NUMBER.
  525.  
  526. 
  527. File: elisp,  Node: nil and t,  Next: Evaluation Notation,  Prev: Some Terms,  Up: Conventions
  528.  
  529. `nil' and `t'
  530. -------------
  531.  
  532.    In Lisp, the symbol `nil' is overloaded with three meanings: it is a
  533. symbol with the name `nil'; it is the logical truth value FALSE; and it
  534. is the empty list--the list of zero elements.  When used as a variable,
  535. `nil' always has the value `nil'.
  536.  
  537.    As far as the Lisp reader is concerned, `()' and `nil' are
  538. identical: they stand for the same object, the symbol `nil'.  The
  539. different ways of writing the symbol are intended entirely for human
  540. readers.  After the Lisp reader has read either `()' or `nil', there is
  541. no way to determine which representation was actually written by the
  542. programmer.
  543.  
  544.    In this manual, we use `()' when we wish to emphasize that it means
  545. the empty list, and we use `nil' when we wish to emphasize that it
  546. means the truth value FALSE.  That is a good convention to use in Lisp
  547. programs also.
  548.  
  549.      (cons 'foo ())                ; Emphasize the empty list
  550.      (not nil)                     ; Emphasize the truth value FALSE
  551.  
  552.    In contexts where a truth value is expected, any non-`nil' value is
  553. considered to be TRUE.  However, `t' is the preferred way to represent
  554. the truth value TRUE.  When you need to choose a value which represents
  555. TRUE, and there is no other basis for choosing, use `t'.  The symbol
  556. `t' always has value `t'.
  557.  
  558.    In Emacs Lisp, `nil' and `t' are special symbols that always
  559. evaluate to themselves.  This is so that you do not need to quote them
  560. to use them as constants in a program.  An attempt to change their
  561. values results in a `setting-constant' error.  *Note Accessing
  562. Variables::.
  563.  
  564. 
  565. File: elisp,  Node: Evaluation Notation,  Next: Printing Notation,  Prev: nil and t,  Up: Conventions
  566.  
  567. Evaluation Notation
  568. -------------------
  569.  
  570.    A Lisp expression that you can evaluate is called a "form".
  571. Evaluating a form always produces a result, which is a Lisp object.  In
  572. the examples in this manual, this is indicated with `=>':
  573.  
  574.      (car '(1 2))
  575.           => 1
  576.  
  577. You can read this as "`(car '(1 2))' evaluates to 1".
  578.  
  579.    When a form is a macro call, it expands into a new form for Lisp to
  580. evaluate.  We show the result of the expansion with `==>'.  We may or
  581. may not show the actual result of the evaluation of the expanded form.
  582.  
  583.      (third '(a b c))
  584.           ==> (car (cdr (cdr '(a b c))))
  585.           => c
  586.  
  587.    Sometimes to help describe one form we show another form which
  588. produces identical results.  The exact equivalence of two forms is
  589. indicated with `=='.
  590.  
  591.      (make-sparse-keymap) == (list 'keymap)
  592.  
  593. 
  594. File: elisp,  Node: Printing Notation,  Next: Error Messages,  Prev: Evaluation Notation,  Up: Conventions
  595.  
  596. Printing Notation
  597. -----------------
  598.  
  599.    Many of the examples in this manual print text when they are
  600. evaluated.  If you execute the code from an example in a Lisp
  601. Interaction buffer (such as the buffer `*scratch*'), the printed text
  602. is inserted into the buffer.  If the example is executed by other means
  603. (such as by evaluating the function `eval-region'), the text printed is
  604. usually displayed in the echo area.  You should be aware that text
  605. displayed in the echo area is truncated to a single line.
  606.  
  607.    In examples that print text, the printed text is indicated with
  608. `-|', irrespective of how the form is executed.  The value returned by
  609. evaluating the form (here `bar') follows on a separate line.
  610.  
  611.      (progn (print 'foo) (print 'bar))
  612.           -| foo
  613.           -| bar
  614.           => bar
  615.  
  616. 
  617. File: elisp,  Node: Error Messages,  Next: Buffer Text Notation,  Prev: Printing Notation,  Up: Conventions
  618.  
  619. Error Messages
  620. --------------
  621.  
  622.    Some examples cause errors to be signaled.  In them, the error
  623. message (which always appears in the echo area) is shown on a line
  624. starting with `error-->'.  Note that `error-->' itself does not appear
  625. in the echo area.
  626.  
  627.      (+ 23 'x)
  628.      error--> Wrong type argument: integer-or-marker-p, x
  629.  
  630. 
  631. File: elisp,  Node: Buffer Text Notation,  Next: Format of Descriptions,  Prev: Error Messages,  Up: Conventions
  632.  
  633. Buffer Text Notation
  634. --------------------
  635.  
  636.    Some examples show modifications to text in a buffer, with "before"
  637. and "after" versions of the text.  In such cases, the entire contents
  638. of the buffer in question are included between two lines of dashes
  639. containing the buffer name.  In addition, the location of point is shown
  640. as `-!-'.  (The symbol for point, of course, is not part of the text in
  641. the buffer; it indicates the place *between* two characters where point
  642. is located.)
  643.  
  644.      ---------- Buffer: foo ----------
  645.      This is the -!-contents of foo.
  646.      ---------- Buffer: foo ----------
  647.      
  648.      (insert "changed ")
  649.           => nil
  650.      ---------- Buffer: foo ----------
  651.      This is the changed -!-contents of foo.
  652.      ---------- Buffer: foo ----------
  653.  
  654. 
  655. File: elisp,  Node: Format of Descriptions,  Prev: Buffer Text Notation,  Up: Conventions
  656.  
  657. Format of Descriptions
  658. ----------------------
  659.  
  660.    Functions, variables, macros, commands, user options, and special
  661. forms are described in this manual in a uniform format.  The first line
  662. of a description contains the name of the item followed by its
  663. arguments, if any.  The category--function, variable, or
  664. whatever--appears at the beginning of the line.  The description
  665. follows on succeeding lines, sometimes with examples.
  666.  
  667. * Menu:
  668.  
  669. * A Sample Function Description::
  670. * A Sample Variable Description::
  671.  
  672. 
  673. File: elisp,  Node: A Sample Function Description,  Next: A Sample Variable Description,  Prev: Format of Descriptions,  Up: Format of Descriptions
  674.  
  675. A Sample Function Description
  676. .............................
  677.  
  678.    In a function description, the name of the function being described
  679. appears first.  It is followed on the same line by a list of parameters.
  680. The names used for the parameters are also used in the body of the
  681. description.
  682.  
  683.    The appearance of the keyword `&optional' in the parameter list
  684. indicates that the arguments for subsequent parameters may be omitted
  685. (omitted parameters default to `nil').  Do not write `&optional' when
  686. you call the function.
  687.  
  688.    The keyword `&rest' (which will always be followed by a single
  689. parameter) indicates that any number of arguments can follow.  The value
  690. of the single following parameter will be a list of all these arguments.
  691. Do not write `&rest' when you call the function.
  692.  
  693.    Here is a description of an imaginary function `foo':
  694.  
  695.  - Function: foo INTEGER1 &optional INTEGER2 &rest INTEGERS
  696.      The function `foo' subtracts INTEGER1 from INTEGER2, then adds all
  697.      the rest of the arguments to the result.  If INTEGER2 is not
  698.      supplied, then the number 19 is used by default.
  699.  
  700.           (foo 1 5 3 9)
  701.                => 16
  702.           (foo 5)
  703.                => 14
  704.  
  705.      More generally,
  706.  
  707.           (foo W X Y...)
  708.           ==
  709.           (+ (- X W) Y...)
  710.  
  711.    Any parameter whose name contains the name of a type (e.g., INTEGER,
  712. INTEGER1 or BUFFER) is expected to be of that type.  A plural of a type
  713. (such as BUFFERS) often means a list of objects of that type.
  714. Parameters named OBJECT may be of any type.  (*Note Types of Lisp
  715. Object::, for a list of Emacs object types.) Parameters with other
  716. sorts of names (e.g., NEW-FILE) are discussed specifically in the
  717. description of the function.  In some sections, features common to
  718. parameters of several functions are described at the beginning.
  719.  
  720.    *Note Lambda Expressions::, for a more complete description of
  721. optional and rest arguments.
  722.  
  723.    Command, macro, and special form descriptions have the same format,
  724. but the word `Function' is replaced by `Command', `Macro', or `Special
  725. Form', respectively.  Commands are simply functions that may be called
  726. interactively; macros process their arguments differently from functions
  727. (the arguments are not evaluated), but are presented the same way.
  728.  
  729.    Special form descriptions use a more complex notation to specify
  730. optional and repeated parameters because they can break the argument
  731. list down into separate arguments in more complicated ways.
  732. ``[oPTIONAL-ARG]'' means that OPTIONAL-ARG is optional and
  733. `REPEATED-ARGS...' stands for zero or more arguments.  Parentheses are
  734. used when several arguments are grouped into additional levels of list
  735. structure.  Here is an example:
  736.  
  737.  - Special Form: count-loop (VAR [FROM TO [INC]]) BODY...
  738.      This imaginary special form implements a loop that executes the
  739.      BODY forms and then increments the variable VAR on each iteration.
  740.      On the first iteration, the variable has the value FROM; on
  741.      subsequent iterations, it is incremented by 1 (or by INC if that
  742.      is given).  The loop exits before executing BODY if VAR equals TO.
  743.      Here is an example:
  744.  
  745.           (count-loop (i 0 10)
  746.             (prin1 i) (princ " ")
  747.             (prin1 (aref vector i)) (terpri))
  748.  
  749.      If FROM and TO are omitted, then VAR is bound to `nil' before the
  750.      loop begins, and the loop exits if VAR is non-`nil' at the
  751.      beginning of an iteration.  Here is an example:
  752.  
  753.           (count-loop (done)
  754.             (if (pending)
  755.                 (fixit)
  756.               (setq done t)))
  757.  
  758.      In this special form, the arguments FROM and TO are optional, but
  759.      must both be present or both absent.  If they are present, INC may
  760.      optionally be specified as well.  These arguments are grouped with
  761.      the argument VAR into a list, to distinguish them from BODY, which
  762.      includes all remaining elements of the form.
  763.  
  764. 
  765. File: elisp,  Node: A Sample Variable Description,  Prev: A Sample Function Description,  Up: Format of Descriptions
  766.  
  767. A Sample Variable Description
  768. .............................
  769.  
  770.    A "variable" is a name that can hold a value.  Although any variable
  771. can be set by the user, certain variables that exist specifically so
  772. that users can change them are called "user options".  Ordinary
  773. variables and user options are described using a format like that for
  774. functions except that there are no arguments.
  775.  
  776.    Here is a description of the imaginary `electric-future-map'
  777. variable.
  778.  
  779.  - Variable: electric-future-map
  780.      The value of this variable is a full keymap used by electric
  781.      command future mode.  The functions in this map will allow you to
  782.      edit commands you have not yet thought about executing.
  783.  
  784.    User option descriptions have the same format, but `Variable' is
  785. replaced by `User Option'.
  786.  
  787. 
  788. File: elisp,  Node: Acknowledgements,  Prev: Conventions,  Up: Introduction
  789.  
  790. Acknowledgements
  791. ================
  792.  
  793.    This manual was written by Robert Krawitz, Bil Lewis, Dan LaLiberte,
  794. Richard M. Stallman and Chris Welty, the volunteers of the GNU manual
  795. group, in an effort extending over several years.  Robert J. Chassell
  796. helped to review and edit the manual, with the support of the Defense
  797. Advanced Research Projects Agency, ARPA Order 6082, arranged by Warren
  798. A. Hunt, Jr. of Computational Logic, Inc.
  799.  
  800.    Corrections were supplied by Karl Berry, Jim Blandy, Bard Bloom,
  801. David Boyes, Alan Carroll, David A. Duff, Beverly Erlebacher, David
  802. Eckelkamp, Eirik Fuller, Eric Hanchrow, George Hartzell, Nathan Hess,
  803. Dan Jacobson, Jak Kirman, Bob Knighten, Frederick M. Korz, Joe Lammens,
  804. K. Richard Magill, Brian Marick, Roland McGrath, Skip Montanaro, John
  805. Gardiner Myers, Arnold D. Robbins, Raul Rockwell, Shinichirou Sugou,
  806. Kimmo Suominen, Edward Tharp, Bill Trost, Jean White, Matthew Wilding,
  807. Carl Witty, Dale Worley, Rusty Wright, and David D. Zuhn.
  808.  
  809. 
  810. File: elisp,  Node: Types of Lisp Object,  Next: Numbers,  Prev: Introduction,  Up: Top
  811.  
  812. Lisp Data Types
  813. ***************
  814.  
  815.    A Lisp "object" is a piece of data used and manipulated by Lisp
  816. programs.  For our purposes, a "type" or "data type" is a set of
  817. possible objects.
  818.  
  819.    Every object belongs to at least one type.  Objects of the same type
  820. have similar structures and may usually be used in the same contexts.
  821. Types can overlap, and objects can belong to two or more types.
  822. Consequently, we can ask whether an object belongs to a particular type,
  823. but not for "the" type of an object.
  824.  
  825.    A few fundamental object types are built into Emacs.  These, from
  826. which all other types are constructed, are called "primitive types".
  827. Each object belongs to one and only one primitive type.  These types
  828. include "integer", "float", "cons", "symbol", "string", "vector",
  829. "subr", "byte-code function", and several special types, such as
  830. "buffer", that are related to editing.  (*Note Editing Types::.)
  831.  
  832.    Each primitive type has a corresponding Lisp function that checks
  833. whether an object is a member of that type.
  834.  
  835.    Note that Lisp is unlike many other languages in that Lisp objects
  836. are "self-typing": the primitive type of the object is implicit in the
  837. object itself.  For example, if an object is a vector, it cannot be
  838. treated as a number because Lisp knows it is a vector, not a number.
  839.  
  840.    In most languages, the programmer must declare the data type of each
  841. variable, and the type is known by the compiler but not represented in
  842. the data.  Such type declarations do not exist in Emacs Lisp.  A Lisp
  843. variable can have any type of value, and remembers the type of any value
  844. you store in it.
  845.  
  846.    This chapter describes the purpose, printed representation, and read
  847. syntax of each of the standard types in GNU Emacs Lisp.  Details on how
  848. to use these types can be found in later chapters.
  849.  
  850. * Menu:
  851.  
  852. * Printed Representation::      How Lisp objects are represented as text.
  853. * Comments::                    Comments and their formatting conventions.
  854. * Programming Types::           Types found in all Lisp systems.
  855. * Editing Types::               Types specific to Emacs.
  856. * Type Predicates::             Tests related to types.
  857. * Equality Predicates::         Tests of equality between any two objects.
  858.  
  859. 
  860. File: elisp,  Node: Printed Representation,  Next: Comments,  Up: Types of Lisp Object
  861.  
  862. Printed Representation and Read Syntax
  863. ======================================
  864.  
  865.    The "printed representation" of an object is the format of the
  866. output generated by the Lisp printer (the function `print') for that
  867. object.  The "read syntax" of an object is the format of the input
  868. accepted by the Lisp reader (the function `read') for that object.
  869. Most objects have more than one possible read syntax.  Some types of
  870. object have no read syntax; except for these cases, the printed
  871. representation of an object is also a read syntax for it.
  872.  
  873.    In other languages, an expression is text; it has no other form.  In
  874. Lisp, an expression is primarily a Lisp object and only secondarily the
  875. text that is the object's read syntax.  Often there is no need to
  876. emphasize this distinction, but you must keep it in the back of your
  877. mind, or you will occasionally be very confused.
  878.  
  879.    Every type has a printed representation.  Some types have no read
  880. syntax, since it may not make sense to enter objects of these types
  881. directly in a Lisp program.  For example, the buffer type does not have
  882. a read syntax.  Objects of these types are printed in "hash notation":
  883. the characters `#<' followed by a descriptive string (typically the
  884. type name followed by the name of the object), and closed with a
  885. matching `>'.  Hash notation cannot be read at all, so the Lisp reader
  886. signals the error `invalid-read-syntax' whenever a `#<' is encountered.
  887.  
  888.      (current-buffer)
  889.           => #<buffer objects.texi>
  890.  
  891.    When you evaluate an expression interactively, the Lisp interpreter
  892. first reads the textual representation of it, producing a Lisp object,
  893. and then evaluates that object (*note Evaluation::.).  However,
  894. evaluation and reading are separate activities.  Reading returns the
  895. Lisp object represented by the text that is read; the object may or may
  896. not be evaluated later.  *Note Input Functions::, for a description of
  897. `read', the basic function for reading objects.
  898.  
  899. 
  900. File: elisp,  Node: Comments,  Next: Programming Types,  Prev: Printed Representation,  Up: Types of Lisp Object
  901.  
  902. Comments
  903. ========
  904.  
  905.    A "comment" is text that is written in a program only for the sake
  906. of humans that read the program, and that has no effect on the meaning
  907. of the program.  In Lisp, a comment starts with a semicolon (`;') if it
  908. is not within a string or character constant, and continues to the end
  909. of line.  Comments are discarded by the Lisp reader, and do not become
  910. part of the Lisp objects which represent the program within the Lisp
  911. system.
  912.  
  913.    *Note Comment Tips::, for conventions for formatting comments.
  914.  
  915. 
  916. File: elisp,  Node: Programming Types,  Next: Editing Types,  Prev: Comments,  Up: Types of Lisp Object
  917.  
  918. Programming Types
  919. =================
  920.  
  921.    There are two general categories of types in Emacs Lisp: those having
  922. to do with Lisp programming, and those having to do with editing.  The
  923. former are provided in many Lisp implementations, in one form or
  924. another.  The latter are unique to Emacs Lisp.
  925.  
  926. * Menu:
  927.  
  928. * Integer Type::        Numbers without fractional parts.
  929. * Floating Point Type:: Numbers with fractional parts and with a large range.
  930. * Character Type::      The representation of letters, numbers and
  931.                         control characters.
  932. * Sequence Type::       Both lists and arrays are classified as sequences.
  933. * List Type::           Lists gave Lisp its name (not to mention reputation).
  934. * Array Type::          Arrays include strings and vectors.
  935. * String Type::         An (efficient) array of characters.
  936. * Vector Type::         One-dimensional arrays.
  937. * Symbol Type::         A multi-use object that refers to a function,
  938.                         variable, property list, or itself.
  939. * Lisp Function Type::  A piece of executable code you can call from elsewhere.
  940. * Lisp Macro Type::     A method of expanding an expression into another
  941.                           expression, more fundamental but less pretty.
  942. * Primitive Function Type::     A function written in C, callable from Lisp.
  943. * Byte-Code Type::      A function written in Lisp, then compiled.
  944. * Autoload Type::       A type used for automatically loading seldom-used
  945.                         functions.
  946.  
  947. 
  948. File: elisp,  Node: Integer Type,  Next: Floating Point Type,  Up: Programming Types
  949.  
  950. Integer Type
  951. ------------
  952.  
  953.    Integers are the only kind of number in GNU Emacs Lisp, version 18.
  954. The range of values for integers is -8388608 to 8388607 (24 bits; i.e.,
  955. -2**23 to 2**23 - 1) on most machines, but is 25 or 26 bits on some
  956. systems.  It is important to note that the Emacs Lisp arithmetic
  957. functions do not check for overflow.  Thus `(1+ 8388607)' is -8388608
  958. on 24-bit implementations.
  959.  
  960.    The read syntax for numbers is a sequence of (base ten) digits with
  961. an optional sign.  The printed representation produced by the Lisp
  962. interpreter never has a leading `+'.
  963.  
  964.      -1               ; The integer -1.
  965.      1                ; The integer 1.
  966.      +1               ; Also the integer 1.
  967.      16777217         ; Also the integer 1!
  968.                       ;   (on a 24-bit or 25-bit implementation)
  969.  
  970.    *Note Numbers::, for more information.
  971.  
  972. 
  973. File: elisp,  Node: Floating Point Type,  Next: Character Type,  Prev: Integer Type,  Up: Programming Types
  974.  
  975. Floating Point Type
  976. -------------------
  977.  
  978.    Emacs version 19 supports floating point numbers, if compiled with
  979. the macro `LISP_FLOAT_TYPE' defined.  The precise range of floating
  980. point numbers is machine-specific.
  981.  
  982.    The printed representation for floating point numbers requires either
  983. a decimal point (with at least one digit following), an exponent, or
  984. both.  For example, `1500.0', `15e2', `15.0e2', `1.5e3', and `.15e4'
  985. are five ways of writing a floating point number whose value is 1500.
  986. They are all equivalent.
  987.  
  988.    *Note Numbers::, for more information.
  989.  
  990.