Mercurial > hg > xemacs-beta
comparison man/internals/internals.texi @ 70:131b0175ea99 r20-0b30
Import from CVS: tag r20-0b30
author | cvs |
---|---|
date | Mon, 13 Aug 2007 09:02:59 +0200 |
parents | 2e6f5e180fb8 |
children | 48d667d6f17f |
comparison
equal
deleted
inserted
replaced
69:804d1389bcd6 | 70:131b0175ea99 |
---|---|
5 @c %**end of header | 5 @c %**end of header |
6 | 6 |
7 @ifinfo | 7 @ifinfo |
8 | 8 |
9 Copyright @copyright{} 1992 - 1996 Ben Wing. | 9 Copyright @copyright{} 1992 - 1996 Ben Wing. |
10 Copyright @copyright{} 1996, 1997 Sun Microsystems. | 10 Copyright @copyright{} 1996 Sun Microsystems. |
11 Copyright @copyright{} 1994, 1995 Free Software Foundation. | 11 Copyright @copyright{} 1994, 1995 Free Software Foundation. |
12 Copyright @copyright{} 1994, 1995 Board of Trustees, University of Illinois. | 12 Copyright @copyright{} 1994, 1995 Board of Trustees, University of Illinois. |
13 | 13 |
14 | 14 |
15 Permission is granted to make and distribute verbatim copies of this | 15 Permission is granted to make and distribute verbatim copies of this |
57 @setchapternewpage odd | 57 @setchapternewpage odd |
58 @finalout | 58 @finalout |
59 | 59 |
60 @titlepage | 60 @titlepage |
61 @title XEmacs Internals Manual | 61 @title XEmacs Internals Manual |
62 @subtitle Version 1.1, March 1997 | 62 @subtitle Version 1.0, March 1996 |
63 | 63 |
64 @author Ben Wing | 64 @author Ben Wing |
65 @author Martin Buchholz | |
66 @page | 65 @page |
67 @vskip 0pt plus 1fill | 66 @vskip 0pt plus 1fill |
68 | 67 |
69 @noindent | 68 @noindent |
70 Copyright @copyright{} 1992 - 1996 Ben Wing. @* | 69 Copyright @copyright{} 1992 - 1996 Ben Wing. @* |
71 Copyright @copyright{} 1996 Sun Microsystems, Inc. @* | 70 Copyright @copyright{} 1996 Sun Microsystems, Inc. @* |
72 Copyright @copyright{} 1994 Free Software Foundation. @* | 71 Copyright @copyright{} 1994 Free Software Foundation. @* |
73 Copyright @copyright{} 1994, 1995 Board of Trustees, University of Illinois. | 72 Copyright @copyright{} 1994, 1995 Board of Trustees, University of Illinois. |
74 | 73 |
75 @sp 2 | 74 @sp 2 |
76 Version 1.1 @* | 75 Version 1.0 @* |
77 March, 1997.@* | 76 March, 1996.@* |
78 | 77 |
79 Permission is granted to make and distribute verbatim copies of this | 78 Permission is granted to make and distribute verbatim copies of this |
80 manual provided the copyright notice and this permission notice are | 79 manual provided the copyright notice and this permission notice are |
81 preserved on all copies. | 80 preserved on all copies. |
82 | 81 |
207 * Symbol Values:: | 206 * Symbol Values:: |
208 | 207 |
209 Buffers and Textual Representation | 208 Buffers and Textual Representation |
210 | 209 |
211 * Introduction to Buffers:: A buffer holds a block of text such as a file. | 210 * Introduction to Buffers:: A buffer holds a block of text such as a file. |
212 * The Text in a Buffer:: Representation of the text in a buffer. | 211 * A Buffer@'s Text:: Representation of the text in a buffer. |
213 * Buffer Lists:: Keeping track of all buffers. | 212 * Buffer Lists:: Keeping track of all buffers. |
214 * Markers and Extents:: Tagging locations within a buffer. | 213 * Markers and Extents:: Tagging locations within a buffer. |
215 * Bufbytes and Emchars:: Representation of individual characters. | 214 * Bufbytes and Emchars:: Representation of individual characters. |
216 * The Buffer Object:: The Lisp object corresponding to a buffer. | 215 * The Buffer Object:: The Lisp object corresponding to a buffer. |
217 | 216 |
299 | 298 |
300 @menu | 299 @menu |
301 * Through Version 18:: Unification prevails. | 300 * Through Version 18:: Unification prevails. |
302 * Lucid Emacs:: One version 19 Emacs. | 301 * Lucid Emacs:: One version 19 Emacs. |
303 * GNU Emacs 19:: The other version 19 Emacs. | 302 * GNU Emacs 19:: The other version 19 Emacs. |
304 * GNU Emacs 20:: The other version 20 Emacs. | |
305 * XEmacs:: The continuation of Lucid Emacs. | 303 * XEmacs:: The continuation of Lucid Emacs. |
306 @end menu | 304 @end menu |
307 | 305 |
308 @node Through Version 18 | 306 @node Through Version 18 |
309 @section Through Version 18 | 307 @section Through Version 18 |
486 version 19.11 (first XEmacs) released September 13, 1994. | 484 version 19.11 (first XEmacs) released September 13, 1994. |
487 @item | 485 @item |
488 version 19.12 released June 23, 1995. | 486 version 19.12 released June 23, 1995. |
489 @item | 487 @item |
490 version 19.13 released September 1, 1995. | 488 version 19.13 released September 1, 1995. |
491 @item | |
492 version 19.14 released June 23, 1996. | |
493 @item | |
494 version 20.0 released February 9, 1997. | |
495 @item | |
496 version 19.15 released March 28, 1997. | |
497 @item | |
498 version 20.1 (not released to the net) April 15, 1997. | |
499 @item | |
500 version 20.2 released May 16, 1997. | |
501 @end itemize | 489 @end itemize |
502 | 490 |
503 @node GNU Emacs 19 | 491 @node GNU Emacs 19 |
504 @section GNU Emacs 19 | 492 @section GNU Emacs 19 |
505 @cindex GNU Emacs 19 | 493 @cindex GNU Emacs 19 |
554 version 19.27 (beta) released September 14, 1994. | 542 version 19.27 (beta) released September 14, 1994. |
555 @item | 543 @item |
556 version 19.28 (first ``official'' release) released November 1, 1994. | 544 version 19.28 (first ``official'' release) released November 1, 1994. |
557 @item | 545 @item |
558 version 19.29 released June 21, 1995. | 546 version 19.29 released June 21, 1995. |
559 @item | |
560 version 19.30 released November 24, 1995. | |
561 @item | |
562 version 19.31 released May 25, 1996. | |
563 @item | |
564 version 19.32 released July 31, 1996. | |
565 @item | |
566 version 19.33 released August 11, 1996. | |
567 @item | |
568 version 19.34 released August 21, 1996. | |
569 @item | |
570 version 19.34b released September 6, 1996. | |
571 @end itemize | 547 @end itemize |
572 | 548 |
573 @cindex Mlynarik, Richard | 549 @cindex Mlynarik, Richard |
574 In some ways, GNU Emacs 19 was better than Lucid Emacs; in some ways, | 550 In some ways, GNU Emacs 19 was better than Lucid Emacs; in some ways, |
575 worse. Lucid soon began incorporating features from GNU Emacs 19 into | 551 worse. Lucid soon began incorporating features from GNU Emacs 19 into |
576 Lucid Emacs; the work was mostly done by Richard Mlynarik, who had been | 552 Lucid Emacs; the work was mostly done by Richard Mlynarik, who had been |
577 working on and using GNU Emacs for a long time (back as far as version | 553 working on and using GNU Emacs for a long time (back as far as version |
578 16 or 17). | 554 16 or 17). |
579 | 555 |
580 @node GNU Emacs 20 | |
581 @section GNU Emacs 20 | |
582 @cindex GNU Emacs 20 | |
583 @cindex FSF Emacs | |
584 | |
585 On February 2, 1997 work began on GNU Emacs to integrate Mule. The first | |
586 release was made in September of that year. | |
587 | |
588 A timeline for Emacs 20 is | |
589 | |
590 @itemize @bullet | |
591 @item | |
592 version 20.1 released September 17, 1997. | |
593 @item | |
594 version 20.2 released September 20, 1997. | |
595 @end itemize | |
596 | |
597 @node XEmacs | 556 @node XEmacs |
598 @section XEmacs | 557 @section XEmacs |
599 @cindex XEmacs | 558 @cindex XEmacs |
600 | 559 |
601 @cindex Sun Microsystems | 560 @cindex Sun Microsystems |
602 @cindex University of Illinois | 561 @cindex University of Illinois |
603 @cindex Illinois, University of | 562 @cindex Illinois, University of |
604 @cindex SPARCWorks | 563 @cindex SPARCWorks |
605 @cindex Andreessen, Marc | 564 @cindex Andreessen, Marc |
606 @cindex Baur, Steve | |
607 @cindex Buchholz, Martin | |
608 @cindex Kaplan, Simon | 565 @cindex Kaplan, Simon |
609 @cindex Wing, Ben | 566 @cindex Wing, Ben |
610 @cindex Thompson, Chuck | 567 @cindex Thompson, Chuck |
611 @cindex Win-Emacs | 568 @cindex Win-Emacs |
612 @cindex Epoch | 569 @cindex Epoch |
632 version 19.11. In June 1994, Lucid folded and Jamie quit to work for | 589 version 19.11. In June 1994, Lucid folded and Jamie quit to work for |
633 the newly formed Mosaic Communications Corp., later Netscape | 590 the newly formed Mosaic Communications Corp., later Netscape |
634 Communications Corp. (co-founded by the same Marc Andreessen, who had | 591 Communications Corp. (co-founded by the same Marc Andreessen, who had |
635 quit his Epoch job to work on a graphical browser for the World Wide | 592 quit his Epoch job to work on a graphical browser for the World Wide |
636 Web). Chuck then become the primary maintainer of XEmacs, and put out | 593 Web). Chuck then become the primary maintainer of XEmacs, and put out |
637 versions 19.11 through 19.14 in conjunction with Ben. For 19.12 and | 594 versions 19.11, 19.12, and 19.13 in conjunction with Ben. For 19.12 and |
638 19.13, Chuck added the new redisplay and many other display improvements | 595 19.13, Chuck added the new redisplay and many other display improvements |
639 and Ben added MULE support (support for Asian and other languages) and | 596 and Ben added MULE support (support for Asian and other languages) and |
640 redesigned most of the internal Lisp subsystems to better support the | 597 redesigned most of the internal Lisp subsystems to better support the |
641 MULE work and the various other features being added to XEmacs. After | 598 MULE work and the various other features being added to XEmacs. |
642 19.14 Chuck retired as primary maintainer and Steve Baur stepped in. | |
643 | |
644 @cindex MULE merged XEmacs appears | |
645 Soon after 19.13 was released, work began in earnest on the MULE | |
646 internationalization code and the source tree was divided into two | |
647 development paths. The MULE version was initially called 19.20, but was | |
648 soon renamed to 20.0. In 1996 Martin Buchholz of Sun Microsystems took | |
649 over the care and feeding of it and worked on it in parallel with the | |
650 19.14 development that was occurring at the same time. After much work | |
651 by Martin, it was decided to release 20.0 ahead of 19.15 in February | |
652 1997. The source tree remained divided until 20.1 when the version 19 | |
653 source was finally retired. | |
654 | 599 |
655 @cindex merging attempts | 600 @cindex merging attempts |
656 Many attempts have been made to merge XEmacs and GNU Emacs, but they | 601 Many attempts have been made to merge XEmacs and GNU Emacs, but they |
657 have consistently run into the same technical disagreements and other | 602 have consistently run into the same technical disagreements and other |
658 problems that Lucid ran into when originally attempting to merge Lucid | 603 problems that Lucid ran into when originally attempting to merge Lucid |
907 | 852 |
908 XEmacs also contains a great deal of Lisp code. This implements the | 853 XEmacs also contains a great deal of Lisp code. This implements the |
909 operations that make XEmacs useful as an editor as well as just a | 854 operations that make XEmacs useful as an editor as well as just a |
910 Lisp environment, and also contains many add-on packages that allow | 855 Lisp environment, and also contains many add-on packages that allow |
911 XEmacs to browse directories, act as a mail and Usenet news reader, | 856 XEmacs to browse directories, act as a mail and Usenet news reader, |
912 compile Lisp code, etc. There is actually more Lisp code than | 857 compile Lisp code, etc. There is actually a lot more Lisp code than |
913 C code associated with XEmacs, but much of the Lisp code is | 858 C code associated with XEmacs, but much of the Lisp code is |
914 peripheral to the actual operation of the editor. The Lisp code | 859 peripheral to the actual operation of the editor. The Lisp code |
915 all lies in subdirectories underneath the @file{lisp/} directory. | 860 all lies in subdirectories underneath the @file{lisp/} directory. |
916 | 861 |
917 The @file{lwlib/} directory contains C code that implements a | 862 The @file{lwlib/} directory contains C code that implements a |
926 | 871 |
927 The @file{lib-src/} directory contains C code for various auxiliary | 872 The @file{lib-src/} directory contains C code for various auxiliary |
928 programs that are used in connection with XEmacs. Some of them are used | 873 programs that are used in connection with XEmacs. Some of them are used |
929 during the build process; others are used to perform certain functions | 874 during the build process; others are used to perform certain functions |
930 that cannot conveniently be placed in the XEmacs executable (e.g. the | 875 that cannot conveniently be placed in the XEmacs executable (e.g. the |
931 @file{movemail} program for fetching mail out of @file{/var/spool/mail}, | 876 @file{movemail} program for fetching mail out of /var/spool/mail, which |
932 which must be setgid to @file{mail} on many systems; and the | 877 must be setgid to @file{mail} on many systems; and the 'gnuclient' |
933 @file{gnuclient} program, which allows an external script to communicate | 878 program, which allows an external script to communicate with a running |
934 with a running XEmacs process). | 879 XEmacs process). |
935 | 880 |
936 The @file{man/} directory contains the sources for the XEmacs | 881 The @file{man/} directory contains the sources for the XEmacs |
937 documentation. It is mostly in a form called Texinfo, which can be | 882 documentation. It is mostly in a form called Texinfo, which can be |
938 converted into either a printed document (by passing it through @TeX{}) | 883 converted into either a printed document (by passing it through TeX) or |
939 or into on-line documentation called @dfn{info files}. | 884 into on-line documentation called @dfn{info files}. |
940 | 885 |
941 The @file{info/} directory contains the results of formatting the | 886 The @file{info/} directory contains the results of formatting the |
942 XEmacs documentation as @dfn{info files}, for on-line use. These files | 887 XEmacs documentation as @dfn{info files}, for on-line use. These files |
943 are used when you enter the Info system using @kbd{C-h i} or through the | 888 are used when you enter the Info system using @kbd{C-h i} or through the |
944 Help menu. | 889 Help menu. |
977 windows on the screen, and if you simply run it, it will exit | 922 windows on the screen, and if you simply run it, it will exit |
978 immediately. The Makefile runs @file{temacs} with certain options that | 923 immediately. The Makefile runs @file{temacs} with certain options that |
979 cause it to initialize itself, read in a number of basic Lisp files, and | 924 cause it to initialize itself, read in a number of basic Lisp files, and |
980 then dump itself out into a new executable called @file{xemacs}. This | 925 then dump itself out into a new executable called @file{xemacs}. This |
981 new executable has been pre-initialized and contains pre-digested Lisp | 926 new executable has been pre-initialized and contains pre-digested Lisp |
982 code that is necessary for the editor to function (this includes most | 927 code that is necessary for the editor to function (this includes some |
983 basic Lisp functions, e.g. @code{not}, that can be defined in terms of | 928 extremely basic Lisp functions, e.g. @code{not}, that can be defined in |
984 other Lisp primitives; some initialization code that is called when | 929 terms of other Lisp primitives; some initialization code that is called |
985 certain objects, such as frames, are created; and all of the standard | 930 when certain objects, such as frames, are created; and all of the |
986 keybindings and code for the actions they result in). This executable, | 931 standard keybindings and code for the actions they result in). This |
987 @file{xemacs}, is the executable that you run to use the XEmacs editor. | 932 executable, @file{xemacs}, is the executable that you run to use the |
933 XEmacs editor. | |
988 | 934 |
989 @node XEmacs From the Inside, The XEmacs Object System (Abstractly Speaking), XEmacs From the Perspective of Building, Top | 935 @node XEmacs From the Inside, The XEmacs Object System (Abstractly Speaking), XEmacs From the Perspective of Building, Top |
990 @chapter XEmacs From the Inside | 936 @chapter XEmacs From the Inside |
991 | 937 |
992 Internally, XEmacs is quite complex, and can be very confusing. To | 938 Internally, XEmacs is quite complex, and can be very confusing. To |
993 simplify things, it can be useful to think of XEmacs as containing an | 939 simplify things, it can be useful to think of XEmacs as containing an |
994 event loop that ``drives'' everything, and a number of other subsystems, | 940 event loop that ``drives'' everything, and a number of other subsystems, |
995 such as a Lisp engine and a redisplay mechanism. Each of these other | 941 such as a Lisp engine and a redisplay mechanism. Each of these others |
996 subsystems exists simultaneously in XEmacs, and each has a certain | 942 subsystems exists simultaneously in XEmacs, and each has a certain |
997 state. The flow of control continually passes in and out of these | 943 state. The flow of control continually passes in and out of these |
998 different subsystems in the course of normal operation of the editor. | 944 different subsystems in the course of normal operation of the editor. |
999 | 945 |
1000 It is important to keep in mind that, most of the time, the editor is | 946 It is important to keep in mind that, most of the time, the editor is |
1022 | 968 |
1023 @item | 969 @item |
1024 The buffer mechanism is responsible for keeping track of what buffers | 970 The buffer mechanism is responsible for keeping track of what buffers |
1025 exist and what text is in them. It is periodically given commands | 971 exist and what text is in them. It is periodically given commands |
1026 (usually from the user) to insert or delete text, create a buffer, etc. | 972 (usually from the user) to insert or delete text, create a buffer, etc. |
1027 When it receives a text-change command, it notifies the redisplay | 973 When it receives a textual-change command, it tells the redisplay |
1028 mechanism. | 974 mechanism about this. |
1029 | 975 |
1030 @item | 976 @item |
1031 The redisplay mechanism is responsible for making sure that windows and | 977 The redisplay mechanism is responsible for making sure that windows and |
1032 frames are displayed correctly. It is periodically told (by the event | 978 frames are displayed correctly. It is periodically told (by the event |
1033 loop) to actually ``do its job'', i.e. snoop around and see what the | 979 loop) to actually ``do its job'', i.e. snoop around and see what the |
1219 these types of objects.) | 1165 these types of objects.) |
1220 | 1166 |
1221 XEmacs Lisp also contains numerous specialized objects used to | 1167 XEmacs Lisp also contains numerous specialized objects used to |
1222 implement the editor: | 1168 implement the editor: |
1223 | 1169 |
1224 @table @code | 1170 @table @asis |
1225 @item buffer | 1171 @item buffer |
1226 Stores text like a string, but is optimized for insertion and deletion | 1172 Stores text like a string, but is optimized for insertion and deletion |
1227 and has certain other properties that can be set. | 1173 and has certain other properties that can be set. |
1228 @item frame | 1174 @item frame |
1229 An object with various properties whose displayable representation is a | 1175 An object with various properties whose displayable representation is a |
1268 An object that describes a connection to an externally-running process. | 1214 An object that describes a connection to an externally-running process. |
1269 @end table | 1215 @end table |
1270 | 1216 |
1271 There are some other, less-commonly-encountered general objects: | 1217 There are some other, less-commonly-encountered general objects: |
1272 | 1218 |
1273 @table @code | 1219 @table @asis |
1274 @item hashtable | 1220 @item hashtable |
1275 An object that maps from an arbitrary Lisp object to another arbitrary | 1221 An object that maps from an arbitrary Lisp object to another arbitrary |
1276 Lisp object, using hashing for fast lookup. | 1222 Lisp object, using hashing for fast lookup. |
1277 @item obarray | 1223 @item obarray |
1278 A limited form of hashtable that maps from strings to symbols; obarrays | 1224 A limited form of hashtable that maps from strings to symbols; obarrays |
1292 An object that maps from ranges of integers to arbitrary Lisp objects. | 1238 An object that maps from ranges of integers to arbitrary Lisp objects. |
1293 @end table | 1239 @end table |
1294 | 1240 |
1295 And some strange special-purpose objects: | 1241 And some strange special-purpose objects: |
1296 | 1242 |
1297 @table @code | 1243 @table @asis |
1298 @item charset | 1244 @item charset |
1299 @itemx coding-system | 1245 @itemx coding-system |
1300 Objects used when MULE, or multi-lingual/Asian-language, support is | 1246 Objects used when MULE, or multi-lingual/Asian-language, support is |
1301 enabled. | 1247 enabled. |
1302 @item color-instance | 1248 @item color-instance |
1406 @example | 1352 @example |
1407 ?^[$(B#&^[(B | 1353 ?^[$(B#&^[(B |
1408 @end example | 1354 @end example |
1409 | 1355 |
1410 (where @samp{^[} actually is an @samp{ESC} character) converts to a | 1356 (where @samp{^[} actually is an @samp{ESC} character) converts to a |
1411 particular Kanji character when using an ISO2022-based coding system for | 1357 particular Kanji character. (To decode this gook: @samp{ESC} begins an |
1412 input. (To decode this gook: @samp{ESC} begins an escape sequence; | 1358 escape sequence; @samp{ESC $ (} is a class of escape sequences meaning |
1413 @samp{ESC $ (} is a class of escape sequences meaning ``switch to a | 1359 ``switch to a 94x94 character set''; @samp{ESC $ ( B} means ``switch to |
1414 94x94 character set''; @samp{ESC $ ( B} means ``switch to Japanese | 1360 Japanese Kanji''; @samp{#} and @samp{&} collectively index into a |
1415 Kanji''; @samp{#} and @samp{&} collectively index into a 94-by-94 array | 1361 94-by-94 array of characters [subtract 33 from the ASCII value of each |
1416 of characters [subtract 33 from the ASCII value of each character to get | 1362 character to get the corresponding index]; @samp{ESC (} is a class of |
1417 the corresponding index]; @samp{ESC (} is a class of escape sequences | 1363 escape sequences meaning ``switch to a 94 character set''; @samp{ESC (B} |
1418 meaning ``switch to a 94 character set''; @samp{ESC (B} means ``switch | 1364 means ``switch to US ASCII''. It is a coincidence that the letter |
1419 to US ASCII''. It is a coincidence that the letter @samp{B} is used to | 1365 @samp{B} is used to denote both Japanese Kanji and US ASCII. If the |
1420 denote both Japanese Kanji and US ASCII. If the first @samp{B} were | 1366 first @samp{B} were replaced with an @samp{A}, you'd be requesting a |
1421 replaced with an @samp{A}, you'd be requesting a Chinese Hanzi character | 1367 Chinese Hanzi character from the GB2312 character set.) |
1422 from the GB2312 character set.) | |
1423 | 1368 |
1424 @example | 1369 @example |
1425 "foobar" | 1370 "foobar" |
1426 @end example | 1371 @end example |
1427 | 1372 |
1550 opposite semantics? ``Hysterical reasons'', of course.) | 1495 opposite semantics? ``Hysterical reasons'', of course.) |
1551 | 1496 |
1552 @cindex record type | 1497 @cindex record type |
1553 Note that there are only eight types that the tag can represent, | 1498 Note that there are only eight types that the tag can represent, |
1554 but many more actual types than this. This is handled by having | 1499 but many more actual types than this. This is handled by having |
1555 one of the tag types specify a meta-type called a @dfn{record}; | 1500 one of the tag types specify a meta-object called a @dfn{record}; |
1556 for all such objects, the first four bytes of the pointed-to | 1501 for all such objects, the first four bytes of the pointed-to |
1557 structure indicate what the actual type is. | 1502 structure indicate what the actual type is. |
1558 | 1503 |
1559 Note also that having 28 bits for pointers and integers restricts a | 1504 Note also that having 28 bits for pointers and integers restricts a |
1560 lot of things to 256 megabytes of memory. (Basically, enough pointers | 1505 lot of things to 256 megabytes of memory. (Basically, enough pointers |
1574 (e.g. beginning at 0x80000000). Those machines cope by defining | 1519 (e.g. beginning at 0x80000000). Those machines cope by defining |
1575 @code{DATA_SEG_BITS} in the corresponding @file{m/} or @file{s/} file to | 1520 @code{DATA_SEG_BITS} in the corresponding @file{m/} or @file{s/} file to |
1576 the proper mask. Then, pointers retrieved from Lisp objects are | 1521 the proper mask. Then, pointers retrieved from Lisp objects are |
1577 automatically OR'ed with this value prior to being used. | 1522 automatically OR'ed with this value prior to being used. |
1578 | 1523 |
1579 A corollary of the previous paragraph is that @strong{(pointers to) | 1524 A corollary of the previous paragraph is that @strong{stack-allocated |
1580 stack-allocated structures cannot be put into Lisp objects}. The stack | 1525 structures cannot be put into Lisp objects}. The stack is generally |
1581 is generally located near the top of memory; if you put such a pointer | 1526 located near the top of memory; if you put such a pointer into a Lisp |
1582 into a Lisp object, it will get its top bits chopped off, and you will | 1527 object, it will get its top bits chopped off, and you will lose. |
1583 lose. | |
1584 | 1528 |
1585 Various macros are used to construct Lisp objects and extract the | 1529 Various macros are used to construct Lisp objects and extract the |
1586 components. Macros of the form @code{XINT()}, @code{XCHAR()}, | 1530 components. Macros of the form @code{XINT()}, @code{XCHAR()}, |
1587 @code{XSTRING()}, @code{XSYMBOL()}, etc. mask out the pointer/integer | 1531 @code{XSTRING()}, @code{XSYMBOL()}, etc. mask out the pointer/integer |
1588 field and cast it to the appropriate type. All of the macros that | 1532 field and cast it to the appropriate type. All of the macros that |
1603 object is really of the correct type. This is great for catching places | 1547 object is really of the correct type. This is great for catching places |
1604 where an incorrect type is being dereferenced -- this typically results | 1548 where an incorrect type is being dereferenced -- this typically results |
1605 in a pointer being dereferenced as the wrong type of structure, with | 1549 in a pointer being dereferenced as the wrong type of structure, with |
1606 unpredictable (and sometimes not easily traceable) results. | 1550 unpredictable (and sometimes not easily traceable) results. |
1607 | 1551 |
1608 There are similar @code{XSET@var{TYPE}()} macros that construct a Lisp object. | 1552 There are similar @code{XSET()} macros that construct a Lisp object. |
1609 These macros are of the form @code{XSET@var{TYPE} (@var{lvalue}, @var{result})}, | 1553 These macros are of the form @code{XSET (@var{lvalue}, @var{result})}, |
1610 i.e. they have to be a statement rather than just used in an expression. | 1554 i.e. they have to be a statement rather than just used in an expression. |
1611 The reason for this is that standard C doesn't let you ``construct'' a | 1555 The reason for this is that standard C doesn't let you ``construct'' a |
1612 structure (but GCC does). Granted, this sometimes isn't too convenient; | 1556 structure (but GCC does). Granted, this sometimes isn't too convenient; |
1613 for the case of integers, at least, you can use the function | 1557 for the case of integers, at least, you can use the function |
1614 @code{make_number()}, which constructs and @emph{returns} an integer | 1558 @code{make_number()}, which constructs and @emph{returns} an integer |
1615 Lisp object. Note that the @code{XSET@var{TYPE}()} macros are also | 1559 Lisp object. Note that the @code{XSET()} macros are also affected by |
1616 affected by @code{ERROR_CHECK_TYPECHECK} and make sure that the | 1560 @code{ERROR_CHECK_TYPECHECK} and make sure that the structure is of the right |
1617 structure is of the right type in the case of record types, where the | 1561 type in the case of record types, where the type is contained in |
1618 type is contained in the structure. | 1562 the structure. |
1619 | 1563 |
1620 @node Rules When Writing New C Code, A Summary of the Various XEmacs Modules, How Lisp Objects Are Represented in C, Top | 1564 @node Rules When Writing New C Code, A Summary of the Various XEmacs Modules, How Lisp Objects Are Represented in C, Top |
1621 @chapter Rules When Writing New C Code | 1565 @chapter Rules When Writing New C Code |
1622 | 1566 |
1623 The XEmacs C Code is extremely complex and intricate, and there are | 1567 The XEmacs C Code is extremely complex and intricate, and there are |
1641 @code{vars_of_*()} function. The former declares any Lisp primitives | 1585 @code{vars_of_*()} function. The former declares any Lisp primitives |
1642 you have defined and defines any symbols you will be using. The latter | 1586 you have defined and defines any symbols you will be using. The latter |
1643 declares any global Lisp variables you have added and initializes global | 1587 declares any global Lisp variables you have added and initializes global |
1644 C variables in the module. For each such function, declare it in | 1588 C variables in the module. For each such function, declare it in |
1645 @file{symsinit.h} and make sure it's called in the appropriate place in | 1589 @file{symsinit.h} and make sure it's called in the appropriate place in |
1646 @file{emacs.c}. @strong{Important}: There are stringent requirements on | 1590 @code{main()}. @strong{Important}: There are stringent requirements on |
1647 exactly what can go into these functions. See the comment in | 1591 exactly what can go into these functions. See the comment in |
1648 @file{emacs.c}. The reason for this is to avoid obscure unwanted | 1592 @code{main()}. The reason for this is to avoid obscure unwanted |
1649 interactions during initialization. If you don't follow these rules, | 1593 interactions during initialization. If you don't follow these rules, |
1650 you'll be sorry! If you want to do anything that isn't allowed, create | 1594 you'll be sorry! If you want to do anything that isn't allowed, create |
1651 a @code{complex_vars_of_*()} function for it. Doing this is tricky, | 1595 a @code{complex_vars_of_*()} function for it. Doing this is tricky, |
1652 though: You have to make sure your function is called at the right time | 1596 though: You have to make sure your function is called at the right time |
1653 so that all the initialization dependencies work out. | 1597 so that all the initialization dependencies work out. |
1654 | 1598 |
1655 Every module includes @file{<config.h>} (angle brackets so that | 1599 Every module includes @file{<config.h>} (angle brackets so that |
1656 @samp{--srcdir} works correctly; @file{config.h} may or may not be in | 1600 @samp{--srcdir} works correctly) and @file{lisp.h}. @file{config.h} |
1657 the same directory as the C sources) and @file{lisp.h}. @file{config.h} | |
1658 should always be included before any other header files (including | 1601 should always be included before any other header files (including |
1659 system header files) to ensure that certain tricks played by various | 1602 system header files) to ensure that certain tricks played by various |
1660 @file{s/} and @file{m/} files work out correctly. | 1603 @file{s/} and @file{m/} files work out correctly. |
1661 | 1604 |
1662 @strong{All global and static variables that are to be modifiable must | 1605 @strong{All global and static variables that are to be modifiable must |
1748 | 1691 |
1749 Let's start with a precise explanation of the arguments to the | 1692 Let's start with a precise explanation of the arguments to the |
1750 @code{DEFUN} macro. Here is a template for them: | 1693 @code{DEFUN} macro. Here is a template for them: |
1751 | 1694 |
1752 @example | 1695 @example |
1753 DEFUN (@var{lname}, @var{fname}, @var{min}, @var{max}, @var{interactive}, /* | 1696 DEFUN (@var{lname}, @var{fname}, @var{min}, @var{max}, @var{interactive} /* |
1754 @var{docstring} | 1697 @var{docstring} |
1755 */ | 1698 */ |
1756 (@var{arglist}) ) | 1699 (@var{arglist}) ) |
1757 @end example | 1700 @end example |
1758 | 1701 |
1759 @table @var | 1702 @table @var |
1760 @item lname | 1703 @item lname |
1761 This string is the name of the Lisp symbol to define as the function | 1704 This is the name of the Lisp symbol to define as the function name; in |
1762 name; in the example above, it is @code{"or"}. | 1705 the example above, it is @code{or}. |
1763 | 1706 |
1764 @item fname | 1707 @item fname |
1765 This is the C function name for this function. This is the name that is | 1708 This is the C function name for this function. This is the name that is |
1766 used in C code for calling the function. The name is, by convention, | 1709 used in C code for calling the function. The name is, by convention, |
1767 @samp{F} prepended to the Lisp name, with all dashes (@samp{-}) in the | 1710 @samp{F} prepended to the Lisp name, with all dashes (@samp{-}) in the |
1816 string is enclosed in a comment, none of the documentation is placed on | 1759 string is enclosed in a comment, none of the documentation is placed on |
1817 the same lines as the comment-start and comment-end characters, and the | 1760 the same lines as the comment-start and comment-end characters, and the |
1818 comment-start characters are on the same line as the interactive | 1761 comment-start characters are on the same line as the interactive |
1819 specification. @file{make-docfile}, which scans the C files for | 1762 specification. @file{make-docfile}, which scans the C files for |
1820 documentation strings, is very particular about what it looks for, and | 1763 documentation strings, is very particular about what it looks for, and |
1821 will not properly extract the doc string if it's not in this exact format. | 1764 will not properly note the doc string if it's not in this exact format. |
1822 | 1765 |
1823 You are free to put the various arguments to @code{DEFUN} on separate | 1766 You are free to put the various arguments to @code{DEFUN} on separate |
1824 lines to avoid overly long lines. However, make sure to put the | 1767 lines to avoid overly long lines. However, make sure to put the |
1825 comment-start characters for the doc string on the same line as the | 1768 comment-start characters for the doc string on the same line as the |
1826 interactive specification, and put a newline directly after them (and | 1769 interactive specification, and put a newline directly after them (and |
1835 | 1778 |
1836 The names of the C arguments will be used as the names of the arguments | 1779 The names of the C arguments will be used as the names of the arguments |
1837 to the Lisp primitive as displayed in its documentation, modulo the same | 1780 to the Lisp primitive as displayed in its documentation, modulo the same |
1838 concerns described above for @code{F...} names (in particular, | 1781 concerns described above for @code{F...} names (in particular, |
1839 underscores in the C arguments become dashes in the Lisp arguments). | 1782 underscores in the C arguments become dashes in the Lisp arguments). |
1840 | 1783 There is one additional kludge: A C argument called @code{defalt} |
1841 There is one additional kludge: A trailing `_' on the C argument is | 1784 becomes the Lisp argument @code{default}. This deliberate misspelling |
1842 discarded when forming the Lisp argument. This allows C language | 1785 is done because @code{default} is a reserved word in the C language. |
1843 reserved words (like @code{default}) or global symbols (like | |
1844 @code{dirname}) to be used as argument names without compiler warnings | |
1845 or errors. | |
1846 | 1786 |
1847 A Lisp function with @w{@var{max} = @code{UNEVALLED}} is a | 1787 A Lisp function with @w{@var{max} = @code{UNEVALLED}} is a |
1848 @w{@dfn{special form}}; its arguments are not evaluated. Instead it | 1788 @w{@dfn{special form}}; its arguments are not evaluated. Instead it |
1849 receives one argument of type @code{Lisp_Object}, a (Lisp) list of the | 1789 receives one argument of type @code{Lisp_Object}, a (Lisp) list of the |
1850 unevaluated arguments, conventionally named @code{(args)}. | 1790 unevaluated arguments, conventionally named @code{(args)}. |
1891 of XEmacs coding. It is @strong{extremely} important that you get this | 1831 of XEmacs coding. It is @strong{extremely} important that you get this |
1892 right and use a great deal of discipline when writing this code. | 1832 right and use a great deal of discipline when writing this code. |
1893 @xref{GCPROing, ,@code{GCPRO}ing}, for full details on how to do this. | 1833 @xref{GCPROing, ,@code{GCPRO}ing}, for full details on how to do this. |
1894 | 1834 |
1895 What @code{DEFUN} actually does is declare a global structure of | 1835 What @code{DEFUN} actually does is declare a global structure of |
1896 type @code{Lisp_Subr} whose name begins with capital @samp{SF} and | 1836 type @code{Lisp_Subr} whose name begins with a capital @samp{S} and |
1897 which contains information about the primitive (e.g. a pointer to the | 1837 which contains information about the primitive (e.g. a pointer to the |
1898 function, its minimum and maximum allowed arguments, a string describing | 1838 function, its minimum and maximum allowed arguments, a string describing |
1899 its Lisp name); @code{DEFUN} then begins a normal C function | 1839 its Lisp name); @code{DEFUN} then begins a normal C function |
1900 declaration using the @code{F...} name. The Lisp subr object that is | 1840 declaration using the @code{F...} name. The Lisp subr object that is |
1901 the function definition of a primitive (i.e. the object in the function | 1841 the function definition of a primitive (i.e. the object in the function |
1902 slot of the symbol that names the primitive) actually points to this | 1842 slot of the symbol that names the primitive) actually points to this |
1903 @samp{SF} structure; when @code{Feval} encounters a subr, it looks in the | 1843 @samp{S} structure; when @code{Feval} encounters a subr, it looks in the |
1904 structure to find out how to call the C function. | 1844 structure to find out how to call the C function. |
1905 | 1845 |
1906 Defining the C function is not enough to make a Lisp primitive | 1846 Defining the C function is not enough to make a Lisp primitive |
1907 available; you must also create the Lisp symbol for the primitive (the | 1847 available; you must also create the Lisp symbol for the primitive (the |
1908 symbol is @dfn{interned}; @pxref{Obarrays}) and store a suitable subr | 1848 symbol is @dfn{interned}; @pxref{Obarrays}) and store a suitable subr |
1909 object in its function cell. (If you don't do this, the primitive won't | 1849 object in its function cell. (If you don't do this, the primitive won't |
1910 be seen by Lisp code.) The code looks like this: | 1850 be seen by Lisp code.) The code looks like this: |
1911 | 1851 |
1912 @example | 1852 @example |
1913 DEFSUBR (@var{fname}); | 1853 defsubr (&@var{subr-structure-name}); |
1914 @end example | 1854 @end example |
1915 | 1855 |
1916 @noindent | 1856 @noindent |
1917 Here @var{fname} is the name you used as the second argument to | 1857 Here @var{subr-structure-name} is the name you used as the third |
1918 @code{DEFUN}. | 1858 argument to @code{DEFUN}. |
1919 | 1859 |
1920 This call to @code{DEFSUBR} should go in the @code{syms_of_*()} | 1860 This call to @code{defsubr} should go in the @code{syms_of_*()} |
1921 function at the end of the module. If no such function exists, create | 1861 function at the end of the module. If no such function exists, create |
1922 it and make sure to also declare it in @file{symsinit.h} and call it | 1862 it and make sure to also declare it in @file{symsinit.h} and call it |
1923 from the appropriate spot in @code{main()}. @xref{General Coding | 1863 from the appropriate spot in @code{main()}. @xref{General Coding |
1924 Rules}. | 1864 Rules}. |
1925 | 1865 |
1926 Note that C code cannot call functions by name unless they are defined | 1866 Note that C code cannot call functions by name unless they are defined |
1927 in C. The way to call a function written in Lisp from C is to use | 1867 in C. The way to call a function written in Lisp is to use |
1928 @code{Ffuncall}, which embodies the Lisp function @code{funcall}. Since | 1868 @code{Ffuncall}, which embodies the Lisp function @code{funcall}. Since |
1929 the Lisp function @code{funcall} accepts an unlimited number of | 1869 the Lisp function @code{funcall} accepts an unlimited number of |
1930 arguments, in C it takes two: the number of Lisp-level arguments, and a | 1870 arguments, in C it takes two: the number of Lisp-level arguments, and a |
1931 one-dimensional array containing their values. The first Lisp-level | 1871 one-dimensional array containing their values. The first Lisp-level |
1932 argument is the Lisp function to call, and the rest are the arguments to | 1872 argument is the Lisp function to call, and the rest are the arguments to |
2148 @file{alloca.c}, etc. are normally placed past @file{lastfile.c}, and | 2088 @file{alloca.c}, etc. are normally placed past @file{lastfile.c}, and |
2149 all of the files that implement Xt widget classes @emph{must} be placed | 2089 all of the files that implement Xt widget classes @emph{must} be placed |
2150 after @file{lastfile.c} because they contain various structures that | 2090 after @file{lastfile.c} because they contain various structures that |
2151 must be statically initialized and into which Xt writes at various | 2091 must be statically initialized and into which Xt writes at various |
2152 times.) @file{pre-crt0.c} and @file{lastfile.c} contain exported symbols | 2092 times.) @file{pre-crt0.c} and @file{lastfile.c} contain exported symbols |
2153 that are used to determine the start and end of XEmacs' initialized | 2093 that are used to determine the start and end of XEmacs's initialized |
2154 data space when dumping. | 2094 data space when dumping. |
2155 | 2095 |
2156 | 2096 |
2157 | 2097 |
2158 @example | 2098 @example |
3132 43058 chartab.c | 3072 43058 chartab.c |
3133 6503 chartab.h | 3073 6503 chartab.h |
3134 9918 casetab.c | 3074 9918 casetab.c |
3135 @end example | 3075 @end example |
3136 | 3076 |
3137 @file{chartab.c} and @file{chartab.h} implement the @dfn{char table} | 3077 @file{chartab.c} and @file{chartab.h} implement the char table Lisp |
3138 Lisp object type, which maps from characters or certain sorts of | 3078 object type, which maps from characters or certain sorts of character |
3139 character ranges to Lisp objects. The implementation of this object | 3079 ranges to Lisp objects. The implementation of this object is optimized |
3140 type is optimized for the internal representation of characters. Char | 3080 for the internal representation of characters. Char tables come in |
3141 tables come in different types, which affect the allowed object types to | 3081 different types, which affect the allowed object types to which a |
3142 which a character can be mapped and also dictate certain other | 3082 character can be mapped and also dictate certain other properties of the |
3143 properties of the char table. | 3083 char table. |
3144 | 3084 |
3145 @cindex case table | 3085 @cindex case table |
3146 @file{casetab.c} implements one sort of char table, the @dfn{case | 3086 @file{casetab.c} implements one sort of char table, the @dfn{case |
3147 table}, which maps characters to other characters of possibly different | 3087 table}, which maps characters to other characters of possibly different |
3148 case. These are used by XEmacs to implement case-changing primitives | 3088 case. These are used by XEmacs to implement case-changing primitives |
3154 49593 syntax.c | 3094 49593 syntax.c |
3155 10200 syntax.h | 3095 10200 syntax.h |
3156 @end example | 3096 @end example |
3157 | 3097 |
3158 @cindex scanner | 3098 @cindex scanner |
3159 This module implements @dfn{syntax tables}, another sort of char table | 3099 This module implements syntax tables, another sort of char table that |
3160 that maps characters into syntax classes that define the syntax of these | 3100 maps characters into syntax classes that define the syntax of these |
3161 characters (e.g. a parenthesis belongs to a class of @samp{open} | 3101 characters (e.g. a parenthesis belongs to a class of @samp{open} characters |
3162 characters that have corresponding @samp{close} characters and can be | 3102 that have corresponding @samp{close} characters and can be nested). |
3163 nested). This module also implements the Lisp @dfn{scanner}, a set of | 3103 This module also implements the Lisp @dfn{scanner}, a set of primitives |
3164 primitives for scanning over text based on syntax tables. This is used, | 3104 for scanning over text based on syntax tables. This is used, for |
3165 for example, to find the matching parenthesis in a command such as | 3105 example, to find the matching parenthesis in a command such as |
3166 @code{forward-sexp}, and by @file{font-lock.c} to locate quoted strings, | 3106 @code{forward-sexp}, and by @file{font-lock.c} to locate quoted strings, |
3167 comments, etc. | 3107 comments, etc. |
3168 | 3108 |
3169 | 3109 |
3170 | 3110 |
3722 two-dimensional set of characters, such as US ASCII or JISX0208 Japanese | 3662 two-dimensional set of characters, such as US ASCII or JISX0208 Japanese |
3723 Kanji). | 3663 Kanji). |
3724 | 3664 |
3725 @file{mule-coding.*} implements the @dfn{coding-system} Lisp object | 3665 @file{mule-coding.*} implements the @dfn{coding-system} Lisp object |
3726 type, which encapsulates a method of converting between different | 3666 type, which encapsulates a method of converting between different |
3727 encodings. An encoding is a representation of a stream of characters, | 3667 encodings. An encoding is a representation of a stream of characters |
3728 possibly from multiple character sets, using a stream of bytes or words, | 3668 from multiple character sets using a stream of bytes or words and |
3729 and defines (e.g.) which escape sequences are used to specify particular | 3669 defines (e.g.) which escape sequences are used to specify particular |
3730 character sets, how the indices for a character are converted into bytes | 3670 character sets, how the indices for a character are converted into bytes |
3731 (sometimes this involves setting the high bit; sometimes complicated | 3671 (sometimes this involves setting the high bit; sometimes complicated |
3732 rearranging of the values takes place, as in the Shift-JIS encoding), | 3672 rearranging of the values takes place, as in the Shift-JIS encoding), |
3733 etc. | 3673 etc. |
3734 | 3674 |
3736 interpreter. CCL is similar in spirit to Lisp byte code and is used to | 3676 interpreter. CCL is similar in spirit to Lisp byte code and is used to |
3737 implement converters for custom encodings. | 3677 implement converters for custom encodings. |
3738 | 3678 |
3739 @file{mule-canna.c} and @file{mule-wnnfns.c} implement interfaces to | 3679 @file{mule-canna.c} and @file{mule-wnnfns.c} implement interfaces to |
3740 external programs used to implement the Canna and WNN input methods, | 3680 external programs used to implement the Canna and WNN input methods, |
3741 respectively. This is currently in beta. | 3681 respectively. This is currently broken. |
3742 | 3682 |
3743 @file{mule-mcpath.c} provides some functions to allow for pathnames | 3683 @file{mule-mcpath.c} provides some functions to allow for pathnames |
3744 containing extended characters. This code is fragmentary, obsolete, and | 3684 containing extended characters. This code is fragmentary, obsolete, and |
3745 completely non-working. Instead, @var{pathname-coding-system} is used | 3685 completely non-working. Instead, @var{pathname-coding-system} is used |
3746 to specify conversions of names of files and directories. The standard | 3686 to specify conversions of names of files and directories. The standard |
3822 @itemize @bullet | 3762 @itemize @bullet |
3823 @item | 3763 @item |
3824 (a) Those for whom the value directly represents the contents of the | 3764 (a) Those for whom the value directly represents the contents of the |
3825 Lisp object. Only two types are in this category: integers and | 3765 Lisp object. Only two types are in this category: integers and |
3826 characters. No special allocation or garbage collection is necessary | 3766 characters. No special allocation or garbage collection is necessary |
3827 for such objects. Lisp objects of these types do not need to be | 3767 for such objects. |
3828 @code{GCPRO}ed. | |
3829 @end itemize | 3768 @end itemize |
3830 | 3769 |
3831 In the remaining three categories, the value is a pointer to a | 3770 In the remaining three categories, the value is a pointer to a |
3832 structure. | 3771 structure. |
3833 | 3772 |
3993 Note that @code{obarray} is one of the @code{staticpro()}d things. | 3932 Note that @code{obarray} is one of the @code{staticpro()}d things. |
3994 Therefore, all functions and variables get marked through this. | 3933 Therefore, all functions and variables get marked through this. |
3995 @item | 3934 @item |
3996 Any shadowed bindings that are sitting on the specpdl stack. | 3935 Any shadowed bindings that are sitting on the specpdl stack. |
3997 @item | 3936 @item |
3998 Any objects sitting in currently active (Lisp) stack frames, | 3937 Any objects sitting in currently active stack frames, |
3999 catches, and condition cases. | 3938 catches, and condition cases. |
4000 @item | 3939 @item |
4001 A couple of special-case places where active objects are | 3940 A couple of special-case places where active objects are |
4002 located. | 3941 located. |
4003 @item | 3942 @item |
4042 just a single lvalue. To effect this, call @code{GCPRO@var{n}} as usual on | 3981 just a single lvalue. To effect this, call @code{GCPRO@var{n}} as usual on |
4043 the first object in the array and then set @code{gcpron.nvars}. | 3982 the first object in the array and then set @code{gcpron.nvars}. |
4044 | 3983 |
4045 @item | 3984 @item |
4046 @strong{Strings are relocated.} What this means in practice is that the | 3985 @strong{Strings are relocated.} What this means in practice is that the |
4047 pointer obtained using @code{XSTRING_DATA()} is liable to change at any | 3986 pointer obtained using @code{string_data()} is liable to change at any |
4048 time, and you should never keep it around past any function call, or | 3987 time, and you should never keep it around past any function call, or |
4049 pass it as an argument to any function that might cause a garbage | 3988 pass it as an argument to any function that might cause a garbage |
4050 collection. This is why a number of functions accept either a | 3989 collection. This is why a number of functions accept either a |
4051 ``non-relocatable'' @code{char *} pointer or a relocatable Lisp string, | 3990 ``non-relocatable'' @code{char *} pointer or a relocatable Lisp string, |
4052 and only access the Lisp string's data at the very last minute. In some | 3991 and only access the Lisp string's data at the very last minute. In some |
4083 If you have the @emph{least smidgeon of doubt} about whether | 4022 If you have the @emph{least smidgeon of doubt} about whether |
4084 you need to @code{GCPRO}, you should @code{GCPRO}. | 4023 you need to @code{GCPRO}, you should @code{GCPRO}. |
4085 | 4024 |
4086 @item | 4025 @item |
4087 Beware of @code{GCPRO}ing something that is uninitialized. If you have | 4026 Beware of @code{GCPRO}ing something that is uninitialized. If you have |
4088 any shade of doubt about this, initialize all your variables to @code{Qnil}. | 4027 any shade of doubt about this, initialize all your variables to Qnil. |
4089 | 4028 |
4090 @item | 4029 @item |
4091 Be careful of traps, like calling @code{Fcons()} in the argument to | 4030 Be careful of traps, like calling @code{Fcons()} in the argument to |
4092 another function. By the ``caller protects'' law, you should be | 4031 another function. By the ``caller protects'' law, you should be |
4093 @code{GCPRO}ing the newly-created cons, but you aren't. A certain | 4032 @code{GCPRO}ing the newly-created cons, but you aren't. A certain |
4492 @section Vector | 4431 @section Vector |
4493 | 4432 |
4494 As mentioned above, each vector is @code{malloc()}ed individually, and | 4433 As mentioned above, each vector is @code{malloc()}ed individually, and |
4495 all are threaded through the variable @code{all_vectors}. Vectors are | 4434 all are threaded through the variable @code{all_vectors}. Vectors are |
4496 marked strangely during garbage collection, by kludging the size field. | 4435 marked strangely during garbage collection, by kludging the size field. |
4497 Note that the @code{struct Lisp_Vector} is declared with its | 4436 Note that the @code{struct Lisp_Vector} is declared with its contents |
4498 @code{contents} field being a @emph{stretchy} array of one element. It | 4437 being an array of one element. It is actually @code{malloc()}ed with |
4499 is actually @code{malloc()}ed with the right size, however, and access | 4438 the right size, however, and access to any element through the contents |
4500 to any element through the @code{contents} array works fine. | 4439 array works fine. |
4501 | 4440 |
4502 @node Bit Vector | 4441 @node Bit Vector |
4503 @section Bit Vector | 4442 @section Bit Vector |
4504 | 4443 |
4505 Bit vectors work exactly like vectors, except for more complicated | 4444 Bit vectors work exactly like vectors, except for more complicated |
4978 @code{command_event_queue}. There is a comment about a ``race | 4917 @code{command_event_queue}. There is a comment about a ``race |
4979 condition'', which is not a good sign. | 4918 condition'', which is not a good sign. |
4980 | 4919 |
4981 @code{next-command-event} and @code{read-char} are higher-level | 4920 @code{next-command-event} and @code{read-char} are higher-level |
4982 interfaces to @code{next-event}. @code{next-command-event} gets the | 4921 interfaces to @code{next-event}. @code{next-command-event} gets the |
4983 next @dfn{command} event (i.e. keypress, mouse event, menu selection, | 4922 next @dfn{command} event (i.e. keypress, mouse event, or menu |
4984 or scrollbar action), calling @code{dispatch-event} on any others. | 4923 selection), calling dispatch-event on any others. @code{read-char} |
4985 @code{read-char} calls @code{next-command-event} and uses | 4924 calls @code{next-command-event} and uses @code{event_to_character()} to |
4986 @code{event_to_character()} to return the character equivalent. With | 4925 return the ASCII equivalent. |
4987 the right kind of input method support, it is possible for (read-char) | |
4988 to return a Kanji character. | |
4989 | 4926 |
4990 @node Converting Events | 4927 @node Converting Events |
4991 @section Converting Events | 4928 @section Converting Events |
4992 | 4929 |
4993 @code{character_to_event()}, @code{event_to_character()}, | 4930 @code{character_to_event()}, @code{event_to_character()}, |
4994 @code{event-to-character}, and @code{character-to-event} convert between | 4931 @code{event-to-character}, and @code{character-to-event} convert between |
4995 characters and keypress events corresponding to the characters. If the | 4932 ASCII characters and keypresses corresponding to the characters. If the |
4996 event was not a keypress, @code{event_to_character()} returns -1 and | 4933 event was not a keypress, @code{event_to_character()} returns -1 and |
4997 @code{event-to-character} returns @code{nil}. These functions convert | 4934 @code{event-to-character} returns @code{nil}. These functions convert |
4998 between character representation and the split-up event representation | 4935 between ASCII representation and the split-up event representation |
4999 (keysym plus mod keys). | 4936 (keysym plus mod keys). |
5000 | 4937 |
5001 @node Dispatching Events; The Command Builder | 4938 @node Dispatching Events; The Command Builder |
5002 @section Dispatching Events; The Command Builder | 4939 @section Dispatching Events; The Command Builder |
5003 | 4940 |
5039 the backtrace structure is changed). | 4976 the backtrace structure is changed). |
5040 | 4977 |
5041 At this point, the function to be called is determined by looking at | 4978 At this point, the function to be called is determined by looking at |
5042 the car of the cons (if this is a symbol, its function definition is | 4979 the car of the cons (if this is a symbol, its function definition is |
5043 retrieved and the process repeated). The function should then consist | 4980 retrieved and the process repeated). The function should then consist |
5044 of either a @code{Lisp_Subr} (built-in function), a | 4981 of either a Lisp_Subr (built-in function), a Lisp_Compiled object, or a |
5045 @code{Lisp_Compiled_Function} object, or a cons whose car is the symbol | 4982 cons whose car is the symbol @code{autoload}, @code{macro}, |
5046 @code{autoload}, @code{macro}, @code{lambda}, or @code{mocklisp}. | 4983 @code{lambda}, or @code{mocklisp}. |
5047 | 4984 |
5048 If the function is a @code{Lisp_Subr}, the lisp object points to a | 4985 If the function is a Lisp_Subr, the lisp object points to a struct |
5049 @code{struct Lisp_Subr} (created by @code{DEFUN()}), which contains a | 4986 Lisp_Subr (created by @code{DEFUN()}), which contains a pointer to the C |
5050 pointer to the C function, a minimum and maximum number of arguments | 4987 function, a minimum and maximum number of arguments (possibly the |
5051 (possibly the special constants @code{MANY} or @code{UNEVALLED}), a | 4988 special constants @code{MANY} or @code{UNEVALLED}), a pointer to the |
5052 pointer to the symbol referring to that subr, and a couple of other | 4989 symbol referring to that subr, and a couple of other things. If the |
5053 things. If the subr wants its arguments @code{UNEVALLED}, they are | 4990 subr wants its arguments @code{UNEVALLED}, they are passed raw as a |
5054 passed raw as a list. Otherwise, an array of evaluated arguments is | 4991 list. Otherwise, an array of evaluated arguments is created and put |
5055 created and put into the backtrace structure, and either passed whole | 4992 into the backtrace structure, and either passed whole (@code{MANY}) or |
5056 (@code{MANY}) or each argument is passed as a C argument. | 4993 each argument is passed as a C argument. |
5057 | 4994 |
5058 If the function is a @code{Lisp_Compiled_Function} object or a lambda, | 4995 If the function is a Lisp_Compiled object or a lambda, |
5059 @code{apply_lambda()} is called. If the function is a macro, | 4996 @code{apply_lambda()} is called. If the function is a macro, |
5060 [..... fill in] is done. If the function is an autoload, | 4997 [..... fill in] is done. If the function is an autoload, |
5061 @code{do_autoload()} is called to load the definition and then eval | 4998 @code{do_autoload()} is called to load the definition and then eval |
5062 starts over [explain this more]. If the function is a mocklisp, | 4999 starts over [explain this more]. If the function is a mocklisp, |
5063 @code{ml_apply()} is called. | 5000 @code{ml_apply()} is called. |
5073 | 5010 |
5074 @code{funcall_lambda()} goes through the formal arguments to the | 5011 @code{funcall_lambda()} goes through the formal arguments to the |
5075 function and binds them to the actual arguments, checking for | 5012 function and binds them to the actual arguments, checking for |
5076 @code{&rest} and @code{&optional} symbols in the formal arguments and | 5013 @code{&rest} and @code{&optional} symbols in the formal arguments and |
5077 making sure the number of actual arguments is correct. Then either | 5014 making sure the number of actual arguments is correct. Then either |
5078 @code{progn} or @code{byte-code} is called to actually execute the body | 5015 progn or byte-code is called to actually execute the body and return a |
5079 and return a value. | 5016 value. |
5080 | 5017 |
5081 @code{Ffuncall()} implements Lisp @code{funcall}. @code{(funcall fun | 5018 @code{Ffuncall()} implements Lisp @code{funcall}. @code{(funcall fun |
5082 x1 x2 x3 ...)} is equivalent to @code{(eval (list fun (quote x1) (quote | 5019 x1 x2 x3 ...)} is equivalent to @code{(eval (list fun (quote x1) (quote |
5083 x2) (quote x3) ...))}. @code{Ffuncall()} contains its own code to do | 5020 x2) (quote x3) ...))}. @code{Ffuncall()} contains its own code to do |
5084 the evaluation, however, and is almost identical to eval. | 5021 the evaluation, however, and is almost identical to eval. |
5122 specpdl array, and @code{specpdl_size} is increased by 1. | 5059 specpdl array, and @code{specpdl_size} is increased by 1. |
5123 | 5060 |
5124 @code{record_unwind_protect()} implements an @dfn{unwind-protect}, | 5061 @code{record_unwind_protect()} implements an @dfn{unwind-protect}, |
5125 which, when placed around a section of code, ensures that some specified | 5062 which, when placed around a section of code, ensures that some specified |
5126 cleanup routine will be executed even if the code exits abnormally | 5063 cleanup routine will be executed even if the code exits abnormally |
5127 (e.g. through a @code{throw} or quit). @code{record_unwind_protect()} | 5064 (e.g. through a throw or quit). @code{record_unwind_protect()} simply |
5128 simply adds a new specbinding to the specpdl array and stores the | 5065 adds a new specbinding to the specpdl array and stores the appropriate |
5129 appropriate information in it. The cleanup routine can either be a C | 5066 information in it. The cleanup routine can either be a C function, |
5130 function, which is stored in the @code{func} field, or a @code{progn} | 5067 which is stored in the @code{func} field, or a progn form, which is stored in |
5131 form, which is stored in the @code{old_value} field. | 5068 the @code{old_value} field. |
5132 | 5069 |
5133 @code{unbind_to()} removes specbindings from the specpdl array until | 5070 @code{unbind_to()} removes specbindings from the specpdl array until |
5134 the specified position is reached. Each specbinding can be one of three | 5071 the specified position is reached. The specbinding can be one of three |
5135 types: | 5072 types: |
5136 | 5073 |
5137 @enumerate | 5074 @enumerate |
5138 @item | 5075 @item |
5139 an unwind-protect with a C cleanup function (@code{func} is not 0, and | 5076 an unwind-protect with a C cleanup function (@code{func} is not 0 -- |
5140 @code{old_value} holds an argument to be passed to the function); | 5077 @code{old_value} holds an argument to be passed to the function); |
5141 @item | 5078 @item |
5142 an unwind-protect with a Lisp form (@code{func} is 0, @code{symbol} | 5079 an unwind-protect with a Lisp form (@code{func} is 0 and @code{symbol} |
5143 is @code{nil}, and @code{old_value} holds the form to be executed with | 5080 is @code{nil} -- @code{old_value} holds the form to be executed with |
5144 @code{Fprogn()}); or | 5081 @code{Fprogn()}); or |
5145 @item | 5082 @item |
5146 a local-variable binding (@code{func} is 0, @code{symbol} is not | 5083 a local-variable binding (@code{func} is 0 and @code{symbol} is not |
5147 @code{nil}, and @code{old_value} holds the old value, which is stored as | 5084 @code{nil} -- @code{old_value} holds the old value, which is stored as |
5148 the symbol's value). | 5085 the symbol's value). |
5149 @end enumerate | 5086 @end enumerate |
5150 | 5087 |
5151 @node Simple Special Forms | 5088 @node Simple Special Forms |
5152 @section Simple Special Forms | 5089 @section Simple Special Forms |
5303 | 5240 |
5304 Usually symbols are created by @code{intern}, but if you really want, | 5241 Usually symbols are created by @code{intern}, but if you really want, |
5305 you can explicitly create a symbol using @code{make-symbol}, giving it | 5242 you can explicitly create a symbol using @code{make-symbol}, giving it |
5306 some name. The resulting symbol is not in any obarray (i.e. it is | 5243 some name. The resulting symbol is not in any obarray (i.e. it is |
5307 @dfn{uninterned}), and you can't add it to any obarray. Therefore its | 5244 @dfn{uninterned}), and you can't add it to any obarray. Therefore its |
5308 primary purpose is as a symbol to use in macros to avoid namespace | 5245 primary purpose is as a carrier of information. (Cons cells could |
5309 pollution. It can also be used as a carrier of information, but cons | 5246 probably be used just as well.) |
5310 cells could probably be used just as well. | |
5311 | 5247 |
5312 You can also use @code{intern-soft} to look up a symbol but not create | 5248 You can also use @code{intern-soft} to look up a symbol but not create |
5313 a new one, and @code{unintern} to remove a symbol from an obarray. This | 5249 a new one, and @code{unintern} to remove a symbol from an obarray. This |
5314 returns the removed symbol. (Remember: You can't put the symbol back | 5250 returns the removed symbol. (Remember: You can't put the symbol back |
5315 into any obarray.) Finally, @code{mapatoms} maps over all of the symbols | 5251 into any obarray.) Finally, @code{mapatoms} maps over all of the symbols |
5361 @node Buffers and Textual Representation, MULE Character Sets and Encodings, Symbols and Variables, Top | 5297 @node Buffers and Textual Representation, MULE Character Sets and Encodings, Symbols and Variables, Top |
5362 @chapter Buffers and Textual Representation | 5298 @chapter Buffers and Textual Representation |
5363 | 5299 |
5364 @menu | 5300 @menu |
5365 * Introduction to Buffers:: A buffer holds a block of text such as a file. | 5301 * Introduction to Buffers:: A buffer holds a block of text such as a file. |
5366 * The Text in a Buffer:: Representation of the text in a buffer. | 5302 * A Buffer@'s Text:: Representation of the text in a buffer. |
5367 * Buffer Lists:: Keeping track of all buffers. | 5303 * Buffer Lists:: Keeping track of all buffers. |
5368 * Markers and Extents:: Tagging locations within a buffer. | 5304 * Markers and Extents:: Tagging locations within a buffer. |
5369 * Bufbytes and Emchars:: Representation of individual characters. | 5305 * Bufbytes and Emchars:: Representation of individual characters. |
5370 * The Buffer Object:: The Lisp object corresponding to a buffer. | 5306 * The Buffer Object:: The Lisp object corresponding to a buffer. |
5371 @end menu | 5307 @end menu |
5377 In this, it is like a string, but a buffer is optimized for | 5313 In this, it is like a string, but a buffer is optimized for |
5378 frequent insertion and deletion, while a string is not. Furthermore: | 5314 frequent insertion and deletion, while a string is not. Furthermore: |
5379 | 5315 |
5380 @enumerate | 5316 @enumerate |
5381 @item | 5317 @item |
5382 Buffers are @dfn{permanent} objects, i.e. once you create them, they | 5318 Buffers are @dfn{permanent} objects, i.e. one you create them, they |
5383 remain around, and need to be explicitly deleted before they go away. | 5319 remain around, and need to be explicitly deleted before they go away. |
5384 @item | 5320 @item |
5385 Each buffer has a unique name, which is a string. Buffers are | 5321 Each buffer has a unique name, which is a string. Buffers are |
5386 normally referred to by name. In this respect, they are like | 5322 normally referred to by name. In this respect, they are like |
5387 symbols. | 5323 symbols. |
5411 can temporarily change the current buffer using @code{set-buffer} (often | 5347 can temporarily change the current buffer using @code{set-buffer} (often |
5412 enclosed in a @code{save-excursion} so that the former current buffer | 5348 enclosed in a @code{save-excursion} so that the former current buffer |
5413 gets restored when the code is finished). However, calling | 5349 gets restored when the code is finished). However, calling |
5414 @code{set-buffer} will NOT cause a permanent change in the current | 5350 @code{set-buffer} will NOT cause a permanent change in the current |
5415 buffer. The reason for this is that the top-level event loop sets | 5351 buffer. The reason for this is that the top-level event loop sets |
5416 @code{current_buffer} to the buffer of the selected window, each time | 5352 current buffer to the buffer of the selected window, each time it |
5417 it finishes executing a user command. | 5353 finishes executing a user command. |
5418 @end enumerate | 5354 @end enumerate |
5419 | 5355 |
5420 Make sure you understand the distinction between @dfn{current buffer} | 5356 Make sure you understand the distinction between @dfn{current buffer} |
5421 and @dfn{buffer of the selected window}, and the distinction between | 5357 and @dfn{buffer of the selected window}, and the distinction between |
5422 @dfn{point} of the current buffer and @dfn{window-point} of the selected | 5358 @dfn{point} of the current buffer and @dfn{window-point} of the selected |
5423 window. (This latter distinction is explained in detail in the section | 5359 window. (This latter distinction is explained in detail in the section |
5424 on windows.) | 5360 on windows.) |
5425 | 5361 |
5426 @node The Text in a Buffer | 5362 @node A Buffer@'s Text |
5427 @section The Text in a Buffer | 5363 @section A Buffer's Text |
5428 | 5364 |
5429 The text in a buffer consists of a sequence of zero or more | 5365 The text in a buffer consists of a sequence of zero or more |
5430 characters. A @dfn{character} is an integer that logically represents | 5366 characters. A @dfn{character} is an integer that logically represents |
5431 a letter, number, space, or other unit of text. Most of the characters | 5367 a letter, number, space, or other unit of text. Most of the characters |
5432 that you will typically encounter belong to the ASCII set of characters, | 5368 that you will typically encounter belong to the ASCII set of characters, |
5435 etc.), Cyrillic and Greek letters, etc. The actual number of possible | 5371 etc.), Cyrillic and Greek letters, etc. The actual number of possible |
5436 characters is quite large. | 5372 characters is quite large. |
5437 | 5373 |
5438 For now, we can view a character as some non-negative integer that | 5374 For now, we can view a character as some non-negative integer that |
5439 has some shape that defines how it typically appears (e.g. as an | 5375 has some shape that defines how it typically appears (e.g. as an |
5440 uppercase A). (The exact way in which a character appears depends on the | 5376 uppercase A). (The exact way in which a character appears depends |
5441 font used to display the character.) The internal type of characters in | 5377 on the font of the character.) The internal type of characters in |
5442 the C code is an @code{Emchar}; this is just an @code{int}, but using a | 5378 the C code is an Emchar; this is just an int, but using a symbolic |
5443 symbolic type makes the code clearer. | 5379 type makes the code clearer. |
5444 | 5380 |
5445 Between every character in a buffer is a @dfn{buffer position} or | 5381 Between every character in a buffer is a @dfn{buffer position} or |
5446 @dfn{character position}. We can speak of the character before or after | 5382 @dfn{character position}. We can speak of the character before or after |
5447 a particular buffer position, and when you insert a character at a | 5383 a particular buffer position, and when you insert a character at a |
5448 particular position, all characters after that position end up at new | 5384 particular position, all characters after that position end up at new |
5494 characters back again). Once the buffer is killed, the memory allocated | 5430 characters back again). Once the buffer is killed, the memory allocated |
5495 for the buffer text will be freed, but it will still be sitting on the | 5431 for the buffer text will be freed, but it will still be sitting on the |
5496 heap, taking up virtual memory, and will not be released back to the | 5432 heap, taking up virtual memory, and will not be released back to the |
5497 operating system. (However, if you have compiled XEmacs with rel-alloc, | 5433 operating system. (However, if you have compiled XEmacs with rel-alloc, |
5498 the situation is different. In this case, the space @emph{will} be | 5434 the situation is different. In this case, the space @emph{will} be |
5499 released back to the operating system. However, this tends to result in a | 5435 released back to the operating system. However, this tends to effect a |
5500 noticeable speed penalty.) | 5436 noticeable speed penalty.) |
5501 | 5437 |
5502 Astute readers may notice that the text in a buffer is represented as | 5438 Astute readers may notice that the text in a buffer is represented as |
5503 an array of @emph{bytes}, while (at least in the MULE case) an Emchar is | 5439 an array of @emph{bytes}, while (at least in the MULE case) an Emchar is |
5504 a 19-bit integer, which clearly cannot fit in a byte. This means (of | 5440 a 19-bit integer, which clearly cannot fit in a byte. This means (of |
5547 @dfn{byte indices}, typedef @code{Bytind} | 5483 @dfn{byte indices}, typedef @code{Bytind} |
5548 @item | 5484 @item |
5549 @dfn{memory indices}, typedef @code{Memind} | 5485 @dfn{memory indices}, typedef @code{Memind} |
5550 @end enumerate | 5486 @end enumerate |
5551 | 5487 |
5552 All three typedefs are just @code{int}s, but defining them this way makes | 5488 All three typedefs are just ints, but defining them this way makes |
5553 things a lot clearer. | 5489 things a lot clearer. |
5554 | 5490 |
5555 Most code works with buffer positions. In particular, all Lisp code | 5491 Most code works with buffer positions. In particular, all Lisp code |
5556 that refers to text in a buffer uses buffer positions. Lisp code does | 5492 that refers to text in a buffer uses buffer positions. Lisp code does |
5557 not know that byte indices or memory indices exist. | 5493 not know that byte indices or memory indices exist. |
5558 | 5494 |
5559 Finally, we have a typedef for the bytes in a buffer. This is a | 5495 Finally, we have a typedef for the bytes in a buffer. This is a |
5560 @code{Bufbyte}, which is an unsigned char. Referring to them as | 5496 @code{Bufbyte}, which is an unsigned char. Referring to them as |
5561 Bufbytes underscores the fact that we are working with a string of bytes | 5497 Bufbytes underscores the fact that we are working with a string of bytes |
5562 in the internal Emacs buffer representation rather than in one of a | 5498 in the internal Emacs buffer representation rather than in one of a |
5563 number of possible alternative representations (e.g. EUC-encoded text, | 5499 number of possible alternative representations (e.g. EUC-coded text, |
5564 etc.). | 5500 etc.). |
5565 | 5501 |
5566 @node Buffer Lists | 5502 @node Buffer Lists |
5567 @section Buffer Lists | 5503 @section Buffer Lists |
5568 | 5504 |