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

  1. This is Info file elisp, produced by Makeinfo-1.52 from the input file
  2. elisp.texi.
  3.  
  4.    This file documents GNU Emacs Lisp.
  5.  
  6.    This is edition 2.0 of the GNU Emacs Lisp Reference Manual, for
  7. Emacs Version 19.
  8.  
  9.    Published by the Free Software Foundation, 675 Massachusetts Avenue,
  10. Cambridge, MA 02139 USA
  11.  
  12.    Copyright (C) 1990, 1991, 1992 Free Software Foundation, Inc.
  13.  
  14.    Permission is granted to make and distribute verbatim copies of this
  15. manual provided the copyright notice and this permission notice are
  16. preserved on all copies.
  17.  
  18.    Permission is granted to copy and distribute modified versions of
  19. this manual under the conditions for verbatim copying, provided that
  20. the entire resulting derived work is distributed under the terms of a
  21. permission notice identical to this one.
  22.  
  23.    Permission is granted to copy and distribute translations of this
  24. manual into another language, under the above conditions for modified
  25. versions, except that this permission notice may be stated in a
  26. translation approved by the Foundation.
  27.  
  28. 
  29. File: elisp,  Node: GNU Emacs Internals,  Next: Standard Errors,  Prev: Tips,  Up: Top
  30.  
  31. GNU Emacs Internals
  32. *******************
  33.  
  34.                                       This chapter describes how the
  35. runnable Emacs executable is dumped with the preloaded Lisp libraries
  36. in it, how storage is allocated, and some internal aspects of GNU Emacs
  37. that may be of interest to C programmers.
  38.  
  39.                                    * Menu:
  40.                                    
  41.                                    * Building Emacs::      How to preload Lisp libraries into Emacs.
  42.                                    * Pure Storage::        A kludge to make preloaded Lisp functions sharable.
  43.                                    * Garbage Collection::  Reclaiming space for Lisp objects no longer used.
  44.                                    * Object Internals::    Data formats of buffers, windows, processes.
  45.                                    * Writing Emacs Primitives::   Writing C code for Emacs.
  46.  
  47. 
  48. File: elisp,  Node: Building Emacs,  Next: Pure Storage,  Prev: GNU Emacs Internals,  Up: GNU Emacs Internals
  49.  
  50. Building Emacs
  51. ==============
  52.  
  53.                                       The first step in building Emacs
  54. is to compile the C sources.  This produces a program called `temacs',
  55. also called a "bare impure Emacs".  It contains the Emacs Lisp
  56. interpreter and I/O routines, but not the editing commands.
  57.  
  58.                                       Then, to create a working Emacs
  59. editor, issue the `temacs -l loadup' command.  This directs `temacs' to
  60. evaluate the Lisp files specified in the file `loadup.el'.  These files
  61. set up the normal Emacs editing environment, resulting in an Emacs
  62. which is still impure but no longer bare.
  63.  
  64.                                       It takes a long time to load the
  65. standard Lisp files.  Luckily, you don't have to do this each time you
  66. run Emacs; `temacs' can dump out an executable program called `emacs'
  67. which has these files preloaded.  `emacs' starts more quickly because
  68. it does not need to load the files.  This is the program that is
  69. normally installed.
  70.  
  71.                                       To create `emacs', use the
  72. command `temacs -batch -l loadup dump'.  The purpose of `-batch' here
  73. is to prevent `temacs' from trying to initialize any of its data on the
  74. terminal; this ensures that the tables of terminal information are
  75. empty in the dumped Emacs.
  76.  
  77.                                       When the `emacs' executable is
  78. started, it automatically loads the user's `.emacs' file, or the
  79. default initialization file `default.el' if the user has none.  (*Note
  80. Starting Up::.)  With the `.emacs' file, you can produce a version of
  81. Emacs that suits you and is not the same as the version other people
  82. use.  With `default.el', you can customize Emacs for all the users at
  83. your site who don't choose to customize it for themselves.  (For further
  84. reflection: why is this different from the case of the barber who shaves
  85. every man who doesn't shave himself?)
  86.  
  87.                                       On some systems, dumping does not
  88. work.  Then, you must start Emacs with the `temacs -l loadup' command
  89. each time you use it.  This takes a long time, but since you need to
  90. start Emacs once a day at most--and once a week or less frequently if
  91. you never log out--the extra time is not too severe a problem.
  92.  
  93.                                       Before `emacs' is dumped, the
  94. documentation strings for primitive and preloaded functions (and
  95. variables) need to be found in the file where they are stored.  This is
  96. done by calling `Snarf-documentation' (*note Accessing
  97. Documentation::.).  These strings were moved out of `emacs' to make it
  98. smaller.  *Note Documentation Basics::.
  99.  
  100.                                     - Function: dump-emacs TO-FILE
  101.                                              FROM-FILE
  102.                                         This function dumps the current
  103.                                         state of Emacs into an
  104.                                         executable file TO-FILE.  It
  105.                                         takes symbols from FROM-FILE
  106.                                         (this is normally the
  107.                                         executable file `temacs').
  108.  
  109.                                         If you use this function in an
  110.                                         Emacs that was already dumped,
  111.                                         you must set
  112.                                         `command-line-processed' to
  113.                                         `nil' first for good results.
  114.                                         *Note Command Line Arguments::.
  115.  
  116.                                     - Command: emacs-version
  117.                                         This function returns a string
  118.                                         describing the version of Emacs
  119.                                         that is running.  It is useful
  120.                                         to include this string in bug
  121.                                         reports.
  122.  
  123.                                              (emacs-version)
  124.                                                => "GNU Emacs 18.36.1 of Fri Feb 27 1987 on slug
  125.                                                   (berkeley-unix)"
  126.  
  127.                                         Called interactively, the
  128.                                         function prints the same
  129.                                         information in the echo area.
  130.  
  131.                                     - Variable: emacs-build-time
  132.                                         The value of this variable is
  133.                                         the time at which Emacs was
  134.                                         built at the local site.
  135.  
  136.                                              emacs-build-time
  137.                                                   => "Fri Feb 27 14:55:57 1987"
  138.  
  139.                                     - Variable: emacs-version
  140.                                         The value of this variable is
  141.                                         the version of Emacs being run.
  142.                                         It is a string, e.g.
  143.                                         `"18.36.1"'.
  144.  
  145. 
  146. File: elisp,  Node: Pure Storage,  Next: Garbage Collection,  Prev: Building Emacs,  Up: GNU Emacs Internals
  147.  
  148. Pure Storage
  149. ============
  150.  
  151.                                       There are two types of storage in
  152. GNU Emacs Lisp for user-created Lisp objects: "normal storage" and
  153. "pure storage".  Normal storage is where all the new data which is
  154. created during an Emacs session is kept; see the following section for
  155. information on normal storage.  Pure storage is used for certain data
  156. in the preloaded standard Lisp files: data that should never change
  157. during actual use of Emacs.
  158.  
  159.                                       Pure storage is allocated only
  160. while `temacs' is loading the standard preloaded Lisp libraries.  In
  161. the file `emacs', it is marked as read-only (on operating systems which
  162. permit this), so that the memory space can be shared by all the Emacs
  163. jobs running on the machine at once.  Pure storage is not expandable; a
  164. fixed amount is allocated when Emacs is compiled, and if that is not
  165. sufficient for the preloaded libraries, `temacs' crashes.  If that
  166. happens, you will have to increase the compilation parameter `PURESIZE'
  167. in the file `config.h'.  This normally won't happen unless you try to
  168. preload additional libraries or add features to the standard ones.
  169.  
  170.                                     - Function: purecopy OBJECT
  171.                                         This function makes a copy of
  172.                                         OBJECT in pure storage and
  173.                                         returns it.  It copies strings
  174.                                         by simply making a new string
  175.                                         with the same characters in
  176.                                         pure storage.  It recursively
  177.                                         copies the contents of vectors
  178.                                         and cons cells.  It does not
  179.                                         make copies of symbols, or any
  180.                                         other objects, but just returns
  181.                                         them unchanged.  It signals an
  182.                                         error if asked to copy markers.
  183.  
  184.                                         This function is used only
  185.                                         while Emacs is being built and
  186.                                         dumped; it is called only in
  187.                                         the file
  188.                                         `emacs/lisp/loaddefs.el'.
  189.  
  190.                                     - Variable: pure-bytes-used
  191.                                         The value of this variable is
  192.                                         the number of bytes of pure
  193.                                         storage allocated so far.
  194.                                         Typically, in a dumped Emacs,
  195.                                         this number is very close to
  196.                                         the total amount of pure
  197.                                         storage available--if it were
  198.                                         not, we would preallocate less.
  199.  
  200.                                     - Variable: purify-flag
  201.                                         This variable determines
  202.                                         whether `defun' should make a
  203.                                         copy of the function definition
  204.                                         in pure storage.  If it is
  205.                                         non-`nil', then the function
  206.                                         definition is copied into pure
  207.                                         storage.
  208.  
  209.                                         This flag is `t' while loading
  210.                                         all of the basic functions for
  211.                                         building Emacs initially
  212.                                         (allowing those functions to be
  213.                                         sharable and non-collectible).
  214.                                         It is set to `nil' when Emacs
  215.                                         is saved out as `emacs'.  The
  216.                                         flag is set and reset in the C
  217.                                         sources.
  218.  
  219.                                         You should not change this flag
  220.                                         in a running Emacs.
  221.  
  222. 
  223. File: elisp,  Node: Garbage Collection,  Next: Writing Emacs Primitives,  Prev: Pure Storage,  Up: GNU Emacs Internals
  224.  
  225. Garbage Collection
  226. ==================
  227.  
  228.                                       When a program creates a list or
  229. the user defines a new function (such as by loading a library), then
  230. that data is placed in normal storage.  If normal storage runs low,
  231. then Emacs asks the operating system to allocate more memory in blocks
  232. of 1k bytes.  Each block is used for one type of Lisp object, so
  233. symbols, cons cells, markers, etc. are segregated in distinct blocks in
  234. memory.  (Vectors, buffers and certain other editing types, which are
  235. fairly large, are allocated in individual blocks, one per object, while
  236. strings are packed into blocks of 8k bytes.)
  237.  
  238.                                       It is quite common to use some
  239. storage for a while, then release it by, for example, killing a buffer
  240. or deleting the last pointer to an object.  Emacs provides a "garbage
  241. collector" to reclaim this abandoned storage.  (This name is
  242. traditional, but "garbage recycler" might be a more intuitive metaphor
  243. for this facility.)
  244.  
  245.                                       The garbage collector operates by
  246. scanning all the objects that have been allocated and marking those
  247. that are still accessible to Lisp programs.  To begin with, all the
  248. symbols, their values and associated function definitions, and any data
  249. presently on the stack, are accessible.  Any objects which can be
  250. reached indirectly through other accessible objects are also accessible.
  251.  
  252.                                       When this is finished, all
  253. inaccessible objects are garbage.  No matter what the Lisp program or
  254. the user does, it is impossible to refer to them, since there is no
  255. longer a way to reach them.  Their space might as well be reused, since
  256. no one will notice.  That is what the garbage collector arranges to do.
  257.  
  258.                                       Unused cons cells are chained
  259. together onto a "free list" for future allocation; likewise for symbols
  260. and markers.  The accessible strings are compacted so they are
  261. contiguous in memory; then the rest of the space formerly occupied by
  262. strings is made available to the string creation functions.  Vectors,
  263. buffers, windows and other large objects are individually allocated and
  264. freed using `malloc'.
  265.  
  266.                                         Common Lisp note: unlike other
  267.                                         Lisps, GNU Emacs Lisp does not
  268.                                         call the garbage collector when
  269.                                         the free list is empty.
  270.                                         Instead, it simply requests the
  271.                                         operating system to allocate
  272.                                         more storage, and processing
  273.                                         continues until
  274.                                         `gc-cons-threshold' bytes have
  275.                                         been used.
  276.  
  277.                                         This means that you can make
  278.                                         sure that the garbage collector
  279.                                         will not run during a certain
  280.                                         portion of a Lisp program by
  281.                                         calling the garbage collector
  282.                                         explicitly just before it
  283.                                         (provided that portion of the
  284.                                         program does not use so much
  285.                                         space as to force a second
  286.                                         garbage collection).
  287.  
  288.                                     - Command: garbage-collect
  289.                                         This command runs a garbage
  290.                                         collection, and returns
  291.                                         information on the amount of
  292.                                         space in use.  (Garbage
  293.                                         collection can also occur
  294.                                         spontaneously if you use more
  295.                                         than `gc-cons-threshold' bytes
  296.                                         of Lisp data since the previous
  297.                                         garbage collection.)
  298.  
  299.                                         `garbage-collect' returns a
  300.                                         list containing the following
  301.                                         information:
  302.  
  303.                                              ((USED-CONSES . FREE-CONSES)
  304.                                               (USED-SYMS . FREE-SYMS)
  305.                                               (USED-MARKERS . FREE-MARKERS)
  306.                                               USED-STRING-CHARS
  307.                                               USED-VECTOR-SLOTS
  308.                                               (USED-FLOATS . FREE-FLOATS))
  309.                                              
  310.                                              (garbage-collect)
  311.                                                   => ((3435 . 2332) (1688 . 0) (57 . 417) 24510 3839 (4 . 1))
  312.  
  313.                                         Here is a table explaining each
  314.                                         element:
  315.  
  316.                                        USED-CONSES
  317.                                              The number of cons cells
  318.                                              in use.
  319.  
  320.                                        FREE-CONSES
  321.                                              The number of cons cells
  322.                                              for which space has been
  323.                                              obtained from the
  324.                                              operating system, but that
  325.                                              are not currently being
  326.                                              used.
  327.  
  328.                                        USED-SYMS
  329.                                              The number of symbols in
  330.                                              use.
  331.  
  332.                                        FREE-SYMS
  333.                                              The number of symbols for
  334.                                              which space has been
  335.                                              obtained from the
  336.                                              operating system, but that
  337.                                              are not currently being
  338.                                              used.
  339.  
  340.                                        USED-MARKERS
  341.                                              The number of markers in
  342.                                              use.
  343.  
  344.                                        FREE-MARKERS
  345.                                              The number of markers for
  346.                                              which space has been
  347.                                              obtained from the
  348.                                              operating system, but that
  349.                                              are not currently being
  350.                                              used.
  351.  
  352.                                        USED-STRING-CHARS
  353.                                              The total size of all
  354.                                              strings, in characters.
  355.  
  356.                                        USED-VECTOR-SLOTS
  357.                                              The total number of
  358.                                              elements of existing
  359.                                              vectors.
  360.  
  361.                                        USED-FLOATS
  362.                                              The number of floats in
  363.                                              use.
  364.  
  365.                                        FREE-FLOATS
  366.                                              The number of floats for
  367.                                              which space has been
  368.                                              obtained from the
  369.                                              operating system, but that
  370.                                              are not currently being
  371.                                              used.
  372.  
  373.                                     - User Option: gc-cons-threshold
  374.                                         The value of this variable is
  375.                                         the number of bytes of storage
  376.                                         that must be allocated for Lisp
  377.                                         objects after one garbage
  378.                                         collection in order to request
  379.                                         another garbage collection.  A
  380.                                         cons cell counts as eight bytes,
  381.                                         a string as one byte per
  382.                                         character plus a few bytes of
  383.                                         overhead, and so on.  (Space
  384.                                         allocated to the contents of
  385.                                         buffers does not count.)  Note
  386.                                         that the new garbage collection
  387.                                         does not happen immediately
  388.                                         when the threshold is
  389.                                         exhausted, but only the next
  390.                                         time the Lisp evaluator is
  391.                                         called.
  392.  
  393.                                         The initial threshold value is
  394.                                         100,000.  If you specify a
  395.                                         larger value, garbage
  396.                                         collection will happen less
  397.                                         often.  This reduces the amount
  398.                                         of time spent garbage
  399.                                         collecting, but increases total
  400.                                         memory use.  You may want to do
  401.                                         this when running a program
  402.                                         which creates lots of Lisp data.
  403.  
  404.                                         You can make collections more
  405.                                         frequent by specifying a
  406.                                         smaller value, down to 10,000.
  407.                                         A value less than 10,000 will
  408.                                         remain in effect only until the
  409.                                         subsequent garbage collection,
  410.                                         at which time `garbage-collect'
  411.                                         will set the threshold back to
  412.                                         10,000.
  413.  
  414.                                     - Function: memory-limit
  415.                                         This function returns the
  416.                                         address of the last byte Emacs
  417.                                         has allocated, divided by 1024.
  418.                                         We divide the value by 1024 to
  419.                                         make sure it fits in a Lisp
  420.                                         integer.
  421.  
  422.                                         You can use this to get a
  423.                                         general idea of how your
  424.                                         actions affect the memory usage.
  425.  
  426. 
  427. File: elisp,  Node: Writing Emacs Primitives,  Next: Object Internals,  Prev: Garbage Collection,  Up: GNU Emacs Internals
  428.  
  429. Writing Emacs Primitives
  430. ========================
  431.  
  432.                                       Lisp primitives are Lisp
  433. functions implemented in C.  The details of interfacing the C function
  434. so that Lisp can call it are handled by a few C macros.  The only way
  435. to really understand how to write new C code is to read the source, but
  436. we can explain some things here.
  437.  
  438.                                       An example of a special form is
  439. the definition of `or', from `eval.c'.  (An ordinary function would
  440. have the same general appearance.)
  441.  
  442.                                         DEFUN ("or", For, Sor, 0, UNEVALLED, 0,
  443.                                           "Eval args until one of them yields non-NIL, then return that value.\n\
  444.                                         The remaining args are not evalled at all.\n\
  445.  
  446.                                         If all args return NIL, return NIL.")
  447.                                           (args)
  448.                                              Lisp_Object args;
  449.                                         {
  450.                                           register Lisp_Object val;
  451.                                           Lisp_Object args_left;
  452.                                           struct gcpro gcpro1;
  453.  
  454.                                         if (NULL(args))
  455.                                             return Qnil;
  456.                                         
  457.                                           args_left = args;
  458.                                           GCPRO1 (args_left);
  459.  
  460.                                         do
  461.                                             {
  462.                                               val = Feval (Fcar (args_left));
  463.                                               if (!NULL (val))
  464.                                                 break;
  465.                                               args_left = Fcdr (args_left);
  466.                                             }
  467.                                           while (!NULL(args_left));
  468.  
  469.                                         UNGCPRO;
  470.                                           return val;
  471.                                         }
  472.  
  473.                                       Let's start with a precise
  474. explanation of the arguments to the `DEFUN' macro.  Here are the
  475. general names for them:
  476.  
  477.                                         DEFUN (LNAME, FNAME, SNAME, MIN, MAX, INTERACTIVE, DOC)
  478.  
  479.                                   LNAME
  480.                                         This is the name of the Lisp
  481.                                         symbol to define with this
  482.                                         function; in the example above,
  483.                                         it is `or'.
  484.  
  485.                                   FNAME
  486.                                         This is the C function name for
  487.                                         this function.  This is the
  488.                                         name that is used in C code for
  489.                                         calling the function.  The name
  490.                                         is, by convention, `F'
  491.                                         prepended to the Lisp name,
  492.                                         with all dashes (`-') in the
  493.                                         Lisp name changed to
  494.                                         underscores.  Thus, to call this
  495.                                         function from C code, call
  496.                                         `For'.  Remember that the
  497.                                         arguments must be of type
  498.                                         `Lisp_Object'; various macros
  499.                                         and functions for creating
  500.                                         values of type `Lisp_Object'
  501.                                         are declared in the file
  502.                                         `lisp.h'.
  503.  
  504.                                   SNAME
  505.                                         This is a C variable name to
  506.                                         use for a structure that holds
  507.                                         the data for the subr object
  508.                                         that represents the function in
  509.                                         Lisp.  This structure conveys
  510.                                         the Lisp symbol name to the
  511.                                         initialization routine that will
  512.                                         create the symbol and store the
  513.                                         subr object as its definition.
  514.                                         By convention, this name is
  515.                                         always FNAME with `F' replaced
  516.                                         with `S'.
  517.  
  518.                                   MIN
  519.                                         This is the minimum number of
  520.                                         arguments that the function
  521.                                         requires.  For `or', no
  522.                                         arguments are required.
  523.  
  524.                                   MAX
  525.                                         This is the maximum number of
  526.                                         arguments that the function
  527.                                         accepts.  Alternatively, it can
  528.                                         be `UNEVALLED', indicating a
  529.                                         special form that receives
  530.                                         unevaluated arguments.  A
  531.                                         function with the equivalent of
  532.                                         an `&rest' argument would have
  533.                                         `MANY' in this position.  Both
  534.                                         `UNEVALLED' and `MANY' are
  535.                                         macros.  This argument must be
  536.                                         one of these macros or a number
  537.                                         at least as large as MIN.  It
  538.                                         may not be greater than six.
  539.  
  540.                                   INTERACTIVE
  541.                                         This is an interactive
  542.                                         specification, a string such as
  543.                                         might be used as the argument
  544.                                         of `interactive' in a Lisp
  545.                                         function.  In the case of `or',
  546.                                         it is 0 (a null pointer),
  547.                                         indicating that `or' cannot be
  548.                                         called interactively.  A value
  549.                                         of `""' indicates an interactive
  550.                                         function taking no arguments.
  551.  
  552.                                   DOC
  553.                                         This is the documentation
  554.                                         string.  It is written just
  555.                                         like a documentation string for
  556.                                         a function defined in Lisp,
  557.                                         except you must write `\n\' at
  558.                                         the end of each line.  In
  559.                                         particular, the first line
  560.                                         should be a single sentence.
  561.  
  562.                                       After the call to the `DEFUN'
  563. macro, you must write the list of argument names that every C function
  564. must have, followed by ordinary C declarations for them.  Normally, all
  565. the arguments must be declared as `Lisp_Object'.  If the function has
  566. no upper limit on the number of arguments in Lisp, then in C it
  567. receives two arguments: the number of Lisp arguments, and the address
  568. of a block containing their values.  These have types `int' and
  569. `Lisp_Object *'.
  570.  
  571.                                       Within the function `For' itself,
  572. note the use of the macros `GCPRO1' and `UNGCPRO'.  `GCPRO1' is used to
  573. "protect" a variable from garbage collection--to inform the garbage
  574. collector that it must look in that variable and regard its contents as
  575. an accessible object.  This is necessary whenever you call `Feval' or
  576. anything that can directly or indirectly call `Feval'.  At such a time,
  577. any Lisp object that you intend to refer to again must be protected
  578. somehow.  `UNGCPRO' cancels the protection of the variables that are
  579. protected in the current function.  It is necessary to do this
  580. explicitly.
  581.  
  582.                                       For most data types, it suffices
  583. to know that one pointer to the object is protected; as long as the
  584. object is not recycled, all pointers to it remain valid.  This is not
  585. so for strings, because the garbage collector can move them.  When a
  586. string is moved, any pointers to it that the garbage collector does not
  587. know about will not be properly relocated.  Therefore, all pointers to
  588. strings must be protected across any point where garbage collection may
  589. be possible.
  590.  
  591.                                       The macro `GCPRO1' protects just
  592. one local variable.  If you want to protect two, use `GCPRO2' instead;
  593. repeating `GCPRO1' will not work.  There are also `GCPRO3' and `GCPRO4'.
  594.  
  595.                                       In addition to using these
  596. macros, you must declare the local variables such as `gcpro1' which
  597. they implicitly use.  If you protect two variables, with `GCPRO2', you
  598. must declare `gcpro1' and `gcpro2', as it uses them both.  Alas, we
  599. can't explain all the tricky details here.
  600.  
  601.                                       Defining the C function is not
  602. enough; you must also create the Lisp symbol for the primitive and
  603. store a suitable subr object in its function cell.  This is done by
  604. adding code to an initialization routine.  The code looks like this:
  605.  
  606.                                         defsubr (&SUBR-STRUCTURE-NAME);
  607.  
  608.                                    SUBR-STRUCTURE-NAME is the name you
  609. used as the third argument to `DEFUN'.
  610.  
  611.                                       If you are adding a primitive to
  612. a file that already has Lisp primitives defined in it, find the
  613. function (near the end of the file) named `syms_of_SOMETHING', and add
  614. that function call to it.  If the file doesn't have this function, or
  615. if you create a new file, add to it a `syms_of_FILENAME' (e.g.,
  616. `syms_of_myfile').  Then find the spot in `emacs.c' where all of these
  617. functions are called, and add a call to `syms_of_FILENAME' there.
  618.  
  619.                                       This function `syms_of_FILENAME'
  620. is also the place to define any C variables which are to be visible as
  621. Lisp variables.  `DEFVAR_LISP' is used to make a C variable of type
  622. `Lisp_Object' visible in Lisp.  `DEFVAR_INT' is used to make a C
  623. variable of type `int' visible in Lisp with a value that is an integer.
  624.  
  625.                                       Here is another function, with
  626. more complicated arguments.  This comes from the code for the X Window
  627. System, and it demonstrates the use of macros and functions to
  628. manipulate Lisp objects.
  629.  
  630.                                         DEFUN ("coordinates-in-window-p", Fcoordinates_in_window_p,
  631.                                           Scoordinates_in_window_p, 2, 2,
  632.                                           "xSpecify coordinate pair: \nXExpression which evals to window: ",
  633.                                           "Return non-nil if POSITIONS is in WINDOW.\n\
  634.                                           \(POSITIONS is a list, (SCREEN-X SCREEN-Y)\)\n\
  635.  
  636.                                         Returned value is list of positions expressed\n\
  637.                                           relative to window upper left corner.")
  638.                                           (coordinate, window)
  639.                                              register Lisp_Object coordinate, window;
  640.                                         {
  641.                                           register Lisp_Object xcoord, ycoord;
  642.  
  643.                                         if (!CONSP (coordinate)) wrong_type_argument (Qlistp, coordinate);
  644.                                           CHECK_WINDOW (window, 2);
  645.                                           xcoord = Fcar (coordinate);
  646.                                           ycoord = Fcar (Fcdr (coordinate));
  647.                                           CHECK_NUMBER (xcoord, 0);
  648.                                           CHECK_NUMBER (ycoord, 1);
  649.  
  650.                                         if ((XINT (xcoord) < XINT (XWINDOW (window)->left))
  651.                                               || (XINT (xcoord) >= (XINT (XWINDOW (window)->left)
  652.                                                                     + XINT (XWINDOW (window)->width))))
  653.                                             {
  654.                                               return Qnil;
  655.                                             }
  656.                                           XFASTINT (xcoord) -= XFASTINT (XWINDOW (window)->left);
  657.  
  658.                                         if (XINT (ycoord) == (screen_height - 1))
  659.                                             return Qnil;
  660.  
  661.                                         if ((XINT (ycoord) < XINT (XWINDOW (window)->top))
  662.                                               || (XINT (ycoord) >= (XINT (XWINDOW (window)->top)
  663.                                                                     + XINT (XWINDOW (window)->height)) - 1))
  664.                                             {
  665.                                               return Qnil;
  666.                                             }
  667.  
  668.                                         XFASTINT (ycoord) -= XFASTINT (XWINDOW (window)->top);
  669.                                           return (Fcons (xcoord, Fcons (ycoord, Qnil)));
  670.                                         }
  671.  
  672.                                       Note that you cannot directly
  673. call functions defined in Lisp as, for example, the primitive function
  674. `Fcons' is called above.  You must create the appropriate Lisp form,
  675. protect everything from garbage collection, and `Feval' the form, as
  676. was done in `For' above.
  677.  
  678.                                       `eval.c' is a very good file to
  679. look through for examples; `lisp.h' contains the definitions for some
  680. important macros and functions.
  681.  
  682. 
  683. File: elisp,  Node: Object Internals,  Prev: Writing Emacs Primitives,  Up: GNU Emacs Internals
  684.  
  685. Object Internals
  686. ================
  687.  
  688.                                       GNU Emacs Lisp manipulates many
  689. different types of data.  The actual data are stored in a heap and the
  690. only access that programs have to it is through pointers.  Pointers are
  691. thirty-two bits wide in most implementations.  Depending on the
  692. operating system and type of machine for which you compile Emacs,
  693. twenty-four to twenty-six bits are used to address the object, and the
  694. remaining six to eight bits are used for a tag that identifies the
  695. object's type.
  696.  
  697.                                       Because all access to data is
  698. through tagged pointers, it is always possible to determine the type of
  699. any object.  This allows variables to be untyped, and the values
  700. assigned to them to be changed without regard to type.  Function
  701. arguments also can be of any type; if you want a function to accept
  702. only a certain type of argument, you must check the type explicitly
  703. using a suitable predicate (*note Type Predicates::.).
  704.  
  705.                                    * Menu:
  706.                                    
  707.                                    * Buffer Internals::    Components of a buffer structure.
  708.                                    * Window Internals::    Components of a window structure.
  709.                                    * Process Internals::   Components of a process structure.
  710.  
  711. 
  712. File: elisp,  Node: Buffer Internals,  Next: Window Internals,  Prev: Object Internals,  Up: Object Internals
  713.  
  714. Buffer Internals
  715. ----------------
  716.  
  717.                                       Buffers contain fields not
  718. directly accessible by the Lisp programmer.  We describe them here,
  719. naming them by the names used in the C code.  Many are accessible
  720. indirectly in Lisp programs via Lisp primitives.
  721.  
  722.                                   `name'
  723.                                         The buffer name is a string
  724.                                         which names the buffer.  It is
  725.                                         guaranteed to be unique.  *Note
  726.                                         Buffer Names::.
  727.  
  728.                                   `save_modified'
  729.                                         This field contains the time
  730.                                         when the buffer was last saved,
  731.                                         as an integer.  *Note Buffer
  732.                                         Modification::.
  733.  
  734.                                   `modtime'
  735.                                         This field contains the
  736.                                         modification time of the
  737.                                         visited file.  It is set when
  738.                                         the file is written or read.
  739.                                         Every time the buffer is written
  740.                                         to the file, this field is
  741.                                         compared to the modification
  742.                                         time of the file.  *Note Buffer
  743.                                         Modification::.
  744.  
  745.                                   `auto_save_modified'
  746.                                         This field contains the time
  747.                                         when the buffer was last
  748.                                         auto-saved.
  749.  
  750.                                   `last_window_start'
  751.                                         This field contains the
  752.                                         `window-start' position in the
  753.                                         buffer as of the last time the
  754.                                         buffer was displayed in a
  755.                                         window.
  756.  
  757.                                   `undodata'
  758.                                         This field points to the
  759.                                         buffer's undo stack.  *Note
  760.                                         Undo::.
  761.  
  762.                                   `syntax_table_v'
  763.                                         This field contains the syntax
  764.                                         table for the buffer.  *Note
  765.                                         Syntax Tables::.
  766.  
  767.                                   `downcase_table'
  768.                                         This field contains the
  769.                                         conversion table for converting
  770.                                         text to lower case.  *Note Case
  771.                                         Table::.
  772.  
  773.                                   `upcase_table'
  774.                                         This field contains the
  775.                                         conversion table for converting
  776.                                         text to upper case.  *Note Case
  777.                                         Table::.
  778.  
  779.                                   `case_canon_table'
  780.                                         This field contains the
  781.                                         conversion table for
  782.                                         canonicalizing text for
  783.                                         case-folding search.  *Note
  784.                                         Case Table::.
  785.  
  786.                                   `case_eqv_table'
  787.                                         This field contains the
  788.                                         equivalence table for
  789.                                         case-folding search.  *Note
  790.                                         Case Table::.
  791.  
  792.                                   `display_table'
  793.                                         This field contains the
  794.                                         buffer's display table, or
  795.                                         `nil' if it doesn't have one.
  796.                                         *Note Display Tables::.
  797.  
  798.                                   `markers'
  799.                                         This field contains the chain
  800.                                         of all markers that point into
  801.                                         the buffer.  At each deletion
  802.                                         or motion of the buffer gap,
  803.                                         all of these markers must be
  804.                                         checked and perhaps updated.
  805.                                         *Note Markers::.
  806.  
  807.                                   `backed_up'
  808.                                         This field is a flag which
  809.                                         tells whether a backup file has
  810.                                         been made for the visited file
  811.                                         of this buffer.
  812.  
  813.                                   `mark'
  814.                                         This field contains the mark
  815.                                         for the buffer.  The mark is a
  816.                                         marker, hence it is also
  817.                                         included on the list `markers'.
  818.                                         *Note The Mark::.
  819.  
  820.                                   `local_var_alist'
  821.                                         This field contains the
  822.                                         association list containing all
  823.                                         of the variables local in this
  824.                                         buffer, and their values.  The
  825.                                         function
  826.                                         `buffer-local-variables'
  827.                                         returns a copy of this list.
  828.                                         *Note Buffer-Local Variables::.
  829.  
  830.                                   `mode_line_format'
  831.                                         This field contains a Lisp
  832.                                         object which controls how to
  833.                                         display the mode line for this
  834.                                         buffer.  *Note Mode Line
  835.                                         Format::.
  836.  
  837. 
  838. File: elisp,  Node: Window Internals,  Next: Process Internals,  Prev: Buffer Internals,  Up: Object Internals
  839.  
  840. Window Internals
  841. ----------------
  842.  
  843.                                       Windows have the following
  844. accessible fields:
  845.  
  846.                                   `frame'
  847.                                         The frame that this window is
  848.                                         on.
  849.  
  850.                                   `mini_p'
  851.                                         Non-`nil' if this window is a
  852.                                         minibuffer window.
  853.  
  854.                                   `height'
  855.                                         The height of the window,
  856.                                         measured in lines.
  857.  
  858.                                   `width'
  859.                                         The width of the window,
  860.                                         measured in columns.
  861.  
  862.                                   `buffer'
  863.                                         The buffer which the window is
  864.                                         displaying.  This may change
  865.                                         often during the life of the
  866.                                         window.
  867.  
  868.                                   `dedicated'
  869.                                         Non-`nil' if this window is
  870.                                         dedicated to its buffer.
  871.  
  872.                                   `start'
  873.                                         The position in the buffer
  874.                                         which is the first character to
  875.                                         be displayed in the window.
  876.  
  877.                                   `pointm'
  878.                                         This is the value of point in
  879.                                         the current buffer when this
  880.                                         window is selected; when it is
  881.                                         not selected, it retains its
  882.                                         previous value.
  883.  
  884.                                   `left'
  885.                                         This is the left-hand edge of
  886.                                         the window, measured in
  887.                                         columns.  (The leftmost column
  888.                                         on the screen is column 0.)
  889.  
  890.                                   `top'
  891.                                         This is the top edge of the
  892.                                         window, measured in lines.
  893.                                         (The top line on the screen is
  894.                                         line 0.)
  895.  
  896.                                   `next'
  897.                                         This is the window that is the
  898.                                         next in the chain of siblings.
  899.  
  900.                                   `prev'
  901.                                         This is the window that is the
  902.                                         previous in the chain of
  903.                                         siblings.
  904.  
  905.                                   `force_start'
  906.                                         This is a flag which, if
  907.                                         non-`nil', says that the window
  908.                                         has been scrolled explicitly by
  909.                                         the Lisp program.  At the next
  910.                                         redisplay, if point is off the
  911.                                         screen, instead of scrolling
  912.                                         the window to show the text
  913.                                         around point, point will be
  914.                                         moved to a location that is on
  915.                                         the screen.
  916.  
  917.                                   `hscroll'
  918.                                         This is the number of columns
  919.                                         that the display in the window
  920.                                         is scrolled horizontally to the
  921.                                         left.  Normally, this is 0.
  922.  
  923.                                   `use_time'
  924.                                         This is the last time that the
  925.                                         window was selected.  The
  926.                                         function `get-lru-window' uses
  927.                                         this field.
  928.  
  929.                                   `display_table'
  930.                                         The window's display table, or
  931.                                         `nil' if none is specified for
  932.                                         it.
  933.  
  934.