This commit was manufactured by cvs2svn to create branch 'utf-2000'.
[chise/xemacs-chise.git-] / info / internals.info-3
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: Working With Character and Byte Positions,  Next: Conversion to and from External Data,  Prev: Character-Related Data Types,  Up: Coding for Mule
42
43 Working With Character and Byte Positions
44 -----------------------------------------
45
46    Now that we have defined the basic character-related types, we can
47 look at the macros and functions designed for work with them and for
48 conversion between them.  Most of these macros are defined in
49 `buffer.h', and we don't discuss all of them here, but only the most
50 important ones.  Examining the existing code is the best way to learn
51 about them.
52
53 `MAX_EMCHAR_LEN'
54      This preprocessor constant is the maximum number of buffer bytes to
55      represent an Emacs character in the variable width internal
56      encoding.  It is useful when allocating temporary strings to keep
57      a known number of characters.  For instance:
58
59           {
60             Charcount cclen;
61             ...
62             {
63               /* Allocate place for CCLEN characters. */
64               Bufbyte *buf = (Bufbyte *)alloca (cclen * MAX_EMCHAR_LEN);
65           ...
66
67      If you followed the previous section, you can guess that,
68      logically, multiplying a `Charcount' value with `MAX_EMCHAR_LEN'
69      produces a `Bytecount' value.
70
71      In the current Mule implementation, `MAX_EMCHAR_LEN' equals 4.
72      Without Mule, it is 1.
73
74 `charptr_emchar'
75 `set_charptr_emchar'
76      The `charptr_emchar' macro takes a `Bufbyte' pointer and returns
77      the `Emchar' stored at that position.  If it were a function, its
78      prototype would be:
79
80           Emchar charptr_emchar (Bufbyte *p);
81
82      `set_charptr_emchar' stores an `Emchar' to the specified byte
83      position.  It returns the number of bytes stored:
84
85           Bytecount set_charptr_emchar (Bufbyte *p, Emchar c);
86
87      It is important to note that `set_charptr_emchar' is safe only for
88      appending a character at the end of a buffer, not for overwriting a
89      character in the middle.  This is because the width of characters
90      varies, and `set_charptr_emchar' cannot resize the string if it
91      writes, say, a two-byte character where a single-byte character
92      used to reside.
93
94      A typical use of `set_charptr_emchar' can be demonstrated by this
95      example, which copies characters from buffer BUF to a temporary
96      string of Bufbytes.
97
98           {
99             Bufpos pos;
100             for (pos = beg; pos < end; pos++)
101               {
102                 Emchar c = BUF_FETCH_CHAR (buf, pos);
103                 p += set_charptr_emchar (buf, c);
104               }
105           }
106
107      Note how `set_charptr_emchar' is used to store the `Emchar' and
108      increment the counter, at the same time.
109
110 `INC_CHARPTR'
111 `DEC_CHARPTR'
112      These two macros increment and decrement a `Bufbyte' pointer,
113      respectively.  They will adjust the pointer by the appropriate
114      number of bytes according to the byte length of the character
115      stored there.  Both macros assume that the memory address is
116      located at the beginning of a valid character.
117
118      Without Mule support, `INC_CHARPTR (p)' and `DEC_CHARPTR (p)'
119      simply expand to `p++' and `p--', respectively.
120
121 `bytecount_to_charcount'
122      Given a pointer to a text string and a length in bytes, return the
123      equivalent length in characters.
124
125           Charcount bytecount_to_charcount (Bufbyte *p, Bytecount bc);
126
127 `charcount_to_bytecount'
128      Given a pointer to a text string and a length in characters,
129      return the equivalent length in bytes.
130
131           Bytecount charcount_to_bytecount (Bufbyte *p, Charcount cc);
132
133 `charptr_n_addr'
134      Return a pointer to the beginning of the character offset CC (in
135      characters) from P.
136
137           Bufbyte *charptr_n_addr (Bufbyte *p, Charcount cc);
138
139 \1f
140 File: internals.info,  Node: Conversion to and from External Data,  Next: General Guidelines for Writing Mule-Aware Code,  Prev: Working With Character and Byte Positions,  Up: Coding for Mule
141
142 Conversion to and from External Data
143 ------------------------------------
144
145    When an external function, such as a C library function, returns a
146 `char' pointer, you should almost never treat it as `Bufbyte'.  This is
147 because these returned strings may contain 8bit characters which can be
148 misinterpreted by XEmacs, and cause a crash.  Likewise, when exporting
149 a piece of internal text to the outside world, you should always
150 convert it to an appropriate external encoding, lest the internal stuff
151 (such as the infamous \201 characters) leak out.
152
153    The interface to conversion between the internal and external
154 representations of text are the numerous conversion macros defined in
155 `buffer.h'.  There used to be a fixed set of external formats supported
156 by these macros, but now any coding system can be used with these
157 macros.  The coding system alias mechanism is used to create the
158 following logical coding systems, which replace the fixed external
159 formats.  The (dontusethis-set-symbol-value-handler) mechanism was
160 enhanced to make this possible (more work on that is needed - like
161 remove the `dontusethis-' prefix).
162
163 `Qbinary'
164      This is the simplest format and is what we use in the absence of a
165      more appropriate format.  This converts according to the `binary'
166      coding system:
167
168        a. On input, bytes 0-255 are converted into (implicitly Latin-1)
169           characters 0-255.  A non-Mule xemacs doesn't really know about
170           different character sets and the fonts to display them, so
171           the bytes can be treated as text in different 1-byte
172           encodings by simply setting the appropriate fonts.  So in a
173           sense, non-Mule xemacs is a multi-lingual editor if, for
174           example, different fonts are used to display text in
175           different buffers, faces, or windows.  The specifier
176           mechanism gives the user complete control over this kind of
177           behavior.
178
179        b. On output, characters 0-255 are converted into bytes 0-255
180           and other characters are converted into `~'.
181
182 `Qfile_name'
183      Format used for filenames.  This is user-definable via either the
184      `file-name-coding-system' or `pathname-coding-system' (now
185      obsolete) variables.
186
187 `Qnative'
188      Format used for the external Unix environment--`argv[]', stuff
189      from `getenv()', stuff from the `/etc/passwd' file, etc.
190      Currently this is the same as Qfile_name.  The two should be
191      distinguished for clarity and possible future separation.
192
193 `Qctext'
194      Compound-text format.  This is the standard X11 format used for
195      data stored in properties, selections, and the like.  This is an
196      8-bit no-lock-shift ISO2022 coding system.  This is a real coding
197      system, unlike Qfile_name, which is user-definable.
198
199    There are two fundamental macros to convert between external and
200 internal format.
201
202    `TO_INTERNAL_FORMAT' converts external data to internal format, and
203 `TO_EXTERNAL_FORMAT' converts the other way around.  The arguments each
204 of these receives are a source type, a source, a sink type, a sink, and
205 a coding system (or a symbol naming a coding system).
206
207    A typical call looks like
208      TO_EXTERNAL_FORMAT (LISP_STRING, str, C_STRING_MALLOC, ptr, Qfile_name);
209
210    which means that the contents of the lisp string `str' are written
211 to a malloc'ed memory area which will be pointed to by `ptr', after the
212 function returns.  The conversion will be done using the `file-name'
213 coding system, which will be controlled by the user indirectly by
214 setting or binding the variable `file-name-coding-system'.
215
216    Some sources and sinks require two C variables to specify.  We use
217 some preprocessor magic to allow different source and sink types, and
218 even different numbers of arguments to specify different types of
219 sources and sinks.
220
221    So we can have a call that looks like
222      TO_INTERNAL_FORMAT (DATA, (ptr, len),
223                          MALLOC, (ptr, len),
224                          coding_system);
225
226    The parenthesized argument pairs are required to make the
227 preprocessor magic work.
228
229    Here are the different source and sink types:
230
231 ``DATA, (ptr, len),''
232      input data is a fixed buffer of size LEN at address PTR
233
234 ``ALLOCA, (ptr, len),''
235      output data is placed in an alloca()ed buffer of size LEN pointed
236      to by PTR
237
238 ``MALLOC, (ptr, len),''
239      output data is in a malloc()ed buffer of size LEN pointed to by PTR
240
241 ``C_STRING_ALLOCA, ptr,''
242      equivalent to `ALLOCA (ptr, len_ignored)' on output.
243
244 ``C_STRING_MALLOC, ptr,''
245      equivalent to `MALLOC (ptr, len_ignored)' on output
246
247 ``C_STRING, ptr,''
248      equivalent to `DATA, (ptr, strlen (ptr) + 1)' on input
249
250 ``LISP_STRING, string,''
251      input or output is a Lisp_Object of type string
252
253 ``LISP_BUFFER, buffer,''
254      output is written to `(point)' in lisp buffer BUFFER
255
256 ``LISP_LSTREAM, lstream,''
257      input or output is a Lisp_Object of type lstream
258
259 ``LISP_OPAQUE, object,''
260      input or output is a Lisp_Object of type opaque
261
262    Often, the data is being converted to a '\0'-byte-terminated string,
263 which is the format required by many external system C APIs.  For these
264 purposes, a source type of `C_STRING' or a sink type of
265 `C_STRING_ALLOCA' or `C_STRING_MALLOC' is appropriate.  Otherwise, we
266 should try to keep XEmacs '\0'-byte-clean, which means using (ptr, len)
267 pairs.
268
269    The sinks to be specified must be lvalues, unless they are the lisp
270 object types `LISP_LSTREAM' or `LISP_BUFFER'.
271
272    For the sink types `ALLOCA' and `C_STRING_ALLOCA', the resulting
273 text is stored in a stack-allocated buffer, which is automatically
274 freed on returning from the function.  However, the sink types `MALLOC'
275 and `C_STRING_MALLOC' return `xmalloc()'ed memory.  The caller is
276 responsible for freeing this memory using `xfree()'.
277
278    Note that it doesn't make sense for `LISP_STRING' to be a source for
279 `TO_INTERNAL_FORMAT' or a sink for `TO_EXTERNAL_FORMAT'.  You'll get an
280 assertion failure if you try.
281
282 \1f
283 File: internals.info,  Node: General Guidelines for Writing Mule-Aware Code,  Next: An Example of Mule-Aware Code,  Prev: Conversion to and from External Data,  Up: Coding for Mule
284
285 General Guidelines for Writing Mule-Aware Code
286 ----------------------------------------------
287
288    This section contains some general guidance on how to write
289 Mule-aware code, as well as some pitfalls you should avoid.
290
291 _Never use `char' and `char *'._
292      In XEmacs, the use of `char' and `char *' is almost always a
293      mistake.  If you want to manipulate an Emacs character from "C",
294      use `Emchar'.  If you want to examine a specific octet in the
295      internal format, use `Bufbyte'.  If you want a Lisp-visible
296      character, use a `Lisp_Object' and `make_char'.  If you want a
297      pointer to move through the internal text, use `Bufbyte *'.  Also
298      note that you almost certainly do not need `Emchar *'.
299
300 _Be careful not to confuse `Charcount', `Bytecount', and `Bufpos'._
301      The whole point of using different types is to avoid confusion
302      about the use of certain variables.  Lest this effect be
303      nullified, you need to be careful about using the right types.
304
305 _Always convert external data_
306      It is extremely important to always convert external data, because
307      XEmacs can crash if unexpected 8bit sequences are copied to its
308      internal buffers literally.
309
310      This means that when a system function, such as `readdir', returns
311      a string, you may need to convert it using one of the conversion
312      macros described in the previous chapter, before passing it
313      further to Lisp.
314
315      Actually, most of the basic system functions that accept
316      '\0'-terminated string arguments, like `stat()' and `open()', have
317      been *encapsulated* so that they are they `always' do internal to
318      external conversion themselves.  This means you must pass
319      internally encoded data, typically the `XSTRING_DATA' of a
320      Lisp_String to these functions.  This is actually a design bug,
321      since it unexpectedly changes the semantics of the system
322      functions.  A better design would be to provide separate versions
323      of these system functions that accepted Lisp_Objects which were
324      lisp strings in place of their current `char *' arguments.
325
326           int stat_lisp (Lisp_Object path, struct stat *buf); /* Implement me */
327
328      Also note that many internal functions, such as `make_string',
329      accept Bufbytes, which removes the need for them to convert the
330      data they receive.  This increases efficiency because that way
331      external data needs to be decoded only once, when it is read.
332      After that, it is passed around in internal format.
333
334 \1f
335 File: internals.info,  Node: An Example of Mule-Aware Code,  Prev: General Guidelines for Writing Mule-Aware Code,  Up: Coding for Mule
336
337 An Example of Mule-Aware Code
338 -----------------------------
339
340    As an example of Mule-aware code, we will analyze the `string'
341 function, which conses up a Lisp string from the character arguments it
342 receives.  Here is the definition, pasted from `alloc.c':
343
344      DEFUN ("string", Fstring, 0, MANY, 0, /*
345      Concatenate all the argument characters and make the result a string.
346      */
347             (int nargs, Lisp_Object *args))
348      {
349        Bufbyte *storage = alloca_array (Bufbyte, nargs * MAX_EMCHAR_LEN);
350        Bufbyte *p = storage;
351      
352        for (; nargs; nargs--, args++)
353          {
354            Lisp_Object lisp_char = *args;
355            CHECK_CHAR_COERCE_INT (lisp_char);
356            p += set_charptr_emchar (p, XCHAR (lisp_char));
357          }
358        return make_string (storage, p - storage);
359      }
360
361    Now we can analyze the source line by line.
362
363    Obviously, string will be as long as there are arguments to the
364 function.  This is why we allocate `MAX_EMCHAR_LEN' * NARGS bytes on
365 the stack, i.e. the worst-case number of bytes for NARGS `Emchar's to
366 fit in the string.
367
368    Then, the loop checks that each element is a character, converting
369 integers in the process.  Like many other functions in XEmacs, this
370 function silently accepts integers where characters are expected, for
371 historical and compatibility reasons.  Unless you know what you are
372 doing, `CHECK_CHAR' will also suffice.  `XCHAR (lisp_char)' extracts
373 the `Emchar' from the `Lisp_Object', and `set_charptr_emchar' stores it
374 to storage, increasing `p' in the process.
375
376    Other instructive examples of correct coding under Mule can be found
377 all over the XEmacs code.  For starters, I recommend
378 `Fnormalize_menu_item_name' in `menubar.c'.  After you have understood
379 this section of the manual and studied the examples, you can proceed
380 writing new Mule-aware code.
381
382 \1f
383 File: internals.info,  Node: Techniques for XEmacs Developers,  Prev: Coding for Mule,  Up: Rules When Writing New C Code
384
385 Techniques for XEmacs Developers
386 ================================
387
388    To make a purified XEmacs, do: `make puremacs'.  To make a
389 quantified XEmacs, do: `make quantmacs'.
390
391    You simply can't dump Quantified and Purified images (unless using
392 the portable dumper).  Purify gets confused when xemacs frees memory in
393 one process that was allocated in a _different_ process on a different
394 machine!.  Run it like so:
395      temacs -batch -l loadup.el run-temacs XEMACS-ARGS...
396
397    Before you go through the trouble, are you compiling with all
398 debugging and error-checking off?  If not, try that first.  Be warned
399 that while Quantify is directly responsible for quite a few
400 optimizations which have been made to XEmacs, doing a run which
401 generates results which can be acted upon is not necessarily a trivial
402 task.
403
404    Also, if you're still willing to do some runs make sure you configure
405 with the `--quantify' flag.  That will keep Quantify from starting to
406 record data until after the loadup is completed and will shut off
407 recording right before it shuts down (which generates enough bogus data
408 to throw most results off).  It also enables three additional elisp
409 commands: `quantify-start-recording-data',
410 `quantify-stop-recording-data' and `quantify-clear-data'.
411
412    If you want to make XEmacs faster, target your favorite slow
413 benchmark, run a profiler like Quantify, `gprof', or `tcov', and figure
414 out where the cycles are going.  Specific projects:
415
416    * Make the garbage collector faster.  Figure out how to write an
417      incremental garbage collector.
418
419    * Write a compiler that takes bytecode and spits out C code.
420      Unfortunately, you will then need a C compiler and a more fully
421      developed module system.
422
423    * Speed up redisplay.
424
425    * Speed up syntax highlighting.  Maybe moving some of the syntax
426      highlighting capabilities into C would make a difference.
427
428    * Implement tail recursion in Emacs Lisp (hard!).
429
430    Unfortunately, Emacs Lisp is slow, and is going to stay slow.
431 Function calls in elisp are especially expensive.  Iterating over a
432 long list is going to be 30 times faster implemented in C than in Elisp.
433
434    Heavily used small code fragments need to be fast.  The traditional
435 way to implement such code fragments in C is with macros.  But macros
436 in C are known to be broken.
437
438    Macro arguments that are repeatedly evaluated may suffer from
439 repeated side effects or suboptimal performance.
440
441    Variable names used in macros may collide with caller's variables,
442 causing (at least) unwanted compiler warnings.
443
444    In order to solve these problems, and maintain statement semantics,
445 one should use the `do { ... } while (0)' trick while trying to
446 reference macro arguments exactly once using local variables.
447
448    Let's take a look at this poor macro definition:
449
450      #define MARK_OBJECT(obj) \
451        if (!marked_p (obj)) mark_object (obj), did_mark = 1
452
453    This macro evaluates its argument twice, and also fails if used like
454 this:
455        if (flag) MARK_OBJECT (obj); else do_something();
456
457    A much better definition is
458
459      #define MARK_OBJECT(obj) do { \
460        Lisp_Object mo_obj = (obj); \
461        if (!marked_p (mo_obj))     \
462          {                         \
463            mark_object (mo_obj);   \
464            did_mark = 1;           \
465          }                         \
466      } while (0)
467
468    Notice the elimination of double evaluation by using the local
469 variable with the obscure name.  Writing safe and efficient macros
470 requires great care.  The one problem with macros that cannot be
471 portably worked around is, since a C block has no value, a macro used
472 as an expression rather than a statement cannot use the techniques just
473 described to avoid multiple evaluation.
474
475    In most cases where a macro has function semantics, an inline
476 function is a better implementation technique.  Modern compiler
477 optimizers tend to inline functions even if they have no `inline'
478 keyword, and configure magic ensures that the `inline' keyword can be
479 safely used as an additional compiler hint.  Inline functions used in a
480 single .c files are easy.  The function must already be defined to be
481 `static'.  Just add another `inline' keyword to the definition.
482
483      inline static int
484      heavily_used_small_function (int arg)
485      {
486        ...
487      }
488
489    Inline functions in header files are trickier, because we would like
490 to make the following optimization if the function is _not_ inlined
491 (for example, because we're compiling for debugging).  We would like the
492 function to be defined externally exactly once, and each calling
493 translation unit would create an external reference to the function,
494 instead of including a definition of the inline function in the object
495 code of every translation unit that uses it.  This optimization is
496 currently only available for gcc.  But you don't have to worry about the
497 trickiness; just define your inline functions in header files using this
498 pattern:
499
500      INLINE_HEADER int
501      i_used_to_be_a_crufty_macro_but_look_at_me_now (int arg);
502      INLINE_HEADER int
503      i_used_to_be_a_crufty_macro_but_look_at_me_now (int arg)
504      {
505        ...
506      }
507
508    The declaration right before the definition is to prevent warnings
509 when compiling with `gcc -Wmissing-declarations'.  I consider issuing
510 this warning for inline functions a gcc bug, but the gcc maintainers
511 disagree.
512
513    Every header which contains inline functions, either directly by
514 using `INLINE_HEADER' or indirectly by using `DECLARE_LRECORD' must be
515 added to `inline.c''s includes to make the optimization described above
516 work.  (Optimization note: if all INLINE_HEADER functions are in fact
517 inlined in all translation units, then the linker can just discard
518 `inline.o', since it contains only unreferenced code).
519
520    To get started debugging XEmacs, take a look at the `.gdbinit' and
521 `.dbxrc' files in the `src' directory.  See the section in the XEmacs
522 FAQ on How to Debug an XEmacs problem with a debugger.
523
524    After making source code changes, run `make check' to ensure that
525 you haven't introduced any regressions.  If you want to make xemacs more
526 reliable, please improve the test suite in `tests/automated'.
527
528    Did you make sure you didn't introduce any new compiler warnings?
529
530    Before submitting a patch, please try compiling at least once with
531
532      configure --with-mule --with-union-type --error-checking=all
533
534    Here are things to know when you create a new source file:
535
536    * All `.c' files should `#include <config.h>' first.  Almost all
537      `.c' files should `#include "lisp.h"' second.
538
539    * Generated header files should be included using the `#include
540      <...>' syntax, not the `#include "..."' syntax.  The generated
541      headers are:
542
543      `config.h sheap-adjust.h paths.h Emacs.ad.h'
544
545      The basic rule is that you should assume builds using `--srcdir'
546      and the `#include <...>' syntax needs to be used when the
547      to-be-included generated file is in a potentially different
548      directory _at compile time_.  The non-obvious C rule is that
549      `#include "..."' means to search for the included file in the same
550      directory as the including file, _not_ in the current directory.
551
552    * Header files should _not_ include `<config.h>' and `"lisp.h"'.  It
553      is the responsibility of the `.c' files that use it to do so.
554
555
556    Here is a checklist of things to do when creating a new lisp object
557 type named FOO:
558
559   1. create FOO.h
560
561   2. create FOO.c
562
563   3. add definitions of `syms_of_FOO', etc. to `FOO.c'
564
565   4. add declarations of `syms_of_FOO', etc. to `symsinit.h'
566
567   5. add calls to `syms_of_FOO', etc. to `emacs.c'
568
569   6. add definitions of macros like `CHECK_FOO' and `FOOP' to `FOO.h'
570
571   7. add the new type index to `enum lrecord_type'
572
573   8. add a DEFINE_LRECORD_IMPLEMENTATION call to `FOO.c'
574
575   9. add an INIT_LRECORD_IMPLEMENTATION call to `syms_of_FOO.c'
576
577 \1f
578 File: internals.info,  Node: A Summary of the Various XEmacs Modules,  Next: Allocation of Objects in XEmacs Lisp,  Prev: Rules When Writing New C Code,  Up: Top
579
580 A Summary of the Various XEmacs Modules
581 ***************************************
582
583    This is accurate as of XEmacs 20.0.
584
585 * Menu:
586
587 * Low-Level Modules::
588 * Basic Lisp Modules::
589 * Modules for Standard Editing Operations::
590 * Editor-Level Control Flow Modules::
591 * Modules for the Basic Displayable Lisp Objects::
592 * Modules for other Display-Related Lisp Objects::
593 * Modules for the Redisplay Mechanism::
594 * Modules for Interfacing with the File System::
595 * Modules for Other Aspects of the Lisp Interpreter and Object System::
596 * Modules for Interfacing with the Operating System::
597 * Modules for Interfacing with X Windows::
598 * Modules for Internationalization::
599
600 \1f
601 File: internals.info,  Node: Low-Level Modules,  Next: Basic Lisp Modules,  Up: A Summary of the Various XEmacs Modules
602
603 Low-Level Modules
604 =================
605
606      config.h
607
608    This is automatically generated from `config.h.in' based on the
609 results of configure tests and user-selected optional features and
610 contains preprocessor definitions specifying the nature of the
611 environment in which XEmacs is being compiled.
612
613      paths.h
614
615    This is automatically generated from `paths.h.in' based on supplied
616 configure values, and allows for non-standard installed configurations
617 of the XEmacs directories.  It's currently broken, though.
618
619      emacs.c
620      signal.c
621
622    `emacs.c' contains `main()' and other code that performs the most
623 basic environment initializations and handles shutting down the XEmacs
624 process (this includes `kill-emacs', the normal way that XEmacs is
625 exited; `dump-emacs', which is used during the build process to write
626 out the XEmacs executable; `run-emacs-from-temacs', which can be used
627 to start XEmacs directly when temacs has finished loading all the Lisp
628 code; and emergency code to handle crashes [XEmacs tries to auto-save
629 all files before it crashes]).
630
631    Low-level code that directly interacts with the Unix signal
632 mechanism, however, is in `signal.c'.  Note that this code does not
633 handle system dependencies in interfacing to signals; that is handled
634 using the `syssignal.h' header file, described in section J below.
635
636      unexaix.c
637      unexalpha.c
638      unexapollo.c
639      unexconvex.c
640      unexec.c
641      unexelf.c
642      unexelfsgi.c
643      unexencap.c
644      unexenix.c
645      unexfreebsd.c
646      unexfx2800.c
647      unexhp9k3.c
648      unexhp9k800.c
649      unexmips.c
650      unexnext.c
651      unexsol2.c
652      unexsunos4.c
653
654    These modules contain code dumping out the XEmacs executable on
655 various different systems. (This process is highly machine-specific and
656 requires intimate knowledge of the executable format and the memory map
657 of the process.) Only one of these modules is actually used; this is
658 chosen by `configure'.
659
660      ecrt0.c
661      lastfile.c
662      pre-crt0.c
663
664    These modules are used in conjunction with the dump mechanism.  On
665 some systems, an alternative version of the C startup code (the actual
666 code that receives control from the operating system when the process is
667 started, and which calls `main()') is required so that the dumping
668 process works properly; `crt0.c' provides this.
669
670    `pre-crt0.c' and `lastfile.c' should be the very first and very last
671 file linked, respectively. (Actually, this is not really true.
672 `lastfile.c' should be after all Emacs modules whose initialized data
673 should be made constant, and before all other Emacs files and all
674 libraries.  In particular, the allocation modules `gmalloc.c',
675 `alloca.c', etc. are normally placed past `lastfile.c', and all of the
676 files that implement Xt widget classes _must_ be placed after
677 `lastfile.c' because they contain various structures that must be
678 statically initialized and into which Xt writes at various times.)
679 `pre-crt0.c' and `lastfile.c' contain exported symbols that are used to
680 determine the start and end of XEmacs' initialized data space when
681 dumping.
682
683      alloca.c
684      free-hook.c
685      getpagesize.h
686      gmalloc.c
687      malloc.c
688      mem-limits.h
689      ralloc.c
690      vm-limit.c
691
692    These handle basic C allocation of memory.  `alloca.c' is an
693 emulation of the stack allocation function `alloca()' on machines that
694 lack this. (XEmacs makes extensive use of `alloca()' in its code.)
695
696    `gmalloc.c' and `malloc.c' are two implementations of the standard C
697 functions `malloc()', `realloc()' and `free()'.  They are often used in
698 place of the standard system-provided `malloc()' because they usually
699 provide a much faster implementation, at the expense of additional
700 memory use.  `gmalloc.c' is a newer implementation that is much more
701 memory-efficient for large allocations than `malloc.c', and should
702 always be preferred if it works. (At one point, `gmalloc.c' didn't work
703 on some systems where `malloc.c' worked; but this should be fixed now.)
704
705    `ralloc.c' is the "relocating allocator".  It provides functions
706 similar to `malloc()', `realloc()' and `free()' that allocate memory
707 that can be dynamically relocated in memory.  The advantage of this is
708 that allocated memory can be shuffled around to place all the free
709 memory at the end of the heap, and the heap can then be shrunk,
710 releasing the memory back to the operating system.  The use of this can
711 be controlled with the configure option `--rel-alloc'; if enabled,
712 memory allocated for buffers will be relocatable, so that if a very
713 large file is visited and the buffer is later killed, the memory can be
714 released to the operating system.  (The disadvantage of this mechanism
715 is that it can be very slow.  On systems with the `mmap()' system call,
716 the XEmacs version of `ralloc.c' uses this to move memory around
717 without actually having to block-copy it, which can speed things up;
718 but it can still cause noticeable performance degradation.)
719
720    `free-hook.c' contains some debugging functions for checking for
721 invalid arguments to `free()'.
722
723    `vm-limit.c' contains some functions that warn the user when memory
724 is getting low.  These are callback functions that are called by
725 `gmalloc.c' and `malloc.c' at appropriate times.
726
727    `getpagesize.h' provides a uniform interface for retrieving the size
728 of a page in virtual memory.  `mem-limits.h' provides a uniform
729 interface for retrieving the total amount of available virtual memory.
730 Both are similar in spirit to the `sys*.h' files described in section
731 J, below.
732
733      blocktype.c
734      blocktype.h
735      dynarr.c
736
737    These implement a couple of basic C data types to facilitate memory
738 allocation.  The `Blocktype' type efficiently manages the allocation of
739 fixed-size blocks by minimizing the number of times that `malloc()' and
740 `free()' are called.  It allocates memory in large chunks, subdivides
741 the chunks into blocks of the proper size, and returns the blocks as
742 requested.  When blocks are freed, they are placed onto a linked list,
743 so they can be efficiently reused.  This data type is not much used in
744 XEmacs currently, because it's a fairly new addition.
745
746    The `Dynarr' type implements a "dynamic array", which is similar to
747 a standard C array but has no fixed limit on the number of elements it
748 can contain.  Dynamic arrays can hold elements of any type, and when
749 you add a new element, the array automatically resizes itself if it
750 isn't big enough.  Dynarrs are extensively used in the redisplay
751 mechanism.
752
753      inline.c
754
755    This module is used in connection with inline functions (available in
756 some compilers).  Often, inline functions need to have a corresponding
757 non-inline function that does the same thing.  This module is where they
758 reside.  It contains no actual code, but defines some special flags that
759 cause inline functions defined in header files to be rendered as actual
760 functions.  It then includes all header files that contain any inline
761 function definitions, so that each one gets a real function equivalent.
762
763      debug.c
764      debug.h
765
766    These functions provide a system for doing internal consistency
767 checks during code development.  This system is not currently used;
768 instead the simpler `assert()' macro is used along with the various
769 checks provided by the `--error-check-*' configuration options.
770
771      universe.h
772
773    This is not currently used.
774
775 \1f
776 File: internals.info,  Node: Basic Lisp Modules,  Next: Modules for Standard Editing Operations,  Prev: Low-Level Modules,  Up: A Summary of the Various XEmacs Modules
777
778 Basic Lisp Modules
779 ==================
780
781      lisp-disunion.h
782      lisp-union.h
783      lisp.h
784      lrecord.h
785      symsinit.h
786
787    These are the basic header files for all XEmacs modules.  Each module
788 includes `lisp.h', which brings the other header files in.  `lisp.h'
789 contains the definitions of the structures and extractor and
790 constructor macros for the basic Lisp objects and various other basic
791 definitions for the Lisp environment, as well as some general-purpose
792 definitions (e.g. `min()' and `max()').  `lisp.h' includes either
793 `lisp-disunion.h' or `lisp-union.h', depending on whether
794 `USE_UNION_TYPE' is defined.  These files define the typedef of the
795 Lisp object itself (as described above) and the low-level macros that
796 hide the actual implementation of the Lisp object.  All extractor and
797 constructor macros for particular types of Lisp objects are defined in
798 terms of these low-level macros.
799
800    As a general rule, all typedefs should go into the typedefs section
801 of `lisp.h' rather than into a module-specific header file even if the
802 structure is defined elsewhere.  This allows function prototypes that
803 use the typedef to be placed into other header files.  Forward structure
804 declarations (i.e. a simple declaration like `struct foo;' where the
805 structure itself is defined elsewhere) should be placed into the
806 typedefs section as necessary.
807
808    `lrecord.h' contains the basic structures and macros that implement
809 all record-type Lisp objects--i.e. all objects whose type is a field in
810 their C structure, which includes all objects except the few most basic
811 ones.
812
813    `lisp.h' contains prototypes for most of the exported functions in
814 the various modules.  Lisp primitives defined using `DEFUN' that need
815 to be called by C code should be declared using `EXFUN'.  Other
816 function prototypes should be placed either into the appropriate
817 section of `lisp.h', or into a module-specific header file, depending
818 on how general-purpose the function is and whether it has
819 special-purpose argument types requiring definitions not in `lisp.h'.)
820 All initialization functions are prototyped in `symsinit.h'.
821
822      alloc.c
823
824    The large module `alloc.c' implements all of the basic allocation and
825 garbage collection for Lisp objects.  The most commonly used Lisp
826 objects are allocated in chunks, similar to the Blocktype data type
827 described above; others are allocated in individually `malloc()'ed
828 blocks.  This module provides the foundation on which all other aspects
829 of the Lisp environment sit, and is the first module initialized at
830 startup.
831
832    Note that `alloc.c' provides a series of generic functions that are
833 not dependent on any particular object type, and interfaces to
834 particular types of objects using a standardized interface of
835 type-specific methods.  This scheme is a fundamental principle of
836 object-oriented programming and is heavily used throughout XEmacs.  The
837 great advantage of this is that it allows for a clean separation of
838 functionality into different modules--new classes of Lisp objects, new
839 event interfaces, new device types, new stream interfaces, etc. can be
840 added transparently without affecting code anywhere else in XEmacs.
841 Because the different subsystems are divided into general and specific
842 code, adding a new subtype within a subsystem will in general not
843 require changes to the generic subsystem code or affect any of the other
844 subtypes in the subsystem; this provides a great deal of robustness to
845 the XEmacs code.
846
847      eval.c
848      backtrace.h
849
850    This module contains all of the functions to handle the flow of
851 control.  This includes the mechanisms of defining functions, calling
852 functions, traversing stack frames, and binding variables; the control
853 primitives and other special forms such as `while', `if', `eval',
854 `let', `and', `or', `progn', etc.; handling of non-local exits,
855 unwind-protects, and exception handlers; entering the debugger; methods
856 for the subr Lisp object type; etc.  It does _not_ include the `read'
857 function, the `print' function, or the handling of symbols and obarrays.
858
859    `backtrace.h' contains some structures related to stack frames and
860 the flow of control.
861
862      lread.c
863
864    This module implements the Lisp reader and the `read' function,
865 which converts text into Lisp objects, according to the read syntax of
866 the objects, as described above.  This is similar to the parser that is
867 a part of all compilers.
868
869      print.c
870
871    This module implements the Lisp print mechanism and the `print'
872 function and related functions.  This is the inverse of the Lisp reader
873 - it converts Lisp objects to a printed, textual representation.
874 (Hopefully something that can be read back in using `read' to get an
875 equivalent object.)
876
877      general.c
878      symbols.c
879      symeval.h
880
881    `symbols.c' implements the handling of symbols, obarrays, and
882 retrieving the values of symbols.  Much of the code is devoted to
883 handling the special "symbol-value-magic" objects that define special
884 types of variables--this includes buffer-local variables, variable
885 aliases, variables that forward into C variables, etc.  This module is
886 initialized extremely early (right after `alloc.c'), because it is here
887 that the basic symbols `t' and `nil' are created, and those symbols are
888 used everywhere throughout XEmacs.
889
890    `symeval.h' contains the definitions of symbol structures and the
891 `DEFVAR_LISP()' and related macros for declaring variables.
892
893      data.c
894      floatfns.c
895      fns.c
896
897    These modules implement the methods and standard Lisp primitives for
898 all the basic Lisp object types other than symbols (which are described
899 above).  `data.c' contains all the predicates (primitives that return
900 whether an object is of a particular type); the integer arithmetic
901 functions; and the basic accessor and mutator primitives for the various
902 object types.  `fns.c' contains all the standard predicates for working
903 with sequences (where, abstractly speaking, a sequence is an ordered set
904 of objects, and can be represented by a list, string, vector, or
905 bit-vector); it also contains `equal', perhaps on the grounds that bulk
906 of the operation of `equal' is comparing sequences.  `floatfns.c'
907 contains methods and primitives for floats and floating-point
908 arithmetic.
909
910      bytecode.c
911      bytecode.h
912
913    `bytecode.c' implements the byte-code interpreter and
914 compiled-function objects, and `bytecode.h' contains associated
915 structures.  Note that the byte-code _compiler_ is written in Lisp.
916
917 \1f
918 File: internals.info,  Node: Modules for Standard Editing Operations,  Next: Editor-Level Control Flow Modules,  Prev: Basic Lisp Modules,  Up: A Summary of the Various XEmacs Modules
919
920 Modules for Standard Editing Operations
921 =======================================
922
923      buffer.c
924      buffer.h
925      bufslots.h
926
927    `buffer.c' implements the "buffer" Lisp object type.  This includes
928 functions that create and destroy buffers; retrieve buffers by name or
929 by other properties; manipulate lists of buffers (remember that buffers
930 are permanent objects and stored in various ordered lists); retrieve or
931 change buffer properties; etc.  It also contains the definitions of all
932 the built-in buffer-local variables (which can be viewed as buffer
933 properties).  It does _not_ contain code to manipulate buffer-local
934 variables (that's in `symbols.c', described above); or code to
935 manipulate the text in a buffer.
936
937    `buffer.h' defines the structures associated with a buffer and the
938 various macros for retrieving text from a buffer and special buffer
939 positions (e.g. `point', the default location for text insertion).  It
940 also contains macros for working with buffer positions and converting
941 between their representations as character offsets and as byte offsets
942 (under MULE, they are different, because characters can be multi-byte).
943 It is one of the largest header files.
944
945    `bufslots.h' defines the fields in the buffer structure that
946 correspond to the built-in buffer-local variables.  It is its own
947 header file because it is included many times in `buffer.c', as a way
948 of iterating over all the built-in buffer-local variables.
949
950      insdel.c
951      insdel.h
952
953    `insdel.c' contains low-level functions for inserting and deleting
954 text in a buffer, keeping track of changed regions for use by
955 redisplay, and calling any before-change and after-change functions
956 that may have been registered for the buffer.  It also contains the
957 actual functions that convert between byte offsets and character
958 offsets.
959
960    `insdel.h' contains associated headers.
961
962      marker.c
963
964    This module implements the "marker" Lisp object type, which
965 conceptually is a pointer to a text position in a buffer that moves
966 around as text is inserted and deleted, so as to remain in the same
967 relative position.  This module doesn't actually move the markers around
968 - that's handled in `insdel.c'.  This module just creates them and
969 implements the primitives for working with them.  As markers are simple
970 objects, this does not entail much.
971
972    Note that the standard arithmetic primitives (e.g. `+') accept
973 markers in place of integers and automatically substitute the value of
974 `marker-position' for the marker, i.e. an integer describing the
975 current buffer position of the marker.
976
977      extents.c
978      extents.h
979
980    This module implements the "extent" Lisp object type, which is like
981 a marker that works over a range of text rather than a single position.
982 Extents are also much more complex and powerful than markers and have a
983 more efficient (and more algorithmically complex) implementation.  The
984 implementation is described in detail in comments in `extents.c'.
985
986    The code in `extents.c' works closely with `insdel.c' so that
987 extents are properly moved around as text is inserted and deleted.
988 There is also code in `extents.c' that provides information needed by
989 the redisplay mechanism for efficient operation. (Remember that extents
990 can have display properties that affect [sometimes drastically, as in
991 the `invisible' property] the display of the text they cover.)
992
993      editfns.c
994
995    `editfns.c' contains the standard Lisp primitives for working with a
996 buffer's text, and calls the low-level functions in `insdel.c'.  It
997 also contains primitives for working with `point' (the default buffer
998 insertion location).
999
1000    `editfns.c' also contains functions for retrieving various
1001 characteristics from the external environment: the current time, the
1002 process ID of the running XEmacs process, the name of the user who ran
1003 this XEmacs process, etc.  It's not clear why this code is in
1004 `editfns.c'.
1005
1006      callint.c
1007      cmds.c
1008      commands.h
1009
1010    These modules implement the basic "interactive" commands, i.e.
1011 user-callable functions.  Commands, as opposed to other functions, have
1012 special ways of getting their parameters interactively (by querying the
1013 user), as opposed to having them passed in a normal function
1014 invocation.  Many commands are not really meant to be called from other
1015 Lisp functions, because they modify global state in a way that's often
1016 undesired as part of other Lisp functions.
1017
1018    `callint.c' implements the mechanism for querying the user for
1019 parameters and calling interactive commands.  The bulk of this module is
1020 code that parses the interactive spec that is supplied with an
1021 interactive command.
1022
1023    `cmds.c' implements the basic, most commonly used editing commands:
1024 commands to move around the current buffer and insert and delete
1025 characters.  These commands are implemented using the Lisp primitives
1026 defined in `editfns.c'.
1027
1028    `commands.h' contains associated structure definitions and
1029 prototypes.
1030
1031      regex.c
1032      regex.h
1033      search.c
1034
1035    `search.c' implements the Lisp primitives for searching for text in
1036 a buffer, and some of the low-level algorithms for doing this.  In
1037 particular, the fast fixed-string Boyer-Moore search algorithm is
1038 implemented in `search.c'.  The low-level algorithms for doing
1039 regular-expression searching, however, are implemented in `regex.c' and
1040 `regex.h'.  These two modules are largely independent of XEmacs, and
1041 are similar to (and based upon) the regular-expression routines used in
1042 `grep' and other GNU utilities.
1043
1044      doprnt.c
1045
1046    `doprnt.c' implements formatted-string processing, similar to
1047 `printf()' command in C.
1048
1049      undo.c
1050
1051    This module implements the undo mechanism for tracking buffer
1052 changes.  Most of this could be implemented in Lisp.
1053
1054 \1f
1055 File: internals.info,  Node: Editor-Level Control Flow Modules,  Next: Modules for the Basic Displayable Lisp Objects,  Prev: Modules for Standard Editing Operations,  Up: A Summary of the Various XEmacs Modules
1056
1057 Editor-Level Control Flow Modules
1058 =================================
1059
1060      event-Xt.c
1061      event-msw.c
1062      event-stream.c
1063      event-tty.c
1064      events-mod.h
1065      gpmevent.c
1066      gpmevent.h
1067      events.c
1068      events.h
1069
1070    These implement the handling of events (user input and other system
1071 notifications).
1072
1073    `events.c' and `events.h' define the "event" Lisp object type and
1074 primitives for manipulating it.
1075
1076    `event-stream.c' implements the basic functions for working with
1077 event queues, dispatching an event by looking it up in relevant keymaps
1078 and such, and handling timeouts; this includes the primitives
1079 `next-event' and `dispatch-event', as well as related primitives such
1080 as `sit-for', `sleep-for', and `accept-process-output'.
1081 (`event-stream.c' is one of the hairiest and trickiest modules in
1082 XEmacs.  Beware!  You can easily mess things up here.)
1083
1084    `event-Xt.c' and `event-tty.c' implement the low-level interfaces
1085 onto retrieving events from Xt (the X toolkit) and from TTY's (using
1086 `read()' and `select()'), respectively.  The event interface enforces a
1087 clean separation between the specific code for interfacing with the
1088 operating system and the generic code for working with events, by
1089 defining an API of basic, low-level event methods; `event-Xt.c' and
1090 `event-tty.c' are two different implementations of this API.  To add
1091 support for a new operating system (e.g. NeXTstep), one merely needs to
1092 provide another implementation of those API functions.
1093
1094    Note that the choice of whether to use `event-Xt.c' or `event-tty.c'
1095 is made at compile time!  Or at the very latest, it is made at startup
1096 time.  `event-Xt.c' handles events for _both_ X and TTY frames;
1097 `event-tty.c' is only used when X support is not compiled into XEmacs.
1098 The reason for this is that there is only one event loop in XEmacs:
1099 thus, it needs to be able to receive events from all different kinds of
1100 frames.
1101
1102      keymap.c
1103      keymap.h
1104
1105    `keymap.c' and `keymap.h' define the "keymap" Lisp object type and
1106 associated methods and primitives. (Remember that keymaps are objects
1107 that associate event descriptions with functions to be called to
1108 "execute" those events; `dispatch-event' looks up events in the
1109 relevant keymaps.)
1110
1111      cmdloop.c
1112
1113    `cmdloop.c' contains functions that implement the actual editor
1114 command loop--i.e. the event loop that cyclically retrieves and
1115 dispatches events.  This code is also rather tricky, just like
1116 `event-stream.c'.
1117
1118      macros.c
1119      macros.h
1120
1121    These two modules contain the basic code for defining keyboard
1122 macros.  These functions don't actually do much; most of the code that
1123 handles keyboard macros is mixed in with the event-handling code in
1124 `event-stream.c'.
1125
1126      minibuf.c
1127
1128    This contains some miscellaneous code related to the minibuffer
1129 (most of the minibuffer code was moved into Lisp by Richard Mlynarik).
1130 This includes the primitives for completion (although filename
1131 completion is in `dired.c'), the lowest-level interface to the
1132 minibuffer (if the command loop were cleaned up, this too could be in
1133 Lisp), and code for dealing with the echo area (this, too, was mostly
1134 moved into Lisp, and the only code remaining is code to call out to
1135 Lisp or provide simple bootstrapping implementations early in temacs,
1136 before the echo-area Lisp code is loaded).
1137
1138 \1f
1139 File: internals.info,  Node: Modules for the Basic Displayable Lisp Objects,  Next: Modules for other Display-Related Lisp Objects,  Prev: Editor-Level Control Flow Modules,  Up: A Summary of the Various XEmacs Modules
1140
1141 Modules for the Basic Displayable Lisp Objects
1142 ==============================================
1143
1144      console-msw.c
1145      console-msw.h
1146      console-stream.c
1147      console-stream.h
1148      console-tty.c
1149      console-tty.h
1150      console-x.c
1151      console-x.h
1152      console.c
1153      console.h
1154
1155    These modules implement the "console" Lisp object type.  A console
1156 contains multiple display devices, but only one keyboard and mouse.
1157 Most of the time, a console will contain exactly one device.
1158
1159    Consoles are the top of a lisp object inclusion hierarchy.  Consoles
1160 contain devices, which contain frames, which contain windows.
1161
1162      device-msw.c
1163      device-tty.c
1164      device-x.c
1165      device.c
1166      device.h
1167
1168    These modules implement the "device" Lisp object type.  This
1169 abstracts a particular screen or connection on which frames are
1170 displayed.  As with Lisp objects, event interfaces, and other
1171 subsystems, the device code is separated into a generic component that
1172 contains a standardized interface (in the form of a set of methods) onto
1173 particular device types.
1174
1175    The device subsystem defines all the methods and provides method
1176 services for not only device operations but also for the frame, window,
1177 menubar, scrollbar, toolbar, and other displayable-object subsystems.
1178 The reason for this is that all of these subsystems have the same
1179 subtypes (X, TTY, NeXTstep, Microsoft Windows, etc.) as devices do.
1180
1181      frame-msw.c
1182      frame-tty.c
1183      frame-x.c
1184      frame.c
1185      frame.h
1186
1187    Each device contains one or more frames in which objects (e.g. text)
1188 are displayed.  A frame corresponds to a window in the window system;
1189 usually this is a top-level window but it could potentially be one of a
1190 number of overlapping child windows within a top-level window, using the
1191 MDI (Multiple Document Interface) protocol in Microsoft Windows or a
1192 similar scheme.
1193
1194    The `frame-*' files implement the "frame" Lisp object type and
1195 provide the generic and device-type-specific operations on frames (e.g.
1196 raising, lowering, resizing, moving, etc.).
1197
1198      window.c
1199      window.h
1200
1201    Each frame consists of one or more non-overlapping "windows" (better
1202 known as "panes" in standard window-system terminology) in which a
1203 buffer's text can be displayed.  Windows can also have scrollbars
1204 displayed around their edges.
1205
1206    `window.c' and `window.h' implement the "window" Lisp object type
1207 and provide code to manage windows.  Since windows have no associated
1208 resources in the window system (the window system knows only about the
1209 frame; no child windows or anything are used for XEmacs windows), there
1210 is no device-type-specific code here; all of that code is part of the
1211 redisplay mechanism or the code for particular object types such as
1212 scrollbars.
1213