Mercurial > hg > xemacs-beta
comparison man/internals/internals.texi @ 116:9f59509498e1 r20-1b10
Import from CVS: tag r20-1b10
author | cvs |
---|---|
date | Mon, 13 Aug 2007 09:23:06 +0200 |
parents | 48d667d6f17f |
children | cca96a509cfe |
comparison
equal
deleted
inserted
replaced
115:f109f7dabbe2 | 116:9f59509498e1 |
---|---|
5 @c %**end of header | 5 @c %**end of header |
6 | 6 |
7 @ifinfo | 7 @ifinfo |
8 | 8 |
9 Copyright @copyright{} 1992 - 1996 Ben Wing. | 9 Copyright @copyright{} 1992 - 1996 Ben Wing. |
10 Copyright @copyright{} 1996 Sun Microsystems. | 10 Copyright @copyright{} 1996, 1997 Sun Microsystems. |
11 Copyright @copyright{} 1994, 1995 Free Software Foundation. | 11 Copyright @copyright{} 1994, 1995 Free Software Foundation. |
12 Copyright @copyright{} 1994, 1995 Board of Trustees, University of Illinois. | 12 Copyright @copyright{} 1994, 1995 Board of Trustees, University of Illinois. |
13 | 13 |
14 | 14 |
15 Permission is granted to make and distribute verbatim copies of this | 15 Permission is granted to make and distribute verbatim copies of this |
57 @setchapternewpage odd | 57 @setchapternewpage odd |
58 @finalout | 58 @finalout |
59 | 59 |
60 @titlepage | 60 @titlepage |
61 @title XEmacs Internals Manual | 61 @title XEmacs Internals Manual |
62 @subtitle Version 1.0, March 1996 | 62 @subtitle Version 1.1, March 1997 |
63 | 63 |
64 @author Ben Wing | 64 @author Ben Wing |
65 @author Martin Buchholz | |
65 @page | 66 @page |
66 @vskip 0pt plus 1fill | 67 @vskip 0pt plus 1fill |
67 | 68 |
68 @noindent | 69 @noindent |
69 Copyright @copyright{} 1992 - 1996 Ben Wing. @* | 70 Copyright @copyright{} 1992 - 1996 Ben Wing. @* |
70 Copyright @copyright{} 1996 Sun Microsystems, Inc. @* | 71 Copyright @copyright{} 1996 Sun Microsystems, Inc. @* |
71 Copyright @copyright{} 1994 Free Software Foundation. @* | 72 Copyright @copyright{} 1994 Free Software Foundation. @* |
72 Copyright @copyright{} 1994, 1995 Board of Trustees, University of Illinois. | 73 Copyright @copyright{} 1994, 1995 Board of Trustees, University of Illinois. |
73 | 74 |
74 @sp 2 | 75 @sp 2 |
75 Version 1.0 @* | 76 Version 1.1 @* |
76 March, 1996.@* | 77 March, 1997.@* |
77 | 78 |
78 Permission is granted to make and distribute verbatim copies of this | 79 Permission is granted to make and distribute verbatim copies of this |
79 manual provided the copyright notice and this permission notice are | 80 manual provided the copyright notice and this permission notice are |
80 preserved on all copies. | 81 preserved on all copies. |
81 | 82 |
868 | 869 |
869 XEmacs also contains a great deal of Lisp code. This implements the | 870 XEmacs also contains a great deal of Lisp code. This implements the |
870 operations that make XEmacs useful as an editor as well as just a | 871 operations that make XEmacs useful as an editor as well as just a |
871 Lisp environment, and also contains many add-on packages that allow | 872 Lisp environment, and also contains many add-on packages that allow |
872 XEmacs to browse directories, act as a mail and Usenet news reader, | 873 XEmacs to browse directories, act as a mail and Usenet news reader, |
873 compile Lisp code, etc. There is actually a lot more Lisp code than | 874 compile Lisp code, etc. There is actually more Lisp code than |
874 C code associated with XEmacs, but much of the Lisp code is | 875 C code associated with XEmacs, but much of the Lisp code is |
875 peripheral to the actual operation of the editor. The Lisp code | 876 peripheral to the actual operation of the editor. The Lisp code |
876 all lies in subdirectories underneath the @file{lisp/} directory. | 877 all lies in subdirectories underneath the @file{lisp/} directory. |
877 | 878 |
878 The @file{lwlib/} directory contains C code that implements a | 879 The @file{lwlib/} directory contains C code that implements a |
887 | 888 |
888 The @file{lib-src/} directory contains C code for various auxiliary | 889 The @file{lib-src/} directory contains C code for various auxiliary |
889 programs that are used in connection with XEmacs. Some of them are used | 890 programs that are used in connection with XEmacs. Some of them are used |
890 during the build process; others are used to perform certain functions | 891 during the build process; others are used to perform certain functions |
891 that cannot conveniently be placed in the XEmacs executable (e.g. the | 892 that cannot conveniently be placed in the XEmacs executable (e.g. the |
892 @file{movemail} program for fetching mail out of /var/spool/mail, which | 893 @file{movemail} program for fetching mail out of @file{/var/spool/mail}, |
893 must be setgid to @file{mail} on many systems; and the 'gnuclient' | 894 which must be setgid to @file{mail} on many systems; and the |
894 program, which allows an external script to communicate with a running | 895 @file{gnuclient} program, which allows an external script to communicate |
895 XEmacs process). | 896 with a running XEmacs process). |
896 | 897 |
897 The @file{man/} directory contains the sources for the XEmacs | 898 The @file{man/} directory contains the sources for the XEmacs |
898 documentation. It is mostly in a form called Texinfo, which can be | 899 documentation. It is mostly in a form called Texinfo, which can be |
899 converted into either a printed document (by passing it through TeX) or | 900 converted into either a printed document (by passing it through @TeX{}) |
900 into on-line documentation called @dfn{info files}. | 901 or into on-line documentation called @dfn{info files}. |
901 | 902 |
902 The @file{info/} directory contains the results of formatting the | 903 The @file{info/} directory contains the results of formatting the |
903 XEmacs documentation as @dfn{info files}, for on-line use. These files | 904 XEmacs documentation as @dfn{info files}, for on-line use. These files |
904 are used when you enter the Info system using @kbd{C-h i} or through the | 905 are used when you enter the Info system using @kbd{C-h i} or through the |
905 Help menu. | 906 Help menu. |
938 windows on the screen, and if you simply run it, it will exit | 939 windows on the screen, and if you simply run it, it will exit |
939 immediately. The Makefile runs @file{temacs} with certain options that | 940 immediately. The Makefile runs @file{temacs} with certain options that |
940 cause it to initialize itself, read in a number of basic Lisp files, and | 941 cause it to initialize itself, read in a number of basic Lisp files, and |
941 then dump itself out into a new executable called @file{xemacs}. This | 942 then dump itself out into a new executable called @file{xemacs}. This |
942 new executable has been pre-initialized and contains pre-digested Lisp | 943 new executable has been pre-initialized and contains pre-digested Lisp |
943 code that is necessary for the editor to function (this includes some | 944 code that is necessary for the editor to function (this includes most |
944 extremely basic Lisp functions, e.g. @code{not}, that can be defined in | 945 basic Lisp functions, e.g. @code{not}, that can be defined in terms of |
945 terms of other Lisp primitives; some initialization code that is called | 946 other Lisp primitives; some initialization code that is called when |
946 when certain objects, such as frames, are created; and all of the | 947 certain objects, such as frames, are created; and all of the standard |
947 standard keybindings and code for the actions they result in). This | 948 keybindings and code for the actions they result in). This executable, |
948 executable, @file{xemacs}, is the executable that you run to use the | 949 @file{xemacs}, is the executable that you run to use the XEmacs editor. |
949 XEmacs editor. | |
950 | 950 |
951 @node XEmacs From the Inside, The XEmacs Object System (Abstractly Speaking), XEmacs From the Perspective of Building, Top | 951 @node XEmacs From the Inside, The XEmacs Object System (Abstractly Speaking), XEmacs From the Perspective of Building, Top |
952 @chapter XEmacs From the Inside | 952 @chapter XEmacs From the Inside |
953 | 953 |
954 Internally, XEmacs is quite complex, and can be very confusing. To | 954 Internally, XEmacs is quite complex, and can be very confusing. To |
955 simplify things, it can be useful to think of XEmacs as containing an | 955 simplify things, it can be useful to think of XEmacs as containing an |
956 event loop that ``drives'' everything, and a number of other subsystems, | 956 event loop that ``drives'' everything, and a number of other subsystems, |
957 such as a Lisp engine and a redisplay mechanism. Each of these others | 957 such as a Lisp engine and a redisplay mechanism. Each of these other |
958 subsystems exists simultaneously in XEmacs, and each has a certain | 958 subsystems exists simultaneously in XEmacs, and each has a certain |
959 state. The flow of control continually passes in and out of these | 959 state. The flow of control continually passes in and out of these |
960 different subsystems in the course of normal operation of the editor. | 960 different subsystems in the course of normal operation of the editor. |
961 | 961 |
962 It is important to keep in mind that, most of the time, the editor is | 962 It is important to keep in mind that, most of the time, the editor is |
984 | 984 |
985 @item | 985 @item |
986 The buffer mechanism is responsible for keeping track of what buffers | 986 The buffer mechanism is responsible for keeping track of what buffers |
987 exist and what text is in them. It is periodically given commands | 987 exist and what text is in them. It is periodically given commands |
988 (usually from the user) to insert or delete text, create a buffer, etc. | 988 (usually from the user) to insert or delete text, create a buffer, etc. |
989 When it receives a textual-change command, it tells the redisplay | 989 When it receives a text-change command, it notifies the redisplay |
990 mechanism about this. | 990 mechanism. |
991 | 991 |
992 @item | 992 @item |
993 The redisplay mechanism is responsible for making sure that windows and | 993 The redisplay mechanism is responsible for making sure that windows and |
994 frames are displayed correctly. It is periodically told (by the event | 994 frames are displayed correctly. It is periodically told (by the event |
995 loop) to actually ``do its job'', i.e. snoop around and see what the | 995 loop) to actually ``do its job'', i.e. snoop around and see what the |
1181 these types of objects.) | 1181 these types of objects.) |
1182 | 1182 |
1183 XEmacs Lisp also contains numerous specialized objects used to | 1183 XEmacs Lisp also contains numerous specialized objects used to |
1184 implement the editor: | 1184 implement the editor: |
1185 | 1185 |
1186 @table @asis | 1186 @table @code |
1187 @item buffer | 1187 @item buffer |
1188 Stores text like a string, but is optimized for insertion and deletion | 1188 Stores text like a string, but is optimized for insertion and deletion |
1189 and has certain other properties that can be set. | 1189 and has certain other properties that can be set. |
1190 @item frame | 1190 @item frame |
1191 An object with various properties whose displayable representation is a | 1191 An object with various properties whose displayable representation is a |
1230 An object that describes a connection to an externally-running process. | 1230 An object that describes a connection to an externally-running process. |
1231 @end table | 1231 @end table |
1232 | 1232 |
1233 There are some other, less-commonly-encountered general objects: | 1233 There are some other, less-commonly-encountered general objects: |
1234 | 1234 |
1235 @table @asis | 1235 @table @code |
1236 @item hashtable | 1236 @item hashtable |
1237 An object that maps from an arbitrary Lisp object to another arbitrary | 1237 An object that maps from an arbitrary Lisp object to another arbitrary |
1238 Lisp object, using hashing for fast lookup. | 1238 Lisp object, using hashing for fast lookup. |
1239 @item obarray | 1239 @item obarray |
1240 A limited form of hashtable that maps from strings to symbols; obarrays | 1240 A limited form of hashtable that maps from strings to symbols; obarrays |
1254 An object that maps from ranges of integers to arbitrary Lisp objects. | 1254 An object that maps from ranges of integers to arbitrary Lisp objects. |
1255 @end table | 1255 @end table |
1256 | 1256 |
1257 And some strange special-purpose objects: | 1257 And some strange special-purpose objects: |
1258 | 1258 |
1259 @table @asis | 1259 @table @code |
1260 @item charset | 1260 @item charset |
1261 @itemx coding-system | 1261 @itemx coding-system |
1262 Objects used when MULE, or multi-lingual/Asian-language, support is | 1262 Objects used when MULE, or multi-lingual/Asian-language, support is |
1263 enabled. | 1263 enabled. |
1264 @item color-instance | 1264 @item color-instance |
1368 @example | 1368 @example |
1369 ?^[$(B#&^[(B | 1369 ?^[$(B#&^[(B |
1370 @end example | 1370 @end example |
1371 | 1371 |
1372 (where @samp{^[} actually is an @samp{ESC} character) converts to a | 1372 (where @samp{^[} actually is an @samp{ESC} character) converts to a |
1373 particular Kanji character. (To decode this gook: @samp{ESC} begins an | 1373 particular Kanji character when using an ISO2022-based coding system for |
1374 escape sequence; @samp{ESC $ (} is a class of escape sequences meaning | 1374 input. (To decode this gook: @samp{ESC} begins an escape sequence; |
1375 ``switch to a 94x94 character set''; @samp{ESC $ ( B} means ``switch to | 1375 @samp{ESC $ (} is a class of escape sequences meaning ``switch to a |
1376 Japanese Kanji''; @samp{#} and @samp{&} collectively index into a | 1376 94x94 character set''; @samp{ESC $ ( B} means ``switch to Japanese |
1377 94-by-94 array of characters [subtract 33 from the ASCII value of each | 1377 Kanji''; @samp{#} and @samp{&} collectively index into a 94-by-94 array |
1378 character to get the corresponding index]; @samp{ESC (} is a class of | 1378 of characters [subtract 33 from the ASCII value of each character to get |
1379 escape sequences meaning ``switch to a 94 character set''; @samp{ESC (B} | 1379 the corresponding index]; @samp{ESC (} is a class of escape sequences |
1380 means ``switch to US ASCII''. It is a coincidence that the letter | 1380 meaning ``switch to a 94 character set''; @samp{ESC (B} means ``switch |
1381 @samp{B} is used to denote both Japanese Kanji and US ASCII. If the | 1381 to US ASCII''. It is a coincidence that the letter @samp{B} is used to |
1382 first @samp{B} were replaced with an @samp{A}, you'd be requesting a | 1382 denote both Japanese Kanji and US ASCII. If the first @samp{B} were |
1383 Chinese Hanzi character from the GB2312 character set.) | 1383 replaced with an @samp{A}, you'd be requesting a Chinese Hanzi character |
1384 from the GB2312 character set.) | |
1384 | 1385 |
1385 @example | 1386 @example |
1386 "foobar" | 1387 "foobar" |
1387 @end example | 1388 @end example |
1388 | 1389 |
1511 opposite semantics? ``Hysterical reasons'', of course.) | 1512 opposite semantics? ``Hysterical reasons'', of course.) |
1512 | 1513 |
1513 @cindex record type | 1514 @cindex record type |
1514 Note that there are only eight types that the tag can represent, | 1515 Note that there are only eight types that the tag can represent, |
1515 but many more actual types than this. This is handled by having | 1516 but many more actual types than this. This is handled by having |
1516 one of the tag types specify a meta-object called a @dfn{record}; | 1517 one of the tag types specify a meta-type called a @dfn{record}; |
1517 for all such objects, the first four bytes of the pointed-to | 1518 for all such objects, the first four bytes of the pointed-to |
1518 structure indicate what the actual type is. | 1519 structure indicate what the actual type is. |
1519 | 1520 |
1520 Note also that having 28 bits for pointers and integers restricts a | 1521 Note also that having 28 bits for pointers and integers restricts a |
1521 lot of things to 256 megabytes of memory. (Basically, enough pointers | 1522 lot of things to 256 megabytes of memory. (Basically, enough pointers |
1535 (e.g. beginning at 0x80000000). Those machines cope by defining | 1536 (e.g. beginning at 0x80000000). Those machines cope by defining |
1536 @code{DATA_SEG_BITS} in the corresponding @file{m/} or @file{s/} file to | 1537 @code{DATA_SEG_BITS} in the corresponding @file{m/} or @file{s/} file to |
1537 the proper mask. Then, pointers retrieved from Lisp objects are | 1538 the proper mask. Then, pointers retrieved from Lisp objects are |
1538 automatically OR'ed with this value prior to being used. | 1539 automatically OR'ed with this value prior to being used. |
1539 | 1540 |
1540 A corollary of the previous paragraph is that @strong{stack-allocated | 1541 A corollary of the previous paragraph is that @strong{(pointers to) |
1541 structures cannot be put into Lisp objects}. The stack is generally | 1542 stack-allocated structures cannot be put into Lisp objects}. The stack |
1542 located near the top of memory; if you put such a pointer into a Lisp | 1543 is generally located near the top of memory; if you put such a pointer |
1543 object, it will get its top bits chopped off, and you will lose. | 1544 into a Lisp object, it will get its top bits chopped off, and you will |
1545 lose. | |
1544 | 1546 |
1545 Various macros are used to construct Lisp objects and extract the | 1547 Various macros are used to construct Lisp objects and extract the |
1546 components. Macros of the form @code{XINT()}, @code{XCHAR()}, | 1548 components. Macros of the form @code{XINT()}, @code{XCHAR()}, |
1547 @code{XSTRING()}, @code{XSYMBOL()}, etc. mask out the pointer/integer | 1549 @code{XSTRING()}, @code{XSYMBOL()}, etc. mask out the pointer/integer |
1548 field and cast it to the appropriate type. All of the macros that | 1550 field and cast it to the appropriate type. All of the macros that |
1563 object is really of the correct type. This is great for catching places | 1565 object is really of the correct type. This is great for catching places |
1564 where an incorrect type is being dereferenced -- this typically results | 1566 where an incorrect type is being dereferenced -- this typically results |
1565 in a pointer being dereferenced as the wrong type of structure, with | 1567 in a pointer being dereferenced as the wrong type of structure, with |
1566 unpredictable (and sometimes not easily traceable) results. | 1568 unpredictable (and sometimes not easily traceable) results. |
1567 | 1569 |
1568 There are similar @code{XSET()} macros that construct a Lisp object. | 1570 There are similar @code{XSET@var{TYPE}()} macros that construct a Lisp object. |
1569 These macros are of the form @code{XSET (@var{lvalue}, @var{result})}, | 1571 These macros are of the form @code{XSET@var{TYPE} (@var{lvalue}, @var{result})}, |
1570 i.e. they have to be a statement rather than just used in an expression. | 1572 i.e. they have to be a statement rather than just used in an expression. |
1571 The reason for this is that standard C doesn't let you ``construct'' a | 1573 The reason for this is that standard C doesn't let you ``construct'' a |
1572 structure (but GCC does). Granted, this sometimes isn't too convenient; | 1574 structure (but GCC does). Granted, this sometimes isn't too convenient; |
1573 for the case of integers, at least, you can use the function | 1575 for the case of integers, at least, you can use the function |
1574 @code{make_number()}, which constructs and @emph{returns} an integer | 1576 @code{make_number()}, which constructs and @emph{returns} an integer |
1575 Lisp object. Note that the @code{XSET()} macros are also affected by | 1577 Lisp object. Note that the @code{XSET@var{TYPE}()} macros are also |
1576 @code{ERROR_CHECK_TYPECHECK} and make sure that the structure is of the right | 1578 affected by @code{ERROR_CHECK_TYPECHECK} and make sure that the |
1577 type in the case of record types, where the type is contained in | 1579 structure is of the right type in the case of record types, where the |
1578 the structure. | 1580 type is contained in the structure. |
1579 | 1581 |
1580 @node Rules When Writing New C Code, A Summary of the Various XEmacs Modules, How Lisp Objects Are Represented in C, Top | 1582 @node Rules When Writing New C Code, A Summary of the Various XEmacs Modules, How Lisp Objects Are Represented in C, Top |
1581 @chapter Rules When Writing New C Code | 1583 @chapter Rules When Writing New C Code |
1582 | 1584 |
1583 The XEmacs C Code is extremely complex and intricate, and there are | 1585 The XEmacs C Code is extremely complex and intricate, and there are |
1601 @code{vars_of_*()} function. The former declares any Lisp primitives | 1603 @code{vars_of_*()} function. The former declares any Lisp primitives |
1602 you have defined and defines any symbols you will be using. The latter | 1604 you have defined and defines any symbols you will be using. The latter |
1603 declares any global Lisp variables you have added and initializes global | 1605 declares any global Lisp variables you have added and initializes global |
1604 C variables in the module. For each such function, declare it in | 1606 C variables in the module. For each such function, declare it in |
1605 @file{symsinit.h} and make sure it's called in the appropriate place in | 1607 @file{symsinit.h} and make sure it's called in the appropriate place in |
1606 @code{main()}. @strong{Important}: There are stringent requirements on | 1608 @file{emacs.c}. @strong{Important}: There are stringent requirements on |
1607 exactly what can go into these functions. See the comment in | 1609 exactly what can go into these functions. See the comment in |
1608 @code{main()}. The reason for this is to avoid obscure unwanted | 1610 @file{emacs.c}. The reason for this is to avoid obscure unwanted |
1609 interactions during initialization. If you don't follow these rules, | 1611 interactions during initialization. If you don't follow these rules, |
1610 you'll be sorry! If you want to do anything that isn't allowed, create | 1612 you'll be sorry! If you want to do anything that isn't allowed, create |
1611 a @code{complex_vars_of_*()} function for it. Doing this is tricky, | 1613 a @code{complex_vars_of_*()} function for it. Doing this is tricky, |
1612 though: You have to make sure your function is called at the right time | 1614 though: You have to make sure your function is called at the right time |
1613 so that all the initialization dependencies work out. | 1615 so that all the initialization dependencies work out. |
1614 | 1616 |
1615 Every module includes @file{<config.h>} (angle brackets so that | 1617 Every module includes @file{<config.h>} (angle brackets so that |
1616 @samp{--srcdir} works correctly) and @file{lisp.h}. @file{config.h} | 1618 @samp{--srcdir} works correctly; @file{config.h} may or may not be in |
1619 the same directory as the C sources) and @file{lisp.h}. @file{config.h} | |
1617 should always be included before any other header files (including | 1620 should always be included before any other header files (including |
1618 system header files) to ensure that certain tricks played by various | 1621 system header files) to ensure that certain tricks played by various |
1619 @file{s/} and @file{m/} files work out correctly. | 1622 @file{s/} and @file{m/} files work out correctly. |
1620 | 1623 |
1621 @strong{All global and static variables that are to be modifiable must | 1624 @strong{All global and static variables that are to be modifiable must |
1707 | 1710 |
1708 Let's start with a precise explanation of the arguments to the | 1711 Let's start with a precise explanation of the arguments to the |
1709 @code{DEFUN} macro. Here is a template for them: | 1712 @code{DEFUN} macro. Here is a template for them: |
1710 | 1713 |
1711 @example | 1714 @example |
1712 DEFUN (@var{lname}, @var{fname}, @var{min}, @var{max}, @var{interactive} /* | 1715 DEFUN (@var{lname}, @var{fname}, @var{min}, @var{max}, @var{interactive}, /* |
1713 @var{docstring} | 1716 @var{docstring} |
1714 */ | 1717 */ |
1715 (@var{arglist}) ) | 1718 (@var{arglist}) ) |
1716 @end example | 1719 @end example |
1717 | 1720 |
1718 @table @var | 1721 @table @var |
1719 @item lname | 1722 @item lname |
1720 This is the name of the Lisp symbol to define as the function name; in | 1723 This string is the name of the Lisp symbol to define as the function |
1721 the example above, it is @code{or}. | 1724 name; in the example above, it is @code{"or"}. |
1722 | 1725 |
1723 @item fname | 1726 @item fname |
1724 This is the C function name for this function. This is the name that is | 1727 This is the C function name for this function. This is the name that is |
1725 used in C code for calling the function. The name is, by convention, | 1728 used in C code for calling the function. The name is, by convention, |
1726 @samp{F} prepended to the Lisp name, with all dashes (@samp{-}) in the | 1729 @samp{F} prepended to the Lisp name, with all dashes (@samp{-}) in the |
1775 string is enclosed in a comment, none of the documentation is placed on | 1778 string is enclosed in a comment, none of the documentation is placed on |
1776 the same lines as the comment-start and comment-end characters, and the | 1779 the same lines as the comment-start and comment-end characters, and the |
1777 comment-start characters are on the same line as the interactive | 1780 comment-start characters are on the same line as the interactive |
1778 specification. @file{make-docfile}, which scans the C files for | 1781 specification. @file{make-docfile}, which scans the C files for |
1779 documentation strings, is very particular about what it looks for, and | 1782 documentation strings, is very particular about what it looks for, and |
1780 will not properly note the doc string if it's not in this exact format. | 1783 will not properly extract the doc string if it's not in this exact format. |
1781 | 1784 |
1782 You are free to put the various arguments to @code{DEFUN} on separate | 1785 You are free to put the various arguments to @code{DEFUN} on separate |
1783 lines to avoid overly long lines. However, make sure to put the | 1786 lines to avoid overly long lines. However, make sure to put the |
1784 comment-start characters for the doc string on the same line as the | 1787 comment-start characters for the doc string on the same line as the |
1785 interactive specification, and put a newline directly after them (and | 1788 interactive specification, and put a newline directly after them (and |
1847 of XEmacs coding. It is @strong{extremely} important that you get this | 1850 of XEmacs coding. It is @strong{extremely} important that you get this |
1848 right and use a great deal of discipline when writing this code. | 1851 right and use a great deal of discipline when writing this code. |
1849 @xref{GCPROing, ,@code{GCPRO}ing}, for full details on how to do this. | 1852 @xref{GCPROing, ,@code{GCPRO}ing}, for full details on how to do this. |
1850 | 1853 |
1851 What @code{DEFUN} actually does is declare a global structure of | 1854 What @code{DEFUN} actually does is declare a global structure of |
1852 type @code{Lisp_Subr} whose name begins with a capital @samp{S} and | 1855 type @code{Lisp_Subr} whose name begins with capital @samp{SF} and |
1853 which contains information about the primitive (e.g. a pointer to the | 1856 which contains information about the primitive (e.g. a pointer to the |
1854 function, its minimum and maximum allowed arguments, a string describing | 1857 function, its minimum and maximum allowed arguments, a string describing |
1855 its Lisp name); @code{DEFUN} then begins a normal C function | 1858 its Lisp name); @code{DEFUN} then begins a normal C function |
1856 declaration using the @code{F...} name. The Lisp subr object that is | 1859 declaration using the @code{F...} name. The Lisp subr object that is |
1857 the function definition of a primitive (i.e. the object in the function | 1860 the function definition of a primitive (i.e. the object in the function |
1858 slot of the symbol that names the primitive) actually points to this | 1861 slot of the symbol that names the primitive) actually points to this |
1859 @samp{S} structure; when @code{Feval} encounters a subr, it looks in the | 1862 @samp{SF} structure; when @code{Feval} encounters a subr, it looks in the |
1860 structure to find out how to call the C function. | 1863 structure to find out how to call the C function. |
1861 | 1864 |
1862 Defining the C function is not enough to make a Lisp primitive | 1865 Defining the C function is not enough to make a Lisp primitive |
1863 available; you must also create the Lisp symbol for the primitive (the | 1866 available; you must also create the Lisp symbol for the primitive (the |
1864 symbol is @dfn{interned}; @pxref{Obarrays}) and store a suitable subr | 1867 symbol is @dfn{interned}; @pxref{Obarrays}) and store a suitable subr |
1865 object in its function cell. (If you don't do this, the primitive won't | 1868 object in its function cell. (If you don't do this, the primitive won't |
1866 be seen by Lisp code.) The code looks like this: | 1869 be seen by Lisp code.) The code looks like this: |
1867 | 1870 |
1868 @example | 1871 @example |
1869 defsubr (&@var{subr-structure-name}); | 1872 DEFSUBR (@var{fname}); |
1870 @end example | 1873 @end example |
1871 | 1874 |
1872 @noindent | 1875 @noindent |
1873 Here @var{subr-structure-name} is the name you used as the third | 1876 Here @var{fname} is the name you used as the second argument to |
1874 argument to @code{DEFUN}. | 1877 @code{DEFUN}. |
1875 | 1878 |
1876 This call to @code{defsubr} should go in the @code{syms_of_*()} | 1879 This call to @code{DEFSUBR} should go in the @code{syms_of_*()} |
1877 function at the end of the module. If no such function exists, create | 1880 function at the end of the module. If no such function exists, create |
1878 it and make sure to also declare it in @file{symsinit.h} and call it | 1881 it and make sure to also declare it in @file{symsinit.h} and call it |
1879 from the appropriate spot in @code{main()}. @xref{General Coding | 1882 from the appropriate spot in @code{main()}. @xref{General Coding |
1880 Rules}. | 1883 Rules}. |
1881 | 1884 |
1882 Note that C code cannot call functions by name unless they are defined | 1885 Note that C code cannot call functions by name unless they are defined |
1883 in C. The way to call a function written in Lisp is to use | 1886 in C. The way to call a function written in Lisp from C is to use |
1884 @code{Ffuncall}, which embodies the Lisp function @code{funcall}. Since | 1887 @code{Ffuncall}, which embodies the Lisp function @code{funcall}. Since |
1885 the Lisp function @code{funcall} accepts an unlimited number of | 1888 the Lisp function @code{funcall} accepts an unlimited number of |
1886 arguments, in C it takes two: the number of Lisp-level arguments, and a | 1889 arguments, in C it takes two: the number of Lisp-level arguments, and a |
1887 one-dimensional array containing their values. The first Lisp-level | 1890 one-dimensional array containing their values. The first Lisp-level |
1888 argument is the Lisp function to call, and the rest are the arguments to | 1891 argument is the Lisp function to call, and the rest are the arguments to |
2104 @file{alloca.c}, etc. are normally placed past @file{lastfile.c}, and | 2107 @file{alloca.c}, etc. are normally placed past @file{lastfile.c}, and |
2105 all of the files that implement Xt widget classes @emph{must} be placed | 2108 all of the files that implement Xt widget classes @emph{must} be placed |
2106 after @file{lastfile.c} because they contain various structures that | 2109 after @file{lastfile.c} because they contain various structures that |
2107 must be statically initialized and into which Xt writes at various | 2110 must be statically initialized and into which Xt writes at various |
2108 times.) @file{pre-crt0.c} and @file{lastfile.c} contain exported symbols | 2111 times.) @file{pre-crt0.c} and @file{lastfile.c} contain exported symbols |
2109 that are used to determine the start and end of XEmacs's initialized | 2112 that are used to determine the start and end of XEmacs' initialized |
2110 data space when dumping. | 2113 data space when dumping. |
2111 | 2114 |
2112 | 2115 |
2113 | 2116 |
2114 @example | 2117 @example |
3088 43058 chartab.c | 3091 43058 chartab.c |
3089 6503 chartab.h | 3092 6503 chartab.h |
3090 9918 casetab.c | 3093 9918 casetab.c |
3091 @end example | 3094 @end example |
3092 | 3095 |
3093 @file{chartab.c} and @file{chartab.h} implement the char table Lisp | 3096 @file{chartab.c} and @file{chartab.h} implement the @dfn{char table} |
3094 object type, which maps from characters or certain sorts of character | 3097 Lisp object type, which maps from characters or certain sorts of |
3095 ranges to Lisp objects. The implementation of this object is optimized | 3098 character ranges to Lisp objects. The implementation of this object |
3096 for the internal representation of characters. Char tables come in | 3099 type is optimized for the internal representation of characters. Char |
3097 different types, which affect the allowed object types to which a | 3100 tables come in different types, which affect the allowed object types to |
3098 character can be mapped and also dictate certain other properties of the | 3101 which a character can be mapped and also dictate certain other |
3099 char table. | 3102 properties of the char table. |
3100 | 3103 |
3101 @cindex case table | 3104 @cindex case table |
3102 @file{casetab.c} implements one sort of char table, the @dfn{case | 3105 @file{casetab.c} implements one sort of char table, the @dfn{case |
3103 table}, which maps characters to other characters of possibly different | 3106 table}, which maps characters to other characters of possibly different |
3104 case. These are used by XEmacs to implement case-changing primitives | 3107 case. These are used by XEmacs to implement case-changing primitives |
3110 49593 syntax.c | 3113 49593 syntax.c |
3111 10200 syntax.h | 3114 10200 syntax.h |
3112 @end example | 3115 @end example |
3113 | 3116 |
3114 @cindex scanner | 3117 @cindex scanner |
3115 This module implements syntax tables, another sort of char table that | 3118 This module implements @dfn{syntax tables}, another sort of char table |
3116 maps characters into syntax classes that define the syntax of these | 3119 that maps characters into syntax classes that define the syntax of these |
3117 characters (e.g. a parenthesis belongs to a class of @samp{open} characters | 3120 characters (e.g. a parenthesis belongs to a class of @samp{open} |
3118 that have corresponding @samp{close} characters and can be nested). | 3121 characters that have corresponding @samp{close} characters and can be |
3119 This module also implements the Lisp @dfn{scanner}, a set of primitives | 3122 nested). This module also implements the Lisp @dfn{scanner}, a set of |
3120 for scanning over text based on syntax tables. This is used, for | 3123 primitives for scanning over text based on syntax tables. This is used, |
3121 example, to find the matching parenthesis in a command such as | 3124 for example, to find the matching parenthesis in a command such as |
3122 @code{forward-sexp}, and by @file{font-lock.c} to locate quoted strings, | 3125 @code{forward-sexp}, and by @file{font-lock.c} to locate quoted strings, |
3123 comments, etc. | 3126 comments, etc. |
3124 | 3127 |
3125 | 3128 |
3126 | 3129 |
3678 two-dimensional set of characters, such as US ASCII or JISX0208 Japanese | 3681 two-dimensional set of characters, such as US ASCII or JISX0208 Japanese |
3679 Kanji). | 3682 Kanji). |
3680 | 3683 |
3681 @file{mule-coding.*} implements the @dfn{coding-system} Lisp object | 3684 @file{mule-coding.*} implements the @dfn{coding-system} Lisp object |
3682 type, which encapsulates a method of converting between different | 3685 type, which encapsulates a method of converting between different |
3683 encodings. An encoding is a representation of a stream of characters | 3686 encodings. An encoding is a representation of a stream of characters, |
3684 from multiple character sets using a stream of bytes or words and | 3687 possibly from multiple character sets, using a stream of bytes or words, |
3685 defines (e.g.) which escape sequences are used to specify particular | 3688 and defines (e.g.) which escape sequences are used to specify particular |
3686 character sets, how the indices for a character are converted into bytes | 3689 character sets, how the indices for a character are converted into bytes |
3687 (sometimes this involves setting the high bit; sometimes complicated | 3690 (sometimes this involves setting the high bit; sometimes complicated |
3688 rearranging of the values takes place, as in the Shift-JIS encoding), | 3691 rearranging of the values takes place, as in the Shift-JIS encoding), |
3689 etc. | 3692 etc. |
3690 | 3693 |
3692 interpreter. CCL is similar in spirit to Lisp byte code and is used to | 3695 interpreter. CCL is similar in spirit to Lisp byte code and is used to |
3693 implement converters for custom encodings. | 3696 implement converters for custom encodings. |
3694 | 3697 |
3695 @file{mule-canna.c} and @file{mule-wnnfns.c} implement interfaces to | 3698 @file{mule-canna.c} and @file{mule-wnnfns.c} implement interfaces to |
3696 external programs used to implement the Canna and WNN input methods, | 3699 external programs used to implement the Canna and WNN input methods, |
3697 respectively. This is currently broken. | 3700 respectively. This is currently in beta. |
3698 | 3701 |
3699 @file{mule-mcpath.c} provides some functions to allow for pathnames | 3702 @file{mule-mcpath.c} provides some functions to allow for pathnames |
3700 containing extended characters. This code is fragmentary, obsolete, and | 3703 containing extended characters. This code is fragmentary, obsolete, and |
3701 completely non-working. Instead, @var{pathname-coding-system} is used | 3704 completely non-working. Instead, @var{pathname-coding-system} is used |
3702 to specify conversions of names of files and directories. The standard | 3705 to specify conversions of names of files and directories. The standard |
3778 @itemize @bullet | 3781 @itemize @bullet |
3779 @item | 3782 @item |
3780 (a) Those for whom the value directly represents the contents of the | 3783 (a) Those for whom the value directly represents the contents of the |
3781 Lisp object. Only two types are in this category: integers and | 3784 Lisp object. Only two types are in this category: integers and |
3782 characters. No special allocation or garbage collection is necessary | 3785 characters. No special allocation or garbage collection is necessary |
3783 for such objects. | 3786 for such objects. Lisp objects of these types do not need to be |
3787 @code{GCPRO}ed. | |
3784 @end itemize | 3788 @end itemize |
3785 | 3789 |
3786 In the remaining three categories, the value is a pointer to a | 3790 In the remaining three categories, the value is a pointer to a |
3787 structure. | 3791 structure. |
3788 | 3792 |
3948 Note that @code{obarray} is one of the @code{staticpro()}d things. | 3952 Note that @code{obarray} is one of the @code{staticpro()}d things. |
3949 Therefore, all functions and variables get marked through this. | 3953 Therefore, all functions and variables get marked through this. |
3950 @item | 3954 @item |
3951 Any shadowed bindings that are sitting on the specpdl stack. | 3955 Any shadowed bindings that are sitting on the specpdl stack. |
3952 @item | 3956 @item |
3953 Any objects sitting in currently active stack frames, | 3957 Any objects sitting in currently active (Lisp) stack frames, |
3954 catches, and condition cases. | 3958 catches, and condition cases. |
3955 @item | 3959 @item |
3956 A couple of special-case places where active objects are | 3960 A couple of special-case places where active objects are |
3957 located. | 3961 located. |
3958 @item | 3962 @item |
3997 just a single lvalue. To effect this, call @code{GCPRO@var{n}} as usual on | 4001 just a single lvalue. To effect this, call @code{GCPRO@var{n}} as usual on |
3998 the first object in the array and then set @code{gcpron.nvars}. | 4002 the first object in the array and then set @code{gcpron.nvars}. |
3999 | 4003 |
4000 @item | 4004 @item |
4001 @strong{Strings are relocated.} What this means in practice is that the | 4005 @strong{Strings are relocated.} What this means in practice is that the |
4002 pointer obtained using @code{string_data()} is liable to change at any | 4006 pointer obtained using @code{XSTRING_DATA()} is liable to change at any |
4003 time, and you should never keep it around past any function call, or | 4007 time, and you should never keep it around past any function call, or |
4004 pass it as an argument to any function that might cause a garbage | 4008 pass it as an argument to any function that might cause a garbage |
4005 collection. This is why a number of functions accept either a | 4009 collection. This is why a number of functions accept either a |
4006 ``non-relocatable'' @code{char *} pointer or a relocatable Lisp string, | 4010 ``non-relocatable'' @code{char *} pointer or a relocatable Lisp string, |
4007 and only access the Lisp string's data at the very last minute. In some | 4011 and only access the Lisp string's data at the very last minute. In some |
4038 If you have the @emph{least smidgeon of doubt} about whether | 4042 If you have the @emph{least smidgeon of doubt} about whether |
4039 you need to @code{GCPRO}, you should @code{GCPRO}. | 4043 you need to @code{GCPRO}, you should @code{GCPRO}. |
4040 | 4044 |
4041 @item | 4045 @item |
4042 Beware of @code{GCPRO}ing something that is uninitialized. If you have | 4046 Beware of @code{GCPRO}ing something that is uninitialized. If you have |
4043 any shade of doubt about this, initialize all your variables to Qnil. | 4047 any shade of doubt about this, initialize all your variables to @code{Qnil}. |
4044 | 4048 |
4045 @item | 4049 @item |
4046 Be careful of traps, like calling @code{Fcons()} in the argument to | 4050 Be careful of traps, like calling @code{Fcons()} in the argument to |
4047 another function. By the ``caller protects'' law, you should be | 4051 another function. By the ``caller protects'' law, you should be |
4048 @code{GCPRO}ing the newly-created cons, but you aren't. A certain | 4052 @code{GCPRO}ing the newly-created cons, but you aren't. A certain |
4447 @section Vector | 4451 @section Vector |
4448 | 4452 |
4449 As mentioned above, each vector is @code{malloc()}ed individually, and | 4453 As mentioned above, each vector is @code{malloc()}ed individually, and |
4450 all are threaded through the variable @code{all_vectors}. Vectors are | 4454 all are threaded through the variable @code{all_vectors}. Vectors are |
4451 marked strangely during garbage collection, by kludging the size field. | 4455 marked strangely during garbage collection, by kludging the size field. |
4452 Note that the @code{struct Lisp_Vector} is declared with its contents | 4456 Note that the @code{struct Lisp_Vector} is declared with its |
4453 being an array of one element. It is actually @code{malloc()}ed with | 4457 @code{contents} field being a @emph{stretchy} array of one element. It |
4454 the right size, however, and access to any element through the contents | 4458 is actually @code{malloc()}ed with the right size, however, and access |
4455 array works fine. | 4459 to any element through the @code{contents} array works fine. |
4456 | 4460 |
4457 @node Bit Vector | 4461 @node Bit Vector |
4458 @section Bit Vector | 4462 @section Bit Vector |
4459 | 4463 |
4460 Bit vectors work exactly like vectors, except for more complicated | 4464 Bit vectors work exactly like vectors, except for more complicated |
4933 @code{command_event_queue}. There is a comment about a ``race | 4937 @code{command_event_queue}. There is a comment about a ``race |
4934 condition'', which is not a good sign. | 4938 condition'', which is not a good sign. |
4935 | 4939 |
4936 @code{next-command-event} and @code{read-char} are higher-level | 4940 @code{next-command-event} and @code{read-char} are higher-level |
4937 interfaces to @code{next-event}. @code{next-command-event} gets the | 4941 interfaces to @code{next-event}. @code{next-command-event} gets the |
4938 next @dfn{command} event (i.e. keypress, mouse event, or menu | 4942 next @dfn{command} event (i.e. keypress, mouse event, menu selection, |
4939 selection), calling dispatch-event on any others. @code{read-char} | 4943 or scrollbar action), calling @code{dispatch-event} on any others. |
4940 calls @code{next-command-event} and uses @code{event_to_character()} to | 4944 @code{read-char} calls @code{next-command-event} and uses |
4941 return the ASCII equivalent. | 4945 @code{event_to_character()} to return the character equivalent. With |
4946 the right kind of input method support, it is possible for (read-char) | |
4947 to return a Kanji character. | |
4942 | 4948 |
4943 @node Converting Events | 4949 @node Converting Events |
4944 @section Converting Events | 4950 @section Converting Events |
4945 | 4951 |
4946 @code{character_to_event()}, @code{event_to_character()}, | 4952 @code{character_to_event()}, @code{event_to_character()}, |
4947 @code{event-to-character}, and @code{character-to-event} convert between | 4953 @code{event-to-character}, and @code{character-to-event} convert between |
4948 ASCII characters and keypresses corresponding to the characters. If the | 4954 characters and keypress events corresponding to the characters. If the |
4949 event was not a keypress, @code{event_to_character()} returns -1 and | 4955 event was not a keypress, @code{event_to_character()} returns -1 and |
4950 @code{event-to-character} returns @code{nil}. These functions convert | 4956 @code{event-to-character} returns @code{nil}. These functions convert |
4951 between ASCII representation and the split-up event representation | 4957 between character representation and the split-up event representation |
4952 (keysym plus mod keys). | 4958 (keysym plus mod keys). |
4953 | 4959 |
4954 @node Dispatching Events; The Command Builder | 4960 @node Dispatching Events; The Command Builder |
4955 @section Dispatching Events; The Command Builder | 4961 @section Dispatching Events; The Command Builder |
4956 | 4962 |
4992 the backtrace structure is changed). | 4998 the backtrace structure is changed). |
4993 | 4999 |
4994 At this point, the function to be called is determined by looking at | 5000 At this point, the function to be called is determined by looking at |
4995 the car of the cons (if this is a symbol, its function definition is | 5001 the car of the cons (if this is a symbol, its function definition is |
4996 retrieved and the process repeated). The function should then consist | 5002 retrieved and the process repeated). The function should then consist |
4997 of either a Lisp_Subr (built-in function), a Lisp_Compiled object, or a | 5003 of either a @code{Lisp_Subr} (built-in function), a |
4998 cons whose car is the symbol @code{autoload}, @code{macro}, | 5004 @code{Lisp_Compiled_Function} object, or a cons whose car is the symbol |
4999 @code{lambda}, or @code{mocklisp}. | 5005 @code{autoload}, @code{macro}, @code{lambda}, or @code{mocklisp}. |
5000 | 5006 |
5001 If the function is a Lisp_Subr, the lisp object points to a struct | 5007 If the function is a @code{Lisp_Subr}, the lisp object points to a |
5002 Lisp_Subr (created by @code{DEFUN()}), which contains a pointer to the C | 5008 @code{struct Lisp_Subr} (created by @code{DEFUN()}), which contains a |
5003 function, a minimum and maximum number of arguments (possibly the | 5009 pointer to the C function, a minimum and maximum number of arguments |
5004 special constants @code{MANY} or @code{UNEVALLED}), a pointer to the | 5010 (possibly the special constants @code{MANY} or @code{UNEVALLED}), a |
5005 symbol referring to that subr, and a couple of other things. If the | 5011 pointer to the symbol referring to that subr, and a couple of other |
5006 subr wants its arguments @code{UNEVALLED}, they are passed raw as a | 5012 things. If the subr wants its arguments @code{UNEVALLED}, they are |
5007 list. Otherwise, an array of evaluated arguments is created and put | 5013 passed raw as a list. Otherwise, an array of evaluated arguments is |
5008 into the backtrace structure, and either passed whole (@code{MANY}) or | 5014 created and put into the backtrace structure, and either passed whole |
5009 each argument is passed as a C argument. | 5015 (@code{MANY}) or each argument is passed as a C argument. |
5010 | 5016 |
5011 If the function is a Lisp_Compiled object or a lambda, | 5017 If the function is a @code{Lisp_Compiled_Function} object or a lambda, |
5012 @code{apply_lambda()} is called. If the function is a macro, | 5018 @code{apply_lambda()} is called. If the function is a macro, |
5013 [..... fill in] is done. If the function is an autoload, | 5019 [..... fill in] is done. If the function is an autoload, |
5014 @code{do_autoload()} is called to load the definition and then eval | 5020 @code{do_autoload()} is called to load the definition and then eval |
5015 starts over [explain this more]. If the function is a mocklisp, | 5021 starts over [explain this more]. If the function is a mocklisp, |
5016 @code{ml_apply()} is called. | 5022 @code{ml_apply()} is called. |
5026 | 5032 |
5027 @code{funcall_lambda()} goes through the formal arguments to the | 5033 @code{funcall_lambda()} goes through the formal arguments to the |
5028 function and binds them to the actual arguments, checking for | 5034 function and binds them to the actual arguments, checking for |
5029 @code{&rest} and @code{&optional} symbols in the formal arguments and | 5035 @code{&rest} and @code{&optional} symbols in the formal arguments and |
5030 making sure the number of actual arguments is correct. Then either | 5036 making sure the number of actual arguments is correct. Then either |
5031 progn or byte-code is called to actually execute the body and return a | 5037 @code{progn} or @code{byte-code} is called to actually execute the body |
5032 value. | 5038 and return a value. |
5033 | 5039 |
5034 @code{Ffuncall()} implements Lisp @code{funcall}. @code{(funcall fun | 5040 @code{Ffuncall()} implements Lisp @code{funcall}. @code{(funcall fun |
5035 x1 x2 x3 ...)} is equivalent to @code{(eval (list fun (quote x1) (quote | 5041 x1 x2 x3 ...)} is equivalent to @code{(eval (list fun (quote x1) (quote |
5036 x2) (quote x3) ...))}. @code{Ffuncall()} contains its own code to do | 5042 x2) (quote x3) ...))}. @code{Ffuncall()} contains its own code to do |
5037 the evaluation, however, and is almost identical to eval. | 5043 the evaluation, however, and is almost identical to eval. |
5075 specpdl array, and @code{specpdl_size} is increased by 1. | 5081 specpdl array, and @code{specpdl_size} is increased by 1. |
5076 | 5082 |
5077 @code{record_unwind_protect()} implements an @dfn{unwind-protect}, | 5083 @code{record_unwind_protect()} implements an @dfn{unwind-protect}, |
5078 which, when placed around a section of code, ensures that some specified | 5084 which, when placed around a section of code, ensures that some specified |
5079 cleanup routine will be executed even if the code exits abnormally | 5085 cleanup routine will be executed even if the code exits abnormally |
5080 (e.g. through a throw or quit). @code{record_unwind_protect()} simply | 5086 (e.g. through a @code{throw} or quit). @code{record_unwind_protect()} |
5081 adds a new specbinding to the specpdl array and stores the appropriate | 5087 simply adds a new specbinding to the specpdl array and stores the |
5082 information in it. The cleanup routine can either be a C function, | 5088 appropriate information in it. The cleanup routine can either be a C |
5083 which is stored in the @code{func} field, or a progn form, which is stored in | 5089 function, which is stored in the @code{func} field, or a @code{progn} |
5084 the @code{old_value} field. | 5090 form, which is stored in the @code{old_value} field. |
5085 | 5091 |
5086 @code{unbind_to()} removes specbindings from the specpdl array until | 5092 @code{unbind_to()} removes specbindings from the specpdl array until |
5087 the specified position is reached. The specbinding can be one of three | 5093 the specified position is reached. Each specbinding can be one of three |
5088 types: | 5094 types: |
5089 | 5095 |
5090 @enumerate | 5096 @enumerate |
5091 @item | 5097 @item |
5092 an unwind-protect with a C cleanup function (@code{func} is not 0 -- | 5098 an unwind-protect with a C cleanup function (@code{func} is not 0, and |
5093 @code{old_value} holds an argument to be passed to the function); | 5099 @code{old_value} holds an argument to be passed to the function); |
5094 @item | 5100 @item |
5095 an unwind-protect with a Lisp form (@code{func} is 0 and @code{symbol} | 5101 an unwind-protect with a Lisp form (@code{func} is 0, @code{symbol} |
5096 is @code{nil} -- @code{old_value} holds the form to be executed with | 5102 is @code{nil}, and @code{old_value} holds the form to be executed with |
5097 @code{Fprogn()}); or | 5103 @code{Fprogn()}); or |
5098 @item | 5104 @item |
5099 a local-variable binding (@code{func} is 0 and @code{symbol} is not | 5105 a local-variable binding (@code{func} is 0, @code{symbol} is not |
5100 @code{nil} -- @code{old_value} holds the old value, which is stored as | 5106 @code{nil}, and @code{old_value} holds the old value, which is stored as |
5101 the symbol's value). | 5107 the symbol's value). |
5102 @end enumerate | 5108 @end enumerate |
5103 | 5109 |
5104 @node Simple Special Forms | 5110 @node Simple Special Forms |
5105 @section Simple Special Forms | 5111 @section Simple Special Forms |
5256 | 5262 |
5257 Usually symbols are created by @code{intern}, but if you really want, | 5263 Usually symbols are created by @code{intern}, but if you really want, |
5258 you can explicitly create a symbol using @code{make-symbol}, giving it | 5264 you can explicitly create a symbol using @code{make-symbol}, giving it |
5259 some name. The resulting symbol is not in any obarray (i.e. it is | 5265 some name. The resulting symbol is not in any obarray (i.e. it is |
5260 @dfn{uninterned}), and you can't add it to any obarray. Therefore its | 5266 @dfn{uninterned}), and you can't add it to any obarray. Therefore its |
5261 primary purpose is as a carrier of information. (Cons cells could | 5267 primary purpose is as a symbol to use in macros to avoid namespace |
5262 probably be used just as well.) | 5268 pollution. It can also be used as a carrier of information, but cons |
5269 cells could probably be used just as well. | |
5263 | 5270 |
5264 You can also use @code{intern-soft} to look up a symbol but not create | 5271 You can also use @code{intern-soft} to look up a symbol but not create |
5265 a new one, and @code{unintern} to remove a symbol from an obarray. This | 5272 a new one, and @code{unintern} to remove a symbol from an obarray. This |
5266 returns the removed symbol. (Remember: You can't put the symbol back | 5273 returns the removed symbol. (Remember: You can't put the symbol back |
5267 into any obarray.) Finally, @code{mapatoms} maps over all of the symbols | 5274 into any obarray.) Finally, @code{mapatoms} maps over all of the symbols |
5329 In this, it is like a string, but a buffer is optimized for | 5336 In this, it is like a string, but a buffer is optimized for |
5330 frequent insertion and deletion, while a string is not. Furthermore: | 5337 frequent insertion and deletion, while a string is not. Furthermore: |
5331 | 5338 |
5332 @enumerate | 5339 @enumerate |
5333 @item | 5340 @item |
5334 Buffers are @dfn{permanent} objects, i.e. one you create them, they | 5341 Buffers are @dfn{permanent} objects, i.e. once you create them, they |
5335 remain around, and need to be explicitly deleted before they go away. | 5342 remain around, and need to be explicitly deleted before they go away. |
5336 @item | 5343 @item |
5337 Each buffer has a unique name, which is a string. Buffers are | 5344 Each buffer has a unique name, which is a string. Buffers are |
5338 normally referred to by name. In this respect, they are like | 5345 normally referred to by name. In this respect, they are like |
5339 symbols. | 5346 symbols. |
5363 can temporarily change the current buffer using @code{set-buffer} (often | 5370 can temporarily change the current buffer using @code{set-buffer} (often |
5364 enclosed in a @code{save-excursion} so that the former current buffer | 5371 enclosed in a @code{save-excursion} so that the former current buffer |
5365 gets restored when the code is finished). However, calling | 5372 gets restored when the code is finished). However, calling |
5366 @code{set-buffer} will NOT cause a permanent change in the current | 5373 @code{set-buffer} will NOT cause a permanent change in the current |
5367 buffer. The reason for this is that the top-level event loop sets | 5374 buffer. The reason for this is that the top-level event loop sets |
5368 current buffer to the buffer of the selected window, each time it | 5375 @code{current_buffer} to the buffer of the selected window, each time |
5369 finishes executing a user command. | 5376 it finishes executing a user command. |
5370 @end enumerate | 5377 @end enumerate |
5371 | 5378 |
5372 Make sure you understand the distinction between @dfn{current buffer} | 5379 Make sure you understand the distinction between @dfn{current buffer} |
5373 and @dfn{buffer of the selected window}, and the distinction between | 5380 and @dfn{buffer of the selected window}, and the distinction between |
5374 @dfn{point} of the current buffer and @dfn{window-point} of the selected | 5381 @dfn{point} of the current buffer and @dfn{window-point} of the selected |
5387 etc.), Cyrillic and Greek letters, etc. The actual number of possible | 5394 etc.), Cyrillic and Greek letters, etc. The actual number of possible |
5388 characters is quite large. | 5395 characters is quite large. |
5389 | 5396 |
5390 For now, we can view a character as some non-negative integer that | 5397 For now, we can view a character as some non-negative integer that |
5391 has some shape that defines how it typically appears (e.g. as an | 5398 has some shape that defines how it typically appears (e.g. as an |
5392 uppercase A). (The exact way in which a character appears depends | 5399 uppercase A). (The exact way in which a character appears depends on the |
5393 on the font of the character.) The internal type of characters in | 5400 font used to display the character.) The internal type of characters in |
5394 the C code is an Emchar; this is just an int, but using a symbolic | 5401 the C code is an @code{Emchar}; this is just an @code{int}, but using a |
5395 type makes the code clearer. | 5402 symbolic type makes the code clearer. |
5396 | 5403 |
5397 Between every character in a buffer is a @dfn{buffer position} or | 5404 Between every character in a buffer is a @dfn{buffer position} or |
5398 @dfn{character position}. We can speak of the character before or after | 5405 @dfn{character position}. We can speak of the character before or after |
5399 a particular buffer position, and when you insert a character at a | 5406 a particular buffer position, and when you insert a character at a |
5400 particular position, all characters after that position end up at new | 5407 particular position, all characters after that position end up at new |
5446 characters back again). Once the buffer is killed, the memory allocated | 5453 characters back again). Once the buffer is killed, the memory allocated |
5447 for the buffer text will be freed, but it will still be sitting on the | 5454 for the buffer text will be freed, but it will still be sitting on the |
5448 heap, taking up virtual memory, and will not be released back to the | 5455 heap, taking up virtual memory, and will not be released back to the |
5449 operating system. (However, if you have compiled XEmacs with rel-alloc, | 5456 operating system. (However, if you have compiled XEmacs with rel-alloc, |
5450 the situation is different. In this case, the space @emph{will} be | 5457 the situation is different. In this case, the space @emph{will} be |
5451 released back to the operating system. However, this tends to effect a | 5458 released back to the operating system. However, this tends to result in a |
5452 noticeable speed penalty.) | 5459 noticeable speed penalty.) |
5453 | 5460 |
5454 Astute readers may notice that the text in a buffer is represented as | 5461 Astute readers may notice that the text in a buffer is represented as |
5455 an array of @emph{bytes}, while (at least in the MULE case) an Emchar is | 5462 an array of @emph{bytes}, while (at least in the MULE case) an Emchar is |
5456 a 19-bit integer, which clearly cannot fit in a byte. This means (of | 5463 a 19-bit integer, which clearly cannot fit in a byte. This means (of |
5499 @dfn{byte indices}, typedef @code{Bytind} | 5506 @dfn{byte indices}, typedef @code{Bytind} |
5500 @item | 5507 @item |
5501 @dfn{memory indices}, typedef @code{Memind} | 5508 @dfn{memory indices}, typedef @code{Memind} |
5502 @end enumerate | 5509 @end enumerate |
5503 | 5510 |
5504 All three typedefs are just ints, but defining them this way makes | 5511 All three typedefs are just @code{int}s, but defining them this way makes |
5505 things a lot clearer. | 5512 things a lot clearer. |
5506 | 5513 |
5507 Most code works with buffer positions. In particular, all Lisp code | 5514 Most code works with buffer positions. In particular, all Lisp code |
5508 that refers to text in a buffer uses buffer positions. Lisp code does | 5515 that refers to text in a buffer uses buffer positions. Lisp code does |
5509 not know that byte indices or memory indices exist. | 5516 not know that byte indices or memory indices exist. |
5510 | 5517 |
5511 Finally, we have a typedef for the bytes in a buffer. This is a | 5518 Finally, we have a typedef for the bytes in a buffer. This is a |
5512 @code{Bufbyte}, which is an unsigned char. Referring to them as | 5519 @code{Bufbyte}, which is an unsigned char. Referring to them as |
5513 Bufbytes underscores the fact that we are working with a string of bytes | 5520 Bufbytes underscores the fact that we are working with a string of bytes |
5514 in the internal Emacs buffer representation rather than in one of a | 5521 in the internal Emacs buffer representation rather than in one of a |
5515 number of possible alternative representations (e.g. EUC-coded text, | 5522 number of possible alternative representations (e.g. EUC-encoded text, |
5516 etc.). | 5523 etc.). |
5517 | 5524 |
5518 @node Buffer Lists | 5525 @node Buffer Lists |
5519 @section Buffer Lists | 5526 @section Buffer Lists |
5520 | 5527 |