home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Professional / OS2PRO194.ISO / os2 / prgramer / unix / info / elisp.i02 (.txt) < prev    next >
GNU Info File  |  1993-06-14  |  52KB  |  901 lines

  1. This is Info file elisp, produced by Makeinfo-1.47 from the input file
  2. elisp.texi.
  3.    This file documents GNU Emacs Lisp.
  4.    This is edition 1.03 of the GNU Emacs Lisp Reference Manual, for
  5. Emacs Version 18.
  6.    Published by the Free Software Foundation, 675 Massachusetts Avenue,
  7. Cambridge, MA 02139 USA
  8.    Copyright (C) 1990 Free Software Foundation, Inc.
  9.    Permission is granted to make and distribute verbatim copies of this
  10. manual provided the copyright notice and this permission notice are
  11. preserved on all copies.
  12.    Permission is granted to copy and distribute modified versions of
  13. this manual under the conditions for verbatim copying, provided that
  14. the entire resulting derived work is distributed under the terms of a
  15. permission notice identical to this one.
  16.    Permission is granted to copy and distribute translations of this
  17. manual into another language, under the above conditions for modified
  18. versions, except that this permission notice may be stated in a
  19. translation approved by the Foundation.
  20. File: elisp,  Node: Printing Notation,  Next: Error Messages,  Prev: Evaluation Notation,  Up: Conventions
  21. Printing Notation
  22. -----------------
  23.    Many of the examples in this manual print text when they are
  24. evaluated.  If you execute the code from an example in a Lisp
  25. Interaction buffer (such as the buffer `*scratch*'), the printed text
  26. is inserted into the buffer.  If the example is executed by other means
  27. (such as by evaluating the function `eval-region'), the text printed is
  28. usually displayed in the echo area.  You should be aware that text
  29. displayed in the echo area is truncated to a single line.
  30.    In examples that print text, the printed text is indicated with
  31. `-|', irrespective of how the form is executed.  The value returned by
  32. evaluating the form (here `bar') follows on a separate line.
  33.      (progn (print 'foo) (print 'bar))
  34.           -| foo
  35.           -| bar
  36.           => bar
  37. File: elisp,  Node: Error Messages,  Next: Buffer Text Notation,  Prev: Printing Notation,  Up: Conventions
  38. Error Messages
  39. --------------
  40.    Some examples cause errors to be signaled.  In them, the error
  41. message (which always appears in the echo area) is shown on a line
  42. starting with `error-->'.  Note that `error-->' itself does not appear
  43. in the echo area.
  44.      (+ 23 'x)
  45.      error--> Wrong type argument: integer-or-marker-p, x
  46. File: elisp,  Node: Buffer Text Notation,  Next: Format of Descriptions,  Prev: Error Messages,  Up: Conventions
  47. Buffer Text Notation
  48. --------------------
  49.    Some examples show modifications to text in a buffer, with "before"
  50. and "after" versions of the text.  In such cases, the entire contents
  51. of the buffer in question are included between two lines of dashes
  52. containing the buffer name.  In addition, the location of point is shown
  53. as `-!-'.  (The symbol for point, of course, is not part of the text in
  54. the buffer; it indicates the place *between* two characters where point
  55. is located.)
  56.      ---------- Buffer: foo ----------
  57.      This is the -!-contents of foo.
  58.      ---------- Buffer: foo ----------
  59.      
  60.      (insert "changed ")
  61.           => nil
  62.      ---------- Buffer: foo ----------
  63.      This is the changed -!-contents of foo.
  64.      ---------- Buffer: foo ----------
  65. File: elisp,  Node: Format of Descriptions,  Prev: Buffer Text Notation,  Up: Conventions
  66. Format of Descriptions
  67. ----------------------
  68.    Functions, variables, macros, commands, user options, and special
  69. forms are described in this manual in a uniform format.  The first line
  70. of a description contains the name of the item followed by its
  71. arguments, if any. The category--function, variable, or
  72. whatever--appears at the beginning of the line. The description follows
  73. on succeeding lines, sometimes with examples.
  74. * Menu:
  75. * A Sample Function Description::
  76. * A Sample Variable Description::
  77. File: elisp,  Node: A Sample Function Description,  Next: A Sample Variable Description,  Prev: Format of Descriptions,  Up: Format of Descriptions
  78. A Sample Function Description
  79. .............................
  80.    In a function description, the name of the function being described
  81. appears first.  It is followed on the same line by a list of parameters.
  82. The names used for the parameters are also used in the body of the
  83. description.
  84.    The appearance of the keyword `&optional' in the parameter list
  85. indicates that the arguments for subsequent parameters may be omitted
  86. (omitted parameters default to `nil').  Do not write `&optional' when
  87. you call the function.
  88.    The keyword `&rest' (which will always be followed by a single
  89. parameter) indicates that any number of arguments can follow.  The value
  90. of the single following parameter will be a list of all these arguments.
  91. Do not write `&rest' when you call the function.
  92.    Here is a description of an imaginary function `foo':
  93.  -- Function: foo INTEGER1 &optional INTEGER2 &rest INTEGERS
  94.      The function `foo' subtracts INTEGER1 from INTEGER2, then adds all
  95.      the rest of the arguments to the result.  If INTEGER2 is not
  96.      supplied, then the number 19 is used by default.
  97.           (foo 1 5 3 9)
  98.                => 16
  99.           (foo 5)
  100.                => 14
  101.      More generally,
  102.           (foo W X Y...)
  103.           ==
  104.           (+ (- X W) Y...)
  105.    Any parameter whose name contains the name of a type (e.g., INTEGER,
  106. INTEGER1 or BUFFER) is expected to be of that type.  A plural of a type
  107. (such as BUFFERS) often means a list of objects of that type. 
  108. Parameters named OBJECT may be of any type. (*Note Types of Lisp
  109. Object::, for a list of Emacs object types.) Parameters with other
  110. sorts of names (e.g., NEW-FILE) are discussed specifically in the
  111. description of the function.  In some sections, features common to
  112. parameters of several functions are described at the beginning.
  113.    *Note Lambda Expressions::, for a more complete description of
  114. optional and rest arguments.
  115.    Command, macro, and special form descriptions have the same format,
  116. but the word `Function' is replaced by `Command', `Macro', or `Special
  117. Form', respectively.  Commands are simply functions that may be called
  118. interactively; macros process their arguments differently from functions
  119. (the arguments are not evaluated), but are presented the same way.
  120.    Special form descriptions use a more complex notation to specify
  121. optional and repeated parameters because they can break the argument
  122. list down into separate arguments in more complicated ways.
  123. ``[OPTIONAL-ARG]'' means that OPTIONAL-ARG is optional and
  124. `REPEATED-ARGS...' stands for zero or more arguments.  Parentheses are
  125. used when several arguments are grouped into additional levels of list
  126. structure.  Here is an example:
  127.  -- Special Form: count-loop (VAR [FROM TO [INC]]) BODY...
  128.      This imaginary special form implements a loop that executes the
  129.      BODY forms and then increments the variable VAR on each iteration.
  130.       On the first iteration, the variable has the value FROM; on
  131.      subsequent iterations, it is incremented by 1 (or by INC if that
  132.      is given).  The loop exits before executing BODY if VAR equals TO.
  133.       Here is an example:
  134.           (count-loop (i 0 10)
  135.             (prin1 i) (princ " ")
  136.             (prin1 (aref vector i)) (terpri))
  137.      If FROM and TO are omitted, then VAR is bound to `nil' before the
  138.      loop begins, and the loop exits if VAR is non-`nil' at the
  139.      beginning of an iteration.  Here is an example:
  140.           (count-loop (done)
  141.             (if (pending)
  142.                 (fixit)
  143.               (setq done t)))
  144.      In this special form, the arguments FROM and TO are optional, but
  145.      must both be present or both absent.  If they are present, INC may
  146.      optionally be specified as well.  These arguments are grouped with
  147.      the argument VAR into a list, to distinguish them from BODY, which
  148.      includes all remaining elements of the form.
  149. File: elisp,  Node: A Sample Variable Description,  Prev: A Sample Function Description,  Up: Format of Descriptions
  150. A Sample Variable Description
  151. .............................
  152.    A "variable" is a name that can hold a value.  Although any variable
  153. can be set by the user, certain variables that exist specifically so
  154. that users can change them are called "user options".  Ordinary
  155. variables and user options are described using a format like that for
  156. functions except that there are no arguments.
  157.    Here is a description of the imaginary `electric-future-map'
  158. variable.
  159.  -- Variable: electric-future-map
  160.      The value of this variable is a full keymap used by electric
  161.      command future mode.  The functions in this map will allow you to
  162.      edit commands you have not yet thought about executing.
  163.    User option descriptions have the same format, but `Variable' is
  164. replaced by `User Option'.
  165. File: elisp,  Node: Acknowledgements,  Prev: Conventions,  Up: Introduction
  166. Acknowledgements
  167. ================
  168.    This manual was written by Robert Krawitz, Bil Lewis, Dan LaLiberte,
  169. Richard M. Stallman and Chris Welty, the volunteers of the GNU manual
  170. group, in an effort extending over several years.  Robert J. Chassell
  171. helped to review and edit the manual, with the support of the Defense
  172. Advanced Research Projects Agency, ARPA Order 6082, arranged by Warren
  173. A. Hunt, Jr. of Computational Logic, Inc.
  174.    Corrections were supplied by Karl Berry, Bard Bloom, David Boyes,
  175. Alan Carroll, David A. Duff, Beverly Erlebacher, David Eckelkamp, Eirik
  176. Fuller, Eric Hanchrow, George Hartzell, Nathan Hess, Dan Jacobson, Jak
  177. Kirman, Bob Knighten, Frederick M. Korz, Joe Lammens, K. Richard Magill,
  178. Brian Marick, Roland McGrath, Skip Montanaro, John Gardiner Myers,
  179. Arnold D. Robbins, Raul Rockwell, Shinichirou Sugou, Kimmo Suominen,
  180. Edward Tharp, Bill Trost, Jean White, Matthew Wilding, Carl Witty, Dale
  181. Worley, Rusty Wright, and David D. Zuhn.
  182. File: elisp,  Node: Types of Lisp Object,  Next: Numbers,  Prev: Introduction,  Up: Top
  183. Lisp Data Types
  184. ***************
  185.    A Lisp "object" is a piece of data used and manipulated by Lisp
  186. programs.  For our purposes, a "type" or "data type" is a set of
  187. possible objects.
  188.    Every object belongs to at least one type.  Objects of the same type
  189. have similar structures and may usually be used in the same contexts.
  190. Types can overlap, and objects can belong to two or more types.
  191. Consequently, we can ask whether an object belongs to a particular type,
  192. but not for "the" type of an object.
  193.    A few fundamental object types are built into Emacs.  These, from
  194. which all other types are constructed, are called "primitive types".
  195. They include "integer", "cons", "symbol", "string", "vector", "subr"
  196. and several special types, such as "buffer", that are related to
  197. editing.  (*Note Editing Types::.)
  198.    While an object may be a member of more than one type, every object
  199. is a member of exactly one primitive type.  The primitive type of an
  200. object is stored with the object's data.  A Lisp function is provided
  201. for each primitive type to check whether an object is a member of that
  202. type.
  203.    Note that Lisp is unlike many other languages in that Lisp objects
  204. are "self-typing": the primitive type of the object is implicit in the
  205. object itself.  For example, if an object is a vector, it cannot be
  206. treated as a number because Lisp knows it is a vector, not a number.  In
  207. most languages, the programmer must declare the data type of each
  208. variable, and the type is known by the compiler but not represented in
  209. the data.  Such type declarations do not exist in Emacs Lisp.
  210.    This chapter describes the purpose, printed representation, and read
  211. syntax of each of the standard types in GNU Emacs Lisp.  Details on how
  212. to use these types can be found in later chapters.
  213. * Menu:
  214. * Printed Representation::      How Lisp objects are represented as text.
  215. * Comments::                    Comments and their formatting conventions.
  216. * Programming Types::           Types found in all Lisp systems.
  217. * Editing Types::               Types specific to Emacs.
  218. * Type Predicates::             Tests related to types.
  219. * Equality Predicates::         Tests of equality between any two objects.
  220. File: elisp,  Node: Printed Representation,  Next: Comments,  Prev: Types of Lisp Object,  Up: Types of Lisp Object
  221. Printed Representation and Read Syntax
  222. ======================================
  223.    The "printed representation" of an object is the format of the
  224. output generated by the Lisp printer (the function `print') for that
  225. object.  The "read syntax" of an object is the format of the input
  226. accepted by the Lisp reader (the function `read') for that object. 
  227. Most objects have more than one possible read syntax.  Some types of
  228. object have no read syntax; except in these cases, the printed
  229. representation of an object is also a read syntax for it.
  230.    In other languages, an expression is text; it has no other form.  In
  231. Lisp, an expression is primarily a Lisp object and only secondarily the
  232. text that is the object's read syntax.  Often there is no need to
  233. emphasize this distinction, but you must keep it in the back of your
  234. mind, or you will occasionally be very confused.
  235.    Every type has a printed representation.  Some types have no read
  236. syntax, since it may not make sense to enter objects of these types
  237. directly in a Lisp program.  For example, the buffer type does not have
  238. a read syntax.  Objects of these types are printed in "hash notation":
  239. the characters `#<' followed by a descriptive string (typically the
  240. type name followed by the name of the object), and closed with a
  241. matching `>'.  Hash notation cannot be read at all, so the Lisp reader
  242. signals the error `invalid-read-syntax' whenever a `#' is encountered.
  243.      (current-buffer)
  244.           => #<buffer objects.texi>
  245.    When you evaluate an expression interactively, the Lisp interpreter
  246. first reads the textual representation of it, producing a Lisp object,
  247. and then evaluates that object (*note Evaluation::.).  However,
  248. evaluation and reading are separate activities.  Reading returns the
  249. Lisp object represented by the text that is read; the object may or may
  250. not be evaluated later.  *Note Input Functions::, for a description of
  251. `read', the basic function for reading objects.
  252. File: elisp,  Node: Comments,  Next: Programming Types,  Prev: Printed Representation,  Up: Types of Lisp Object
  253. Comments
  254. ========
  255.    A "comment" is text that is written in a program only for the sake
  256. of humans that read the program, and that has no effect on the meaning
  257. of the program.  In Lisp, a comment starts with a semicolon (`;') and
  258. continues to the end of line.  Comments are discarded by the Lisp
  259. reader, and do not become part of the Lisp objects which represent the
  260. program within the Lisp system.
  261.    We recommend these conventions for where to put comments and how to
  262. indent them:
  263.      Comments that start with a single semicolon, `;', should all be
  264.      aligned to the same column on the right of the source code.  Such
  265.      comments usually explain how the code on the same line does its
  266.      job.  In Lisp mode and related modes, the `M-;'
  267.      (`indent-for-comment') command automatically inserts such a `;' in
  268.      the right place, or aligns such a comment if it is already
  269.      inserted.
  270.      (The following examples are taken from the Emacs sources.)
  271.           (setq base-version-list                 ; there was a base
  272.                 (assoc (substring fn 0 start-vn)  ; version to which
  273.                        file-version-assoc-list))  ; this looks like
  274.                                                   ; a subversion
  275.      Comments that start with two semicolons, `;;', should be aligned to
  276.      the same level of indentation as the code.  Such comments are used
  277.      to describe the purpose of the following lines or the state of the
  278.      program at that point.  For example:
  279.             (prog1 (setq auto-fill-hook
  280.                          ...
  281.                          ...
  282.               ;; update mode-line
  283.               (set-buffer-modified-p (buffer-modified-p))))
  284.      These comments are also written before a function definition to
  285.      explain what the function does and how to call it properly.
  286. `;;;'
  287.      Comments that start with three semicolons, `;;;', should start at
  288.      the left margin.  Such comments are not used within function
  289.      definitions, but are used to make more general comments.  For
  290.      example:
  291.           ;;; This Lisp code is run in Emacs when it is to operate as
  292.           ;;; a server for other processes.
  293. `;;;;'
  294.      Comments that start with four semicolons, `;;;;', should be aligned
  295.      to the left margin and are used for headings of major sections of a
  296.      program.  For example:
  297.           ;;;; The kill ring
  298. The indentation commands of the Lisp modes in Emacs, such as `M-;'
  299. (`indent-for-comment') and TAB (`lisp-indent-line') automatically
  300. indent comments according to these conventions, depending on the the
  301. number of semicolons.  *Note  Manipulating Comments: (emacs)Comments.
  302.    Any character may be included in a comment, but it is advisable to
  303. precede a character with syntactic significance in Lisp (such as `\' or
  304. unpaired `(' or `)') with a `\', to prevent it from confusing the Emacs
  305. commands for editing Lisp.
  306. File: elisp,  Node: Programming Types,  Next: Editing Types,  Prev: Comments,  Up: Types of Lisp Object
  307. Programming Types
  308. =================
  309.    There are two general categories of types in Emacs Lisp: those having
  310. to do with Lisp programming, and those having to do with editing.  The
  311. former are provided in many Lisp implementations, in one form or
  312. another.  The latter are unique to Emacs Lisp.
  313. * Menu:
  314. * Number Type::         Primarily integers.
  315. * Character Type::      The representation of letters, numbers and
  316.                         control characters.
  317. * Sequence Type::       Both lists and arrays are classified as sequences.
  318. * List Type::           Lists gave Lisp its name (not to mention reputation).
  319. * Array Type::          Arrays include strings and vectors.
  320. * String Type::         An (efficient) array of characters.
  321. * Vector Type::         One-dimensional arrays.
  322. * Symbol Type::         A multi-use object that refers to a function,
  323.                         variable, property list, or itself.
  324. * Lisp Function Type::  A piece of executable code you can call from elsewhere.
  325. * Lisp Macro Type::     A method of expanding an expression into another
  326.                           expression, more fundamental but less pretty.
  327. * Primitive Function Type::     A function written in C, callable from Lisp.
  328. * Autoload Type::       A type used for automatically loading seldom-used
  329.                         functions.
  330. File: elisp,  Node: Number Type,  Next: Character Type,  Prev: Programming Types,  Up: Programming Types
  331. Number Type
  332. -----------
  333.    Integers are the only kind of number in GNU Emacs Lisp, version 18.
  334. The range of values for integers is -8388608 to 8388607 (24 bits; i.e.,
  335. -2**23 to 2**23 - 1) on most machines, but is 25 or 26 bits on some
  336. systems.  It is important to note that the Emacs Lisp arithmetic
  337. functions do not check for overflow.  Thus `(1+ 8388607)' is -8388608
  338. on 24-bit implementations.
  339.    Version 19 supports floating point numbers.
  340.    The read syntax for numbers is a sequence of (base ten) digits with
  341. an optional sign.  The printed representation produced by the Lisp
  342. interpreter never has a leading `+'.
  343.      -1               ; The integer -1.
  344.      1                ; The integer 1.
  345.      +1               ; Also the integer 1.
  346.      16777217         ; Also the integer 1! (on a 24-bit or 25-bit implementation)
  347.    *Note Numbers::, for more information.
  348. File: elisp,  Node: Character Type,  Next: Sequence Type,  Prev: Number Type,  Up: Programming Types
  349. Character Type
  350. --------------
  351.    A "character" in Emacs Lisp is nothing more than an integer.  In
  352. other words, characters are represented by their eight-bit ASCII
  353. values.  For example, the character `A' is represented as the
  354. integer 65.  If an arbitrary integer is used as a character, only the
  355. lower eight bits are significant.
  356.    Individual characters are not often used in programs.  It is far more
  357. common to work with *strings*, which are sequences composed of
  358. characters.  *Note String Type::.
  359.    Since characters are really integers, the printed representation of a
  360. character is a decimal number.  This is also a possible read syntax for
  361. a character, but it is not convenient for that purpose.  Therefore,
  362. Emacs Lisp provides a variety of read syntax formats, such as `?A' and
  363. `?\101', for entering characters.  They all start with a question mark.
  364.    The usual read syntax for alphanumeric characters is a question mark
  365. followed by the character; thus, `?A' for the character `A', `?B' for
  366. the character `B', and `?a' for the character `a'.  For example:
  367.      ?Q => 81
  368.      
  369.      ?q => 113
  370.    The characters backspace, tab, newline, vertical tab, formfeed,
  371. return, and escape may be represented as `?\b', `?\t', `?\n', `?\v',
  372. `?\f', `?\r', `?\e', respectively.  Those values are 8, 9, 10, 11, 12,
  373. 13, and 27 in decimal. Thus,
  374.      ?\b => 8                 ; backspace, BS, `C-h'
  375.      ?\t => 9                 ; tab, TAB, `C-i'
  376.      ?\n => 10                ; newline, LFD, `C-j'
  377.      ?\v => 11                ; vertical tab, `C-k'
  378.      ?\f => 12                ; formfeed character, `C-l'
  379.      ?\r => 13                ; carriage return, RET, `C-m'
  380.      ?\e => 27                ; escape character, ESC, `C-['
  381.      ?\\ => 92                ; backslash character, `\'
  382.    Control characters may be represented using yet another read syntax.
  383. This consists of a question mark followed by a backslash, caret, and the
  384. corresponding non-control character, in either upper or lower case.  For
  385. example, either `?\^I' or `?\^i' may be used as the read syntax for the
  386. character `C-i', the character whose value is 9.
  387.    Instead of the `^', you can use `C-'; thus, `?\C-i' is equivalent to
  388. `?\^I', and `?\C-i' is equivalent to `?\^i'.  For example:
  389.      ?\^I => 9
  390.      
  391.      ?\C-I => 9
  392.    The DEL key can be considered and written as `Control-?':
  393.      ?\^? => 127
  394.      
  395.      ?\C-? => 127
  396.    When you represent control characters to be found in files or
  397. strings, we recommend the `^' syntax; but when you refer to keyboard
  398. input, we prefer the `C-' syntax.  This does not affect the meaning of
  399. the program, but may guide the understanding of people who read it.
  400.    A "meta character" is a character that has its eighth bit set. The
  401. read syntax for these characters is question mark, backslash, `M-', and
  402. the corresponding seven-bit character.  For example, `?\M-A' stands for
  403. `M-A', the character with code 193 (301 octal).  The seven-bit
  404. character can be written directly or specified by any of the `\'
  405. escapes described above or below.  Thus, `M-A' can be written as
  406. `?\M-A', or as `?\M-\101', or as `?\301'.  Likewise, the character
  407. whose decimal printed representation is 130 (202 octal) can use any one
  408. of the following for its read syntax: `?\202', `?\M-\C-b', `?\C-\M-b',
  409. or `?\M-\002'.  For example:
  410.      ?\C-\M-b => 130          ?\M-\C-b => 130
  411.      
  412.      ?\^\M-b => 130           ?\M-\002 => 130
  413.    Finally, the most general read syntax consists of a question mark
  414. followed by a backslash and the ASCII code for the character in octal
  415. (up to three octal digits); thus, `?\101' for the character `A',
  416. `?\001' for the character `C-a', and `?\002' for the character `C-b'. 
  417. Although this syntax can represent any character, it is preferred only
  418. when the precise octal value is more important than the ASCII
  419. representation.  (These sequences which start with backslash are also
  420. known as "escape sequences", because backslash plays the role of an
  421. escape character, but they have nothing to do with the character ESC.)
  422.      ?\012 => 10        ?\n => 10         ?\C-j => 10
  423.      
  424.      ?\101 => 65        ?A => 65
  425.      
  426.      ?\301 => 193       ?\M-A => 193      ?\M-\101 => 193
  427.    A backslash is allowed, and harmless, preceding any character without
  428. a special escape meaning; thus, `?\A' is equivalent to `?A'. There is
  429. no reason to use a backslash before most such characters. However, any
  430. of the characters `()\|;'`"#.,' should be preceded by a backslash to
  431. avoid confusing the Emacs commands for editing Lisp code. Whitespace
  432. characters such as space, tab, newline and formfeed should also be
  433. preceded by a backslash.  However, it is cleaner to use one of the
  434. easily readable escape sequences, such as `\t', instead of an actual
  435. control character such as a tab.
  436. File: elisp,  Node: Sequence Type,  Next: List Type,  Prev: Character Type,  Up: Programming Types
  437. Sequence Types
  438. --------------
  439.    A "sequence" is a Lisp object that represents an ordered set of
  440. elements.  There are two kinds of sequence in Emacs Lisp, lists and
  441. arrays.  Thus, an object of type list or of type array is also
  442. considered a sequence.
  443.    Arrays are further subdivided into strings and vectors.  Vectors can
  444. hold elements of any type, but string elements must be
  445. characters--integers from 0 to 255.
  446.    Lists, strings and vectors are different, but they have important
  447. similarities.  For example, all have a length L, and all have elements
  448. which can be indexed from zero to L minus one.  Also, several
  449. functions, called sequence functions, accept any kind of sequence.  For
  450. example, the function `elt' can be used to extract an element of a
  451. sequence, given its index.  *Note Sequences Arrays Vectors::.
  452.    It is impossible to read the same sequence twice, in the sense of
  453. `eq' (*note Equality Predicates::.), since sequences are always created
  454. anew upon reading.  There is one exception: the empty list `()' is
  455. always read as the same object, `nil'.
  456. File: elisp,  Node: List Type,  Next: Array Type,  Prev: Sequence Type,  Up: Programming Types
  457. List Type
  458. ---------
  459.    A "list" is a series of cons cells, linked together.  A "cons cell"
  460. is an object comprising two pointers named the CAR and the CDR.  Each
  461. of them can point to any Lisp object, but when the cons cell is part of
  462. a list, the CDR points either to another cons cell or to the empty
  463. list.  *Note Lists::, for functions that work on lists.
  464.    The names CAR and CDR have only historical meaning now.  The
  465. original Lisp implementation ran on an IBM 704 computer which divided
  466. words into two parts, called the "address" part and the "decrement";
  467. CAR was an instruction to extract the contents of the address part of a
  468. register, and CDR an instruction to extract the contents of the
  469. decrement.  By contrast, "cons cells" are named for the function `cons'
  470. that creates them, which in turn is named for its purpose, the
  471. construction of cells.
  472.    Because cons cells are so central to Lisp, we also have a word for
  473. "an object which is not a cons cell".  These objects are called "atoms".
  474.    The read syntax and printed representation for lists are identical,
  475. and consist of a left parenthesis, an arbitrary number of elements, and
  476. a right parenthesis.
  477.    Upon reading, any object inside the parentheses is made into an
  478. element of the list.  That is, a cons cell is made for each element.
  479. The CAR of the cons cell points to the element, and its CDR points to
  480. the next cons cell which holds the next element in the list. The CDR of
  481. the last cons cell is set to point to `nil'.
  482.    A list can be illustrated by a diagram in which the cons cells are
  483. shown as pairs of boxes.  (The Lisp reader cannot read such an
  484. illustration; unlike the textual notation, which can be understood both
  485. humans and computers, the box illustrations can only be understood by
  486. humans.)  The following represents the three-element list `(rose violet
  487. buttercup)':
  488.          ___ ___      ___ ___      ___ ___
  489.         |___|___|--> |___|___|--> |___|___|--> nil
  490.           |            |            |
  491.           |            |            |
  492.            --> rose     --> violet   --> buttercup
  493.    In the diagram, each box represents a slot that can refer to any Lisp
  494. object.  Each pair of boxes represents a cons cell.  Each arrow is a
  495. reference to a Lisp object, either an atom or another cons cell.
  496.    In this example, the first box, the CAR of the first cons cell,
  497. refers to or "contains" `rose' (a symbol).  The second box, the CDR of
  498. the first cons cell, refers to the next pair of boxes, the second cons
  499. cell.  The CAR of the second cons cell refers to `violet' and the CDR
  500. refers to the third cons cell.  The CDR of the third (and last) cons
  501. cell refers to `nil'.
  502.    Here is another diagram of the same list, `(rose violet buttercup)',
  503. sketched in a different manner:
  504.       ---------------         ----------------         -------------------
  505.      |car    |cdr    |       |car     |cdr    |       |car        |cdr    |
  506.      | rose  |   o---------->| violet |   o---------->| buttercup |  nil  |
  507.      |       |       |       |        |       |       |           |       |
  508.       ---------------         ----------------         -------------------
  509.    A list with no elements in it is the "empty list"; it is identical
  510. to the symbol `nil'.  In other words, `nil' is both a symbol and a list.
  511.    Here are examples of lists written in Lisp syntax:
  512.      (A 2 "A")            ; A list of three elements.
  513.      ()                   ; A list of no elements (the empty list).
  514.      nil                  ; A list of no elements (the empty list).
  515.      ("A ()")             ; A list of one element: the string `"A ()"'.
  516.      (A ())               ; A list of two elements: `A' and the empty list.
  517.      (A nil)              ; Equivalent to the previous.
  518.      ((A B C))            ; A list of one element
  519.                           ; (which is a list of three elements).
  520.    Here is the list `(A ())', or equivalently `(A nil)', depicted with
  521. boxes and arrows:
  522.          ___ ___      ___ ___
  523.         |___|___|--> |___|___|--> nil
  524.           |            |
  525.           |            |
  526.            --> A        --> nil
  527. * Menu:
  528. * Dotted Pair Notation::        An alternative syntax for lists.
  529. * Association List Type::       A specially constructed list.
  530. File: elisp,  Node: Dotted Pair Notation,  Next: Association List Type,  Prev: List Type,  Up: List Type
  531. Dotted Pair Notation
  532. ....................
  533.    "Dotted pair notation" is an alternative syntax for cons cells that
  534. represents the CAR and CDR explicitly.  In this syntax, `(A . B)'
  535. stands for a cons cell whose CAR is the object A, and whose CDR is the
  536. object B.  Dotted pair notation is therefore more general than list
  537. syntax.  In the dotted pair notation, the list `(1 2 3)' is written as
  538. `(1 .  (2 . (3 . nil)))'.  For `nil'-terminated lists, the two
  539. notations produce the same result, but list notation is usually clearer
  540. and more convenient when it is applicable.  When printing a list, the
  541. dotted pair notation is only used if the CDR of a cell is not a list.
  542.    Box notation can also be used to illustrate what dotted pairs look
  543. like.  For example, `(rose . violet)' is diagrammed as follows:
  544.          ___ ___
  545.         |___|___|--> violet
  546.           |
  547.           |
  548.            --> rose
  549.    Dotted pair notation can be combined with list notation to represent
  550. a chain of cons cells with a non-`nil' final CDR.  For example, `(rose
  551. violet . buttercup)' is equivalent to `(rose . (violet . buttercup))'. 
  552. The object looks like this:
  553.          ___ ___      ___ ___
  554.         |___|___|--> |___|___|--> buttercup
  555.           |            |
  556.           |            |
  557.            --> rose     --> violet
  558.    These diagrams make it evident that `(rose . violet . buttercup)'
  559. must have an invalid syntax since it would require that a cons cell
  560. have three parts rather than two.
  561.    The list `(rose violet)' is equivalent to `(rose . (violet))' and
  562. looks like this:
  563.          ___ ___      ___ ___
  564.         |___|___|--> |___|___|--> nil
  565.           |            |
  566.           |            |
  567.            --> rose     --> violet
  568.    Similarly, the three-element list `(rose violet buttercup)' is
  569. equivalent to `(rose . (violet . (buttercup)))'. It looks like this:
  570.          ___ ___      ___ ___      ___ ___
  571.         |___|___|--> |___|___|--> |___|___|--> nil
  572.           |            |            |
  573.           |            |            |
  574.            --> rose     --> violet   --> buttercup
  575. File: elisp,  Node: Association List Type,  Prev: Dotted Pair Notation,  Up: List Type
  576. Association List Type
  577. .....................
  578.    An "association list" or "alist" is a specially-constructed list
  579. whose elements are cons cells.  In each element, the CAR is considered
  580. a "key", and the CDR is considered an "associated value".  (In some
  581. cases, the associated value is stored in the CAR of the CDR.) 
  582. Association lists are often used to implement stacks, since new
  583. associations may easily be added to or removed from the front of the
  584. list.
  585.    For example,
  586.      (setq alist-of-colors '((rose . red) (lily . white)  (buttercup . yellow)))
  587. sets the variable `alist-of-colors' to an alist of three elements.  In
  588. the first element, `rose' is the key and `red' is the value.
  589.    *Note Association Lists::, for a further explanation of alists and
  590. for functions that work on alists.
  591. File: elisp,  Node: Array Type,  Next: String Type,  Prev: List Type,  Up: Programming Types
  592. Array Type
  593. ----------
  594.    An "array" is composed of an arbitrary number of other Lisp objects,
  595. arranged in a contiguous block of memory.  Any element of an array may
  596. be accessed in constant time.  In contrast, accessing an element of a
  597. list requires time proportional to the position of the element in the
  598. list.  (Elements at the end of a list take longer to access than
  599. elements at the beginning of a list.)
  600.    Emacs defines two types of array, strings and vectors.  A string is
  601. an array of characters and a vector is an array of arbitrary objects. 
  602. Both are one-dimensional.  (Most other programming languages support
  603. multidimensional arrays, but we don't think they are essential in Emacs
  604. Lisp.)  Each type of array has its own read syntax; see *Note String
  605. Type::, and *Note Vector Type::.
  606.    An array may have any length up to the largest integer; but once
  607. created, it has a fixed size.  The first element of an array has index
  608. zero, the second element has index 1, and so on.  This is called
  609. "zero-origin" indexing.  For example, an array of four elements has
  610. indices 0, 1, 2, and 3.
  611.    The array type is contained in the sequence type and contains both
  612. strings and vectors.
  613. File: elisp,  Node: String Type,  Next: Vector Type,  Prev: Array Type,  Up: Programming Types
  614. String Type
  615. -----------
  616.    A "string" is an array of characters.  Strings are used for many
  617. purposes in Emacs, as can be expected in a text editor; for example, as
  618. the names of Lisp symbols, as messages for the user, and to represent
  619. text extracted from buffers.  Strings in Lisp are constants; evaluation
  620. of a string returns the same string.
  621.    The read syntax for strings is a double-quote, an arbitrary number of
  622. characters, and another double-quote, `"like this"'.  The Lisp reader
  623. accepts the same formats for reading the characters of a string as it
  624. does for reading single characters (without the question mark that
  625. begins a character literal).  You can enter a nonprinting character such
  626. as tab, `C-a' or `M-C-A' using the convenient escape sequences, like
  627. this: `"\t, \C-a, \M-\C-a"'.  You can include a double-quote in a
  628. string by preceding it with a backslash; thus, `"\""' is a string
  629. containing just a single double-quote character. (*Note Character
  630. Type::, for a description of the read syntax for characters.)
  631.    In contrast with the C programming language, newlines are allowed in
  632. Emacs Lisp string literals.  But an escaped newline--one that is
  633. preceded by `\'--does not become part of the string; i.e., the Lisp
  634. reader ignores an escaped newline in a string literal.
  635.      "It is useful to include newlines in
  636.      documentation strings, but the newline is \
  637.      ignored if escaped."
  638.           => "It is useful to include newlines in
  639.      documentation strings, but the newline is ignored if escaped."
  640.    The printed representation of a string consists of a double-quote,
  641. the characters it contains, and another double-quote.  However, any
  642. backslash or double-quote characters in the string are preceded with a
  643. backslash like this: `"this \" is an embedded quote"'.
  644.    *Note Strings and Characters::, for functions that work on strings.
  645. File: elisp,  Node: Vector Type,  Next: Symbol Type,  Prev: String Type,  Up: Programming Types
  646. Vector Type
  647. -----------
  648.    A "vector" is a one-dimensional array of elements of any type.  It
  649. takes a constant amount of time to access any element of a vector.  (In
  650. a list, the access time of an element is proportional to the distance of
  651. the element from the beginning of the list.)
  652.    The printed representation of a vector consists of a left square
  653. bracket, the elements, and a right square bracket.  This is also the
  654. read syntax.  Like numbers and strings, vectors are considered constants
  655. for evaluation.
  656.      [1 "two" (three)]      ; A vector of three elements.
  657.           => [1 "two" (three)]
  658.    *Note Vectors::, for functions that work with vectors.
  659. File: elisp,  Node: Symbol Type,  Next: Lisp Function Type,  Prev: Vector Type,  Up: Programming Types
  660. Symbol Type
  661. -----------
  662.    A "symbol" in GNU Emacs Lisp is an object with a name.  The symbol
  663. name is the printed representation of the symbol.  In ordinary use, the
  664. name is unique--no two symbols have the same name.
  665.    A symbol may be used in programs as a variable, as a function name,
  666. or to hold a list of properties.  Or it may serve only to be distinct
  667. from all other Lisp objects, so that its presence in a data structure
  668. may be recognized reliably.  In a given context, usually only one of
  669. these uses is intended.
  670.    A symbol name can contain any characters whatever.  Most symbol names
  671. are written with letters, digits, and the punctuation characters
  672. `-+=*/'.  Such names require no special punctuation; the characters of
  673. the name suffice as long as the name does not look like a number. (If
  674. it does, write a `\' at the beginning of the name to force
  675. interpretation as a symbol.)  The characters `_~!@$%^&:<>{}' are less
  676. often used but also require no special punctuation.  Any other
  677. characters may be included in a symbol's name by escaping them with a
  678. backslash.  In contrast to its use in strings, however, a backslash in
  679. the name of a symbol quotes the single character that follows the
  680. backslash, without conversion.  For example, in a string, `\t'
  681. represents a tab character; in the name of a symbol, however, `\t'
  682. merely quotes the letter `t'.  To have a symbol with a tab character in
  683. its name, you must actually type an tab (preceded with a backslash).
  684. But you would hardly ever do such a thing.
  685.      Common Lisp note: in Common Lisp, lower case letters are always
  686.      "folded" to upper case, unless they are explicitly escaped.  This
  687.      is in contrast to Emacs Lisp, in which upper case and lower case
  688.      letters are distinct.
  689.    Here are several examples of symbol names.  Note that the `+' in the
  690. fifth example is escaped to prevent it from being read as a number.
  691. This is not necessary in the last example because the rest of the name
  692. makes it invalid as a number.
  693.      foo                 ; A symbol named `foo'.
  694.      FOO                 ; A symbol named `FOO', different from `foo'.
  695.      char-to-string      ; A symbol named `char-to-string'.
  696.      1+                  ; A symbol named `1+'
  697.                          ;     (not `+1', which is an integer).
  698.      \+1                 ; A symbol named `+1' (not a very readable name).
  699.      \(*\ 1\ 2\)         ; A symbol named `(* 1 2)' (a worse name).
  700.      +-*/_~!@$%^&=:<>{}  ; A symbol named `+-*/_~!@$%^&=:<>{}'.
  701.                          ;     These characters need not be escaped.
  702. File: elisp,  Node: Lisp Function Type,  Next: Lisp Macro Type,  Prev: Symbol Type,  Up: Programming Types
  703. Lisp Function Type
  704. ------------------
  705.    Just as functions in other programming languages are executable, a
  706. "Lisp function" object is a piece of executable code.  However, Lisp
  707. functions are primarily Lisp objects, and only secondarily the text
  708. which represents them.  These Lisp objects are lambda expressions: lists
  709. whose first element is the symbol `lambda' (*note Lambda
  710. Expressions::.).
  711.    In most programming languages, it is impossible to have a function
  712. without a name.  In Lisp, a function has no intrinsic name.  A lambda
  713. expression is also called an "anonymous function" (*note Anonymous
  714. Functions::.).  A named function in Lisp is actually a symbol with a
  715. valid function in its function cell (*note Defining Functions::.).
  716.    Most of the time, functions are called when their names are written
  717. in Lisp expressions in Lisp programs.  However, a function object found
  718. or constructed at run time can be called and passed arguments with the
  719. primitive functions `funcall' and `apply'.  *Note Calling Functions::.
  720. File: elisp,  Node: Lisp Macro Type,  Next: Primitive Function Type,  Prev: Lisp Function Type,  Up: Programming Types
  721. Lisp Macro Type
  722. ---------------
  723.    A "Lisp macro" is a user-defined construct that extends the Lisp
  724. language.  It is represented as an object much like a function, but with
  725. different parameter-passing semantics.  A Lisp macro has the form of a
  726. list whose first element is the symbol `macro' and whose CDR is a Lisp
  727. function object, including the `lambda' symbol.
  728.    Lisp macro objects are usually defined with the built-in function
  729. `defmacro', but any list that begins with `macro' is a macro as far as
  730. Emacs is concerned.  *Note Macros::, for an explanation of how to write
  731. a macro.
  732. File: elisp,  Node: Primitive Function Type,  Next: Autoload Type,  Prev: Lisp Macro Type,  Up: Programming Types
  733. Primitive Function Type
  734. -----------------------
  735.    A "primitive function" is a function callable from Lisp but written
  736. in the C programming language.  Primitive functions are also called
  737. "subrs" or "built-in functions".  (The word "subr" is derived from
  738. "subroutine".)  Most primitive functions evaluate all their arguments
  739. when they are called.  A primitive function that does not evaluate all
  740. its arguments is called a "special form" (*note Special Forms::.).
  741.    It does not matter to the caller of a function whether the function
  742. is primitive.  However, this does matter if you are trying to
  743. substitute a function written in Lisp for a primitive of the same name.
  744.  The reason is that the primitive function may be called directly from
  745. C code.  When the redefined function is called from Lisp, the new
  746. definition will be used; but calls from C code may still use the old
  747. definition.
  748.    The term "function" is used to refer to all Emacs functions, whether
  749. written in Lisp or C.  *Note Lisp Function Type::, for information
  750. about the functions written in Lisp.
  751.    Primitive functions have no read syntax and print in hash notation
  752. with the name of the subroutine.
  753.      (symbol-function 'car)          ; Access the function cell of the symbol.
  754.           => #<subr car>
  755.      (subrp (symbol-function 'car))  ; Is this a primitive function?
  756.           => t                       ; Yes.
  757. File: elisp,  Node: Autoload Type,  Prev: Primitive Function Type,  Up: Programming Types
  758. Autoload Type
  759. -------------
  760.    An "autoload object" is a list whose first element is the symbol
  761. `autoload'.  It is stored as the function definition of a symbol to say
  762. that a file of Lisp code should be loaded when necessary to find the
  763. true definition of that symbol.  The autoload object contains the name
  764. of the file, plus some other information about the real definition.
  765.    After the file has been loaded, the symbol should have a new function
  766. definition that is not an autoload object.  The new definition is then
  767. called as if it had been there to begin with.  From the user's point of
  768. view, the function call works as expected, using the function definition
  769. in the loaded file.
  770.    An autoload object is usually created with the function `autoload',
  771. which stores the object in the function cell of a symbol.  *Note
  772. Autoload::, for more details.
  773. File: elisp,  Node: Editing Types,  Next: Type Predicates,  Prev: Programming Types,  Up: Types of Lisp Object
  774. Editing Types
  775. =============
  776.    The types in the previous section are common to many Lisp-like
  777. languages.  But Emacs Lisp provides several additional data types for
  778. purposes connected with editing.
  779. * Menu:
  780. * Buffer Type::         The basic object of editing.
  781. * Window Type::         What makes buffers visible.
  782. * Window Configuration Type::   Save what the screen looks like.
  783. * Marker Type::         A position in a buffer.
  784. * Process Type::        A process running on the underlying OS.
  785. * Stream Type::         Receive or send characters.
  786. * Keymap Type::         What function a keystroke invokes.
  787. * Syntax Table Type::   What a character means.
  788. File: elisp,  Node: Buffer Type,  Next: Window Type,  Prev: Editing Types,  Up: Editing Types
  789. Buffer Type
  790. -----------
  791.    A "buffer" is an object that holds text that can be edited (*note
  792. Buffers::.).  Most buffers hold the contents of a disk file (*note
  793. Files::.) so they can be edited, but some are used for other purposes. 
  794. Most buffers are also meant to be seen by the user, and therefore
  795. displayed, at some time, in a window (*note Windows::.).  But a buffer
  796. need not be displayed in a window.
  797.    The contents of a buffer are much like a string, but buffers are not
  798. used like strings in Emacs Lisp, and the available operations are
  799. different.  For example, text can be inserted into a buffer very
  800. quickly, while "inserting" text into a string is accomplished by
  801. concatenation and the result is an entirely new string object.
  802.    Each buffer has a designated position called "point" (*note
  803. Positions::.).  And one buffer is the "current buffer".  Most editing
  804. commands act on the contents of the current buffer in the neighborhood
  805. of point.  Many other functions manipulate or test the characters in
  806. the current buffer and much of this manual is devoted to describing
  807. these functions (*note Text::.).
  808.    Several other data structures are associated with each buffer:
  809.    * a local syntax table (*note Syntax Tables::.);
  810.    * a local keymap (*note Keymaps::.); and,
  811.    * a local variable binding list (*note Variables::.).
  812. The local keymap and variable list contain entries which individually
  813. override global bindings or values.  These are used to customize the
  814. behavior of programs in different buffers, without actually changing the
  815. programs.
  816.    Buffers have no read syntax.  They print in hash notation with the
  817. buffer name.
  818.      (current-buffer)
  819.           => #<buffer objects.texi>
  820. File: elisp,  Node: Window Type,  Next: Window Configuration Type,  Prev: Buffer Type,  Up: Editing Types
  821. Window Type
  822. -----------
  823.    A "window" describes the portion of the terminal screen that Emacs
  824. uses to display a buffer.  Every window has one associated buffer, whose
  825. contents appear in the window.  By contrast, a given buffer may appear
  826. in one window, no window, or several windows.
  827.    Though many windows may exist simultaneously, one window is
  828. designated the "selected window".  This is the window where the cursor
  829. is (usually) displayed when Emacs is ready for a command.  The selected
  830. window usually displays the current buffer, but this is not necessarily
  831. the case.
  832.    Windows have no read syntax.  They print in hash notation, giving the
  833. window number and the name of the buffer being displayed.  The window
  834. numbers exist to identify windows uniquely, since the buffer displayed
  835. in any given window can change frequently.
  836.      (selected-window)
  837.           => #<window 1 on objects.texi>
  838.    *Note Windows::, for a description of the functions that work on
  839. windows.
  840. File: elisp,  Node: Window Configuration Type,  Next: Marker Type,  Prev: Window Type,  Up: Editing Types
  841. Window Configuration Type
  842. -------------------------
  843.    A "window configuration" stores information about the positions and
  844. sizes of windows at the time the window configuration is created, so
  845. that the screen layout may be recreated later.
  846.    Window configurations have no read syntax.  They print as
  847. `#<window-configuration>'.  *Note Window Configurations::, for a
  848. description of several functions related to window configurations.
  849. File: elisp,  Node: Marker Type,  Next: Process Type,  Prev: Window Configuration Type,  Up: Editing Types
  850. Marker Type
  851. -----------
  852.    A "marker" denotes a position in a specific buffer.  Markers
  853. therefore have two components: one for the buffer, and one for the
  854. position.  The position value is changed automatically as necessary as
  855. text is inserted into or deleted from the buffer.  This is to ensure
  856. that the marker always points between the same two characters in the
  857. buffer.
  858.    Markers have no read syntax.  They print in hash notation, giving the
  859. current character position and the name of the buffer.
  860.      (point-marker)
  861.           => #<marker at 10779 in objects.texi>
  862.    *Note Markers::, for information on how to test, create, copy, and
  863. move markers.
  864. File: elisp,  Node: Process Type,  Next: Stream Type,  Prev: Marker Type,  Up: Editing Types
  865. Process Type
  866. ------------
  867.    The word "process" means a running program.  Emacs itself runs in a
  868. process of this sort.  However, in Emacs Lisp, a process is a Lisp
  869. object that designates a subprocess created by Emacs process.  External
  870. subprocesses, such as shells, GDB, ftp, and compilers, may be used to
  871. extend the processing capability of Emacs.
  872.    A process takes input from Emacs and returns output to Emacs for
  873. further manipulation.  Both text and signals can be communicated between
  874. Emacs and a subprocess.
  875.    Processes have no read syntax.  They print in hash notation, giving
  876. the name of the process:
  877.      (process-list)
  878.           => (#<process shell>)
  879.    *Note Processes::, for information about functions that create,
  880. delete, return information about, send input or signals to, and receive
  881. output from processes.
  882. File: elisp,  Node: Stream Type,  Next: Keymap Type,  Prev: Process Type,  Up: Editing Types
  883. Stream Type
  884. -----------
  885.    A "stream" is an object that can be used as a source or sink for
  886. characters--either to supply characters for input or to accept them as
  887. output.  Many different types can be used this way: markers, buffers,
  888. strings, and functions.  Most often, input streams (character sources)
  889. obtain characters from the keyboard, a buffer, or a file, and output
  890. streams (character sinks) send characters to a buffer, such as a
  891. `*Help*' buffer, or to the echo area.
  892.    The object `nil', in addition to its other meanings, may be used as
  893. a stream.  It stands for the value of the variable `standard-input' or
  894. `standard-output'.  Also, the object `t' as a stream specifies input
  895. using the minibuffer (*note Minibuffers::.) or output in the echo area
  896. (*note The Echo Area::.).
  897.    Streams have no special printed representation or read syntax, and
  898. print as whatever primitive type they are.
  899.    *Note Streams::, for a description of various functions related to
  900. streams, including various parsing and printing functions.
  901.