XEmacs 21.2.29 "Hestia".
[chise/xemacs-chise.git.1] / info / internals.info-1
1 This is ../info/internals.info, produced by makeinfo version 4.0 from
2 internals/internals.texi.
3
4 INFO-DIR-SECTION XEmacs Editor
5 START-INFO-DIR-ENTRY
6 * Internals: (internals).       XEmacs Internals Manual.
7 END-INFO-DIR-ENTRY
8
9    Copyright (C) 1992 - 1996 Ben Wing.  Copyright (C) 1996, 1997 Sun
10 Microsystems.  Copyright (C) 1994 - 1998 Free Software Foundation.
11 Copyright (C) 1994, 1995 Board of Trustees, University of Illinois.
12
13    Permission is granted to make and distribute verbatim copies of this
14 manual provided the copyright notice and this permission notice are
15 preserved on all copies.
16
17    Permission is granted to copy and distribute modified versions of
18 this manual under the conditions for verbatim copying, provided that the
19 entire resulting derived work is distributed under the terms of a
20 permission notice identical to this one.
21
22    Permission is granted to copy and distribute translations of this
23 manual into another language, under the above conditions for modified
24 versions, except that this permission notice may be stated in a
25 translation approved by the Foundation.
26
27    Permission is granted to copy and distribute modified versions of
28 this manual under the conditions for verbatim copying, provided also
29 that the section entitled "GNU General Public License" is included
30 exactly as in the original, and provided that the entire resulting
31 derived work is distributed under the terms of a permission notice
32 identical to this one.
33
34    Permission is granted to copy and distribute translations of this
35 manual into another language, under the above conditions for modified
36 versions, except that the section entitled "GNU General Public License"
37 may be included in a translation approved by the Free Software
38 Foundation instead of in the original English.
39
40 \1f
41 File: internals.info,  Node: Top,  Next: A History of Emacs,  Prev: (dir),  Up: (dir)
42
43    This Info file contains v1.0 of the XEmacs Internals Manual.
44
45 * Menu:
46
47 * A History of Emacs::          Times, dates, important events.
48 * XEmacs From the Outside::     A broad conceptual overview.
49 * The Lisp Language::           An overview.
50 * XEmacs From the Perspective of Building::
51 * XEmacs From the Inside::
52 * The XEmacs Object System (Abstractly Speaking)::
53 * How Lisp Objects Are Represented in C::
54 * Rules When Writing New C Code::
55 * A Summary of the Various XEmacs Modules::
56 * Allocation of Objects in XEmacs Lisp::
57 * Dumping::
58 * Events and the Event Loop::
59 * Evaluation; Stack Frames; Bindings::
60 * Symbols and Variables::
61 * Buffers and Textual Representation::
62 * MULE Character Sets and Encodings::
63 * The Lisp Reader and Compiler::
64 * Lstreams::
65 * Consoles; Devices; Frames; Windows::
66 * The Redisplay Mechanism::
67 * Extents::
68 * Faces::
69 * Glyphs::
70 * Specifiers::
71 * Menus::
72 * Subprocesses::
73 * Interface to X Windows::
74 * Index::
75
76
77 A History of Emacs
78
79 * Through Version 18::          Unification prevails.
80 * Lucid Emacs::                 One version 19 Emacs.
81 * GNU Emacs 19::                The other version 19 Emacs.
82 * GNU Emacs 20::                The other version 20 Emacs.
83 * XEmacs::                      The continuation of Lucid Emacs.
84
85 Rules When Writing New C Code
86
87 * General Coding Rules::
88 * Writing Lisp Primitives::
89 * Adding Global Lisp Variables::
90 * Coding for Mule::
91 * Techniques for XEmacs Developers::
92
93 Coding for Mule
94
95 * Character-Related Data Types::
96 * Working With Character and Byte Positions::
97 * Conversion to and from External Data::
98 * General Guidelines for Writing Mule-Aware Code::
99 * An Example of Mule-Aware Code::
100
101 A Summary of the Various XEmacs Modules
102
103 * Low-Level Modules::
104 * Basic Lisp Modules::
105 * Modules for Standard Editing Operations::
106 * Editor-Level Control Flow Modules::
107 * Modules for the Basic Displayable Lisp Objects::
108 * Modules for other Display-Related Lisp Objects::
109 * Modules for the Redisplay Mechanism::
110 * Modules for Interfacing with the File System::
111 * Modules for Other Aspects of the Lisp Interpreter and Object System::
112 * Modules for Interfacing with the Operating System::
113 * Modules for Interfacing with X Windows::
114 * Modules for Internationalization::
115
116 Allocation of Objects in XEmacs Lisp
117
118 * Introduction to Allocation::
119 * Garbage Collection::
120 * GCPROing::
121 * Garbage Collection - Step by Step::
122 * Integers and Characters::
123 * Allocation from Frob Blocks::
124 * lrecords::
125 * Low-level allocation::
126 * Pure Space::
127 * Cons::
128 * Vector::
129 * Bit Vector::
130 * Symbol::
131 * Marker::
132 * String::
133 * Compiled Function::
134
135 Garbage Collection - Step by Step
136
137 * Invocation::
138 * garbage_collect_1::
139 * mark_object::
140 * gc_sweep::
141 * sweep_lcrecords_1::
142 * compact_string_chars::
143 * sweep_strings::
144 * sweep_bit_vectors_1::
145
146 Dumping
147
148 * Overview::
149 * Data descriptions::
150 * Dumping phase::
151 * Reloading phase::
152
153 Dumping phase
154
155 * Object inventory::
156 * Address allocation::
157 * The header::
158 * Data dumping::
159 * Pointers dumping::
160
161 Events and the Event Loop
162
163 * Introduction to Events::
164 * Main Loop::
165 * Specifics of the Event Gathering Mechanism::
166 * Specifics About the Emacs Event::
167 * The Event Stream Callback Routines::
168 * Other Event Loop Functions::
169 * Converting Events::
170 * Dispatching Events; The Command Builder::
171
172 Evaluation; Stack Frames; Bindings
173
174 * Evaluation::
175 * Dynamic Binding; The specbinding Stack; Unwind-Protects::
176 * Simple Special Forms::
177 * Catch and Throw::
178
179 Symbols and Variables
180
181 * Introduction to Symbols::
182 * Obarrays::
183 * Symbol Values::
184
185 Buffers and Textual Representation
186
187 * Introduction to Buffers::     A buffer holds a block of text such as a file.
188 * The Text in a Buffer::        Representation of the text in a buffer.
189 * Buffer Lists::                Keeping track of all buffers.
190 * Markers and Extents::         Tagging locations within a buffer.
191 * Bufbytes and Emchars::        Representation of individual characters.
192 * The Buffer Object::           The Lisp object corresponding to a buffer.
193
194 MULE Character Sets and Encodings
195
196 * Character Sets::
197 * Encodings::
198 * Internal Mule Encodings::
199 * CCL::
200
201 Encodings
202
203 * Japanese EUC (Extended Unix Code)::
204 * JIS7::
205
206 Internal Mule Encodings
207
208 * Internal String Encoding::
209 * Internal Character Encoding::
210
211 Lstreams
212
213 * Creating an Lstream::         Creating an lstream object.
214 * Lstream Types::               Different sorts of things that are streamed.
215 * Lstream Functions::           Functions for working with lstreams.
216 * Lstream Methods::             Creating new lstream types.
217
218 Consoles; Devices; Frames; Windows
219
220 * Introduction to Consoles; Devices; Frames; Windows::
221 * Point::
222 * Window Hierarchy::
223 * The Window Object::
224
225 The Redisplay Mechanism
226
227 * Critical Redisplay Sections::
228 * Line Start Cache::
229 * Redisplay Piece by Piece::
230
231 Extents
232
233 * Introduction to Extents::     Extents are ranges over text, with properties.
234 * Extent Ordering::             How extents are ordered internally.
235 * Format of the Extent Info::   The extent information in a buffer or string.
236 * Zero-Length Extents::         A weird special case.
237 * Mathematics of Extent Ordering::  A rigorous foundation.
238 * Extent Fragments::            Cached information useful for redisplay.
239
240 \1f
241 File: internals.info,  Node: A History of Emacs,  Next: XEmacs From the Outside,  Prev: Top,  Up: Top
242
243 A History of Emacs
244 ******************
245
246    XEmacs is a powerful, customizable text editor and development
247 environment.  It began as Lucid Emacs, which was in turn derived from
248 GNU Emacs, a program written by Richard Stallman of the Free Software
249 Foundation.  GNU Emacs dates back to the 1970's, and was modelled after
250 a package called "Emacs", written in 1976, that was a set of macros on
251 top of TECO, an old, old text editor written at MIT on the DEC PDP 10
252 under one of the earliest time-sharing operating systems, ITS
253 (Incompatible Timesharing System). (ITS dates back well before Unix.)
254 ITS, TECO, and Emacs were products of a group of people at MIT who
255 called themselves "hackers", who shared an idealistic belief system
256 about the free exchange of information and were fanatical in their
257 devotion to and time spent with computers. (The hacker subculture dates
258 back to the late 1950's at MIT and is described in detail in Steven
259 Levy's book `Hackers'.  This book also includes a lot of information
260 about Stallman himself and the development of Lisp, a programming
261 language developed at MIT that underlies Emacs.)
262
263 * Menu:
264
265 * Through Version 18::          Unification prevails.
266 * Lucid Emacs::                 One version 19 Emacs.
267 * GNU Emacs 19::                The other version 19 Emacs.
268 * GNU Emacs 20::                The other version 20 Emacs.
269 * XEmacs::                      The continuation of Lucid Emacs.
270
271 \1f
272 File: internals.info,  Node: Through Version 18,  Next: Lucid Emacs,  Prev: A History of Emacs,  Up: A History of Emacs
273
274 Through Version 18
275 ==================
276
277    Although the history of the early versions of GNU Emacs is unclear,
278 the history is well-known from the middle of 1985.  A time line is:
279
280    * GNU Emacs version 15 (15.34) was released sometime in 1984 or 1985
281      and shared some code with a version of Emacs written by James
282      Gosling (the same James Gosling who later created the Java
283      language).
284
285    * GNU Emacs version 16 (first released version was 16.56) was
286      released on July 15, 1985.  All Gosling code was removed due to
287      potential copyright problems with the code.
288
289    * version 16.57: released on September 16, 1985.
290
291    * versions 16.58, 16.59: released on September 17, 1985.
292
293    * version 16.60: released on September 19, 1985.  These later
294      version 16's incorporated patches from the net, esp. for getting
295      Emacs to work under System V.
296
297    * version 17.36 (first official v17 release) released on December 20,
298      1985.  Included a TeX-able user manual.  First official unpatched
299      version that worked on vanilla System V machines.
300
301    * version 17.43 (second official v17 release) released on January 25,
302      1986.
303
304    * version 17.45 released on January 30, 1986.
305
306    * version 17.46 released on February 4, 1986.
307
308    * version 17.48 released on February 10, 1986.
309
310    * version 17.49 released on February 12, 1986.
311
312    * version 17.55 released on March 18, 1986.
313
314    * version 17.57 released on March 27, 1986.
315
316    * version 17.58 released on April 4, 1986.
317
318    * version 17.61 released on April 12, 1986.
319
320    * version 17.63 released on May 7, 1986.
321
322    * version 17.64 released on May 12, 1986.
323
324    * version 18.24 (a beta version) released on October 2, 1986.
325
326    * version 18.30 (a beta version) released on November 15, 1986.
327
328    * version 18.31 (a beta version) released on November 23, 1986.
329
330    * version 18.32 (a beta version) released on December 7, 1986.
331
332    * version 18.33 (a beta version) released on December 12, 1986.
333
334    * version 18.35 (a beta version) released on January 5, 1987.
335
336    * version 18.36 (a beta version) released on January 21, 1987.
337
338    * January 27, 1987: The Great Usenet Renaming.  net.emacs is now
339      comp.emacs.
340
341    * version 18.37 (a beta version) released on February 12, 1987.
342
343    * version 18.38 (a beta version) released on March 3, 1987.
344
345    * version 18.39 (a beta version) released on March 14, 1987.
346
347    * version 18.40 (a beta version) released on March 18, 1987.
348
349    * version 18.41 (the first "official" release) released on March 22,
350      1987.
351
352    * version 18.45 released on June 2, 1987.
353
354    * version 18.46 released on June 9, 1987.
355
356    * version 18.47 released on June 18, 1987.
357
358    * version 18.48 released on September 3, 1987.
359
360    * version 18.49 released on September 18, 1987.
361
362    * version 18.50 released on February 13, 1988.
363
364    * version 18.51 released on May 7, 1988.
365
366    * version 18.52 released on September 1, 1988.
367
368    * version 18.53 released on February 24, 1989.
369
370    * version 18.54 released on April 26, 1989.
371
372    * version 18.55 released on August 23, 1989.  This is the earliest
373      version that is still available by FTP.
374
375    * version 18.56 released on January 17, 1991.
376
377    * version 18.57 released late January, 1991.
378
379    * version 18.58 released ?????.
380
381    * version 18.59 released October 31, 1992.
382
383 \1f
384 File: internals.info,  Node: Lucid Emacs,  Next: GNU Emacs 19,  Prev: Through Version 18,  Up: A History of Emacs
385
386 Lucid Emacs
387 ===========
388
389    Lucid Emacs was developed by the (now-defunct) Lucid Inc., a maker of
390 C++ and Lisp development environments.  It began when Lucid decided they
391 wanted to use Emacs as the editor and cornerstone of their C++
392 development environment (called "Energize").  They needed many features
393 that were not available in the existing version of GNU Emacs (version
394 18.5something), in particular good and integrated support for GUI
395 elements such as mouse support, multiple fonts, multiple window-system
396 windows, etc.  A branch of GNU Emacs called Epoch, written at the
397 University of Illinois, existed that supplied many of these features;
398 however, Lucid needed more than what existed in Epoch.  At the time, the
399 Free Software Foundation was working on version 19 of Emacs (this was
400 sometime around 1991), which was planned to have similar features, and
401 so Lucid decided to work with the Free Software Foundation.  Their plan
402 was to add features that they needed, and coordinate with the FSF so
403 that the features would get included back into Emacs version 19.
404
405    Delays in the release of version 19 occurred, however (resulting in
406 it finally being released more than a year after what was initially
407 planned), and Lucid encountered unexpected technical resistance in
408 getting their changes merged back into version 19, so they decided to
409 release their own version of Emacs, which became Lucid Emacs 19.0.
410
411    The initial authors of Lucid Emacs were Matthieu Devin, Harlan
412 Sexton, and Eric Benson, and the work was later taken over by Jamie
413 Zawinski, who became "Mr. Lucid Emacs" for many releases.
414
415    A time line for Lucid Emacs/XEmacs is
416
417    * version 19.0 shipped with Energize 1.0, April 1992.
418
419    * version 19.1 released June 4, 1992.
420
421    * version 19.2 released June 19, 1992.
422
423    * version 19.3 released September 9, 1992.
424
425    * version 19.4 released January 21, 1993.
426
427    * version 19.5 was a repackaging of 19.4 with a few bug fixes and
428      shipped with Energize 2.0.  Never released to the net.
429
430    * version 19.6 released April 9, 1993.
431
432    * version 19.7 was a repackaging of 19.6 with a few bug fixes and
433      shipped with Energize 2.1.  Never released to the net.
434
435    * version 19.8 released September 6, 1993.
436
437    * version 19.9 released January 12, 1994.
438
439    * version 19.10 released May 27, 1994.
440
441    * version 19.11 (first XEmacs) released September 13, 1994.
442
443    * version 19.12 released June 23, 1995.
444
445    * version 19.13 released September 1, 1995.
446
447    * version 19.14 released June 23, 1996.
448
449    * version 20.0 released February 9, 1997.
450
451    * version 19.15 released March 28, 1997.
452
453    * version 20.1 (not released to the net) April 15, 1997.
454
455    * version 20.2 released May 16, 1997.
456
457    * version 19.16 released October 31, 1997.
458
459    * version 20.3 (the first stable version of XEmacs 20.x) released
460      November 30, 1997.  version 20.4 released February 28, 1998.
461
462 \1f
463 File: internals.info,  Node: GNU Emacs 19,  Next: GNU Emacs 20,  Prev: Lucid Emacs,  Up: A History of Emacs
464
465 GNU Emacs 19
466 ============
467
468    About a year after the initial release of Lucid Emacs, the FSF
469 released a beta of their version of Emacs 19 (referred to here as "GNU
470 Emacs").  By this time, the current version of Lucid Emacs was 19.6.
471 (Strangely, the first released beta from the FSF was GNU Emacs 19.7.) A
472 time line for GNU Emacs version 19 is
473
474    * version 19.8 (beta) released May 27, 1993.
475
476    * version 19.9 (beta) released May 27, 1993.
477
478    * version 19.10 (beta) released May 30, 1993.
479
480    * version 19.11 (beta) released June 1, 1993.
481
482    * version 19.12 (beta) released June 2, 1993.
483
484    * version 19.13 (beta) released June 8, 1993.
485
486    * version 19.14 (beta) released June 17, 1993.
487
488    * version 19.15 (beta) released June 19, 1993.
489
490    * version 19.16 (beta) released July 6, 1993.
491
492    * version 19.17 (beta) released late July, 1993.
493
494    * version 19.18 (beta) released August 9, 1993.
495
496    * version 19.19 (beta) released August 15, 1993.
497
498    * version 19.20 (beta) released November 17, 1993.
499
500    * version 19.21 (beta) released November 17, 1993.
501
502    * version 19.22 (beta) released November 28, 1993.
503
504    * version 19.23 (beta) released May 17, 1994.
505
506    * version 19.24 (beta) released May 16, 1994.
507
508    * version 19.25 (beta) released June 3, 1994.
509
510    * version 19.26 (beta) released September 11, 1994.
511
512    * version 19.27 (beta) released September 14, 1994.
513
514    * version 19.28 (first "official" release) released November 1, 1994.
515
516    * version 19.29 released June 21, 1995.
517
518    * version 19.30 released November 24, 1995.
519
520    * version 19.31 released May 25, 1996.
521
522    * version 19.32 released July 31, 1996.
523
524    * version 19.33 released August 11, 1996.
525
526    * version 19.34 released August 21, 1996.
527
528    * version 19.34b released September 6, 1996.
529
530    In some ways, GNU Emacs 19 was better than Lucid Emacs; in some ways,
531 worse.  Lucid soon began incorporating features from GNU Emacs 19 into
532 Lucid Emacs; the work was mostly done by Richard Mlynarik, who had been
533 working on and using GNU Emacs for a long time (back as far as version
534 16 or 17).
535
536 \1f
537 File: internals.info,  Node: GNU Emacs 20,  Next: XEmacs,  Prev: GNU Emacs 19,  Up: A History of Emacs
538
539 GNU Emacs 20
540 ============
541
542    On February 2, 1997 work began on GNU Emacs to integrate Mule.  The
543 first release was made in September of that year.
544
545    A timeline for Emacs 20 is
546
547    * version 20.1 released September 17, 1997.
548
549    * version 20.2 released September 20, 1997.
550
551    * version 20.3 released August 19, 1998.
552
553 \1f
554 File: internals.info,  Node: XEmacs,  Prev: GNU Emacs 20,  Up: A History of Emacs
555
556 XEmacs
557 ======
558
559    Around the time that Lucid was developing Energize, Sun Microsystems
560 was developing their own development environment (called "SPARCWorks")
561 and also decided to use Emacs.  They joined forces with the Epoch team
562 at the University of Illinois and later with Lucid.  The maintainer of
563 the last-released version of Epoch was Marc Andreessen, but he dropped
564 out and the Epoch project, headed by Simon Kaplan, lured Chuck Thompson
565 away from a system administration job to become the primary Lucid Emacs
566 author for Epoch and Sun.  Chuck's area of specialty became the
567 redisplay engine (he replaced the old Lucid Emacs redisplay engine with
568 a ported version from Epoch and then later rewrote it from scratch).
569 Sun also hired Ben Wing (the author of Win-Emacs, a port of Lucid Emacs
570 to Microsoft Windows 3.1) in 1993, for what was initially a one-month
571 contract to fix some event problems but later became a many-year
572 involvement, punctuated by a six-month contract with Amdahl Corporation.
573
574    In 1994, Sun and Lucid agreed to rename Lucid Emacs to XEmacs (a name
575 not favorable to either company); the first release called XEmacs was
576 version 19.11.  In June 1994, Lucid folded and Jamie quit to work for
577 the newly formed Mosaic Communications Corp., later Netscape
578 Communications Corp. (co-founded by the same Marc Andreessen, who had
579 quit his Epoch job to work on a graphical browser for the World Wide
580 Web).  Chuck then become the primary maintainer of XEmacs, and put out
581 versions 19.11 through 19.14 in conjunction with Ben.  For 19.12 and
582 19.13, Chuck added the new redisplay and many other display improvements
583 and Ben added MULE support (support for Asian and other languages) and
584 redesigned most of the internal Lisp subsystems to better support the
585 MULE work and the various other features being added to XEmacs.  After
586 19.14 Chuck retired as primary maintainer and Steve Baur stepped in.
587
588    Soon after 19.13 was released, work began in earnest on the MULE
589 internationalization code and the source tree was divided into two
590 development paths.  The MULE version was initially called 19.20, but was
591 soon renamed to 20.0.  In 1996 Martin Buchholz of Sun Microsystems took
592 over the care and feeding of it and worked on it in parallel with the
593 19.14 development that was occurring at the same time.  After much work
594 by Martin, it was decided to release 20.0 ahead of 19.15 in February
595 1997.  The source tree remained divided until 20.2 when the version 19
596 source was finally retired at version 19.16.
597
598    In 1997, Sun finally dropped all pretense of support for XEmacs and
599 Martin Buchholz left the company in November.  Since then, and mostly
600 for the previous year, because Steve Baur was never paid to work on
601 XEmacs, XEmacs has existed solely on the contributions of volunteers
602 from the Free Software Community.  Starting from 1997, Hrvoje Niksic and
603 Kyle Jones have figured prominently in XEmacs development.
604
605    Many attempts have been made to merge XEmacs and GNU Emacs, but they
606 have consistently failed.
607
608    A more detailed history is contained in the XEmacs About page.
609
610 \1f
611 File: internals.info,  Node: XEmacs From the Outside,  Next: The Lisp Language,  Prev: A History of Emacs,  Up: Top
612
613 XEmacs From the Outside
614 ***********************
615
616    XEmacs appears to the outside world as an editor, but it is really a
617 Lisp environment.  At its heart is a Lisp interpreter; it also
618 "happens" to contain many specialized object types (e.g. buffers,
619 windows, frames, events) that are useful for implementing an editor.
620 Some of these objects (in particular windows and frames) have
621 displayable representations, and XEmacs provides a function
622 `redisplay()' that ensures that the display of all such objects matches
623 their internal state.  Most of the time, a standard Lisp environment is
624 in a "read-eval-print" loop--i.e. "read some Lisp code, execute it, and
625 print the results".  XEmacs has a similar loop:
626
627    * read an event
628
629    * dispatch the event (i.e. "do it")
630
631    * redisplay
632
633    Reading an event is done using the Lisp function `next-event', which
634 waits for something to happen (typically, the user presses a key or
635 moves the mouse) and returns an event object describing this.
636 Dispatching an event is done using the Lisp function `dispatch-event',
637 which looks up the event in a keymap object (a particular kind of
638 object that associates an event with a Lisp function) and calls that
639 function.  The function "does" what the user has requested by changing
640 the state of particular frame objects, buffer objects, etc.  Finally,
641 `redisplay()' is called, which updates the display to reflect those
642 changes just made.  Thus is an "editor" born.
643
644    Note that you do not have to use XEmacs as an editor; you could just
645 as well make it do your taxes, compute pi, play bridge, etc.  You'd just
646 have to write functions to do those operations in Lisp.
647
648 \1f
649 File: internals.info,  Node: The Lisp Language,  Next: XEmacs From the Perspective of Building,  Prev: XEmacs From the Outside,  Up: Top
650
651 The Lisp Language
652 *****************
653
654    Lisp is a general-purpose language that is higher-level than C and in
655 many ways more powerful than C.  Powerful dialects of Lisp such as
656 Common Lisp are probably much better languages for writing very large
657 applications than is C. (Unfortunately, for many non-technical reasons
658 C and its successor C++ have become the dominant languages for
659 application development.  These languages are both inadequate for
660 extremely large applications, which is evidenced by the fact that newer,
661 larger programs are becoming ever harder to write and are requiring ever
662 more programmers despite great increases in C development environments;
663 and by the fact that, although hardware speeds and reliability have been
664 growing at an exponential rate, most software is still generally
665 considered to be slow and buggy.)
666
667    The new Java language holds promise as a better general-purpose
668 development language than C.  Java has many features in common with
669 Lisp that are not shared by C (this is not a coincidence, since Java
670 was designed by James Gosling, a former Lisp hacker).  This will be
671 discussed more later.
672
673    For those used to C, here is a summary of the basic differences
674 between C and Lisp:
675
676   1. Lisp has an extremely regular syntax.  Every function, expression,
677      and control statement is written in the form
678
679              (FUNC ARG1 ARG2 ...)
680
681      This is as opposed to C, which writes functions as
682
683              func(ARG1, ARG2, ...)
684
685      but writes expressions involving operators as (e.g.)
686
687              ARG1 + ARG2
688
689      and writes control statements as (e.g.)
690
691              while (EXPR) { STATEMENT1; STATEMENT2; ... }
692
693      Lisp equivalents of the latter two would be
694
695              (+ ARG1 ARG2 ...)
696
697      and
698
699              (while EXPR STATEMENT1 STATEMENT2 ...)
700
701   2. Lisp is a safe language.  Assuming there are no bugs in the Lisp
702      interpreter/compiler, it is impossible to write a program that
703      "core dumps" or otherwise causes the machine to execute an illegal
704      instruction.  This is very different from C, where perhaps the most
705      common outcome of a bug is exactly such a crash.  A corollary of
706      this is that the C operation of casting a pointer is impossible
707      (and unnecessary) in Lisp, and that it is impossible to access
708      memory outside the bounds of an array.
709
710   3. Programs and data are written in the same form.  The
711      parenthesis-enclosing form described above for statements is the
712      same form used for the most common data type in Lisp, the list.
713      Thus, it is possible to represent any Lisp program using Lisp data
714      types, and for one program to construct Lisp statements and then
715      dynamically "evaluate" them, or cause them to execute.
716
717   4. All objects are "dynamically typed".  This means that part of every
718      object is an indication of what type it is.  A Lisp program can
719      manipulate an object without knowing what type it is, and can
720      query an object to determine its type.  This means that,
721      correspondingly, variables and function parameters can hold
722      objects of any type and are not normally declared as being of any
723      particular type.  This is opposed to the "static typing" of C,
724      where variables can hold exactly one type of object and must be
725      declared as such, and objects do not contain an indication of
726      their type because it's implicit in the variables they are stored
727      in.  It is possible in C to have a variable hold different types
728      of objects (e.g. through the use of `void *' pointers or
729      variable-argument functions), but the type information must then be
730      passed explicitly in some other fashion, leading to additional
731      program complexity.
732
733   5. Allocated memory is automatically reclaimed when it is no longer
734      in use.  This operation is called "garbage collection" and
735      involves looking through all variables to see what memory is being
736      pointed to, and reclaiming any memory that is not pointed to and
737      is thus "inaccessible" and out of use.  This is as opposed to C,
738      in which allocated memory must be explicitly reclaimed using
739      `free()'.  If you simply drop all pointers to memory without
740      freeing it, it becomes "leaked" memory that still takes up space.
741      Over a long period of time, this can cause your program to grow
742      and grow until it runs out of memory.
743
744   6. Lisp has built-in facilities for handling errors and exceptions.
745      In C, when an error occurs, usually either the program exits
746      entirely or the routine in which the error occurs returns a value
747      indicating this.  If an error occurs in a deeply-nested routine,
748      then every routine currently called must unwind itself normally
749      and return an error value back up to the next routine.  This means
750      that every routine must explicitly check for an error in all the
751      routines it calls; if it does not do so, unexpected and often
752      random behavior results.  This is an extremely common source of
753      bugs in C programs.  An alternative would be to do a non-local
754      exit using `longjmp()', but that is often very dangerous because
755      the routines that were exited past had no opportunity to clean up
756      after themselves and may leave things in an inconsistent state,
757      causing a crash shortly afterwards.
758
759      Lisp provides mechanisms to make such non-local exits safe.  When
760      an error occurs, a routine simply signals that an error of a
761      particular class has occurred, and a non-local exit takes place.
762      Any routine can trap errors occurring in routines it calls by
763      registering an error handler for some or all classes of errors.
764      (If no handler is registered, a default handler, generally
765      installed by the top-level event loop, is executed; this prints
766      out the error and continues.) Routines can also specify cleanup
767      code (called an "unwind-protect") that will be called when control
768      exits from a block of code, no matter how that exit occurs--i.e.
769      even if a function deeply nested below it causes a non-local exit
770      back to the top level.
771
772      Note that this facility has appeared in some recent vintages of C,
773      in particular Visual C++ and other PC compilers written for the
774      Microsoft Win32 API.
775
776   7. In Emacs Lisp, local variables are "dynamically scoped".  This
777      means that if you declare a local variable in a particular
778      function, and then call another function, that subfunction can
779      "see" the local variable you declared.  This is actually
780      considered a bug in Emacs Lisp and in all other early dialects of
781      Lisp, and was corrected in Common Lisp. (In Common Lisp, you can
782      still declare dynamically scoped variables if you want to--they
783      are sometimes useful--but variables by default are "lexically
784      scoped" as in C.)
785
786    For those familiar with Lisp, Emacs Lisp is modelled after MacLisp,
787 an early dialect of Lisp developed at MIT (no relation to the Macintosh
788 computer).  There is a Common Lisp compatibility package available for
789 Emacs that provides many of the features of Common Lisp.
790
791    The Java language is derived in many ways from C, and shares a
792 similar syntax, but has the following features in common with Lisp (and
793 different from C):
794
795   1. Java is a safe language, like Lisp.
796
797   2. Java provides garbage collection, like Lisp.
798
799   3. Java has built-in facilities for handling errors and exceptions,
800      like Lisp.
801
802   4. Java has a type system that combines the best advantages of both
803      static and dynamic typing.  Objects (except very simple types) are
804      explicitly marked with their type, as in dynamic typing; but there
805      is a hierarchy of types and functions are declared to accept only
806      certain types, thus providing the increased compile-time
807      error-checking of static typing.
808
809    The Java language also has some negative attributes:
810
811   1. Java uses the edit/compile/run model of software development.  This
812      makes it hard to use interactively.  For example, to use Java like
813      `bc' it is necessary to write a special purpose, albeit tiny,
814      application.  In Emacs Lisp, a calculator comes built-in without
815      any effort - one can always just type an expression in the
816      `*scratch*' buffer.
817
818   2. Java tries too hard to enforce, not merely enable, portability,
819      making ordinary access to standard OS facilities painful.  Java
820      has an "agenda".  I think this is why `chdir' is not part of
821      standard Java, which is inexcusable.
822
823    Unfortunately, there is no perfect language.  Static typing allows a
824 compiler to catch programmer errors and produce more efficient code, but
825 makes programming more tedious and less fun.  For the forseeable future,
826 an Ideal Editing and Programming Environment (and that is what XEmacs
827 aspires to) will be programmable in multiple languages: high level ones
828 like Lisp for user customization and prototyping, and lower level ones
829 for infrastructure and industrial strength applications.  If I had my
830 way, XEmacs would be friendly towards the Python, Scheme, C++, ML,
831 etc... communities.  But there are serious technical difficulties to
832 achieving that goal.
833
834    The word "application" in the previous paragraph was used
835 intentionally.  XEmacs implements an API for programs written in Lisp
836 that makes it a full-fledged application platform, very much like an OS
837 inside the real OS.
838
839 \1f
840 File: internals.info,  Node: XEmacs From the Perspective of Building,  Next: XEmacs From the Inside,  Prev: The Lisp Language,  Up: Top
841
842 XEmacs From the Perspective of Building
843 ***************************************
844
845    The heart of XEmacs is the Lisp environment, which is written in C.
846 This is contained in the `src/' subdirectory.  Underneath `src/' are
847 two subdirectories of header files: `s/' (header files for particular
848 operating systems) and `m/' (header files for particular machine
849 types).  In practice the distinction between the two types of header
850 files is blurred.  These header files define or undefine certain
851 preprocessor constants and macros to indicate particular
852 characteristics of the associated machine or operating system.  As part
853 of the configure process, one `s/' file and one `m/' file is identified
854 for the particular environment in which XEmacs is being built.
855
856    XEmacs also contains a great deal of Lisp code.  This implements the
857 operations that make XEmacs useful as an editor as well as just a Lisp
858 environment, and also contains many add-on packages that allow XEmacs to
859 browse directories, act as a mail and Usenet news reader, compile Lisp
860 code, etc.  There is actually more Lisp code than C code associated with
861 XEmacs, but much of the Lisp code is peripheral to the actual operation
862 of the editor.  The Lisp code all lies in subdirectories underneath the
863 `lisp/' directory.
864
865    The `lwlib/' directory contains C code that implements a generalized
866 interface onto different X widget toolkits and also implements some
867 widgets of its own that behave like Motif widgets but are faster, free,
868 and in some cases more powerful.  The code in this directory compiles
869 into a library and is mostly independent from XEmacs.
870
871    The `etc/' directory contains various data files associated with
872 XEmacs.  Some of them are actually read by XEmacs at startup; others
873 merely contain useful information of various sorts.
874
875    The `lib-src/' directory contains C code for various auxiliary
876 programs that are used in connection with XEmacs.  Some of them are used
877 during the build process; others are used to perform certain functions
878 that cannot conveniently be placed in the XEmacs executable (e.g. the
879 `movemail' program for fetching mail out of `/var/spool/mail', which
880 must be setgid to `mail' on many systems; and the `gnuclient' program,
881 which allows an external script to communicate with a running XEmacs
882 process).
883
884    The `man/' directory contains the sources for the XEmacs
885 documentation.  It is mostly in a form called Texinfo, which can be
886 converted into either a printed document (by passing it through TeX) or
887 into on-line documentation called "info files".
888
889    The `info/' directory contains the results of formatting the XEmacs
890 documentation as "info files", for on-line use.  These files are used
891 when you enter the Info system using `C-h i' or through the Help menu.
892
893    The `dynodump/' directory contains auxiliary code used to build
894 XEmacs on Solaris platforms.
895
896    The other directories contain various miscellaneous code and
897 information that is not normally used or needed.
898
899    The first step of building involves running the `configure' program
900 and passing it various parameters to specify any optional features you
901 want and compiler arguments and such, as described in the `INSTALL'
902 file.  This determines what the build environment is, chooses the
903 appropriate `s/' and `m/' file, and runs a series of tests to determine
904 many details about your environment, such as which library functions
905 are available and exactly how they work.  The reason for running these
906 tests is that it allows XEmacs to be compiled on a much wider variety
907 of platforms than those that the XEmacs developers happen to be
908 familiar with, including various sorts of hybrid platforms.  This is
909 especially important now that many operating systems give you a great
910 deal of control over exactly what features you want installed, and allow
911 for easy upgrading of parts of a system without upgrading the rest.  It
912 would be impossible to pre-determine and pre-specify the information for
913 all possible configurations.
914
915    In fact, the `s/' and `m/' files are basically _evil_, since they
916 contain unmaintainable platform-specific hard-coded information.
917 XEmacs has been moving in the direction of having all system-specific
918 information be determined dynamically by `configure'.  Perhaps someday
919 we can `rm -rf src/s src/m'.
920
921    When configure is done running, it generates `Makefile's and
922 `GNUmakefile's and the file `src/config.h' (which describes the
923 features of your system) from template files.  You then run `make',
924 which compiles the auxiliary code and programs in `lib-src/' and
925 `lwlib/' and the main XEmacs executable in `src/'.  The result of
926 compiling and linking is an executable called `temacs', which is _not_
927 the final XEmacs executable.  `temacs' by itself is not intended to
928 function as an editor or even display any windows on the screen, and if
929 you simply run it, it will exit immediately.  The `Makefile' runs
930 `temacs' with certain options that cause it to initialize itself, read
931 in a number of basic Lisp files, and then dump itself out into a new
932 executable called `xemacs'.  This new executable has been
933 pre-initialized and contains pre-digested Lisp code that is necessary
934 for the editor to function (this includes most basic editing functions,
935 e.g. `kill-line', that can be defined in terms of other Lisp
936 primitives; some initialization code that is called when certain
937 objects, such as frames, are created; and all of the standard
938 keybindings and code for the actions they result in).  This executable,
939 `xemacs', is the executable that you run to use the XEmacs editor.
940
941    Although `temacs' is not intended to be run as an editor, it can, by
942 using the incantation `temacs -batch -l loadup.el run-temacs'.  This is
943 useful when the dumping procedure described above is broken, or when
944 using certain program debugging tools such as Purify.  These tools get
945 mighty confused by the tricks played by the XEmacs build process, such
946 as allocation memory in one process, and freeing it in the next.
947
948 \1f
949 File: internals.info,  Node: XEmacs From the Inside,  Next: The XEmacs Object System (Abstractly Speaking),  Prev: XEmacs From the Perspective of Building,  Up: Top
950
951 XEmacs From the Inside
952 **********************
953
954    Internally, XEmacs is quite complex, and can be very confusing.  To
955 simplify things, it can be useful to think of XEmacs as containing an
956 event loop that "drives" everything, and a number of other subsystems,
957 such as a Lisp engine and a redisplay mechanism.  Each of these other
958 subsystems exists simultaneously in XEmacs, and each has a certain
959 state.  The flow of control continually passes in and out of these
960 different subsystems in the course of normal operation of the editor.
961
962    It is important to keep in mind that, most of the time, the editor is
963 "driven" by the event loop.  Except during initialization and batch
964 mode, all subsystems are entered directly or indirectly through the
965 event loop, and ultimately, control exits out of all subsystems back up
966 to the event loop.  This cycle of entering a subsystem, exiting back out
967 to the event loop, and starting another iteration of the event loop
968 occurs once each keystroke, mouse motion, etc.
969
970    If you're trying to understand a particular subsystem (other than the
971 event loop), think of it as a "daemon" process or "servant" that is
972 responsible for one particular aspect of a larger system, and
973 periodically receives commands or environment changes that cause it to
974 do something.  Ultimately, these commands and environment changes are
975 always triggered by the event loop.  For example:
976
977    * The window and frame mechanism is responsible for keeping track of
978      what windows and frames exist, what buffers are in them, etc.  It
979      is periodically given commands (usually from the user) to make a
980      change to the current window/frame state: i.e. create a new frame,
981      delete a window, etc.
982
983    * The buffer mechanism is responsible for keeping track of what
984      buffers exist and what text is in them.  It is periodically given
985      commands (usually from the user) to insert or delete text, create
986      a buffer, etc.  When it receives a text-change command, it
987      notifies the redisplay mechanism.
988
989    * The redisplay mechanism is responsible for making sure that
990      windows and frames are displayed correctly.  It is periodically
991      told (by the event loop) to actually "do its job", i.e. snoop
992      around and see what the current state of the environment (mostly
993      of the currently-existing windows, frames, and buffers) is, and
994      make sure that that state matches what's actually displayed.  It
995      keeps lots and lots of information around (such as what is
996      actually being displayed currently, and what the environment was
997      last time it checked) so that it can minimize the work it has to
998      do.  It is also helped along in that whenever a relevant change to
999      the environment occurs, the redisplay mechanism is told about
1000      this, so it has a pretty good idea of where it has to look to find
1001      possible changes and doesn't have to look everywhere.
1002
1003    * The Lisp engine is responsible for executing the Lisp code in
1004      which most user commands are written.  It is entered through a
1005      call to `eval' or `funcall', which occurs as a result of
1006      dispatching an event from the event loop.  The functions it calls
1007      issue commands to the buffer mechanism, the window/frame
1008      subsystem, etc.
1009
1010    * The Lisp allocation subsystem is responsible for keeping track of
1011      Lisp objects.  It is given commands from the Lisp engine to
1012      allocate objects, garbage collect, etc.
1013
1014    etc.
1015
1016    The important idea here is that there are a number of independent
1017 subsystems each with its own responsibility and persistent state, just
1018 like different employees in a company, and each subsystem is
1019 periodically given commands from other subsystems.  Commands can flow
1020 from any one subsystem to any other, but there is usually some sort of
1021 hierarchy, with all commands originating from the event subsystem.
1022
1023    XEmacs is entered in `main()', which is in `emacs.c'.  When this is
1024 called the first time (in a properly-invoked `temacs'), it does the
1025 following:
1026
1027   1. It does some very basic environment initializations, such as
1028      determining where it and its directories (e.g. `lisp/' and `etc/')
1029      reside and setting up signal handlers.
1030
1031   2. It initializes the entire Lisp interpreter.
1032
1033   3. It sets the initial values of many built-in variables (including
1034      many variables that are visible to Lisp programs), such as the
1035      global keymap object and the built-in faces (a face is an object
1036      that describes the display characteristics of text).  This
1037      involves creating Lisp objects and thus is dependent on step (2).
1038
1039   4. It performs various other initializations that are relevant to the
1040      particular environment it is running in, such as retrieving
1041      environment variables, determining the current date and the user
1042      who is running the program, examining its standard input, creating
1043      any necessary file descriptors, etc.
1044
1045   5. At this point, the C initialization is complete.  A Lisp program
1046      that was specified on the command line (usually `loadup.el') is
1047      called (temacs is normally invoked as `temacs -batch -l loadup.el
1048      dump').  `loadup.el' loads all of the other Lisp files that are
1049      needed for the operation of the editor, calls the `dump-emacs'
1050      function to write out `xemacs', and then kills the temacs process.
1051
1052    When `xemacs' is then run, it only redoes steps (1) and (4) above;
1053 all variables already contain the values they were set to when the
1054 executable was dumped, and all memory that was allocated with
1055 `malloc()' is still around. (XEmacs knows whether it is being run as
1056 `xemacs' or `temacs' because it sets the global variable `initialized'
1057 to 1 after step (4) above.) At this point, `xemacs' calls a Lisp
1058 function to do any further initialization, which includes parsing the
1059 command-line (the C code can only do limited command-line parsing,
1060 which includes looking for the `-batch' and `-l' flags and a few other
1061 flags that it needs to know about before initialization is complete),
1062 creating the first frame (or "window" in standard window-system
1063 parlance), running the user's init file (usually the file `.emacs' in
1064 the user's home directory), etc.  The function to do this is usually
1065 called `normal-top-level'; `loadup.el' tells the C code about this
1066 function by setting its name as the value of the Lisp variable
1067 `top-level'.
1068
1069    When the Lisp initialization code is done, the C code enters the
1070 event loop, and stays there for the duration of the XEmacs process.
1071 The code for the event loop is contained in `keyboard.c', and is called
1072 `Fcommand_loop_1()'.  Note that this event loop could very well be
1073 written in Lisp, and in fact a Lisp version exists; but apparently,
1074 doing this makes XEmacs run noticeably slower.
1075
1076    Notice how much of the initialization is done in Lisp, not in C.  In
1077 general, XEmacs tries to move as much code as is possible into Lisp.
1078 Code that remains in C is code that implements the Lisp interpreter
1079 itself, or code that needs to be very fast, or code that needs to do
1080 system calls or other such stuff that needs to be done in C, or code
1081 that needs to have access to "forbidden" structures. (One conscious
1082 aspect of the design of Lisp under XEmacs is a clean separation between
1083 the external interface to a Lisp object's functionality and its internal
1084 implementation.  Part of this design is that Lisp programs are
1085 forbidden from accessing the contents of the object other than through
1086 using a standard API.  In this respect, XEmacs Lisp is similar to
1087 modern Lisp dialects but differs from GNU Emacs, which tends to expose
1088 the implementation and allow Lisp programs to look at it directly.  The
1089 major advantage of hiding the implementation is that it allows the
1090 implementation to be redesigned without affecting any Lisp programs,
1091 including those that might want to be "clever" by looking directly at
1092 the object's contents and possibly manipulating them.)
1093
1094    Moving code into Lisp makes the code easier to debug and maintain and
1095 makes it much easier for people who are not XEmacs developers to
1096 customize XEmacs, because they can make a change with much less chance
1097 of obscure and unwanted interactions occurring than if they were to
1098 change the C code.
1099