comparison man/internals/internals.texi @ 462:0784d089fdc9 r21-2-46

Import from CVS: tag r21-2-46
author cvs
date Mon, 13 Aug 2007 11:44:37 +0200
parents d7a9135ec789
children 5aa1854ad537
comparison
equal deleted inserted replaced
461:120ed4009e51 462:0784d089fdc9
103 @page 103 @page
104 104
105 @node Top, A History of Emacs, (dir), (dir) 105 @node Top, A History of Emacs, (dir), (dir)
106 106
107 @ifinfo 107 @ifinfo
108 This Info file contains v1.0 of the XEmacs Internals Manual. 108 This Info file contains v1.3 of the XEmacs Internals Manual, August 1999.
109 @end ifinfo 109 @end ifinfo
110 110
111 @menu 111 @menu
112 * A History of Emacs:: Times, dates, important events. 112 * A History of Emacs:: Times, dates, important events.
113 * XEmacs From the Outside:: A broad conceptual overview. 113 * XEmacs From the Outside:: A broad conceptual overview.
307 @end detailmenu 307 @end detailmenu
308 @end menu 308 @end menu
309 309
310 @node A History of Emacs, XEmacs From the Outside, Top, Top 310 @node A History of Emacs, XEmacs From the Outside, Top, Top
311 @chapter A History of Emacs 311 @chapter A History of Emacs
312 @cindex history of Emacs 312 @cindex history of Emacs, a
313 @cindex Emacs, a history of
313 @cindex Hackers (Steven Levy) 314 @cindex Hackers (Steven Levy)
314 @cindex Levy, Steven 315 @cindex Levy, Steven
315 @cindex ITS (Incompatible Timesharing System) 316 @cindex ITS (Incompatible Timesharing System)
316 @cindex Stallman, Richard 317 @cindex Stallman, Richard
317 @cindex RMS 318 @cindex RMS
343 * GNU Emacs 19:: The other version 19 Emacs. 344 * GNU Emacs 19:: The other version 19 Emacs.
344 * GNU Emacs 20:: The other version 20 Emacs. 345 * GNU Emacs 20:: The other version 20 Emacs.
345 * XEmacs:: The continuation of Lucid Emacs. 346 * XEmacs:: The continuation of Lucid Emacs.
346 @end menu 347 @end menu
347 348
348 @node Through Version 18, Lucid Emacs, A History of Emacs, A History of Emacs 349 @node Through Version 18
349 @section Through Version 18 350 @section Through Version 18
351 @cindex version 18, through
350 @cindex Gosling, James 352 @cindex Gosling, James
351 @cindex Great Usenet Renaming 353 @cindex Great Usenet Renaming
352 354
353 Although the history of the early versions of GNU Emacs is unclear, 355 Although the history of the early versions of GNU Emacs is unclear,
354 the history is well-known from the middle of 1985. A time line is: 356 the history is well-known from the middle of 1985. A time line is:
456 version 18.58 released ?????. 458 version 18.58 released ?????.
457 @item 459 @item
458 version 18.59 released October 31, 1992. 460 version 18.59 released October 31, 1992.
459 @end itemize 461 @end itemize
460 462
461 @node Lucid Emacs, GNU Emacs 19, Through Version 18, A History of Emacs 463 @node Lucid Emacs
462 @section Lucid Emacs 464 @section Lucid Emacs
463 @cindex Lucid Emacs 465 @cindex Lucid Emacs
464 @cindex Lucid Inc. 466 @cindex Lucid Inc.
465 @cindex Energize 467 @cindex Energize
466 @cindex Epoch 468 @cindex Epoch
544 version 20.3 (the first stable version of XEmacs 20.x) released November 30, 546 version 20.3 (the first stable version of XEmacs 20.x) released November 30,
545 1997. 547 1997.
546 version 20.4 released February 28, 1998. 548 version 20.4 released February 28, 1998.
547 @end itemize 549 @end itemize
548 550
549 @node GNU Emacs 19, GNU Emacs 20, Lucid Emacs, A History of Emacs 551 @node GNU Emacs 19
550 @section GNU Emacs 19 552 @section GNU Emacs 19
551 @cindex GNU Emacs 19 553 @cindex GNU Emacs 19
554 @cindex Emacs 19, GNU
555 @cindex version 19, GNU Emacs
552 @cindex FSF Emacs 556 @cindex FSF Emacs
553 557
554 About a year after the initial release of Lucid Emacs, the FSF 558 About a year after the initial release of Lucid Emacs, the FSF
555 released a beta of their version of Emacs 19 (referred to here as ``GNU 559 released a beta of their version of Emacs 19 (referred to here as ``GNU
556 Emacs''). By this time, the current version of Lucid Emacs was 560 Emacs''). By this time, the current version of Lucid Emacs was
621 worse. Lucid soon began incorporating features from GNU Emacs 19 into 625 worse. Lucid soon began incorporating features from GNU Emacs 19 into
622 Lucid Emacs; the work was mostly done by Richard Mlynarik, who had been 626 Lucid Emacs; the work was mostly done by Richard Mlynarik, who had been
623 working on and using GNU Emacs for a long time (back as far as version 627 working on and using GNU Emacs for a long time (back as far as version
624 16 or 17). 628 16 or 17).
625 629
626 @node GNU Emacs 20, XEmacs, GNU Emacs 19, A History of Emacs 630 @node GNU Emacs 20
627 @section GNU Emacs 20 631 @section GNU Emacs 20
628 @cindex GNU Emacs 20 632 @cindex GNU Emacs 20
633 @cindex Emacs 20, GNU
634 @cindex version 20, GNU Emacs
629 @cindex FSF Emacs 635 @cindex FSF Emacs
630 636
631 On February 2, 1997 work began on GNU Emacs to integrate Mule. The first 637 On February 2, 1997 work began on GNU Emacs to integrate Mule. The first
632 release was made in September of that year. 638 release was made in September of that year.
633 639
640 version 20.2 released September 20, 1997. 646 version 20.2 released September 20, 1997.
641 @item 647 @item
642 version 20.3 released August 19, 1998. 648 version 20.3 released August 19, 1998.
643 @end itemize 649 @end itemize
644 650
645 @node XEmacs, , GNU Emacs 20, A History of Emacs 651 @node XEmacs
646 @section XEmacs 652 @section XEmacs
647 @cindex XEmacs 653 @cindex XEmacs
648 654
649 @cindex Sun Microsystems 655 @cindex Sun Microsystems
650 @cindex University of Illinois 656 @cindex University of Illinois
718 724
719 A more detailed history is contained in the XEmacs About page. 725 A more detailed history is contained in the XEmacs About page.
720 726
721 @node XEmacs From the Outside, The Lisp Language, A History of Emacs, Top 727 @node XEmacs From the Outside, The Lisp Language, A History of Emacs, Top
722 @chapter XEmacs From the Outside 728 @chapter XEmacs From the Outside
729 @cindex XEmacs from the outside
730 @cindex outside, XEmacs from the
723 @cindex read-eval-print 731 @cindex read-eval-print
724 732
725 XEmacs appears to the outside world as an editor, but it is really a 733 XEmacs appears to the outside world as an editor, but it is really a
726 Lisp environment. At its heart is a Lisp interpreter; it also 734 Lisp environment. At its heart is a Lisp interpreter; it also
727 ``happens'' to contain many specialized object types (e.g. buffers, 735 ``happens'' to contain many specialized object types (e.g. buffers,
760 as well make it do your taxes, compute pi, play bridge, etc. You'd just 768 as well make it do your taxes, compute pi, play bridge, etc. You'd just
761 have to write functions to do those operations in Lisp. 769 have to write functions to do those operations in Lisp.
762 770
763 @node The Lisp Language, XEmacs From the Perspective of Building, XEmacs From the Outside, Top 771 @node The Lisp Language, XEmacs From the Perspective of Building, XEmacs From the Outside, Top
764 @chapter The Lisp Language 772 @chapter The Lisp Language
773 @cindex Lisp language, the
765 @cindex Lisp vs. C 774 @cindex Lisp vs. C
766 @cindex C vs. Lisp 775 @cindex C vs. Lisp
767 @cindex Lisp vs. Java 776 @cindex Lisp vs. Java
768 @cindex Java vs. Lisp 777 @cindex Java vs. Lisp
769 @cindex dynamic scoping 778 @cindex dynamic scoping
981 that makes it a full-fledged application platform, very much like an OS 990 that makes it a full-fledged application platform, very much like an OS
982 inside the real OS. 991 inside the real OS.
983 992
984 @node XEmacs From the Perspective of Building, XEmacs From the Inside, The Lisp Language, Top 993 @node XEmacs From the Perspective of Building, XEmacs From the Inside, The Lisp Language, Top
985 @chapter XEmacs From the Perspective of Building 994 @chapter XEmacs From the Perspective of Building
995 @cindex XEmacs from the perspective of building
996 @cindex building, XEmacs from the perspective of
986 997
987 The heart of XEmacs is the Lisp environment, which is written in C. 998 The heart of XEmacs is the Lisp environment, which is written in C.
988 This is contained in the @file{src/} subdirectory. Underneath 999 This is contained in the @file{src/} subdirectory. Underneath
989 @file{src/} are two subdirectories of header files: @file{s/} (header 1000 @file{src/} are two subdirectories of header files: @file{s/} (header
990 files for particular operating systems) and @file{m/} (header files for 1001 files for particular operating systems) and @file{m/} (header files for
1090 get mighty confused by the tricks played by the XEmacs build process, 1101 get mighty confused by the tricks played by the XEmacs build process,
1091 such as allocation memory in one process, and freeing it in the next. 1102 such as allocation memory in one process, and freeing it in the next.
1092 1103
1093 @node XEmacs From the Inside, The XEmacs Object System (Abstractly Speaking), XEmacs From the Perspective of Building, Top 1104 @node XEmacs From the Inside, The XEmacs Object System (Abstractly Speaking), XEmacs From the Perspective of Building, Top
1094 @chapter XEmacs From the Inside 1105 @chapter XEmacs From the Inside
1106 @cindex XEmacs from the inside
1107 @cindex inside, XEmacs from the
1095 1108
1096 Internally, XEmacs is quite complex, and can be very confusing. To 1109 Internally, XEmacs is quite complex, and can be very confusing. To
1097 simplify things, it can be useful to think of XEmacs as containing an 1110 simplify things, it can be useful to think of XEmacs as containing an
1098 event loop that ``drives'' everything, and a number of other subsystems, 1111 event loop that ``drives'' everything, and a number of other subsystems,
1099 such as a Lisp engine and a redisplay mechanism. Each of these other 1112 such as a Lisp engine and a redisplay mechanism. Each of these other
1249 of obscure and unwanted interactions occurring than if they were to 1262 of obscure and unwanted interactions occurring than if they were to
1250 change the C code. 1263 change the C code.
1251 1264
1252 @node The XEmacs Object System (Abstractly Speaking), How Lisp Objects Are Represented in C, XEmacs From the Inside, Top 1265 @node The XEmacs Object System (Abstractly Speaking), How Lisp Objects Are Represented in C, XEmacs From the Inside, Top
1253 @chapter The XEmacs Object System (Abstractly Speaking) 1266 @chapter The XEmacs Object System (Abstractly Speaking)
1267 @cindex XEmacs object system (abstractly speaking), the
1268 @cindex object system (abstractly speaking), the XEmacs
1254 1269
1255 At the heart of the Lisp interpreter is its management of objects. 1270 At the heart of the Lisp interpreter is its management of objects.
1256 XEmacs Lisp contains many built-in objects, some of which are 1271 XEmacs Lisp contains many built-in objects, some of which are
1257 simple and others of which can be very complex; and some of which 1272 simple and others of which can be very complex; and some of which
1258 are very common, and others of which are rarely used or are only 1273 are very common, and others of which are rarely used or are only
1608 nor do most complex objects, which contain too much state to be easily 1623 nor do most complex objects, which contain too much state to be easily
1609 initialized through a read syntax. 1624 initialized through a read syntax.
1610 1625
1611 @node How Lisp Objects Are Represented in C, Rules When Writing New C Code, The XEmacs Object System (Abstractly Speaking), Top 1626 @node How Lisp Objects Are Represented in C, Rules When Writing New C Code, The XEmacs Object System (Abstractly Speaking), Top
1612 @chapter How Lisp Objects Are Represented in C 1627 @chapter How Lisp Objects Are Represented in C
1628 @cindex Lisp objects are represented in C, how
1629 @cindex objects are represented in C, how Lisp
1630 @cindex represented in C, how Lisp objects are
1613 1631
1614 Lisp objects are represented in C using a 32-bit or 64-bit machine word 1632 Lisp objects are represented in C using a 32-bit or 64-bit machine word
1615 (depending on the processor; i.e. DEC Alphas use 64-bit Lisp objects and 1633 (depending on the processor; i.e. DEC Alphas use 64-bit Lisp objects and
1616 most other processors use 32-bit Lisp objects). The representation 1634 most other processors use 32-bit Lisp objects). The representation
1617 stuffs a pointer together with a tag, as follows: 1635 stuffs a pointer together with a tag, as follows:
1692 nothing unless the corresponding configure error checking flag was 1710 nothing unless the corresponding configure error checking flag was
1693 specified. 1711 specified.
1694 1712
1695 @node Rules When Writing New C Code, A Summary of the Various XEmacs Modules, How Lisp Objects Are Represented in C, Top 1713 @node Rules When Writing New C Code, A Summary of the Various XEmacs Modules, How Lisp Objects Are Represented in C, Top
1696 @chapter Rules When Writing New C Code 1714 @chapter Rules When Writing New C Code
1715 @cindex writing new C code, rules when
1716 @cindex C code, rules when writing new
1717 @cindex code, rules when writing new C
1697 1718
1698 The XEmacs C Code is extremely complex and intricate, and there are many 1719 The XEmacs C Code is extremely complex and intricate, and there are many
1699 rules that are more or less consistently followed throughout the code. 1720 rules that are more or less consistently followed throughout the code.
1700 Many of these rules are not obvious, so they are explained here. It is 1721 Many of these rules are not obvious, so they are explained here. It is
1701 of the utmost importance that you follow them. If you don't, you may 1722 of the utmost importance that you follow them. If you don't, you may
1703 situations, often in code far away from where the actual breakage is. 1724 situations, often in code far away from where the actual breakage is.
1704 1725
1705 @menu 1726 @menu
1706 * General Coding Rules:: 1727 * General Coding Rules::
1707 * Writing Lisp Primitives:: 1728 * Writing Lisp Primitives::
1729 * Writing Good Comments::
1708 * Adding Global Lisp Variables:: 1730 * Adding Global Lisp Variables::
1731 * Proper Use of Unsigned Types::
1709 * Coding for Mule:: 1732 * Coding for Mule::
1710 * Techniques for XEmacs Developers:: 1733 * Techniques for XEmacs Developers::
1711 @end menu 1734 @end menu
1712 1735
1713 @node General Coding Rules, Writing Lisp Primitives, Rules When Writing New C Code, Rules When Writing New C Code 1736 @node General Coding Rules
1714 @section General Coding Rules 1737 @section General Coding Rules
1738 @cindex coding rules, general
1715 1739
1716 The C code is actually written in a dialect of C called @dfn{Clean C}, 1740 The C code is actually written in a dialect of C called @dfn{Clean C},
1717 meaning that it can be compiled, mostly warning-free, with either a C or 1741 meaning that it can be compiled, mostly warning-free, with either a C or
1718 C++ compiler. Coding in Clean C has several advantages over plain C. 1742 C++ compiler. Coding in Clean C has several advantages over plain C.
1719 C++ compilers are more nit-picking, and a number of coding errors have 1743 C++ compilers are more nit-picking, and a number of coding errors have
1826 case of @code{GET_EXTERNAL_LIST_LENGTH}, validating the properness of 1850 case of @code{GET_EXTERNAL_LIST_LENGTH}, validating the properness of
1827 the list. The macros @code{EXTERNAL_LIST_LOOP_DELETE_IF} and 1851 the list. The macros @code{EXTERNAL_LIST_LOOP_DELETE_IF} and
1828 @code{LIST_LOOP_DELETE_IF} delete elements from a lisp list satisfying some 1852 @code{LIST_LOOP_DELETE_IF} delete elements from a lisp list satisfying some
1829 predicate. 1853 predicate.
1830 1854
1831 @node Writing Lisp Primitives, Adding Global Lisp Variables, General Coding Rules, Rules When Writing New C Code 1855 @node Writing Lisp Primitives
1832 @section Writing Lisp Primitives 1856 @section Writing Lisp Primitives
1857 @cindex writing Lisp primitives
1858 @cindex Lisp primitives, writing
1859 @cindex primitives, writing Lisp
1833 1860
1834 Lisp primitives are Lisp functions implemented in C. The details of 1861 Lisp primitives are Lisp functions implemented in C. The details of
1835 interfacing the C function so that Lisp can call it are handled by a few 1862 interfacing the C function so that Lisp can call it are handled by a few
1836 C macros. The only way to really understand how to write new C code is 1863 C macros. The only way to really understand how to write new C code is
1837 to read the source, but we can explain some things here. 1864 to read the source, but we can explain some things here.
2070 2097
2071 @file{eval.c} is a very good file to look through for examples; 2098 @file{eval.c} is a very good file to look through for examples;
2072 @file{lisp.h} contains the definitions for important macros and 2099 @file{lisp.h} contains the definitions for important macros and
2073 functions. 2100 functions.
2074 2101
2075 @node Adding Global Lisp Variables, Coding for Mule, Writing Lisp Primitives, Rules When Writing New C Code 2102 @node Writing Good Comments
2103 @section Writing Good Comments
2104 @cindex writing good comments
2105 @cindex comments, writing good
2106
2107 Comments are a lifeline for programmers trying to understand tricky
2108 code. In general, the less obvious it is what you are doing, the more
2109 you need a comment, and the more detailed it needs to be. You should
2110 always be on guard when you're writing code for stuff that's tricky, and
2111 should constantly be putting yourself in someone else's shoes and asking
2112 if that person could figure out without much difficulty what's going
2113 on. (Assume they are a competent programmer who understands the
2114 essentials of how the XEmacs code is structured but doesn't know much
2115 about the module you're working on or any algorithms you're using.) If
2116 you're not sure whether they would be able to, add a comment. Always
2117 err on the side of more comments, rather than less.
2118
2119 Generally, when making comments, there is no need to attribute them with
2120 your name or initials. This especially goes for small,
2121 easy-to-understand, non-opinionated ones. Also, comments indicating
2122 where, when, and by whom a file was changed are @emph{strongly}
2123 discouraged, and in general will be removed as they are discovered.
2124 This is exactly what @file{ChangeLogs} are there for. However, it can
2125 occasionally be useful to mark exactly where (but not when or by whom)
2126 changes are made, particularly when making small changes to a file
2127 imported from elsewhere. These marks help when later on a newer version
2128 of the file is imported and the changes need to be merged. (If
2129 everything were always kept in CVS, there would be no need for this.
2130 But in practice, this often doesn't happen, or the CVS repository is
2131 later on lost or unavailable to the person doing the update.)
2132
2133 When putting in an explicit opinion in a comment, you should
2134 @emph{always} attribute it with your name, and optionally the date.
2135 This also goes for long, complex comments explaining in detail the
2136 workings of something -- by putting your name there, you make it
2137 possible for someone who has questions about how that thing works to
2138 determine who wrote the comment so they can write to them. Preferably,
2139 use your actual name and not your initials, unless your initials are
2140 generally recognized (e.g. @samp{jwz}). You can use only your first
2141 name if it's obvious who you are; otherwise, give first and last name.
2142 If you're not a regular contributor, you might consider putting your
2143 email address in -- it may be in the ChangeLog, but after awhile
2144 ChangeLogs have a tendency of disappearing or getting
2145 muddled. (E.g. your comment may get copied somewhere else or even into
2146 another program, and tracking down the proper ChangeLog may be very
2147 difficult.)
2148
2149 If you come across an opinion that is not or no longer valid, or you
2150 come across any comment that no longer applies but you want to keep it
2151 around, enclose it in @samp{[[ } and @samp{ ]]} marks and add a comment
2152 afterwards explaining why the preceding comment is no longer valid. Put
2153 your name on this comment, as explained above.
2154
2155 Just as comments are a lifeline to programmers, incorrect comments are
2156 death. If you come across an incorrect comment, @strong{immediately}
2157 correct it or flag it as incorrect, as described in the previous
2158 paragraph. Whenever you work on a section of code, @emph{always} make
2159 sure to update any comments to be correct -- or, at the very least, flag
2160 them as incorrect.
2161
2162 To indicate a "todo" or other problem, use four pound signs --
2163 i.e. @samp{####}.
2164
2165 @node Adding Global Lisp Variables
2076 @section Adding Global Lisp Variables 2166 @section Adding Global Lisp Variables
2167 @cindex global Lisp variables, adding
2168 @cindex variables, adding global Lisp
2077 2169
2078 Global variables whose names begin with @samp{Q} are constants whose 2170 Global variables whose names begin with @samp{Q} are constants whose
2079 value is a symbol of a particular name. The name of the variable should 2171 value is a symbol of a particular name. The name of the variable should
2080 be derived from the name of the symbol using the same rules as for Lisp 2172 be derived from the name of the symbol using the same rules as for Lisp
2081 primitives. These variables are initialized using a call to 2173 primitives. These variables are initialized using a call to
2132 garbage-collection mechanism won't know that the object in this variable 2224 garbage-collection mechanism won't know that the object in this variable
2133 is in use, and will happily collect it and reuse its storage for another 2225 is in use, and will happily collect it and reuse its storage for another
2134 Lisp object, and you will be the one who's unhappy when you can't figure 2226 Lisp object, and you will be the one who's unhappy when you can't figure
2135 out how your variable got overwritten. 2227 out how your variable got overwritten.
2136 2228
2137 @node Coding for Mule, Techniques for XEmacs Developers, Adding Global Lisp Variables, Rules When Writing New C Code 2229 @node Proper Use of Unsigned Types
2230 @section Proper Use of Unsigned Types
2231 @cindex unsigned types, proper use of
2232 @cindex types, proper use of unsigned
2233
2234 Avoid using @code{unsigned int} and @code{unsigned long} whenever
2235 possible. Unsigned types are viral -- any arithmetic or comparisons
2236 involving mixed signed and unsigned types are automatically converted to
2237 unsigned, which is almost certainly not what you want. Many subtle and
2238 hard-to-find bugs are created by careless use of unsigned types. In
2239 general, you should almost @emph{never} use an unsigned type to hold a
2240 regular quantity of any sort. The only exceptions are
2241
2242 @enumerate
2243 @item
2244 When there's a reasonable possibility you will actually need all 32 or
2245 64 bits to store the quantity.
2246 @item
2247 When calling existing API's that require unsigned types. In this case,
2248 you should still do all manipulation using signed types, and do the
2249 conversion at the very threshold of the API call.
2250 @item
2251 In existing code that you don't want to modify because you don't
2252 maintain it.
2253 @item
2254 In bit-field structures.
2255 @end enumerate
2256
2257 Other reasonable uses of @code{unsigned int} and @code{unsigned long}
2258 are representing non-quantities -- e.g. bit-oriented flags and such.
2259
2260 @node Coding for Mule
2138 @section Coding for Mule 2261 @section Coding for Mule
2139 @cindex Coding for Mule 2262 @cindex coding for Mule
2263 @cindex Mule, coding for
2140 2264
2141 Although Mule support is not compiled by default in XEmacs, many people 2265 Although Mule support is not compiled by default in XEmacs, many people
2142 are using it, and we consider it crucial that new code works correctly 2266 are using it, and we consider it crucial that new code works correctly
2143 with multibyte characters. This is not hard; it is only a matter of 2267 with multibyte characters. This is not hard; it is only a matter of
2144 following several simple user-interface guidelines. Even if you never 2268 following several simple user-interface guidelines. Even if you never
2155 * Conversion to and from External Data:: 2279 * Conversion to and from External Data::
2156 * General Guidelines for Writing Mule-Aware Code:: 2280 * General Guidelines for Writing Mule-Aware Code::
2157 * An Example of Mule-Aware Code:: 2281 * An Example of Mule-Aware Code::
2158 @end menu 2282 @end menu
2159 2283
2160 @node Character-Related Data Types, Working With Character and Byte Positions, Coding for Mule, Coding for Mule 2284 @node Character-Related Data Types
2161 @subsection Character-Related Data Types 2285 @subsection Character-Related Data Types
2286 @cindex character-related data types
2287 @cindex data types, character-related
2162 2288
2163 First, let's review the basic character-related datatypes used by 2289 First, let's review the basic character-related datatypes used by
2164 XEmacs. Note that the separate @code{typedef}s are not mandatory in the 2290 XEmacs. Note that the separate @code{typedef}s are not mandatory in the
2165 current implementation (all of them boil down to @code{unsigned char} or 2291 current implementation (all of them boil down to @code{unsigned char} or
2166 @code{int}), but they improve clarity of code a great deal, because one 2292 @code{int}), but they improve clarity of code a great deal, because one
2232 which are equivalent to @code{unsigned char}. Obviously, an 2358 which are equivalent to @code{unsigned char}. Obviously, an
2233 @code{Extcount} is the distance between two @code{Extbyte}s. Extbytes 2359 @code{Extcount} is the distance between two @code{Extbyte}s. Extbytes
2234 and Extcounts are not all that frequent in XEmacs code. 2360 and Extcounts are not all that frequent in XEmacs code.
2235 @end table 2361 @end table
2236 2362
2237 @node Working With Character and Byte Positions, Conversion to and from External Data, Character-Related Data Types, Coding for Mule 2363 @node Working With Character and Byte Positions
2238 @subsection Working With Character and Byte Positions 2364 @subsection Working With Character and Byte Positions
2365 @cindex character and byte positions, working with
2366 @cindex byte positions, working with character and
2367 @cindex positions, working with character and byte
2239 2368
2240 Now that we have defined the basic character-related types, we can look 2369 Now that we have defined the basic character-related types, we can look
2241 at the macros and functions designed for work with them and for 2370 at the macros and functions designed for work with them and for
2242 conversion between them. Most of these macros are defined in 2371 conversion between them. Most of these macros are defined in
2243 @file{buffer.h}, and we don't discuss all of them here, but only the 2372 @file{buffer.h}, and we don't discuss all of them here, but only the
2356 @example 2485 @example
2357 Bufbyte *charptr_n_addr (Bufbyte *p, Charcount cc); 2486 Bufbyte *charptr_n_addr (Bufbyte *p, Charcount cc);
2358 @end example 2487 @end example
2359 @end table 2488 @end table
2360 2489
2361 @node Conversion to and from External Data, General Guidelines for Writing Mule-Aware Code, Working With Character and Byte Positions, Coding for Mule 2490 @node Conversion to and from External Data
2362 @subsection Conversion to and from External Data 2491 @subsection Conversion to and from External Data
2492 @cindex conversion to and from external data
2493 @cindex external data, conversion to and from
2363 2494
2364 When an external function, such as a C library function, returns a 2495 When an external function, such as a C library function, returns a
2365 @code{char} pointer, you should almost never treat it as @code{Bufbyte}. 2496 @code{char} pointer, you should almost never treat it as @code{Bufbyte}.
2366 This is because these returned strings may contain 8bit characters which 2497 This is because these returned strings may contain 8bit characters which
2367 can be misinterpreted by XEmacs, and cause a crash. Likewise, when 2498 can be misinterpreted by XEmacs, and cause a crash. Likewise, when
2498 Note that it doesn't make sense for @code{LISP_STRING} to be a source 2629 Note that it doesn't make sense for @code{LISP_STRING} to be a source
2499 for @code{TO_INTERNAL_FORMAT} or a sink for @code{TO_EXTERNAL_FORMAT}. 2630 for @code{TO_INTERNAL_FORMAT} or a sink for @code{TO_EXTERNAL_FORMAT}.
2500 You'll get an assertion failure if you try. 2631 You'll get an assertion failure if you try.
2501 2632
2502 2633
2503 @node General Guidelines for Writing Mule-Aware Code, An Example of Mule-Aware Code, Conversion to and from External Data, Coding for Mule 2634 @node General Guidelines for Writing Mule-Aware Code
2504 @subsection General Guidelines for Writing Mule-Aware Code 2635 @subsection General Guidelines for Writing Mule-Aware Code
2636 @cindex writing Mule-aware code, general guidelines for
2637 @cindex Mule-aware code, general guidelines for writing
2638 @cindex code, general guidelines for writing Mule-aware
2505 2639
2506 This section contains some general guidance on how to write Mule-aware 2640 This section contains some general guidance on how to write Mule-aware
2507 code, as well as some pitfalls you should avoid. 2641 code, as well as some pitfalls you should avoid.
2508 2642
2509 @table @emph 2643 @table @emph
2550 they receive. This increases efficiency because that way external data 2684 they receive. This increases efficiency because that way external data
2551 needs to be decoded only once, when it is read. After that, it is 2685 needs to be decoded only once, when it is read. After that, it is
2552 passed around in internal format. 2686 passed around in internal format.
2553 @end table 2687 @end table
2554 2688
2555 @node An Example of Mule-Aware Code, , General Guidelines for Writing Mule-Aware Code, Coding for Mule 2689 @node An Example of Mule-Aware Code
2556 @subsection An Example of Mule-Aware Code 2690 @subsection An Example of Mule-Aware Code
2691 @cindex code, an example of Mule-aware
2692 @cindex Mule-aware code, an example of
2557 2693
2558 As an example of Mule-aware code, we will analyze the @code{string} 2694 As an example of Mule-aware code, we will analyze the @code{string}
2559 function, which conses up a Lisp string from the character arguments it 2695 function, which conses up a Lisp string from the character arguments it
2560 receives. Here is the definition, pasted from @code{alloc.c}: 2696 receives. Here is the definition, pasted from @code{alloc.c}:
2561 2697
2600 over the XEmacs code. For starters, I recommend 2736 over the XEmacs code. For starters, I recommend
2601 @code{Fnormalize_menu_item_name} in @file{menubar.c}. After you have 2737 @code{Fnormalize_menu_item_name} in @file{menubar.c}. After you have
2602 understood this section of the manual and studied the examples, you can 2738 understood this section of the manual and studied the examples, you can
2603 proceed writing new Mule-aware code. 2739 proceed writing new Mule-aware code.
2604 2740
2605 @node Techniques for XEmacs Developers, , Coding for Mule, Rules When Writing New C Code 2741 @node Techniques for XEmacs Developers
2606 @section Techniques for XEmacs Developers 2742 @section Techniques for XEmacs Developers
2607 2743 @cindex techniques for XEmacs developers
2744 @cindex developers, techniques for XEmacs
2745
2746 @cindex Purify
2747 @cindex Quantify
2608 To make a purified XEmacs, do: @code{make puremacs}. 2748 To make a purified XEmacs, do: @code{make puremacs}.
2609 To make a quantified XEmacs, do: @code{make quantmacs}. 2749 To make a quantified XEmacs, do: @code{make quantmacs}.
2610 2750
2611 You simply can't dump Quantified and Purified images (unless using the 2751 You simply can't dump Quantified and Purified images (unless using the
2612 portable dumper). Purify gets confused when xemacs frees memory in one 2752 portable dumper). Purify gets confused when xemacs frees memory in one
2614 machine!. Run it like so: 2754 machine!. Run it like so:
2615 @example 2755 @example
2616 temacs -batch -l loadup.el run-temacs @var{xemacs-args...} 2756 temacs -batch -l loadup.el run-temacs @var{xemacs-args...}
2617 @end example 2757 @end example
2618 2758
2759 @cindex error checking
2619 Before you go through the trouble, are you compiling with all 2760 Before you go through the trouble, are you compiling with all
2620 debugging and error-checking off? If not, try that first. Be warned 2761 debugging and error-checking off? If not, try that first. Be warned
2621 that while Quantify is directly responsible for quite a few 2762 that while Quantify is directly responsible for quite a few
2622 optimizations which have been made to XEmacs, doing a run which 2763 optimizations which have been made to XEmacs, doing a run which
2623 generates results which can be acted upon is not necessarily a trivial 2764 generates results which can be acted upon is not necessarily a trivial
2658 2799
2659 Heavily used small code fragments need to be fast. The traditional way 2800 Heavily used small code fragments need to be fast. The traditional way
2660 to implement such code fragments in C is with macros. But macros in C 2801 to implement such code fragments in C is with macros. But macros in C
2661 are known to be broken. 2802 are known to be broken.
2662 2803
2804 @cindex macro hygiene
2663 Macro arguments that are repeatedly evaluated may suffer from repeated 2805 Macro arguments that are repeatedly evaluated may suffer from repeated
2664 side effects or suboptimal performance. 2806 side effects or suboptimal performance.
2665 2807
2666 Variable names used in macros may collide with caller's variables, 2808 Variable names used in macros may collide with caller's variables,
2667 causing (at least) unwanted compiler warnings. 2809 causing (at least) unwanted compiler warnings.
2700 care. The one problem with macros that cannot be portably worked around 2842 care. The one problem with macros that cannot be portably worked around
2701 is, since a C block has no value, a macro used as an expression rather 2843 is, since a C block has no value, a macro used as an expression rather
2702 than a statement cannot use the techniques just described to avoid 2844 than a statement cannot use the techniques just described to avoid
2703 multiple evaluation. 2845 multiple evaluation.
2704 2846
2847 @cindex inline functions
2705 In most cases where a macro has function semantics, an inline function 2848 In most cases where a macro has function semantics, an inline function
2706 is a better implementation technique. Modern compiler optimizers tend 2849 is a better implementation technique. Modern compiler optimizers tend
2707 to inline functions even if they have no @code{inline} keyword, and 2850 to inline functions even if they have no @code{inline} keyword, and
2708 configure magic ensures that the @code{inline} keyword can be safely 2851 configure magic ensures that the @code{inline} keyword can be safely
2709 used as an additional compiler hint. Inline functions used in a single 2852 used as an additional compiler hint. Inline functions used in a single
2742 2885
2743 The declaration right before the definition is to prevent warnings when 2886 The declaration right before the definition is to prevent warnings when
2744 compiling with @code{gcc -Wmissing-declarations}. I consider issuing 2887 compiling with @code{gcc -Wmissing-declarations}. I consider issuing
2745 this warning for inline functions a gcc bug, but the gcc maintainers disagree. 2888 this warning for inline functions a gcc bug, but the gcc maintainers disagree.
2746 2889
2890 @cindex inline functions, headers
2891 @cindex header files, inline functions
2747 Every header which contains inline functions, either directly by using 2892 Every header which contains inline functions, either directly by using
2748 @code{INLINE_HEADER} or indirectly by using @code{DECLARE_LRECORD} must 2893 @code{INLINE_HEADER} or indirectly by using @code{DECLARE_LRECORD} must
2749 be added to @file{inline.c}'s includes to make the optimization 2894 be added to @file{inline.c}'s includes to make the optimization
2750 described above work. (Optimization note: if all INLINE_HEADER 2895 described above work. (Optimization note: if all INLINE_HEADER
2751 functions are in fact inlined in all translation units, then the linker 2896 functions are in fact inlined in all translation units, then the linker
2792 @code{"lisp.h"}. It is the responsibility of the @file{.c} files that 2937 @code{"lisp.h"}. It is the responsibility of the @file{.c} files that
2793 use it to do so. 2938 use it to do so.
2794 2939
2795 @end itemize 2940 @end itemize
2796 2941
2942 @cindex Lisp object types, creating
2943 @cindex creating Lisp object types
2944 @cindex object types, creating Lisp
2797 Here is a checklist of things to do when creating a new lisp object type 2945 Here is a checklist of things to do when creating a new lisp object type
2798 named @var{foo}: 2946 named @var{foo}:
2799 2947
2800 @enumerate 2948 @enumerate
2801 @item 2949 @item
2819 add an INIT_LRECORD_IMPLEMENTATION call to @code{syms_of_@var{foo}.c} 2967 add an INIT_LRECORD_IMPLEMENTATION call to @code{syms_of_@var{foo}.c}
2820 @end enumerate 2968 @end enumerate
2821 2969
2822 @node A Summary of the Various XEmacs Modules, Allocation of Objects in XEmacs Lisp, Rules When Writing New C Code, Top 2970 @node A Summary of the Various XEmacs Modules, Allocation of Objects in XEmacs Lisp, Rules When Writing New C Code, Top
2823 @chapter A Summary of the Various XEmacs Modules 2971 @chapter A Summary of the Various XEmacs Modules
2972 @cindex modules, a summary of the various XEmacs
2824 2973
2825 This is accurate as of XEmacs 20.0. 2974 This is accurate as of XEmacs 20.0.
2826 2975
2827 @menu 2976 @menu
2828 * Low-Level Modules:: 2977 * Low-Level Modules::
2837 * Modules for Interfacing with the Operating System:: 2986 * Modules for Interfacing with the Operating System::
2838 * Modules for Interfacing with X Windows:: 2987 * Modules for Interfacing with X Windows::
2839 * Modules for Internationalization:: 2988 * Modules for Internationalization::
2840 @end menu 2989 @end menu
2841 2990
2842 @node Low-Level Modules, Basic Lisp Modules, A Summary of the Various XEmacs Modules, A Summary of the Various XEmacs Modules 2991 @node Low-Level Modules
2843 @section Low-Level Modules 2992 @section Low-Level Modules
2993 @cindex low-level modules
2994 @cindex modules, low-level
2844 2995
2845 @example 2996 @example
2846 config.h 2997 config.h
2847 @end example 2998 @end example
2848 2999
3053 3204
3054 This is not currently used. 3205 This is not currently used.
3055 3206
3056 3207
3057 3208
3058 @node Basic Lisp Modules, Modules for Standard Editing Operations, Low-Level Modules, A Summary of the Various XEmacs Modules 3209 @node Basic Lisp Modules
3059 @section Basic Lisp Modules 3210 @section Basic Lisp Modules
3211 @cindex Lisp modules, basic
3212 @cindex modules, basic Lisp
3060 3213
3061 @example 3214 @example
3062 lisp-disunion.h 3215 lisp-disunion.h
3063 lisp-union.h 3216 lisp-union.h
3064 lisp.h 3217 lisp.h
3227 structures. Note that the byte-code @emph{compiler} is written in Lisp. 3380 structures. Note that the byte-code @emph{compiler} is written in Lisp.
3228 3381
3229 3382
3230 3383
3231 3384
3232 @node Modules for Standard Editing Operations, Editor-Level Control Flow Modules, Basic Lisp Modules, A Summary of the Various XEmacs Modules 3385 @node Modules for Standard Editing Operations
3233 @section Modules for Standard Editing Operations 3386 @section Modules for Standard Editing Operations
3387 @cindex modules for standard editing operations
3388 @cindex editing operations, modules for standard
3234 3389
3235 @example 3390 @example
3236 buffer.c 3391 buffer.c
3237 buffer.h 3392 buffer.h
3238 bufslots.h 3393 bufslots.h
3397 This module implements the undo mechanism for tracking buffer changes. 3552 This module implements the undo mechanism for tracking buffer changes.
3398 Most of this could be implemented in Lisp. 3553 Most of this could be implemented in Lisp.
3399 3554
3400 3555
3401 3556
3402 @node Editor-Level Control Flow Modules, Modules for the Basic Displayable Lisp Objects, Modules for Standard Editing Operations, A Summary of the Various XEmacs Modules 3557 @node Editor-Level Control Flow Modules
3403 @section Editor-Level Control Flow Modules 3558 @section Editor-Level Control Flow Modules
3559 @cindex control flow modules, editor-level
3560 @cindex modules, editor-level control flow
3404 3561
3405 @example 3562 @example
3406 event-Xt.c 3563 event-Xt.c
3407 event-msw.c 3564 event-msw.c
3408 event-stream.c 3565 event-stream.c
3499 bootstrapping implementations early in temacs, before the echo-area Lisp 3656 bootstrapping implementations early in temacs, before the echo-area Lisp
3500 code is loaded). 3657 code is loaded).
3501 3658
3502 3659
3503 3660
3504 @node Modules for the Basic Displayable Lisp Objects, Modules for other Display-Related Lisp Objects, Editor-Level Control Flow Modules, A Summary of the Various XEmacs Modules 3661 @node Modules for the Basic Displayable Lisp Objects
3505 @section Modules for the Basic Displayable Lisp Objects 3662 @section Modules for the Basic Displayable Lisp Objects
3663 @cindex modules for the basic displayable Lisp objects
3664 @cindex displayable Lisp objects, modules for the basic
3665 @cindex Lisp objects, modules for the basic displayable
3666 @cindex objects, modules for the basic displayable Lisp
3506 3667
3507 @example 3668 @example
3508 console-msw.c 3669 console-msw.c
3509 console-msw.h 3670 console-msw.h
3510 console-stream.c 3671 console-stream.c
3590 is part of the redisplay mechanism or the code for particular object 3751 is part of the redisplay mechanism or the code for particular object
3591 types such as scrollbars. 3752 types such as scrollbars.
3592 3753
3593 3754
3594 3755
3595 @node Modules for other Display-Related Lisp Objects, Modules for the Redisplay Mechanism, Modules for the Basic Displayable Lisp Objects, A Summary of the Various XEmacs Modules 3756 @node Modules for other Display-Related Lisp Objects
3596 @section Modules for other Display-Related Lisp Objects 3757 @section Modules for other Display-Related Lisp Objects
3758 @cindex modules for other display-related Lisp objects
3759 @cindex display-related Lisp objects, modules for other
3760 @cindex Lisp objects, modules for other display-related
3597 3761
3598 @example 3762 @example
3599 faces.c 3763 faces.c
3600 faces.h 3764 faces.h
3601 @end example 3765 @end example
3680 These modules decode GIF-format image files, for use with glyphs. 3844 These modules decode GIF-format image files, for use with glyphs.
3681 These files were removed due to Unisys patent infringement concerns. 3845 These files were removed due to Unisys patent infringement concerns.
3682 3846
3683 3847
3684 3848
3685 @node Modules for the Redisplay Mechanism, Modules for Interfacing with the File System, Modules for other Display-Related Lisp Objects, A Summary of the Various XEmacs Modules 3849 @node Modules for the Redisplay Mechanism
3686 @section Modules for the Redisplay Mechanism 3850 @section Modules for the Redisplay Mechanism
3851 @cindex modules for the redisplay mechanism
3852 @cindex redisplay mechanism, modules for the
3687 3853
3688 @example 3854 @example
3689 redisplay-output.c 3855 redisplay-output.c
3690 redisplay-msw.c 3856 redisplay-msw.c
3691 redisplay-tty.c 3857 redisplay-tty.c
3753 These files provide some miscellaneous TTY-output functions and should 3919 These files provide some miscellaneous TTY-output functions and should
3754 probably be merged into @file{redisplay-tty.c}. 3920 probably be merged into @file{redisplay-tty.c}.
3755 3921
3756 3922
3757 3923
3758 @node Modules for Interfacing with the File System, Modules for Other Aspects of the Lisp Interpreter and Object System, Modules for the Redisplay Mechanism, A Summary of the Various XEmacs Modules 3924 @node Modules for Interfacing with the File System
3759 @section Modules for Interfacing with the File System 3925 @section Modules for Interfacing with the File System
3926 @cindex modules for interfacing with the file system
3927 @cindex interfacing with the file system, modules for
3928 @cindex file system, modules for interfacing with the
3760 3929
3761 @example 3930 @example
3762 lstream.c 3931 lstream.c
3763 lstream.h 3932 lstream.h
3764 @end example 3933 @end example
3854 for expanding symbolic links, on systems that don't implement it or have 4023 for expanding symbolic links, on systems that don't implement it or have
3855 a broken implementation. 4024 a broken implementation.
3856 4025
3857 4026
3858 4027
3859 @node Modules for Other Aspects of the Lisp Interpreter and Object System, Modules for Interfacing with the Operating System, Modules for Interfacing with the File System, A Summary of the Various XEmacs Modules 4028 @node Modules for Other Aspects of the Lisp Interpreter and Object System
3860 @section Modules for Other Aspects of the Lisp Interpreter and Object System 4029 @section Modules for Other Aspects of the Lisp Interpreter and Object System
4030 @cindex modules for other aspects of the Lisp interpreter and object system
4031 @cindex Lisp interpreter and object system, modules for other aspects of the
4032 @cindex interpreter and object system, modules for other aspects of the Lisp
4033 @cindex object system, modules for other aspects of the Lisp interpreter and
3861 4034
3862 @example 4035 @example
3863 elhash.c 4036 elhash.c
3864 elhash.h 4037 elhash.h
3865 hash.c 4038 hash.c
4016 various security applications on the Internet. 4189 various security applications on the Internet.
4017 4190
4018 4191
4019 4192
4020 4193
4021 @node Modules for Interfacing with the Operating System, Modules for Interfacing with X Windows, Modules for Other Aspects of the Lisp Interpreter and Object System, A Summary of the Various XEmacs Modules 4194 @node Modules for Interfacing with the Operating System
4022 @section Modules for Interfacing with the Operating System 4195 @section Modules for Interfacing with the Operating System
4196 @cindex modules for interfacing with the operating system
4197 @cindex interfacing with the operating system, modules for
4198 @cindex operating system, modules for interfacing with the
4023 4199
4024 @example 4200 @example
4025 callproc.c 4201 callproc.c
4026 process.c 4202 process.c
4027 process.h 4203 process.h
4245 This module provides some terminal-control code necessary on versions of 4421 This module provides some terminal-control code necessary on versions of
4246 AIX prior to 4.1. 4422 AIX prior to 4.1.
4247 4423
4248 4424
4249 4425
4250 @node Modules for Interfacing with X Windows, Modules for Internationalization, Modules for Interfacing with the Operating System, A Summary of the Various XEmacs Modules 4426 @node Modules for Interfacing with X Windows
4251 @section Modules for Interfacing with X Windows 4427 @section Modules for Interfacing with X Windows
4428 @cindex modules for interfacing with X Windows
4429 @cindex interfacing with X Windows, modules for
4430 @cindex X Windows, modules for interfacing with
4252 4431
4253 @example 4432 @example
4254 Emacs.ad.h 4433 Emacs.ad.h
4255 @end example 4434 @end example
4256 4435
4390 4569
4391 Don't touch this code; something is liable to break if you do. 4570 Don't touch this code; something is liable to break if you do.
4392 4571
4393 4572
4394 4573
4395 @node Modules for Internationalization, , Modules for Interfacing with X Windows, A Summary of the Various XEmacs Modules 4574 @node Modules for Internationalization
4396 @section Modules for Internationalization 4575 @section Modules for Internationalization
4576 @cindex modules for internationalization
4577 @cindex internationalization, modules for
4397 4578
4398 @example 4579 @example
4399 mule-canna.c 4580 mule-canna.c
4400 mule-ccl.c 4581 mule-ccl.c
4401 mule-charset.c 4582 mule-charset.c
4469 4650
4470 4651
4471 4652
4472 @node Allocation of Objects in XEmacs Lisp, Dumping, A Summary of the Various XEmacs Modules, Top 4653 @node Allocation of Objects in XEmacs Lisp, Dumping, A Summary of the Various XEmacs Modules, Top
4473 @chapter Allocation of Objects in XEmacs Lisp 4654 @chapter Allocation of Objects in XEmacs Lisp
4655 @cindex allocation of objects in XEmacs Lisp
4656 @cindex objects in XEmacs Lisp, allocation of
4657 @cindex Lisp objects, allocation of in XEmacs
4474 4658
4475 @menu 4659 @menu
4476 * Introduction to Allocation:: 4660 * Introduction to Allocation::
4477 * Garbage Collection:: 4661 * Garbage Collection::
4478 * GCPROing:: 4662 * GCPROing::
4488 * Marker:: 4672 * Marker::
4489 * String:: 4673 * String::
4490 * Compiled Function:: 4674 * Compiled Function::
4491 @end menu 4675 @end menu
4492 4676
4493 @node Introduction to Allocation, Garbage Collection, Allocation of Objects in XEmacs Lisp, Allocation of Objects in XEmacs Lisp 4677 @node Introduction to Allocation
4494 @section Introduction to Allocation 4678 @section Introduction to Allocation
4679 @cindex allocation, introduction to
4495 4680
4496 Emacs Lisp, like all Lisps, has garbage collection. This means that 4681 Emacs Lisp, like all Lisps, has garbage collection. This means that
4497 the programmer never has to explicitly free (destroy) an object; it 4682 the programmer never has to explicitly free (destroy) an object; it
4498 happens automatically when the object becomes inaccessible. Most 4683 happens automatically when the object becomes inaccessible. Most
4499 experts agree that garbage collection is a necessity in a modern, 4684 experts agree that garbage collection is a necessity in a modern,
4559 like vectors. You can basically view them as exactly like vectors 4744 like vectors. You can basically view them as exactly like vectors
4560 except that their type is stored in lrecord fashion rather than 4745 except that their type is stored in lrecord fashion rather than
4561 in directly-tagged fashion. 4746 in directly-tagged fashion.
4562 4747
4563 4748
4564 @node Garbage Collection, GCPROing, Introduction to Allocation, Allocation of Objects in XEmacs Lisp 4749 @node Garbage Collection
4565 @section Garbage Collection 4750 @section Garbage Collection
4566 @cindex garbage collection 4751 @cindex garbage collection
4567 4752
4568 @cindex mark and sweep 4753 @cindex mark and sweep
4569 Garbage collection is simple in theory but tricky to implement. 4754 Garbage collection is simple in theory but tricky to implement.
4583 @code{garbage-collect} but is also called automatically by @code{eval}, 4768 @code{garbage-collect} but is also called automatically by @code{eval},
4584 once a certain amount of memory has been allocated since the last 4769 once a certain amount of memory has been allocated since the last
4585 garbage collection (according to @code{gc-cons-threshold}). 4770 garbage collection (according to @code{gc-cons-threshold}).
4586 4771
4587 4772
4588 @node GCPROing, Garbage Collection - Step by Step, Garbage Collection, Allocation of Objects in XEmacs Lisp 4773 @node GCPROing
4589 @section @code{GCPRO}ing 4774 @section @code{GCPRO}ing
4775 @cindex @code{GCPRO}ing
4776 @cindex garbage collection protection
4777 @cindex protection, garbage collection
4590 4778
4591 @code{GCPRO}ing is one of the ugliest and trickiest parts of Emacs 4779 @code{GCPRO}ing is one of the ugliest and trickiest parts of Emacs
4592 internals. The basic idea is that whenever garbage collection 4780 internals. The basic idea is that whenever garbage collection
4593 occurs, all in-use objects must be reachable somehow or 4781 occurs, all in-use objects must be reachable somehow or
4594 other from one of the roots of accessibility. The roots 4782 other from one of the roots of accessibility. The roots
4739 anything that looks like a reference to an object as a reference. This 4927 anything that looks like a reference to an object as a reference. This
4740 will result in a few objects not getting collected when they should, but 4928 will result in a few objects not getting collected when they should, but
4741 it obviates the need for @code{GCPRO}ing, and allows garbage collection 4929 it obviates the need for @code{GCPRO}ing, and allows garbage collection
4742 to happen at any point at all, such as during object allocation. 4930 to happen at any point at all, such as during object allocation.
4743 4931
4744 @node Garbage Collection - Step by Step, Integers and Characters, GCPROing, Allocation of Objects in XEmacs Lisp 4932 @node Garbage Collection - Step by Step
4745 @section Garbage Collection - Step by Step 4933 @section Garbage Collection - Step by Step
4746 @cindex garbage collection step by step 4934 @cindex garbage collection - step by step
4747 4935
4748 @menu 4936 @menu
4749 * Invocation:: 4937 * Invocation::
4750 * garbage_collect_1:: 4938 * garbage_collect_1::
4751 * mark_object:: 4939 * mark_object::
4754 * compact_string_chars:: 4942 * compact_string_chars::
4755 * sweep_strings:: 4943 * sweep_strings::
4756 * sweep_bit_vectors_1:: 4944 * sweep_bit_vectors_1::
4757 @end menu 4945 @end menu
4758 4946
4759 @node Invocation, garbage_collect_1, Garbage Collection - Step by Step, Garbage Collection - Step by Step 4947 @node Invocation
4760 @subsection Invocation 4948 @subsection Invocation
4761 @cindex garbage collection, invocation 4949 @cindex garbage collection, invocation
4762 4950
4763 The first thing that anyone should know about garbage collection is: 4951 The first thing that anyone should know about garbage collection is:
4764 when and how the garbage collector is invoked. One might think that this 4952 when and how the garbage collector is invoked. One might think that this
4814 everything related to @code{eval} (@code{Feval_buffer}, @code{call0}, 5002 everything related to @code{eval} (@code{Feval_buffer}, @code{call0},
4815 ...) and inside @code{Fsignal}. The latter is used to handle signals, as 5003 ...) and inside @code{Fsignal}. The latter is used to handle signals, as
4816 for example the ones raised by every @code{QUIT}-macro triggered after 5004 for example the ones raised by every @code{QUIT}-macro triggered after
4817 pressing Ctrl-g. 5005 pressing Ctrl-g.
4818 5006
4819 @node garbage_collect_1, mark_object, Invocation, Garbage Collection - Step by Step 5007 @node garbage_collect_1
4820 @subsection @code{garbage_collect_1} 5008 @subsection @code{garbage_collect_1}
4821 @cindex @code{garbage_collect_1} 5009 @cindex @code{garbage_collect_1}
4822 5010
4823 We can now describe exactly what happens after the invocation takes 5011 We can now describe exactly what happens after the invocation takes
4824 place. 5012 place.
5004 A small memory reserve is always held back that can be reached by 5192 A small memory reserve is always held back that can be reached by
5005 @code{breathing_space}. If nothing more is left, we create a new reserve 5193 @code{breathing_space}. If nothing more is left, we create a new reserve
5006 and exit. 5194 and exit.
5007 @end enumerate 5195 @end enumerate
5008 5196
5009 @node mark_object, gc_sweep, garbage_collect_1, Garbage Collection - Step by Step 5197 @node mark_object
5010 @subsection @code{mark_object} 5198 @subsection @code{mark_object}
5011 @cindex @code{mark_object} 5199 @cindex @code{mark_object}
5012 5200
5013 The first thing that is checked while marking an object is whether the 5201 The first thing that is checked while marking an object is whether the
5014 object is a real Lisp object @code{Lisp_Type_Record} or just an integer 5202 object is a real Lisp object @code{Lisp_Type_Record} or just an integer
5038 be performed. 5226 be performed.
5039 5227
5040 In case another object was returned, as mentioned before, we reiterate 5228 In case another object was returned, as mentioned before, we reiterate
5041 the whole @code{mark_object} process beginning with this next object. 5229 the whole @code{mark_object} process beginning with this next object.
5042 5230
5043 @node gc_sweep, sweep_lcrecords_1, mark_object, Garbage Collection - Step by Step 5231 @node gc_sweep
5044 @subsection @code{gc_sweep} 5232 @subsection @code{gc_sweep}
5045 @cindex @code{gc_sweep} 5233 @cindex @code{gc_sweep}
5046 5234
5047 The job of this function is to free all unmarked records from memory. As 5235 The job of this function is to free all unmarked records from memory. As
5048 we know, there are different types of objects implemented and managed, and 5236 we know, there are different types of objects implemented and managed, and
5133 (by @code{UNMARK_...}). While going through one block, we note if the 5321 (by @code{UNMARK_...}). While going through one block, we note if the
5134 whole block is empty. If so, the whole block is freed (using 5322 whole block is empty. If so, the whole block is freed (using
5135 @code{xfree}) and the free list state is set to the state it had before 5323 @code{xfree}) and the free list state is set to the state it had before
5136 handling this block. 5324 handling this block.
5137 5325
5138 @node sweep_lcrecords_1, compact_string_chars, gc_sweep, Garbage Collection - Step by Step 5326 @node sweep_lcrecords_1
5139 @subsection @code{sweep_lcrecords_1} 5327 @subsection @code{sweep_lcrecords_1}
5140 @cindex @code{sweep_lcrecords_1} 5328 @cindex @code{sweep_lcrecords_1}
5141 5329
5142 After nullifying the complete lcrecord statistics, we go over all 5330 After nullifying the complete lcrecord statistics, we go over all
5143 lcrecords two separate times. They are all chained together in a list with 5331 lcrecords two separate times. They are all chained together in a list with
5154 through the whole list. In case an object is read only or marked, it 5342 through the whole list. In case an object is read only or marked, it
5155 has to persist, otherwise it is manually freed by calling 5343 has to persist, otherwise it is manually freed by calling
5156 @code{xfree}. During this loop, the lcrecord statistics are kept up to 5344 @code{xfree}. During this loop, the lcrecord statistics are kept up to
5157 date by calling @code{tick_lcrecord_stats} with the right arguments, 5345 date by calling @code{tick_lcrecord_stats} with the right arguments,
5158 5346
5159 @node compact_string_chars, sweep_strings, sweep_lcrecords_1, Garbage Collection - Step by Step 5347 @node compact_string_chars
5160 @subsection @code{compact_string_chars} 5348 @subsection @code{compact_string_chars}
5161 @cindex @code{compact_string_chars} 5349 @cindex @code{compact_string_chars}
5162 5350
5163 The purpose of this function is to compact all the data parts of the 5351 The purpose of this function is to compact all the data parts of the
5164 strings that are held in so-called @code{string_chars_block}, i.e. the 5352 strings that are held in so-called @code{string_chars_block}, i.e. the
5200 @code{string_chars_block}, sitting in @code{current_string_chars_block}, 5388 @code{string_chars_block}, sitting in @code{current_string_chars_block},
5201 is reset on the last block to which we moved a string, 5389 is reset on the last block to which we moved a string,
5202 i.e. @code{to_block}, and all remaining blocks (we know that they just 5390 i.e. @code{to_block}, and all remaining blocks (we know that they just
5203 carry garbage) are explicitly @code{xfree}d. 5391 carry garbage) are explicitly @code{xfree}d.
5204 5392
5205 @node sweep_strings, sweep_bit_vectors_1, compact_string_chars, Garbage Collection - Step by Step 5393 @node sweep_strings
5206 @subsection @code{sweep_strings} 5394 @subsection @code{sweep_strings}
5207 @cindex @code{sweep_strings} 5395 @cindex @code{sweep_strings}
5208 5396
5209 The sweeping for the fixed sized string objects is essentially exactly 5397 The sweeping for the fixed sized string objects is essentially exactly
5210 the same as it is for all other fixed size types. As before, the freeing 5398 the same as it is for all other fixed size types. As before, the freeing
5221 addition: in case, the string was not allocated in a 5409 addition: in case, the string was not allocated in a
5222 @code{string_chars_block} because it exceeded the maximal length, and 5410 @code{string_chars_block} because it exceeded the maximal length, and
5223 therefore it was @code{malloc}ed separately, we know also @code{xfree} 5411 therefore it was @code{malloc}ed separately, we know also @code{xfree}
5224 it explicitly. 5412 it explicitly.
5225 5413
5226 @node sweep_bit_vectors_1, , sweep_strings, Garbage Collection - Step by Step 5414 @node sweep_bit_vectors_1
5227 @subsection @code{sweep_bit_vectors_1} 5415 @subsection @code{sweep_bit_vectors_1}
5228 @cindex @code{sweep_bit_vectors_1} 5416 @cindex @code{sweep_bit_vectors_1}
5229 5417
5230 Bit vectors are also one of the rare types that are @code{malloc}ed 5418 Bit vectors are also one of the rare types that are @code{malloc}ed
5231 individually. Consequently, while sweeping, all further needless 5419 individually. Consequently, while sweeping, all further needless
5235 all unmarked bit vectors are unlinked by calling @code{xfree} and all of 5423 all unmarked bit vectors are unlinked by calling @code{xfree} and all of
5236 them become unmarked. 5424 them become unmarked.
5237 In addition, the bookkeeping information used for garbage 5425 In addition, the bookkeeping information used for garbage
5238 collector's output purposes is updated. 5426 collector's output purposes is updated.
5239 5427
5240 @node Integers and Characters, Allocation from Frob Blocks, Garbage Collection - Step by Step, Allocation of Objects in XEmacs Lisp 5428 @node Integers and Characters
5241 @section Integers and Characters 5429 @section Integers and Characters
5430 @cindex integers and characters
5431 @cindex characters, integers and
5242 5432
5243 Integer and character Lisp objects are created from integers using the 5433 Integer and character Lisp objects are created from integers using the
5244 macros @code{XSETINT()} and @code{XSETCHAR()} or the equivalent 5434 macros @code{XSETINT()} and @code{XSETCHAR()} or the equivalent
5245 functions @code{make_int()} and @code{make_char()}. (These are actually 5435 functions @code{make_int()} and @code{make_char()}. (These are actually
5246 macros on most systems.) These functions basically just do some moving 5436 macros on most systems.) These functions basically just do some moving
5249 5439
5250 @code{XSETINT()} and the like will truncate values given to them that 5440 @code{XSETINT()} and the like will truncate values given to them that
5251 are too big; i.e. you won't get the value you expected but the tag bits 5441 are too big; i.e. you won't get the value you expected but the tag bits
5252 will at least be correct. 5442 will at least be correct.
5253 5443
5254 @node Allocation from Frob Blocks, lrecords, Integers and Characters, Allocation of Objects in XEmacs Lisp 5444 @node Allocation from Frob Blocks
5255 @section Allocation from Frob Blocks 5445 @section Allocation from Frob Blocks
5446 @cindex allocation from frob blocks
5447 @cindex frob blocks, allocation from
5256 5448
5257 The uninitialized memory required by a @code{Lisp_Object} of a particular type 5449 The uninitialized memory required by a @code{Lisp_Object} of a particular type
5258 is allocated using 5450 is allocated using
5259 @code{ALLOCATE_FIXED_TYPE()}. This only occurs inside of the 5451 @code{ALLOCATE_FIXED_TYPE()}. This only occurs inside of the
5260 lowest-level object-creating functions in @file{alloc.c}: 5452 lowest-level object-creating functions in @file{alloc.c}:
5276 @code{ALLOCATE_FIXED_TYPE_FROM_BLOCK()}, which looks at the end of the 5468 @code{ALLOCATE_FIXED_TYPE_FROM_BLOCK()}, which looks at the end of the
5277 last frob block for space, and creates a new frob block if there is 5469 last frob block for space, and creates a new frob block if there is
5278 none. (There are actually two versions of these macros, one of which is 5470 none. (There are actually two versions of these macros, one of which is
5279 more defensive but less efficient and is used for error-checking.) 5471 more defensive but less efficient and is used for error-checking.)
5280 5472
5281 @node lrecords, Low-level allocation, Allocation from Frob Blocks, Allocation of Objects in XEmacs Lisp 5473 @node lrecords
5282 @section lrecords 5474 @section lrecords
5475 @cindex lrecords
5283 5476
5284 [see @file{lrecord.h}] 5477 [see @file{lrecord.h}]
5285 5478
5286 All lrecords have at the beginning of their structure a @code{struct 5479 All lrecords have at the beginning of their structure a @code{struct
5287 lrecord_header}. This just contains a type number and some flags, 5480 lrecord_header}. This just contains a type number and some flags,
5515 (i.e. declared with a @code{_SEQUENCE_IMPLEMENTATION} macro.) This should 5708 (i.e. declared with a @code{_SEQUENCE_IMPLEMENTATION} macro.) This should
5516 simply return the object's size in bytes, exactly as you might expect. 5709 simply return the object's size in bytes, exactly as you might expect.
5517 For an example, see the methods for window configurations and opaques. 5710 For an example, see the methods for window configurations and opaques.
5518 @end enumerate 5711 @end enumerate
5519 5712
5520 @node Low-level allocation, Cons, lrecords, Allocation of Objects in XEmacs Lisp 5713 @node Low-level allocation
5521 @section Low-level allocation 5714 @section Low-level allocation
5715 @cindex low-level allocation
5716 @cindex allocation, low-level
5522 5717
5523 Memory that you want to allocate directly should be allocated using 5718 Memory that you want to allocate directly should be allocated using
5524 @code{xmalloc()} rather than @code{malloc()}. This implements 5719 @code{xmalloc()} rather than @code{malloc()}. This implements
5525 error-checking on the return value, and once upon a time did some more 5720 error-checking on the return value, and once upon a time did some more
5526 vital stuff (i.e. @code{BLOCK_INPUT}, which is no longer necessary). 5721 vital stuff (i.e. @code{BLOCK_INPUT}, which is no longer necessary).
5586 and bit-vector creation routines. These routines also call 5781 and bit-vector creation routines. These routines also call
5587 @code{INCREMENT_CONS_COUNTER()} at the appropriate times; this keeps 5782 @code{INCREMENT_CONS_COUNTER()} at the appropriate times; this keeps
5588 statistics on how much memory is allocated, so that garbage-collection 5783 statistics on how much memory is allocated, so that garbage-collection
5589 can be invoked when the threshold is reached. 5784 can be invoked when the threshold is reached.
5590 5785
5591 @node Cons, Vector, Low-level allocation, Allocation of Objects in XEmacs Lisp 5786 @node Cons
5592 @section Cons 5787 @section Cons
5788 @cindex cons
5593 5789
5594 Conses are allocated in standard frob blocks. The only thing to 5790 Conses are allocated in standard frob blocks. The only thing to
5595 note is that conses can be explicitly freed using @code{free_cons()} 5791 note is that conses can be explicitly freed using @code{free_cons()}
5596 and associated functions @code{free_list()} and @code{free_alist()}. This 5792 and associated functions @code{free_list()} and @code{free_alist()}. This
5597 immediately puts the conses onto the cons free list, and decrements 5793 immediately puts the conses onto the cons free list, and decrements
5600 generating extra objects and thereby triggering GC sooner. 5796 generating extra objects and thereby triggering GC sooner.
5601 However, you have to be @emph{extremely} careful when doing this. 5797 However, you have to be @emph{extremely} careful when doing this.
5602 If you mess this up, you will get BADLY BURNED, and it has happened 5798 If you mess this up, you will get BADLY BURNED, and it has happened
5603 before. 5799 before.
5604 5800
5605 @node Vector, Bit Vector, Cons, Allocation of Objects in XEmacs Lisp 5801 @node Vector
5606 @section Vector 5802 @section Vector
5803 @cindex vector
5607 5804
5608 As mentioned above, each vector is @code{malloc()}ed individually, and 5805 As mentioned above, each vector is @code{malloc()}ed individually, and
5609 all are threaded through the variable @code{all_vectors}. Vectors are 5806 all are threaded through the variable @code{all_vectors}. Vectors are
5610 marked strangely during garbage collection, by kludging the size field. 5807 marked strangely during garbage collection, by kludging the size field.
5611 Note that the @code{struct Lisp_Vector} is declared with its 5808 Note that the @code{struct Lisp_Vector} is declared with its
5612 @code{contents} field being a @emph{stretchy} array of one element. It 5809 @code{contents} field being a @emph{stretchy} array of one element. It
5613 is actually @code{malloc()}ed with the right size, however, and access 5810 is actually @code{malloc()}ed with the right size, however, and access
5614 to any element through the @code{contents} array works fine. 5811 to any element through the @code{contents} array works fine.
5615 5812
5616 @node Bit Vector, Symbol, Vector, Allocation of Objects in XEmacs Lisp 5813 @node Bit Vector
5617 @section Bit Vector 5814 @section Bit Vector
5815 @cindex bit vector
5816 @cindex vector, bit
5618 5817
5619 Bit vectors work exactly like vectors, except for more complicated 5818 Bit vectors work exactly like vectors, except for more complicated
5620 code to access an individual bit, and except for the fact that bit 5819 code to access an individual bit, and except for the fact that bit
5621 vectors are lrecords while vectors are not. (The only difference here is 5820 vectors are lrecords while vectors are not. (The only difference here is
5622 that there's an lrecord implementation pointer at the beginning and the 5821 that there's an lrecord implementation pointer at the beginning and the
5623 tag field in bit vector Lisp words is ``lrecord'' rather than 5822 tag field in bit vector Lisp words is ``lrecord'' rather than
5624 ``vector''.) 5823 ``vector''.)
5625 5824
5626 @node Symbol, Marker, Bit Vector, Allocation of Objects in XEmacs Lisp 5825 @node Symbol
5627 @section Symbol 5826 @section Symbol
5827 @cindex symbol
5628 5828
5629 Symbols are also allocated in frob blocks. Symbols in the awful 5829 Symbols are also allocated in frob blocks. Symbols in the awful
5630 horrible obarray structure are chained through their @code{next} field. 5830 horrible obarray structure are chained through their @code{next} field.
5631 5831
5632 Remember that @code{intern} looks up a symbol in an obarray, creating 5832 Remember that @code{intern} looks up a symbol in an obarray, creating
5633 one if necessary. 5833 one if necessary.
5634 5834
5635 @node Marker, String, Symbol, Allocation of Objects in XEmacs Lisp 5835 @node Marker
5636 @section Marker 5836 @section Marker
5837 @cindex marker
5637 5838
5638 Markers are allocated in frob blocks, as usual. They are kept 5839 Markers are allocated in frob blocks, as usual. They are kept
5639 in a buffer unordered, but in a doubly-linked list so that they 5840 in a buffer unordered, but in a doubly-linked list so that they
5640 can easily be removed. (Formerly this was a singly-linked list, 5841 can easily be removed. (Formerly this was a singly-linked list,
5641 but in some cases garbage collection took an extraordinarily 5842 but in some cases garbage collection took an extraordinarily
5642 long time due to the O(N^2) time required to remove lots of 5843 long time due to the O(N^2) time required to remove lots of
5643 markers from a buffer.) Markers are removed from a buffer in 5844 markers from a buffer.) Markers are removed from a buffer in
5644 the finalize stage, in @code{ADDITIONAL_FREE_marker()}. 5845 the finalize stage, in @code{ADDITIONAL_FREE_marker()}.
5645 5846
5646 @node String, Compiled Function, Marker, Allocation of Objects in XEmacs Lisp 5847 @node String
5647 @section String 5848 @section String
5849 @cindex string
5648 5850
5649 As mentioned above, strings are a special case. A string is logically 5851 As mentioned above, strings are a special case. A string is logically
5650 two parts, a fixed-size object (containing the length, property list, 5852 two parts, a fixed-size object (containing the length, property list,
5651 and a pointer to the actual data), and the actual data in the string. 5853 and a pointer to the actual data), and the actual data in the string.
5652 The fixed-size object is a @code{struct Lisp_String} and is allocated in 5854 The fixed-size object is a @code{struct Lisp_String} and is allocated in
5702 string data (which would normally be obtained from the now-non-existent 5904 string data (which would normally be obtained from the now-non-existent
5703 @code{struct Lisp_String}) at the beginning of the dead string data gap. 5905 @code{struct Lisp_String}) at the beginning of the dead string data gap.
5704 The string compactor recognizes this special 0xFFFFFFFF marker and 5906 The string compactor recognizes this special 0xFFFFFFFF marker and
5705 handles it correctly. 5907 handles it correctly.
5706 5908
5707 @node Compiled Function, , String, Allocation of Objects in XEmacs Lisp 5909 @node Compiled Function
5708 @section Compiled Function 5910 @section Compiled Function
5911 @cindex compiled function
5912 @cindex function, compiled
5709 5913
5710 Not yet documented. 5914 Not yet documented.
5711 5915
5712 5916
5713 @node Dumping, Events and the Event Loop, Allocation of Objects in XEmacs Lisp, Top 5917 @node Dumping, Events and the Event Loop, Allocation of Objects in XEmacs Lisp, Top
5714 @chapter Dumping 5918 @chapter Dumping
5919 @cindex dumping
5715 5920
5716 @section What is dumping and its justification 5921 @section What is dumping and its justification
5922 @cindex dumping and its justification, what is
5717 5923
5718 The C code of XEmacs is just a Lisp engine with a lot of built-in 5924 The C code of XEmacs is just a Lisp engine with a lot of built-in
5719 primitives useful for writing an editor. The editor itself is written 5925 primitives useful for writing an editor. The editor itself is written
5720 mostly in Lisp, and represents around 100K lines of code. Loading and 5926 mostly in Lisp, and represents around 100K lines of code. Loading and
5721 executing the initialization of all this code takes a bit a time (five 5927 executing the initialization of all this code takes a bit a time (five
5754 * Dumping phase:: 5960 * Dumping phase::
5755 * Reloading phase:: 5961 * Reloading phase::
5756 * Remaining issues:: 5962 * Remaining issues::
5757 @end menu 5963 @end menu
5758 5964
5759 @node Overview, Data descriptions, Dumping, Dumping 5965 @node Overview
5760 @section Overview 5966 @section Overview
5967 @cindex dumping overview
5761 5968
5762 The portable dumping system has to: 5969 The portable dumping system has to:
5763 5970
5764 @enumerate 5971 @enumerate
5765 @item 5972 @item
5771 When starting xemacs, reload the dump file, relocate it to its new 5978 When starting xemacs, reload the dump file, relocate it to its new
5772 starting address if needed, and reinitialize all pointers to this 5979 starting address if needed, and reinitialize all pointers to this
5773 data. Also, rebuild all the quickly rebuildable data. 5980 data. Also, rebuild all the quickly rebuildable data.
5774 @end enumerate 5981 @end enumerate
5775 5982
5776 @node Data descriptions, Dumping phase, Overview, Dumping 5983 @node Data descriptions
5777 @section Data descriptions 5984 @section Data descriptions
5985 @cindex dumping data descriptions
5778 5986
5779 The more complex task of the dumper is to be able to write lisp objects 5987 The more complex task of the dumper is to be able to write lisp objects
5780 (lrecords) and C structs to disk and reload them at a different address, 5988 (lrecords) and C structs to disk and reload them at a different address,
5781 updating all the pointers they include in the process. This is done by 5989 updating all the pointers they include in the process. This is done by
5782 using external data descriptions that give information about the layout 5990 using external data descriptions that give information about the layout
5811 the structure. For lrecords, this is part of the 6019 the structure. For lrecords, this is part of the
5812 lrecord_implementation, so we don't need to duplicate it. For C 6020 lrecord_implementation, so we don't need to duplicate it. For C
5813 structures we use a struct struct_description, which includes a size 6021 structures we use a struct struct_description, which includes a size
5814 field and a pointer to an associated array of lrecord_description. 6022 field and a pointer to an associated array of lrecord_description.
5815 6023
5816 @node Dumping phase, Reloading phase, Data descriptions, Dumping 6024 @node Dumping phase
5817 @section Dumping phase 6025 @section Dumping phase
6026 @cindex dumping phase
5818 6027
5819 Dumping is done by calling the function pdump() (in dumper.c) which is 6028 Dumping is done by calling the function pdump() (in dumper.c) which is
5820 invoked from Fdump_emacs (in emacs.c). This function performs a number 6029 invoked from Fdump_emacs (in emacs.c). This function performs a number
5821 of tasks. 6030 of tasks.
5822 6031
5826 * The header:: 6035 * The header::
5827 * Data dumping:: 6036 * Data dumping::
5828 * Pointers dumping:: 6037 * Pointers dumping::
5829 @end menu 6038 @end menu
5830 6039
5831 @node Object inventory, Address allocation, Dumping phase, Dumping phase 6040 @node Object inventory
5832 @subsection Object inventory 6041 @subsection Object inventory
6042 @cindex dumping object inventory
5833 6043
5834 The first task is to build the list of the objects to dump. This 6044 The first task is to build the list of the objects to dump. This
5835 includes: 6045 includes:
5836 6046
5837 @itemize @bullet 6047 @itemize @bullet
5912 6122
5913 Weak lists and weak hash tables are dumped as if they were their 6123 Weak lists and weak hash tables are dumped as if they were their
5914 non-weak equivalent (without changing their type, of course). This has 6124 non-weak equivalent (without changing their type, of course). This has
5915 not yet been a problem. 6125 not yet been a problem.
5916 6126
5917 @node Address allocation, The header, Object inventory, Dumping phase 6127 @node Address allocation
5918 @subsection Address allocation 6128 @subsection Address allocation
6129 @cindex dumping address allocation
5919 6130
5920 6131
5921 The next step is to allocate the offsets of each of the objects in the 6132 The next step is to allocate the offsets of each of the objects in the
5922 final dump file. This is done by @code{pdump_allocate_offset()} which 6133 final dump file. This is done by @code{pdump_allocate_offset()} which
5923 is called indirectly by @code{pdump_scan_by_alignment()}. 6134 is called indirectly by @code{pdump_scan_by_alignment()}.
5949 6160
5950 @code{pdump_allocate_offset()} only has to do a linear allocation, 6161 @code{pdump_allocate_offset()} only has to do a linear allocation,
5951 starting at offset 256 (this leaves room for the header and keeps the 6162 starting at offset 256 (this leaves room for the header and keeps the
5952 alignments happy). 6163 alignments happy).
5953 6164
5954 @node The header, Data dumping, Address allocation, Dumping phase 6165 @node The header
5955 @subsection The header 6166 @subsection The header
6167 @cindex dumping, the header
5956 6168
5957 The next step creates the file and writes a header with a signature and 6169 The next step creates the file and writes a header with a signature and
5958 some random information in it. The @code{reloc_address} field, which 6170 some random information in it. The @code{reloc_address} field, which
5959 indicates at which address the file should be loaded if we want to avoid 6171 indicates at which address the file should be loaded if we want to avoid
5960 post-reload relocation, is set to 0. It then seeks to offset 256 (base 6172 post-reload relocation, is set to 0. It then seeks to offset 256 (base
5961 offset for the objects). 6173 offset for the objects).
5962 6174
5963 @node Data dumping, Pointers dumping, The header, Dumping phase 6175 @node Data dumping
5964 @subsection Data dumping 6176 @subsection Data dumping
6177 @cindex data dumping
6178 @cindex dumping, data
5965 6179
5966 The data is dumped in the same order as the addresses were allocated by 6180 The data is dumped in the same order as the addresses were allocated by
5967 @code{pdump_dump_data()}, called from @code{pdump_scan_by_alignment()}. 6181 @code{pdump_dump_data()}, called from @code{pdump_scan_by_alignment()}.
5968 This function copies the data to a temporary buffer, relocates all 6182 This function copies the data to a temporary buffer, relocates all
5969 pointers in the object to the addresses allocated in step Address 6183 pointers in the object to the addresses allocated in step Address
5970 Allocation, and writes it to the file. Using the same order means that, 6184 Allocation, and writes it to the file. Using the same order means that,
5971 if we are careful with lrecords whose size is not a multiple of 4, we 6185 if we are careful with lrecords whose size is not a multiple of 4, we
5972 are ensured that the object is always written at the offset in the file 6186 are ensured that the object is always written at the offset in the file
5973 allocated in step Address Allocation. 6187 allocated in step Address Allocation.
5974 6188
5975 @node Pointers dumping, , Data dumping, Dumping phase 6189 @node Pointers dumping
5976 @subsection Pointers dumping 6190 @subsection Pointers dumping
6191 @cindex pointers dumping
6192 @cindex dumping, pointers
5977 6193
5978 A bunch of tables needed to reassign properly the global pointers are 6194 A bunch of tables needed to reassign properly the global pointers are
5979 then written. They are: 6195 then written. They are:
5980 6196
5981 @enumerate 6197 @enumerate
6007 @code{lrecord_implementations_table} are handled indirectly using 6223 @code{lrecord_implementations_table} are handled indirectly using
6008 @code{dump_add_opaque} or @code{dump_add_root_struct_ptr}. 6224 @code{dump_add_opaque} or @code{dump_add_root_struct_ptr}.
6009 6225
6010 This is the end of the dumping part. 6226 This is the end of the dumping part.
6011 6227
6012 @node Reloading phase, Remaining issues, Dumping phase, Dumping 6228 @node Reloading phase
6013 @section Reloading phase 6229 @section Reloading phase
6230 @cindex reloading phase
6231 @cindex dumping, reloading phase
6014 6232
6015 @subsection File loading 6233 @subsection File loading
6234 @cindex dumping, file loading
6016 6235
6017 The file is mmap'ed in memory (which ensures a PAGESIZE alignment, at 6236 The file is mmap'ed in memory (which ensures a PAGESIZE alignment, at
6018 least 4096), or if mmap is unavailable or fails, a 256-bytes aligned 6237 least 4096), or if mmap is unavailable or fails, a 256-bytes aligned
6019 malloc is done and the file is loaded. 6238 malloc is done and the file is loaded.
6020 6239
6023 The difference between the actual loading address and the reloc_address 6242 The difference between the actual loading address and the reloc_address
6024 is computed and will be used for all the relocations. 6243 is computed and will be used for all the relocations.
6025 6244
6026 6245
6027 @subsection Putting back the pdump_opaques 6246 @subsection Putting back the pdump_opaques
6247 @cindex dumping, putting back the pdump_opaques
6028 6248
6029 The memory contents are restored in the obvious and trivial way. 6249 The memory contents are restored in the obvious and trivial way.
6030 6250
6031 6251
6032 @subsection Putting back the pdump_root_struct_ptrs 6252 @subsection Putting back the pdump_root_struct_ptrs
6253 @cindex dumping, putting back the pdump_root_struct_ptrs
6033 6254
6034 The variables pointed to by pdump_root_struct_ptrs in the dump phase are 6255 The variables pointed to by pdump_root_struct_ptrs in the dump phase are
6035 reset to the right relocated object addresses. 6256 reset to the right relocated object addresses.
6036 6257
6037 6258
6038 @subsection Object relocation 6259 @subsection Object relocation
6260 @cindex dumping, object relocation
6039 6261
6040 All the objects are relocated using their description and their offset 6262 All the objects are relocated using their description and their offset
6041 by @code{pdump_reloc_one}. This step is unnecessary if the 6263 by @code{pdump_reloc_one}. This step is unnecessary if the
6042 reloc_address is equal to the file loading address. 6264 reloc_address is equal to the file loading address.
6043 6265
6044 6266
6045 @subsection Putting back the pdump_root_objects and pdump_weak_object_chains 6267 @subsection Putting back the pdump_root_objects and pdump_weak_object_chains
6268 @cindex dumping, putting back the pdump_root_objects and pdump_weak_object_chains
6046 6269
6047 Same as Putting back the pdump_root_struct_ptrs. 6270 Same as Putting back the pdump_root_struct_ptrs.
6048 6271
6049 6272
6050 @subsection Reorganize the hash tables 6273 @subsection Reorganize the hash tables
6274 @cindex dumping, reorganize the hash tables
6051 6275
6052 Since some of the hash values in the lisp hash tables are 6276 Since some of the hash values in the lisp hash tables are
6053 address-dependent, their layout is now wrong. So we go through each of 6277 address-dependent, their layout is now wrong. So we go through each of
6054 them and have them resorted by calling @code{pdump_reorganize_hash_table}. 6278 them and have them resorted by calling @code{pdump_reorganize_hash_table}.
6055 6279
6056 @node Remaining issues, , Reloading phase, Dumping 6280 @node Remaining issues
6057 @section Remaining issues 6281 @section Remaining issues
6282 @cindex dumping, remaining issues
6058 6283
6059 The build process will have to start a post-dump xemacs, ask it the 6284 The build process will have to start a post-dump xemacs, ask it the
6060 loading address (which will, hopefully, be always the same between 6285 loading address (which will, hopefully, be always the same between
6061 different xemacs invocations) and relocate the file to the new address. 6286 different xemacs invocations) and relocate the file to the new address.
6062 This way the object relocation phase will not have to be done, which 6287 This way the object relocation phase will not have to be done, which
6073 The DOC file contents should probably end up in the dump file. 6298 The DOC file contents should probably end up in the dump file.
6074 6299
6075 6300
6076 @node Events and the Event Loop, Evaluation; Stack Frames; Bindings, Dumping, Top 6301 @node Events and the Event Loop, Evaluation; Stack Frames; Bindings, Dumping, Top
6077 @chapter Events and the Event Loop 6302 @chapter Events and the Event Loop
6303 @cindex events and the event loop
6304 @cindex event loop, events and the
6078 6305
6079 @menu 6306 @menu
6080 * Introduction to Events:: 6307 * Introduction to Events::
6081 * Main Loop:: 6308 * Main Loop::
6082 * Specifics of the Event Gathering Mechanism:: 6309 * Specifics of the Event Gathering Mechanism::
6085 * Other Event Loop Functions:: 6312 * Other Event Loop Functions::
6086 * Converting Events:: 6313 * Converting Events::
6087 * Dispatching Events; The Command Builder:: 6314 * Dispatching Events; The Command Builder::
6088 @end menu 6315 @end menu
6089 6316
6090 @node Introduction to Events, Main Loop, Events and the Event Loop, Events and the Event Loop 6317 @node Introduction to Events
6091 @section Introduction to Events 6318 @section Introduction to Events
6319 @cindex events, introduction to
6092 6320
6093 An event is an object that encapsulates information about an 6321 An event is an object that encapsulates information about an
6094 interesting occurrence in the operating system. Events are 6322 interesting occurrence in the operating system. Events are
6095 generated either by user action, direct (e.g. typing on the 6323 generated either by user action, direct (e.g. typing on the
6096 keyboard or moving the mouse) or indirect (moving another 6324 keyboard or moving the mouse) or indirect (moving another
6124 Emacs events---there may not be a one-to-one correspondence. 6352 Emacs events---there may not be a one-to-one correspondence.
6125 6353
6126 Emacs events are documented in @file{events.h}; I'll discuss them 6354 Emacs events are documented in @file{events.h}; I'll discuss them
6127 later. 6355 later.
6128 6356
6129 @node Main Loop, Specifics of the Event Gathering Mechanism, Introduction to Events, Events and the Event Loop 6357 @node Main Loop
6130 @section Main Loop 6358 @section Main Loop
6359 @cindex main loop
6360 @cindex events, main loop
6131 6361
6132 The @dfn{command loop} is the top-level loop that the editor is always 6362 The @dfn{command loop} is the top-level loop that the editor is always
6133 running. It loops endlessly, calling @code{next-event} to retrieve an 6363 running. It loops endlessly, calling @code{next-event} to retrieve an
6134 event and @code{dispatch-event} to execute it. @code{dispatch-event} does 6364 event and @code{dispatch-event} to execute it. @code{dispatch-event} does
6135 the appropriate thing with non-user events (process, timeout, 6365 the appropriate thing with non-user events (process, timeout,
6191 wrapper similar to @code{command_loop_2()}. Note also that 6421 wrapper similar to @code{command_loop_2()}. Note also that
6192 @code{initial_command_loop()} sets up a catch for @code{top-level} when 6422 @code{initial_command_loop()} sets up a catch for @code{top-level} when
6193 invoking @code{top_level_1()}, just like when it invokes 6423 invoking @code{top_level_1()}, just like when it invokes
6194 @code{command_loop_2()}. 6424 @code{command_loop_2()}.
6195 6425
6196 @node Specifics of the Event Gathering Mechanism, Specifics About the Emacs Event, Main Loop, Events and the Event Loop 6426 @node Specifics of the Event Gathering Mechanism
6197 @section Specifics of the Event Gathering Mechanism 6427 @section Specifics of the Event Gathering Mechanism
6428 @cindex event gathering mechanism, specifics of the
6198 6429
6199 Here is an approximate diagram of the collection processes 6430 Here is an approximate diagram of the collection processes
6200 at work in XEmacs, under TTY's (TTY's are simpler than X 6431 at work in XEmacs, under TTY's (TTY's are simpler than X
6201 so we'll look at this first): 6432 so we'll look at this first):
6202 6433
6430 which repeatedly calls `next-event' 6661 which repeatedly calls `next-event'
6431 and then dispatches the event 6662 and then dispatches the event
6432 using `dispatch-event' 6663 using `dispatch-event'
6433 @end example 6664 @end example
6434 6665
6435 @node Specifics About the Emacs Event, The Event Stream Callback Routines, Specifics of the Event Gathering Mechanism, Events and the Event Loop 6666 @node Specifics About the Emacs Event
6436 @section Specifics About the Emacs Event 6667 @section Specifics About the Emacs Event
6437 6668 @cindex event, specifics about the Lisp object
6438 @node The Event Stream Callback Routines, Other Event Loop Functions, Specifics About the Emacs Event, Events and the Event Loop 6669
6670 @node The Event Stream Callback Routines
6439 @section The Event Stream Callback Routines 6671 @section The Event Stream Callback Routines
6440 6672 @cindex event stream callback routines, the
6441 @node Other Event Loop Functions, Converting Events, The Event Stream Callback Routines, Events and the Event Loop 6673 @cindex callback routines, the event stream
6674
6675 @node Other Event Loop Functions
6442 @section Other Event Loop Functions 6676 @section Other Event Loop Functions
6677 @cindex event loop functions, other
6443 6678
6444 @code{detect_input_pending()} and @code{input-pending-p} look for 6679 @code{detect_input_pending()} and @code{input-pending-p} look for
6445 input by calling @code{event_stream->event_pending_p} and looking in 6680 input by calling @code{event_stream->event_pending_p} and looking in
6446 @code{[V]unread-command-event} and the @code{command_event_queue} (they 6681 @code{[V]unread-command-event} and the @code{command_event_queue} (they
6447 do not check for an executing keyboard macro, though). 6682 do not check for an executing keyboard macro, though).
6458 @code{read-char} calls @code{next-command-event} and uses 6693 @code{read-char} calls @code{next-command-event} and uses
6459 @code{event_to_character()} to return the character equivalent. With 6694 @code{event_to_character()} to return the character equivalent. With
6460 the right kind of input method support, it is possible for (read-char) 6695 the right kind of input method support, it is possible for (read-char)
6461 to return a Kanji character. 6696 to return a Kanji character.
6462 6697
6463 @node Converting Events, Dispatching Events; The Command Builder, Other Event Loop Functions, Events and the Event Loop 6698 @node Converting Events
6464 @section Converting Events 6699 @section Converting Events
6700 @cindex converting events
6701 @cindex events, converting
6465 6702
6466 @code{character_to_event()}, @code{event_to_character()}, 6703 @code{character_to_event()}, @code{event_to_character()},
6467 @code{event-to-character}, and @code{character-to-event} convert between 6704 @code{event-to-character}, and @code{character-to-event} convert between
6468 characters and keypress events corresponding to the characters. If the 6705 characters and keypress events corresponding to the characters. If the
6469 event was not a keypress, @code{event_to_character()} returns -1 and 6706 event was not a keypress, @code{event_to_character()} returns -1 and
6470 @code{event-to-character} returns @code{nil}. These functions convert 6707 @code{event-to-character} returns @code{nil}. These functions convert
6471 between character representation and the split-up event representation 6708 between character representation and the split-up event representation
6472 (keysym plus mod keys). 6709 (keysym plus mod keys).
6473 6710
6474 @node Dispatching Events; The Command Builder, , Converting Events, Events and the Event Loop 6711 @node Dispatching Events; The Command Builder
6475 @section Dispatching Events; The Command Builder 6712 @section Dispatching Events; The Command Builder
6713 @cindex dispatching events; the command builder
6714 @cindex events; the command builder, dispatching
6715 @cindex command builder, dispatching events; the
6476 6716
6477 Not yet documented. 6717 Not yet documented.
6478 6718
6479 @node Evaluation; Stack Frames; Bindings, Symbols and Variables, Events and the Event Loop, Top 6719 @node Evaluation; Stack Frames; Bindings, Symbols and Variables, Events and the Event Loop, Top
6480 @chapter Evaluation; Stack Frames; Bindings 6720 @chapter Evaluation; Stack Frames; Bindings
6721 @cindex evaluation; stack frames; bindings
6722 @cindex stack frames; bindings, evaluation;
6723 @cindex bindings, evaluation; stack frames;
6481 6724
6482 @menu 6725 @menu
6483 * Evaluation:: 6726 * Evaluation::
6484 * Dynamic Binding; The specbinding Stack; Unwind-Protects:: 6727 * Dynamic Binding; The specbinding Stack; Unwind-Protects::
6485 * Simple Special Forms:: 6728 * Simple Special Forms::
6486 * Catch and Throw:: 6729 * Catch and Throw::
6487 @end menu 6730 @end menu
6488 6731
6489 @node Evaluation, Dynamic Binding; The specbinding Stack; Unwind-Protects, Evaluation; Stack Frames; Bindings, Evaluation; Stack Frames; Bindings 6732 @node Evaluation
6490 @section Evaluation 6733 @section Evaluation
6734 @cindex evaluation
6491 6735
6492 @code{Feval()} evaluates the form (a Lisp object) that is passed to 6736 @code{Feval()} evaluates the form (a Lisp object) that is passed to
6493 it. Note that evaluation is only non-trivial for two types of objects: 6737 it. Note that evaluation is only non-trivial for two types of objects:
6494 symbols and conses. A symbol is evaluated simply by calling 6738 symbols and conses. A symbol is evaluated simply by calling
6495 @code{symbol-value} on it and returning the value. 6739 @code{symbol-value} on it and returning the value.
6614 @code{call3()} call a function, passing it the argument(s) given (the 6858 @code{call3()} call a function, passing it the argument(s) given (the
6615 arguments are given as separate C arguments rather than being passed as 6859 arguments are given as separate C arguments rather than being passed as
6616 an array). @code{apply1()} uses @code{Fapply()} while the others use 6860 an array). @code{apply1()} uses @code{Fapply()} while the others use
6617 @code{Ffuncall()} to do the real work. 6861 @code{Ffuncall()} to do the real work.
6618 6862
6619 @node Dynamic Binding; The specbinding Stack; Unwind-Protects, Simple Special Forms, Evaluation, Evaluation; Stack Frames; Bindings 6863 @node Dynamic Binding; The specbinding Stack; Unwind-Protects
6620 @section Dynamic Binding; The specbinding Stack; Unwind-Protects 6864 @section Dynamic Binding; The specbinding Stack; Unwind-Protects
6865 @cindex dynamic binding; the specbinding stack; unwind-protects
6866 @cindex binding; the specbinding stack; unwind-protects, dynamic
6867 @cindex specbinding stack; unwind-protects, dynamic binding; the
6868 @cindex unwind-protects, dynamic binding; the specbinding stack;
6621 6869
6622 @example 6870 @example
6623 struct specbinding 6871 struct specbinding
6624 @{ 6872 @{
6625 Lisp_Object symbol; 6873 Lisp_Object symbol;
6668 a local-variable binding (@code{func} is 0, @code{symbol} is not 6916 a local-variable binding (@code{func} is 0, @code{symbol} is not
6669 @code{nil}, and @code{old_value} holds the old value, which is stored as 6917 @code{nil}, and @code{old_value} holds the old value, which is stored as
6670 the symbol's value). 6918 the symbol's value).
6671 @end enumerate 6919 @end enumerate
6672 6920
6673 @node Simple Special Forms, Catch and Throw, Dynamic Binding; The specbinding Stack; Unwind-Protects, Evaluation; Stack Frames; Bindings 6921 @node Simple Special Forms
6674 @section Simple Special Forms 6922 @section Simple Special Forms
6923 @cindex special forms, simple
6675 6924
6676 @code{or}, @code{and}, @code{if}, @code{cond}, @code{progn}, 6925 @code{or}, @code{and}, @code{if}, @code{cond}, @code{progn},
6677 @code{prog1}, @code{prog2}, @code{setq}, @code{quote}, @code{function}, 6926 @code{prog1}, @code{prog2}, @code{setq}, @code{quote}, @code{function},
6678 @code{let*}, @code{let}, @code{while} 6927 @code{let*}, @code{let}, @code{while}
6679 6928
6685 Note that, with the exception of @code{Fprogn}, these functions are 6934 Note that, with the exception of @code{Fprogn}, these functions are
6686 typically called in real life only in interpreted code, since the byte 6935 typically called in real life only in interpreted code, since the byte
6687 compiler knows how to convert calls to these functions directly into 6936 compiler knows how to convert calls to these functions directly into
6688 byte code. 6937 byte code.
6689 6938
6690 @node Catch and Throw, , Simple Special Forms, Evaluation; Stack Frames; Bindings 6939 @node Catch and Throw
6691 @section Catch and Throw 6940 @section Catch and Throw
6941 @cindex catch and throw
6942 @cindex throw, catch and
6692 6943
6693 @example 6944 @example
6694 struct catchtag 6945 struct catchtag
6695 @{ 6946 @{
6696 Lisp_Object tag; 6947 Lisp_Object tag;
6746 created since the catch. 6997 created since the catch.
6747 6998
6748 6999
6749 @node Symbols and Variables, Buffers and Textual Representation, Evaluation; Stack Frames; Bindings, Top 7000 @node Symbols and Variables, Buffers and Textual Representation, Evaluation; Stack Frames; Bindings, Top
6750 @chapter Symbols and Variables 7001 @chapter Symbols and Variables
7002 @cindex symbols and variables
7003 @cindex variables, symbols and
6751 7004
6752 @menu 7005 @menu
6753 * Introduction to Symbols:: 7006 * Introduction to Symbols::
6754 * Obarrays:: 7007 * Obarrays::
6755 * Symbol Values:: 7008 * Symbol Values::
6756 @end menu 7009 @end menu
6757 7010
6758 @node Introduction to Symbols, Obarrays, Symbols and Variables, Symbols and Variables 7011 @node Introduction to Symbols
6759 @section Introduction to Symbols 7012 @section Introduction to Symbols
7013 @cindex symbols, introduction to
6760 7014
6761 A symbol is basically just an object with four fields: a name (a 7015 A symbol is basically just an object with four fields: a name (a
6762 string), a value (some Lisp object), a function (some Lisp object), and 7016 string), a value (some Lisp object), a function (some Lisp object), and
6763 a property list (usually a list of alternating keyword/value pairs). 7017 a property list (usually a list of alternating keyword/value pairs).
6764 What makes symbols special is that there is usually only one symbol with 7018 What makes symbols special is that there is usually only one symbol with
6770 there can be a distinct function and variable with the same name. The 7024 there can be a distinct function and variable with the same name. The
6771 property list is used as a more general mechanism of associating 7025 property list is used as a more general mechanism of associating
6772 additional values with particular names, and once again the namespace is 7026 additional values with particular names, and once again the namespace is
6773 independent of the function and variable namespaces. 7027 independent of the function and variable namespaces.
6774 7028
6775 @node Obarrays, Symbol Values, Introduction to Symbols, Symbols and Variables 7029 @node Obarrays
6776 @section Obarrays 7030 @section Obarrays
7031 @cindex obarrays
6777 7032
6778 The identity of symbols with their names is accomplished through a 7033 The identity of symbols with their names is accomplished through a
6779 structure called an obarray, which is just a poorly-implemented hash 7034 structure called an obarray, which is just a poorly-implemented hash
6780 table mapping from strings to symbols whose name is that string. (I say 7035 table mapping from strings to symbols whose name is that string. (I say
6781 ``poorly implemented'' because an obarray appears in Lisp as a vector 7036 ``poorly implemented'' because an obarray appears in Lisp as a vector
6837 a new one, and @code{unintern} to remove a symbol from an obarray. This 7092 a new one, and @code{unintern} to remove a symbol from an obarray. This
6838 returns the removed symbol. (Remember: You can't put the symbol back 7093 returns the removed symbol. (Remember: You can't put the symbol back
6839 into any obarray.) Finally, @code{mapatoms} maps over all of the symbols 7094 into any obarray.) Finally, @code{mapatoms} maps over all of the symbols
6840 in an obarray. 7095 in an obarray.
6841 7096
6842 @node Symbol Values, , Obarrays, Symbols and Variables 7097 @node Symbol Values
6843 @section Symbol Values 7098 @section Symbol Values
7099 @cindex symbol values
7100 @cindex values, symbol
6844 7101
6845 The value field of a symbol normally contains a Lisp object. However, 7102 The value field of a symbol normally contains a Lisp object. However,
6846 a symbol can be @dfn{unbound}, meaning that it logically has no value. 7103 a symbol can be @dfn{unbound}, meaning that it logically has no value.
6847 This is internally indicated by storing a special Lisp object, called 7104 This is internally indicated by storing a special Lisp object, called
6848 @dfn{the unbound marker} and stored in the global variable 7105 @dfn{the unbound marker} and stored in the global variable
6882 well-documented in comments in @file{buffer.c}, @file{symbols.c}, and 7139 well-documented in comments in @file{buffer.c}, @file{symbols.c}, and
6883 @file{lisp.h}. 7140 @file{lisp.h}.
6884 7141
6885 @node Buffers and Textual Representation, MULE Character Sets and Encodings, Symbols and Variables, Top 7142 @node Buffers and Textual Representation, MULE Character Sets and Encodings, Symbols and Variables, Top
6886 @chapter Buffers and Textual Representation 7143 @chapter Buffers and Textual Representation
7144 @cindex buffers and textual representation
7145 @cindex textual representation, buffers and
6887 7146
6888 @menu 7147 @menu
6889 * Introduction to Buffers:: A buffer holds a block of text such as a file. 7148 * Introduction to Buffers:: A buffer holds a block of text such as a file.
6890 * The Text in a Buffer:: Representation of the text in a buffer. 7149 * The Text in a Buffer:: Representation of the text in a buffer.
6891 * Buffer Lists:: Keeping track of all buffers. 7150 * Buffer Lists:: Keeping track of all buffers.
6892 * Markers and Extents:: Tagging locations within a buffer. 7151 * Markers and Extents:: Tagging locations within a buffer.
6893 * Bufbytes and Emchars:: Representation of individual characters. 7152 * Bufbytes and Emchars:: Representation of individual characters.
6894 * The Buffer Object:: The Lisp object corresponding to a buffer. 7153 * The Buffer Object:: The Lisp object corresponding to a buffer.
6895 @end menu 7154 @end menu
6896 7155
6897 @node Introduction to Buffers, The Text in a Buffer, Buffers and Textual Representation, Buffers and Textual Representation 7156 @node Introduction to Buffers
6898 @section Introduction to Buffers 7157 @section Introduction to Buffers
7158 @cindex buffers, introduction to
6899 7159
6900 A buffer is logically just a Lisp object that holds some text. 7160 A buffer is logically just a Lisp object that holds some text.
6901 In this, it is like a string, but a buffer is optimized for 7161 In this, it is like a string, but a buffer is optimized for
6902 frequent insertion and deletion, while a string is not. Furthermore: 7162 frequent insertion and deletion, while a string is not. Furthermore:
6903 7163
6945 and @dfn{buffer of the selected window}, and the distinction between 7205 and @dfn{buffer of the selected window}, and the distinction between
6946 @dfn{point} of the current buffer and @dfn{window-point} of the selected 7206 @dfn{point} of the current buffer and @dfn{window-point} of the selected
6947 window. (This latter distinction is explained in detail in the section 7207 window. (This latter distinction is explained in detail in the section
6948 on windows.) 7208 on windows.)
6949 7209
6950 @node The Text in a Buffer, Buffer Lists, Introduction to Buffers, Buffers and Textual Representation 7210 @node The Text in a Buffer
6951 @section The Text in a Buffer 7211 @section The Text in a Buffer
7212 @cindex text in a buffer, the
7213 @cindex buffer, the text in a
6952 7214
6953 The text in a buffer consists of a sequence of zero or more 7215 The text in a buffer consists of a sequence of zero or more
6954 characters. A @dfn{character} is an integer that logically represents 7216 characters. A @dfn{character} is an integer that logically represents
6955 a letter, number, space, or other unit of text. Most of the characters 7217 a letter, number, space, or other unit of text. Most of the characters
6956 that you will typically encounter belong to the ASCII set of characters, 7218 that you will typically encounter belong to the ASCII set of characters,
7085 Bufbytes underscores the fact that we are working with a string of bytes 7347 Bufbytes underscores the fact that we are working with a string of bytes
7086 in the internal Emacs buffer representation rather than in one of a 7348 in the internal Emacs buffer representation rather than in one of a
7087 number of possible alternative representations (e.g. EUC-encoded text, 7349 number of possible alternative representations (e.g. EUC-encoded text,
7088 etc.). 7350 etc.).
7089 7351
7090 @node Buffer Lists, Markers and Extents, The Text in a Buffer, Buffers and Textual Representation 7352 @node Buffer Lists
7091 @section Buffer Lists 7353 @section Buffer Lists
7354 @cindex buffer lists
7092 7355
7093 Recall earlier that buffers are @dfn{permanent} objects, i.e. that 7356 Recall earlier that buffers are @dfn{permanent} objects, i.e. that
7094 they remain around until explicitly deleted. This entails that there is 7357 they remain around until explicitly deleted. This entails that there is
7095 a list of all the buffers in existence. This list is actually an 7358 a list of all the buffers in existence. This list is actually an
7096 assoc-list (mapping from the buffer's name to the buffer) and is stored 7359 assoc-list (mapping from the buffer's name to the buffer) and is stored
7121 respectively. You can also force a new buffer to be created using 7384 respectively. You can also force a new buffer to be created using
7122 @code{generate-new-buffer}, which takes a name and (if necessary) makes 7385 @code{generate-new-buffer}, which takes a name and (if necessary) makes
7123 a unique name from this by appending a number, and then creates the 7386 a unique name from this by appending a number, and then creates the
7124 buffer. This is basically like the symbol operation @code{gensym}. 7387 buffer. This is basically like the symbol operation @code{gensym}.
7125 7388
7126 @node Markers and Extents, Bufbytes and Emchars, Buffer Lists, Buffers and Textual Representation 7389 @node Markers and Extents
7127 @section Markers and Extents 7390 @section Markers and Extents
7391 @cindex markers and extents
7392 @cindex extents, markers and
7128 7393
7129 Among the things associated with a buffer are things that are 7394 Among the things associated with a buffer are things that are
7130 logically attached to certain buffer positions. This can be used to 7395 logically attached to certain buffer positions. This can be used to
7131 keep track of a buffer position when text is inserted and deleted, so 7396 keep track of a buffer position when text is inserted and deleted, so
7132 that it remains at the same spot relative to the text around it; to 7397 that it remains at the same spot relative to the text around it; to
7161 is no way to determine what markers are in a buffer if you are just 7426 is no way to determine what markers are in a buffer if you are just
7162 given the buffer. Extents remain in a buffer until they are detached 7427 given the buffer. Extents remain in a buffer until they are detached
7163 (which could happen as a result of text being deleted) or the buffer is 7428 (which could happen as a result of text being deleted) or the buffer is
7164 deleted, and primitives do exist to enumerate the extents in a buffer. 7429 deleted, and primitives do exist to enumerate the extents in a buffer.
7165 7430
7166 @node Bufbytes and Emchars, The Buffer Object, Markers and Extents, Buffers and Textual Representation 7431 @node Bufbytes and Emchars
7167 @section Bufbytes and Emchars 7432 @section Bufbytes and Emchars
7433 @cindex Bufbytes and Emchars
7434 @cindex Emchars, Bufbytes and
7168 7435
7169 Not yet documented. 7436 Not yet documented.
7170 7437
7171 @node The Buffer Object, , Bufbytes and Emchars, Buffers and Textual Representation 7438 @node The Buffer Object
7172 @section The Buffer Object 7439 @section The Buffer Object
7440 @cindex buffer object, the
7441 @cindex object, the buffer
7173 7442
7174 Buffers contain fields not directly accessible by the Lisp programmer. 7443 Buffers contain fields not directly accessible by the Lisp programmer.
7175 We describe them here, naming them by the names used in the C code. 7444 We describe them here, naming them by the names used in the C code.
7176 Many are accessible indirectly in Lisp programs via Lisp primitives. 7445 Many are accessible indirectly in Lisp programs via Lisp primitives.
7177 7446
7265 or @code{nil}. 7534 or @code{nil}.
7266 @end table 7535 @end table
7267 7536
7268 @node MULE Character Sets and Encodings, The Lisp Reader and Compiler, Buffers and Textual Representation, Top 7537 @node MULE Character Sets and Encodings, The Lisp Reader and Compiler, Buffers and Textual Representation, Top
7269 @chapter MULE Character Sets and Encodings 7538 @chapter MULE Character Sets and Encodings
7539 @cindex Mule character sets and encodings
7540 @cindex character sets and encodings, Mule
7541 @cindex encodings, Mule character sets and
7270 7542
7271 Recall that there are two primary ways that text is represented in 7543 Recall that there are two primary ways that text is represented in
7272 XEmacs. The @dfn{buffer} representation sees the text as a series of 7544 XEmacs. The @dfn{buffer} representation sees the text as a series of
7273 bytes (Bufbytes), with a variable number of bytes used per character. 7545 bytes (Bufbytes), with a variable number of bytes used per character.
7274 The @dfn{character} representation sees the text as a series of integers 7546 The @dfn{character} representation sees the text as a series of integers
7285 * Encodings:: 7557 * Encodings::
7286 * Internal Mule Encodings:: 7558 * Internal Mule Encodings::
7287 * CCL:: 7559 * CCL::
7288 @end menu 7560 @end menu
7289 7561
7290 @node Character Sets, Encodings, MULE Character Sets and Encodings, MULE Character Sets and Encodings 7562 @node Character Sets
7291 @section Character Sets 7563 @section Character Sets
7564 @cindex character sets
7292 7565
7293 A character set (or @dfn{charset}) is an ordered set of characters. A 7566 A character set (or @dfn{charset}) is an ordered set of characters. A
7294 particular character in a charset is indexed using one or more 7567 particular character in a charset is indexed using one or more
7295 @dfn{position codes}, which are non-negative integers. The number of 7568 @dfn{position codes}, which are non-negative integers. The number of
7296 position codes needed to identify a particular character in a charset is 7569 position codes needed to identify a particular character in a charset is
7366 160 - 255 Latin-1 32 - 127 7639 160 - 255 Latin-1 32 - 127
7367 @end example 7640 @end example
7368 7641
7369 This is a bit ad-hoc but gets the job done. 7642 This is a bit ad-hoc but gets the job done.
7370 7643
7371 @node Encodings, Internal Mule Encodings, Character Sets, MULE Character Sets and Encodings 7644 @node Encodings
7372 @section Encodings 7645 @section Encodings
7646 @cindex encodings, Mule
7647 @cindex Mule encodings
7373 7648
7374 An @dfn{encoding} is a way of numerically representing characters from 7649 An @dfn{encoding} is a way of numerically representing characters from
7375 one or more character sets. If an encoding only encompasses one 7650 one or more character sets. If an encoding only encompasses one
7376 character set, then the position codes for the characters in that 7651 character set, then the position codes for the characters in that
7377 character set could be used directly. This is not possible, however, if 7652 character set could be used directly. This is not possible, however, if
7393 @menu 7668 @menu
7394 * Japanese EUC (Extended Unix Code):: 7669 * Japanese EUC (Extended Unix Code)::
7395 * JIS7:: 7670 * JIS7::
7396 @end menu 7671 @end menu
7397 7672
7398 @node Japanese EUC (Extended Unix Code), JIS7, Encodings, Encodings 7673 @node Japanese EUC (Extended Unix Code)
7399 @subsection Japanese EUC (Extended Unix Code) 7674 @subsection Japanese EUC (Extended Unix Code)
7675 @cindex Japanese EUC (Extended Unix Code)
7676 @cindex EUC (Extended Unix Code), Japanese
7677 @cindex Extended Unix Code, Japanese EUC
7400 7678
7401 This encompasses the character sets Printing-ASCII, Japanese-JISX0201, 7679 This encompasses the character sets Printing-ASCII, Japanese-JISX0201,
7402 and Japanese-JISX0208-Kana (half-width katakana, the right half of 7680 and Japanese-JISX0208-Kana (half-width katakana, the right half of
7403 JISX0201). It uses 8-bit bytes. 7681 JISX0201). It uses 8-bit bytes.
7404 7682
7415 Japanese-JISX0208 PC1 + 0x80 | PC2 + 0x80 7693 Japanese-JISX0208 PC1 + 0x80 | PC2 + 0x80
7416 Japanese-JISX0212 PC1 + 0x80 | PC2 + 0x80 7694 Japanese-JISX0212 PC1 + 0x80 | PC2 + 0x80
7417 @end example 7695 @end example
7418 7696
7419 7697
7420 @node JIS7, , Japanese EUC (Extended Unix Code), Encodings 7698 @node JIS7
7421 @subsection JIS7 7699 @subsection JIS7
7700 @cindex JIS7
7422 7701
7423 This encompasses the character sets Printing-ASCII, 7702 This encompasses the character sets Printing-ASCII,
7424 Japanese-JISX0201-Roman (the left half of JISX0201; this character set 7703 Japanese-JISX0201-Roman (the left half of JISX0201; this character set
7425 is very similar to Printing-ASCII and is a 94-character charset), 7704 is very similar to Printing-ASCII and is a 94-character charset),
7426 Japanese-JISX0208, and Japanese-JISX0201-Kana. It uses 7-bit bytes. 7705 Japanese-JISX0208, and Japanese-JISX0201-Kana. It uses 7-bit bytes.
7450 0x1B 0x28 0x42 ESC ( B invoke Printing-ASCII 7729 0x1B 0x28 0x42 ESC ( B invoke Printing-ASCII
7451 @end example 7730 @end example
7452 7731
7453 Initially, Printing-ASCII is invoked. 7732 Initially, Printing-ASCII is invoked.
7454 7733
7455 @node Internal Mule Encodings, CCL, Encodings, MULE Character Sets and Encodings 7734 @node Internal Mule Encodings
7456 @section Internal Mule Encodings 7735 @section Internal Mule Encodings
7736 @cindex internal Mule encodings
7737 @cindex Mule encodings, internal
7738 @cindex encodings, internal Mule
7457 7739
7458 In XEmacs/Mule, each character set is assigned a unique number, called a 7740 In XEmacs/Mule, each character set is assigned a unique number, called a
7459 @dfn{leading byte}. This is used in the encodings of a character. 7741 @dfn{leading byte}. This is used in the encodings of a character.
7460 Leading bytes are in the range 0x80 - 0xFF (except for ASCII, which has 7742 Leading bytes are in the range 0x80 - 0xFF (except for ASCII, which has
7461 a leading byte of 0), although some leading bytes are reserved. 7743 a leading byte of 0), although some leading bytes are reserved.
7496 @menu 7778 @menu
7497 * Internal String Encoding:: 7779 * Internal String Encoding::
7498 * Internal Character Encoding:: 7780 * Internal Character Encoding::
7499 @end menu 7781 @end menu
7500 7782
7501 @node Internal String Encoding, Internal Character Encoding, Internal Mule Encodings, Internal Mule Encodings 7783 @node Internal String Encoding
7502 @subsection Internal String Encoding 7784 @subsection Internal String Encoding
7785 @cindex internal string encoding
7786 @cindex string encoding, internal
7787 @cindex encoding, internal string
7503 7788
7504 ASCII characters are encoded using their position code directly. Other 7789 ASCII characters are encoded using their position code directly. Other
7505 characters are encoded using their leading byte followed by their 7790 characters are encoded using their leading byte followed by their
7506 position code(s) with the high bit set. Characters in private character 7791 position code(s) with the high bit set. Characters in private character
7507 sets have their leading byte prefixed with a @dfn{leading byte prefix}, 7792 sets have their leading byte prefixed with a @dfn{leading byte prefix},
7546 None of the standard non-modal encodings meet all of these 7831 None of the standard non-modal encodings meet all of these
7547 conditions. For example, EUC satisfies only (2) and (3), while 7832 conditions. For example, EUC satisfies only (2) and (3), while
7548 Shift-JIS and Big5 (not yet described) satisfy only (2). (All 7833 Shift-JIS and Big5 (not yet described) satisfy only (2). (All
7549 non-modal encodings must satisfy (2), in order to be unambiguous.) 7834 non-modal encodings must satisfy (2), in order to be unambiguous.)
7550 7835
7551 @node Internal Character Encoding, , Internal String Encoding, Internal Mule Encodings 7836 @node Internal Character Encoding
7552 @subsection Internal Character Encoding 7837 @subsection Internal Character Encoding
7838 @cindex internal character encoding
7839 @cindex character encoding, internal
7840 @cindex encoding, internal character
7553 7841
7554 One 19-bit word represents a single character. The word is 7842 One 19-bit word represents a single character. The word is
7555 separated into three fields: 7843 separated into three fields:
7556 7844
7557 @example 7845 @example
7581 @end example 7869 @end example
7582 7870
7583 Note that character codes 0 - 255 are the same as the ``binary encoding'' 7871 Note that character codes 0 - 255 are the same as the ``binary encoding''
7584 described above. 7872 described above.
7585 7873
7586 @node CCL, , Internal Mule Encodings, MULE Character Sets and Encodings 7874 @node CCL
7587 @section CCL 7875 @section CCL
7876 @cindex CCL
7588 7877
7589 @example 7878 @example
7590 CCL PROGRAM SYNTAX: 7879 CCL PROGRAM SYNTAX:
7591 CCL_PROGRAM := (CCL_MAIN_BLOCK 7880 CCL_PROGRAM := (CCL_MAIN_BLOCK
7592 [ CCL_EOF_BLOCK ]) 7881 [ CCL_EOF_BLOCK ])
7749 ..........AAAAA 8038 ..........AAAAA
7750 @end example 8039 @end example
7751 8040
7752 @node The Lisp Reader and Compiler, Lstreams, MULE Character Sets and Encodings, Top 8041 @node The Lisp Reader and Compiler, Lstreams, MULE Character Sets and Encodings, Top
7753 @chapter The Lisp Reader and Compiler 8042 @chapter The Lisp Reader and Compiler
8043 @cindex Lisp reader and compiler, the
8044 @cindex reader and compiler, the Lisp
8045 @cindex compiler, the Lisp reader and
7754 8046
7755 Not yet documented. 8047 Not yet documented.
7756 8048
7757 @node Lstreams, Consoles; Devices; Frames; Windows, The Lisp Reader and Compiler, Top 8049 @node Lstreams, Consoles; Devices; Frames; Windows, The Lisp Reader and Compiler, Top
7758 @chapter Lstreams 8050 @chapter Lstreams
8051 @cindex lstreams
7759 8052
7760 An @dfn{lstream} is an internal Lisp object that provides a generic 8053 An @dfn{lstream} is an internal Lisp object that provides a generic
7761 buffering stream implementation. Conceptually, you send data to the 8054 buffering stream implementation. Conceptually, you send data to the
7762 stream or read data from the stream, not caring what's on the other end 8055 stream or read data from the stream, not caring what's on the other end
7763 of the stream. The other end could be another stream, a file 8056 of the stream. The other end could be another stream, a file
7772 * Lstream Types:: Different sorts of things that are streamed. 8065 * Lstream Types:: Different sorts of things that are streamed.
7773 * Lstream Functions:: Functions for working with lstreams. 8066 * Lstream Functions:: Functions for working with lstreams.
7774 * Lstream Methods:: Creating new lstream types. 8067 * Lstream Methods:: Creating new lstream types.
7775 @end menu 8068 @end menu
7776 8069
7777 @node Creating an Lstream, Lstream Types, Lstreams, Lstreams 8070 @node Creating an Lstream
7778 @section Creating an Lstream 8071 @section Creating an Lstream
8072 @cindex lstream, creating an
7779 8073
7780 Lstreams come in different types, depending on what is being interfaced 8074 Lstreams come in different types, depending on what is being interfaced
7781 to. Although the primitive for creating new lstreams is 8075 to. Although the primitive for creating new lstreams is
7782 @code{Lstream_new()}, generally you do not call this directly. Instead, 8076 @code{Lstream_new()}, generally you do not call this directly. Instead,
7783 you call some type-specific creation function, which creates the lstream 8077 you call some type-specific creation function, which creates the lstream
7803 Open for reading, but ``read'' never returns partial MULE characters. 8097 Open for reading, but ``read'' never returns partial MULE characters.
7804 @item "wc" 8098 @item "wc"
7805 Open for writing, but never writes partial MULE characters. 8099 Open for writing, but never writes partial MULE characters.
7806 @end table 8100 @end table
7807 8101
7808 @node Lstream Types, Lstream Functions, Creating an Lstream, Lstreams 8102 @node Lstream Types
7809 @section Lstream Types 8103 @section Lstream Types
8104 @cindex lstream types
8105 @cindex types, lstream
7810 8106
7811 @table @asis 8107 @table @asis
7812 @item stdio 8108 @item stdio
7813 8109
7814 @item filedesc 8110 @item filedesc
7828 @item decoding 8124 @item decoding
7829 8125
7830 @item encoding 8126 @item encoding
7831 @end table 8127 @end table
7832 8128
7833 @node Lstream Functions, Lstream Methods, Lstream Types, Lstreams 8129 @node Lstream Functions
7834 @section Lstream Functions 8130 @section Lstream Functions
8131 @cindex lstream functions
7835 8132
7836 @deftypefun {Lstream *} Lstream_new (Lstream_implementation *@var{imp}, const char *@var{mode}) 8133 @deftypefun {Lstream *} Lstream_new (Lstream_implementation *@var{imp}, const char *@var{mode})
7837 Allocate and return a new Lstream. This function is not really meant to 8134 Allocate and return a new Lstream. This function is not really meant to
7838 be called directly; rather, each stream type should provide its own 8135 be called directly; rather, each stream type should provide its own
7839 stream creation function, which creates the stream and does any other 8136 stream creation function, which creates the stream and does any other
7911 8208
7912 @deftypefun void Lstream_rewind (Lstream *@var{stream}) 8209 @deftypefun void Lstream_rewind (Lstream *@var{stream})
7913 Rewind the stream to the beginning. 8210 Rewind the stream to the beginning.
7914 @end deftypefun 8211 @end deftypefun
7915 8212
7916 @node Lstream Methods, , Lstream Functions, Lstreams 8213 @node Lstream Methods
7917 @section Lstream Methods 8214 @section Lstream Methods
8215 @cindex lstream methods
7918 8216
7919 @deftypefn {Lstream Method} ssize_t reader (Lstream *@var{stream}, unsigned char *@var{data}, size_t @var{size}) 8217 @deftypefn {Lstream Method} ssize_t reader (Lstream *@var{stream}, unsigned char *@var{data}, size_t @var{size})
7920 Read some data from the stream's end and store it into @var{data}, which 8218 Read some data from the stream's end and store it into @var{data}, which
7921 can hold @var{size} bytes. Return the number of bytes read. A return 8219 can hold @var{size} bytes. Return the number of bytes read. A return
7922 value of 0 means no bytes can be read at this time. This may be because 8220 value of 0 means no bytes can be read at this time. This may be because
7978 @code{Lisp_Object} marker. This function can be @code{NULL}. 8276 @code{Lisp_Object} marker. This function can be @code{NULL}.
7979 @end deftypefn 8277 @end deftypefn
7980 8278
7981 @node Consoles; Devices; Frames; Windows, The Redisplay Mechanism, Lstreams, Top 8279 @node Consoles; Devices; Frames; Windows, The Redisplay Mechanism, Lstreams, Top
7982 @chapter Consoles; Devices; Frames; Windows 8280 @chapter Consoles; Devices; Frames; Windows
8281 @cindex consoles; devices; frames; windows
8282 @cindex devices; frames; windows, consoles;
8283 @cindex frames; windows, consoles; devices;
8284 @cindex windows, consoles; devices; frames;
7983 8285
7984 @menu 8286 @menu
7985 * Introduction to Consoles; Devices; Frames; Windows:: 8287 * Introduction to Consoles; Devices; Frames; Windows::
7986 * Point:: 8288 * Point::
7987 * Window Hierarchy:: 8289 * Window Hierarchy::
7988 * The Window Object:: 8290 * The Window Object::
7989 @end menu 8291 @end menu
7990 8292
7991 @node Introduction to Consoles; Devices; Frames; Windows, Point, Consoles; Devices; Frames; Windows, Consoles; Devices; Frames; Windows 8293 @node Introduction to Consoles; Devices; Frames; Windows
7992 @section Introduction to Consoles; Devices; Frames; Windows 8294 @section Introduction to Consoles; Devices; Frames; Windows
8295 @cindex consoles; devices; frames; windows, introduction to
8296 @cindex devices; frames; windows, introduction to consoles;
8297 @cindex frames; windows, introduction to consoles; devices;
8298 @cindex windows, introduction to consoles; devices; frames;
7993 8299
7994 A window-system window that you see on the screen is called a 8300 A window-system window that you see on the screen is called a
7995 @dfn{frame} in Emacs terminology. Each frame is subdivided into one or 8301 @dfn{frame} in Emacs terminology. Each frame is subdivided into one or
7996 more non-overlapping panes, called (confusingly) @dfn{windows}. Each 8302 more non-overlapping panes, called (confusingly) @dfn{windows}. Each
7997 window displays the text of a buffer in it. (See above on Buffers.) Note 8303 window displays the text of a buffer in it. (See above on Buffers.) Note
8028 window, but every frame remembers the last window in it that was 8334 window, but every frame remembers the last window in it that was
8029 selected, and changing the selected frame causes the remembered window 8335 selected, and changing the selected frame causes the remembered window
8030 within it to become the selected window. Similar relationships apply 8336 within it to become the selected window. Similar relationships apply
8031 for consoles to devices and devices to frames. 8337 for consoles to devices and devices to frames.
8032 8338
8033 @node Point, Window Hierarchy, Introduction to Consoles; Devices; Frames; Windows, Consoles; Devices; Frames; Windows 8339 @node Point
8034 @section Point 8340 @section Point
8341 @cindex point
8035 8342
8036 Recall that every buffer has a current insertion position, called 8343 Recall that every buffer has a current insertion position, called
8037 @dfn{point}. Now, two or more windows may be displaying the same buffer, 8344 @dfn{point}. Now, two or more windows may be displaying the same buffer,
8038 and the text cursor in the two windows (i.e. @code{point}) can be in 8345 and the text cursor in the two windows (i.e. @code{point}) can be in
8039 two different places. You may ask, how can that be, since each 8346 two different places. You may ask, how can that be, since each
8049 want to retrieve the correct value of @code{point} for a window, 8356 want to retrieve the correct value of @code{point} for a window,
8050 you must special-case on the selected window and retrieve the 8357 you must special-case on the selected window and retrieve the
8051 buffer's point instead. This is related to why @code{save-window-excursion} 8358 buffer's point instead. This is related to why @code{save-window-excursion}
8052 does not save the selected window's value of @code{point}. 8359 does not save the selected window's value of @code{point}.
8053 8360
8054 @node Window Hierarchy, The Window Object, Point, Consoles; Devices; Frames; Windows 8361 @node Window Hierarchy
8055 @section Window Hierarchy 8362 @section Window Hierarchy
8056 @cindex window hierarchy 8363 @cindex window hierarchy
8057 @cindex hierarchy of windows 8364 @cindex hierarchy of windows
8058 8365
8059 If a frame contains multiple windows (panes), they are always created 8366 If a frame contains multiple windows (panes), they are always created
8147 frames have no root window, and the @code{next} of the minibuffer window 8454 frames have no root window, and the @code{next} of the minibuffer window
8148 is @code{nil} but the @code{prev} points to itself. (#### This is an 8455 is @code{nil} but the @code{prev} points to itself. (#### This is an
8149 artifact that should be fixed.) 8456 artifact that should be fixed.)
8150 @end enumerate 8457 @end enumerate
8151 8458
8152 @node The Window Object, , Window Hierarchy, Consoles; Devices; Frames; Windows 8459 @node The Window Object
8153 @section The Window Object 8460 @section The Window Object
8461 @cindex window object, the
8462 @cindex object, the window
8154 8463
8155 Windows have the following accessible fields: 8464 Windows have the following accessible fields:
8156 8465
8157 @table @code 8466 @table @code
8158 @item frame 8467 @item frame
8254 this field is @code{nil}. 8563 this field is @code{nil}.
8255 @end table 8564 @end table
8256 8565
8257 @node The Redisplay Mechanism, Extents, Consoles; Devices; Frames; Windows, Top 8566 @node The Redisplay Mechanism, Extents, Consoles; Devices; Frames; Windows, Top
8258 @chapter The Redisplay Mechanism 8567 @chapter The Redisplay Mechanism
8568 @cindex redisplay mechanism, the
8259 8569
8260 The redisplay mechanism is one of the most complicated sections of 8570 The redisplay mechanism is one of the most complicated sections of
8261 XEmacs, especially from a conceptual standpoint. This is doubly so 8571 XEmacs, especially from a conceptual standpoint. This is doubly so
8262 because, unlike for the basic aspects of the Lisp interpreter, the 8572 because, unlike for the basic aspects of the Lisp interpreter, the
8263 computer science theories of how to efficiently handle redisplay are not 8573 computer science theories of how to efficiently handle redisplay are not
8279 * Critical Redisplay Sections:: 8589 * Critical Redisplay Sections::
8280 * Line Start Cache:: 8590 * Line Start Cache::
8281 * Redisplay Piece by Piece:: 8591 * Redisplay Piece by Piece::
8282 @end menu 8592 @end menu
8283 8593
8284 @node Critical Redisplay Sections, Line Start Cache, The Redisplay Mechanism, The Redisplay Mechanism 8594 @node Critical Redisplay Sections
8285 @section Critical Redisplay Sections 8595 @section Critical Redisplay Sections
8596 @cindex redisplay sections, critical
8286 @cindex critical redisplay sections 8597 @cindex critical redisplay sections
8287 8598
8288 Within this section, we are defenseless and assume that the 8599 Within this section, we are defenseless and assume that the
8289 following cannot happen: 8600 following cannot happen:
8290 8601
8311 we simply return. #### We should abort instead. 8622 we simply return. #### We should abort instead.
8312 8623
8313 #### If a frame-size change does occur we should probably 8624 #### If a frame-size change does occur we should probably
8314 actually be preempting redisplay. 8625 actually be preempting redisplay.
8315 8626
8316 @node Line Start Cache, Redisplay Piece by Piece, Critical Redisplay Sections, The Redisplay Mechanism 8627 @node Line Start Cache
8317 @section Line Start Cache 8628 @section Line Start Cache
8318 @cindex line start cache 8629 @cindex line start cache
8319 8630
8320 The traditional scrolling code in Emacs breaks in a variable height 8631 The traditional scrolling code in Emacs breaks in a variable height
8321 world. It depends on the key assumption that the number of lines that 8632 world. It depends on the key assumption that the number of lines that
8372 @end itemize 8683 @end itemize
8373 8684
8374 In case you're wondering, the Second Golden Rule of Redisplay is not 8685 In case you're wondering, the Second Golden Rule of Redisplay is not
8375 applicable. 8686 applicable.
8376 8687
8377 @node Redisplay Piece by Piece, , Line Start Cache, The Redisplay Mechanism 8688 @node Redisplay Piece by Piece
8378 @section Redisplay Piece by Piece 8689 @section Redisplay Piece by Piece
8379 @cindex Redisplay Piece by Piece 8690 @cindex redisplay piece by piece
8380 8691
8381 As you can begin to see redisplay is complex and also not well 8692 As you can begin to see redisplay is complex and also not well
8382 documented. Chuck no longer works on XEmacs so this section is my take 8693 documented. Chuck no longer works on XEmacs so this section is my take
8383 on the workings of redisplay. 8694 on the workings of redisplay.
8384 8695
8425 @code{create_text_block} to do with cursor handling and selective 8736 @code{create_text_block} to do with cursor handling and selective
8426 display have been removed. 8737 display have been removed.
8427 8738
8428 @node Extents, Faces, The Redisplay Mechanism, Top 8739 @node Extents, Faces, The Redisplay Mechanism, Top
8429 @chapter Extents 8740 @chapter Extents
8741 @cindex extents
8430 8742
8431 @menu 8743 @menu
8432 * Introduction to Extents:: Extents are ranges over text, with properties. 8744 * Introduction to Extents:: Extents are ranges over text, with properties.
8433 * Extent Ordering:: How extents are ordered internally. 8745 * Extent Ordering:: How extents are ordered internally.
8434 * Format of the Extent Info:: The extent information in a buffer or string. 8746 * Format of the Extent Info:: The extent information in a buffer or string.
8435 * Zero-Length Extents:: A weird special case. 8747 * Zero-Length Extents:: A weird special case.
8436 * Mathematics of Extent Ordering:: A rigorous foundation. 8748 * Mathematics of Extent Ordering:: A rigorous foundation.
8437 * Extent Fragments:: Cached information useful for redisplay. 8749 * Extent Fragments:: Cached information useful for redisplay.
8438 @end menu 8750 @end menu
8439 8751
8440 @node Introduction to Extents, Extent Ordering, Extents, Extents 8752 @node Introduction to Extents
8441 @section Introduction to Extents 8753 @section Introduction to Extents
8754 @cindex extents, introduction to
8442 8755
8443 Extents are regions over a buffer, with a start and an end position 8756 Extents are regions over a buffer, with a start and an end position
8444 denoting the region of the buffer included in the extent. In 8757 denoting the region of the buffer included in the extent. In
8445 addition, either end can be closed or open, meaning that the endpoint 8758 addition, either end can be closed or open, meaning that the endpoint
8446 is or is not logically included in the extent. Insertion of a character 8759 is or is not logically included in the extent. Insertion of a character
8457 automatically go inside or out of extents as necessary with no 8770 automatically go inside or out of extents as necessary with no
8458 further work needing to be done. It didn't work out that way, 8771 further work needing to be done. It didn't work out that way,
8459 however, and just ended up complexifying and buggifying all the 8772 however, and just ended up complexifying and buggifying all the
8460 rest of the code.) 8773 rest of the code.)
8461 8774
8462 @node Extent Ordering, Format of the Extent Info, Introduction to Extents, Extents 8775 @node Extent Ordering
8463 @section Extent Ordering 8776 @section Extent Ordering
8777 @cindex extent ordering
8464 8778
8465 Extents are compared using memory indices. There are two orderings 8779 Extents are compared using memory indices. There are two orderings
8466 for extents and both orders are kept current at all times. The normal 8780 for extents and both orders are kept current at all times. The normal
8467 or @dfn{display} order is as follows: 8781 or @dfn{display} order is as follows:
8468 8782
8491 The display order and the e-order are complementary orders: any 8805 The display order and the e-order are complementary orders: any
8492 theorem about the display order also applies to the e-order if you swap 8806 theorem about the display order also applies to the e-order if you swap
8493 all occurrences of ``display order'' and ``e-order'', ``less than'' and 8807 all occurrences of ``display order'' and ``e-order'', ``less than'' and
8494 ``greater than'', and ``extent start'' and ``extent end''. 8808 ``greater than'', and ``extent start'' and ``extent end''.
8495 8809
8496 @node Format of the Extent Info, Zero-Length Extents, Extent Ordering, Extents 8810 @node Format of the Extent Info
8497 @section Format of the Extent Info 8811 @section Format of the Extent Info
8812 @cindex extent info, format of the
8498 8813
8499 An extent-info structure consists of a list of the buffer or string's 8814 An extent-info structure consists of a list of the buffer or string's
8500 extents and a @dfn{stack of extents} that lists all of the extents over 8815 extents and a @dfn{stack of extents} that lists all of the extents over
8501 a particular position. The stack-of-extents info is used for 8816 a particular position. The stack-of-extents info is used for
8502 optimization purposes---it basically caches some info that might 8817 optimization purposes---it basically caches some info that might
8525 between two extents. Note also that callers of these functions should 8840 between two extents. Note also that callers of these functions should
8526 not be aware of the fact that the extent list is implemented as an 8841 not be aware of the fact that the extent list is implemented as an
8527 array, except for the fact that positions are integers (this should be 8842 array, except for the fact that positions are integers (this should be
8528 generalized to handle integers and linked list equally well). 8843 generalized to handle integers and linked list equally well).
8529 8844
8530 @node Zero-Length Extents, Mathematics of Extent Ordering, Format of the Extent Info, Extents 8845 @node Zero-Length Extents
8531 @section Zero-Length Extents 8846 @section Zero-Length Extents
8847 @cindex zero-length extents
8848 @cindex extents, zero-length
8532 8849
8533 Extents can be zero-length, and will end up that way if their endpoints 8850 Extents can be zero-length, and will end up that way if their endpoints
8534 are explicitly set that way or if their detachable property is @code{nil} 8851 are explicitly set that way or if their detachable property is @code{nil}
8535 and all the text in the extent is deleted. (The exception is open-open 8852 and all the text in the extent is deleted. (The exception is open-open
8536 zero-length extents, which are barred from existing because there is 8853 zero-length extents, which are barred from existing because there is
8554 8871
8555 Note that closed-open, non-detachable zero-length extents behave 8872 Note that closed-open, non-detachable zero-length extents behave
8556 exactly like markers and that open-closed, non-detachable zero-length 8873 exactly like markers and that open-closed, non-detachable zero-length
8557 extents behave like the ``point-type'' marker in Mule. 8874 extents behave like the ``point-type'' marker in Mule.
8558 8875
8559 @node Mathematics of Extent Ordering, Extent Fragments, Zero-Length Extents, Extents 8876 @node Mathematics of Extent Ordering
8560 @section Mathematics of Extent Ordering 8877 @section Mathematics of Extent Ordering
8878 @cindex mathematics of extent ordering
8561 @cindex extent mathematics 8879 @cindex extent mathematics
8562 @cindex mathematics of extents
8563 @cindex extent ordering 8880 @cindex extent ordering
8564 8881
8565 @cindex display order of extents 8882 @cindex display order of extents
8566 @cindex extents, display order 8883 @cindex extents, display order
8567 The extents in a buffer are ordered by ``display order'' because that 8884 The extents in a buffer are ordered by ``display order'' because that
8689 Proof: If @math{F2} does not include @math{I} then its start index is 9006 Proof: If @math{F2} does not include @math{I} then its start index is
8690 greater than @math{I} and thus it is greater than any extent in 9007 greater than @math{I} and thus it is greater than any extent in
8691 @math{S}, including @math{F}. Otherwise, @math{F2} includes @math{I} 9008 @math{S}, including @math{F}. Otherwise, @math{F2} includes @math{I}
8692 and thus is in @math{S}, and thus @math{F2 >= F}. 9009 and thus is in @math{S}, and thus @math{F2 >= F}.
8693 9010
8694 @node Extent Fragments, , Mathematics of Extent Ordering, Extents 9011 @node Extent Fragments
8695 @section Extent Fragments 9012 @section Extent Fragments
8696 @cindex extent fragment 9013 @cindex extent fragments
9014 @cindex fragments, extent
8697 9015
8698 Imagine that the buffer is divided up into contiguous, non-overlapping 9016 Imagine that the buffer is divided up into contiguous, non-overlapping
8699 @dfn{runs} of text such that no extent starts or ends within a run 9017 @dfn{runs} of text such that no extent starts or ends within a run
8700 (extents that abut the run don't count). 9018 (extents that abut the run don't count).
8701 9019
8713 stack-of-extents code, which does the heavy-duty algorithmic work of 9031 stack-of-extents code, which does the heavy-duty algorithmic work of
8714 determining which extents overly a particular position. 9032 determining which extents overly a particular position.
8715 9033
8716 @node Faces, Glyphs, Extents, Top 9034 @node Faces, Glyphs, Extents, Top
8717 @chapter Faces 9035 @chapter Faces
9036 @cindex faces
8718 9037
8719 Not yet documented. 9038 Not yet documented.
8720 9039
8721 @node Glyphs, Specifiers, Faces, Top 9040 @node Glyphs, Specifiers, Faces, Top
8722 @chapter Glyphs 9041 @chapter Glyphs
9042 @cindex glyphs
8723 9043
8724 Glyphs are graphical elements that can be displayed in XEmacs buffers or 9044 Glyphs are graphical elements that can be displayed in XEmacs buffers or
8725 gutters. We use the term graphical element here in the broadest possible 9045 gutters. We use the term graphical element here in the broadest possible
8726 sense since glyphs can be as mundane as text or as arcane as a native 9046 sense since glyphs can be as mundane as text or as arcane as a native
8727 tab widget. 9047 tab widget.
8751 9071
8752 Any action on a glyph first consults the cache before actually 9072 Any action on a glyph first consults the cache before actually
8753 instantiating a widget. 9073 instantiating a widget.
8754 9074
8755 @section Glyph Instantiation 9075 @section Glyph Instantiation
9076 @cindex glyph instantiation
9077 @cindex instantiation, glyph
8756 9078
8757 Glyph instantiation is a hairy topic and requires some explanation. The 9079 Glyph instantiation is a hairy topic and requires some explanation. The
8758 guts of glyph instantiation is contained within 9080 guts of glyph instantiation is contained within
8759 @code{image_instantiate}. A glyph contains an image which is a 9081 @code{image_instantiate}. A glyph contains an image which is a
8760 specifier. When a glyph function - for instance @code{Fglyph_height} - 9082 specifier. When a glyph function - for instance @code{Fglyph_height} -
8817 governing-domain, all other image-instances have a device as the 9139 governing-domain, all other image-instances have a device as the
8818 governing-domain. The governing domain for an image-instance is 9140 governing-domain. The governing domain for an image-instance is
8819 determined using the governing_domain image-instance method. 9141 determined using the governing_domain image-instance method.
8820 9142
8821 @section Widget-Glyphs 9143 @section Widget-Glyphs
9144 @cindex widget-glyphs
8822 9145
8823 @section Widget-Glyphs in the MS-Windows Environment 9146 @section Widget-Glyphs in the MS-Windows Environment
9147 @cindex widget-glyphs in the MS-Windows environment
9148 @cindex MS-Windows environment, widget-glyphs in the
8824 9149
8825 To Do 9150 To Do
8826 9151
8827 @section Widget-Glyphs in the X Environment 9152 @section Widget-Glyphs in the X Environment
9153 @cindex widget-glyphs in the X environment
9154 @cindex X environment, widget-glyphs in the
8828 9155
8829 Widget-glyphs under X make heavy use of lwlib (@pxref{Lucid Widget 9156 Widget-glyphs under X make heavy use of lwlib (@pxref{Lucid Widget
8830 Library}) for manipulating the native toolkit objects. This is primarily 9157 Library}) for manipulating the native toolkit objects. This is primarily
8831 so that different toolkits can be supported for widget-glyphs, just as 9158 so that different toolkits can be supported for widget-glyphs, just as
8832 they are supported for features such as menubars etc. 9159 they are supported for features such as menubars etc.
8849 code quite complex. And of course lwlib has to know at some level what 9176 code quite complex. And of course lwlib has to know at some level what
8850 the widget is and how to set its properties. 9177 the widget is and how to set its properties.
8851 9178
8852 @node Specifiers, Menus, Glyphs, Top 9179 @node Specifiers, Menus, Glyphs, Top
8853 @chapter Specifiers 9180 @chapter Specifiers
9181 @cindex specifiers
8854 9182
8855 Not yet documented. 9183 Not yet documented.
8856 9184
8857 @node Menus, Subprocesses, Specifiers, Top 9185 @node Menus, Subprocesses, Specifiers, Top
8858 @chapter Menus 9186 @chapter Menus
9187 @cindex menus
8859 9188
8860 A menu is set by setting the value of the variable 9189 A menu is set by setting the value of the variable
8861 @code{current-menubar} (which may be buffer-local) and then calling 9190 @code{current-menubar} (which may be buffer-local) and then calling
8862 @code{set-menubar-dirty-flag} to signal a change. This will cause the 9191 @code{set-menubar-dirty-flag} to signal a change. This will cause the
8863 menu to be redrawn at the next redisplay. The format of the data in 9192 menu to be redrawn at the next redisplay. The format of the data in
8906 its argument, which is the callback function or form given in the menu's 9235 its argument, which is the callback function or form given in the menu's
8907 description. 9236 description.
8908 9237
8909 @node Subprocesses, Interface to the X Window System, Menus, Top 9238 @node Subprocesses, Interface to the X Window System, Menus, Top
8910 @chapter Subprocesses 9239 @chapter Subprocesses
9240 @cindex subprocesses
8911 9241
8912 The fields of a process are: 9242 The fields of a process are:
8913 9243
8914 @table @code 9244 @table @code
8915 @item name 9245 @item name
8979 or @code{nil} if it is using pipes. 9309 or @code{nil} if it is using pipes.
8980 @end table 9310 @end table
8981 9311
8982 @node Interface to the X Window System, Index, Subprocesses, Top 9312 @node Interface to the X Window System, Index, Subprocesses, Top
8983 @chapter Interface to the X Window System 9313 @chapter Interface to the X Window System
9314 @cindex X Window System, interface to the
8984 9315
8985 Mostly undocumented. 9316 Mostly undocumented.
8986 9317
8987 @menu 9318 @menu
8988 * Lucid Widget Library:: An interface to various widget sets. 9319 * Lucid Widget Library:: An interface to various widget sets.
8989 @end menu 9320 @end menu
8990 9321
8991 @node Lucid Widget Library, , , Interface to the X Window System 9322 @node Lucid Widget Library
8992 @section Lucid Widget Library 9323 @section Lucid Widget Library
9324 @cindex Lucid Widget Library
9325 @cindex widget library, Lucid
9326 @cindex library, Lucid Widget
8993 9327
8994 Lwlib is extremely poorly documented and quite hairy. The author(s) 9328 Lwlib is extremely poorly documented and quite hairy. The author(s)
8995 blame that on X, Xt, and Motif, with some justice, but also sufficient 9329 blame that on X, Xt, and Motif, with some justice, but also sufficient
8996 hypocrisy to avoid drawing the obvious conclusion about their own work. 9330 hypocrisy to avoid drawing the obvious conclusion about their own work.
8997 9331
9016 * Checkboxes and Radio Buttons:: 9350 * Checkboxes and Radio Buttons::
9017 * Progress Bars:: 9351 * Progress Bars::
9018 * Tab Controls:: 9352 * Tab Controls::
9019 @end menu 9353 @end menu
9020 9354
9021 @node Generic Widget Interface, Scrollbars, , Lucid Widget Library 9355 @node Generic Widget Interface
9022 @subsection Generic Widget Interface 9356 @subsection Generic Widget Interface
9357 @cindex widget interface, generic
9023 9358
9024 In general in any toolkit a widget may be a composite object. In Xt, 9359 In general in any toolkit a widget may be a composite object. In Xt,
9025 all widgets have an X window that they manage, but typically a complex 9360 all widgets have an X window that they manage, but typically a complex
9026 widget will have widget children, each of which manages a subwindow of 9361 widget will have widget children, each of which manages a subwindow of
9027 the parent widget's X window. These children may themselves be 9362 the parent widget's X window. These children may themselves be
9096 9431
9097 The @code{widget_instance} structure also contains a pointer to the root 9432 The @code{widget_instance} structure also contains a pointer to the root
9098 of its tree. Widget instances are further confi 9433 of its tree. Widget instances are further confi
9099 9434
9100 9435
9101 @node Scrollbars, Menubars, Generic Widget Interface, Lucid Widget Library 9436 @node Scrollbars
9102 @subsection Scrollbars 9437 @subsection Scrollbars
9103 9438 @cindex scrollbars
9104 @node Menubars, Checkboxes and Radio Buttons, Scrollbars, Lucid Widget Library 9439
9440 @node Menubars
9105 @subsection Menubars 9441 @subsection Menubars
9106 9442 @cindex menubars
9107 @node Checkboxes and Radio Buttons, Progress Bars, Menubars, Lucid Widget Library 9443
9444 @node Checkboxes and Radio Buttons
9108 @subsection Checkboxes and Radio Buttons 9445 @subsection Checkboxes and Radio Buttons
9109 9446 @cindex checkboxes and radio buttons
9110 @node Progress Bars, Tab Controls, Checkboxes and Radio Buttons, Lucid Widget Library 9447 @cindex radio buttons, checkboxes and
9448 @cindex buttons, checkboxes and radio
9449
9450 @node Progress Bars
9111 @subsection Progress Bars 9451 @subsection Progress Bars
9112 9452 @cindex progress bars
9113 @node Tab Controls, , Progress Bars, Lucid Widget Library 9453 @cindex bars, progress
9454
9455 @node Tab Controls
9114 @subsection Tab Controls 9456 @subsection Tab Controls
9457 @cindex tab controls
9115 9458
9116 @include index.texi 9459 @include index.texi
9117 9460
9118 @c Print the tables of contents 9461 @c Print the tables of contents
9119 @summarycontents 9462 @summarycontents