428
|
1 \input texinfo @c -*-texinfo-*-
|
|
2 @c %**start of header
|
|
3 @setfilename ../../info/internals.info
|
|
4 @settitle XEmacs Internals Manual
|
|
5 @c %**end of header
|
|
6
|
|
7 @ifinfo
|
|
8 @dircategory XEmacs Editor
|
|
9 @direntry
|
440
|
10 * Internals: (internals). XEmacs Internals Manual.
|
428
|
11 @end direntry
|
|
12
|
|
13 Copyright @copyright{} 1992 - 1996 Ben Wing.
|
|
14 Copyright @copyright{} 1996, 1997 Sun Microsystems.
|
|
15 Copyright @copyright{} 1994 - 1998 Free Software Foundation.
|
|
16 Copyright @copyright{} 1994, 1995 Board of Trustees, University of Illinois.
|
|
17
|
|
18
|
|
19 Permission is granted to make and distribute verbatim copies of this
|
|
20 manual provided the copyright notice and this permission notice are
|
|
21 preserved on all copies.
|
|
22
|
|
23 @ignore
|
|
24 Permission is granted to process this file through TeX and print the
|
|
25 results, provided the printed document carries copying permission notice
|
|
26 identical to this one except for the removal of this paragraph (this
|
|
27 paragraph not being relevant to the printed manual).
|
|
28
|
|
29 @end ignore
|
|
30 Permission is granted to copy and distribute modified versions of this
|
|
31 manual under the conditions for verbatim copying, provided that the
|
|
32 entire resulting derived work is distributed under the terms of a
|
|
33 permission notice identical to this one.
|
|
34
|
|
35 Permission is granted to copy and distribute translations of this manual
|
|
36 into another language, under the above conditions for modified versions,
|
|
37 except that this permission notice may be stated in a translation
|
|
38 approved by the Foundation.
|
|
39
|
|
40 Permission is granted to copy and distribute modified versions of this
|
|
41 manual under the conditions for verbatim copying, provided also that the
|
|
42 section entitled ``GNU General Public License'' is included exactly as
|
|
43 in the original, and provided that the entire resulting derived work is
|
|
44 distributed under the terms of a permission notice identical to this
|
|
45 one.
|
|
46
|
|
47 Permission is granted to copy and distribute translations of this manual
|
|
48 into another language, under the above conditions for modified versions,
|
|
49 except that the section entitled ``GNU General Public License'' may be
|
|
50 included in a translation approved by the Free Software Foundation
|
|
51 instead of in the original English.
|
|
52 @end ifinfo
|
|
53
|
|
54 @c Combine indices.
|
|
55 @synindex cp fn
|
|
56 @syncodeindex vr fn
|
|
57 @syncodeindex ky fn
|
|
58 @syncodeindex pg fn
|
|
59 @syncodeindex tp fn
|
|
60
|
|
61 @setchapternewpage odd
|
|
62 @finalout
|
|
63
|
|
64 @titlepage
|
|
65 @title XEmacs Internals Manual
|
464
|
66 @subtitle Version 1.4, March 2001
|
428
|
67
|
|
68 @author Ben Wing
|
|
69 @author Martin Buchholz
|
|
70 @author Hrvoje Niksic
|
|
71 @author Matthias Neubauer
|
442
|
72 @author Olivier Galibert
|
428
|
73 @page
|
|
74 @vskip 0pt plus 1fill
|
|
75
|
|
76 @noindent
|
464
|
77 Copyright @copyright{} 1992 - 1996, 2001 Ben Wing. @*
|
428
|
78 Copyright @copyright{} 1996, 1997 Sun Microsystems, Inc. @*
|
|
79 Copyright @copyright{} 1994 - 1998 Free Software Foundation. @*
|
|
80 Copyright @copyright{} 1994, 1995 Board of Trustees, University of Illinois.
|
|
81
|
|
82 @sp 2
|
464
|
83 Version 1.4 @*
|
|
84 March 2001.@*
|
428
|
85
|
|
86 Permission is granted to make and distribute verbatim copies of this
|
|
87 manual provided the copyright notice and this permission notice are
|
|
88 preserved on all copies.
|
|
89
|
|
90 Permission is granted to copy and distribute modified versions of this
|
|
91 manual under the conditions for verbatim copying, provided also that the
|
|
92 section entitled ``GNU General Public License'' is included
|
|
93 exactly as in the original, and provided that the entire resulting
|
|
94 derived work is distributed under the terms of a permission notice
|
|
95 identical to this one.
|
|
96
|
|
97 Permission is granted to copy and distribute translations of this manual
|
|
98 into another language, under the above conditions for modified versions,
|
|
99 except that the section entitled ``GNU General Public License'' may be
|
|
100 included in a translation approved by the Free Software Foundation
|
|
101 instead of in the original English.
|
|
102 @end titlepage
|
|
103 @page
|
|
104
|
|
105 @node Top, A History of Emacs, (dir), (dir)
|
|
106
|
|
107 @ifinfo
|
464
|
108 This Info file contains v1.4 of the XEmacs Internals Manual, March 2001.
|
428
|
109 @end ifinfo
|
|
110
|
|
111 @menu
|
|
112 * A History of Emacs:: Times, dates, important events.
|
|
113 * XEmacs From the Outside:: A broad conceptual overview.
|
|
114 * The Lisp Language:: An overview.
|
|
115 * XEmacs From the Perspective of Building::
|
|
116 * XEmacs From the Inside::
|
|
117 * The XEmacs Object System (Abstractly Speaking)::
|
|
118 * How Lisp Objects Are Represented in C::
|
|
119 * Rules When Writing New C Code::
|
802
|
120 * CVS Techniques::
|
428
|
121 * A Summary of the Various XEmacs Modules::
|
|
122 * Allocation of Objects in XEmacs Lisp::
|
442
|
123 * Dumping::
|
428
|
124 * Events and the Event Loop::
|
|
125 * Evaluation; Stack Frames; Bindings::
|
|
126 * Symbols and Variables::
|
|
127 * Buffers and Textual Representation::
|
|
128 * MULE Character Sets and Encodings::
|
|
129 * The Lisp Reader and Compiler::
|
|
130 * Lstreams::
|
|
131 * Consoles; Devices; Frames; Windows::
|
|
132 * The Redisplay Mechanism::
|
|
133 * Extents::
|
|
134 * Faces::
|
|
135 * Glyphs::
|
|
136 * Specifiers::
|
|
137 * Menus::
|
|
138 * Subprocesses::
|
446
|
139 * Interface to the X Window System::
|
442
|
140 * Index::
|
|
141
|
|
142 @detailmenu
|
|
143
|
|
144 --- The Detailed Node Listing ---
|
428
|
145
|
|
146 A History of Emacs
|
|
147
|
|
148 * Through Version 18:: Unification prevails.
|
|
149 * Lucid Emacs:: One version 19 Emacs.
|
|
150 * GNU Emacs 19:: The other version 19 Emacs.
|
442
|
151 * GNU Emacs 20:: The other version 20 Emacs.
|
428
|
152 * XEmacs:: The continuation of Lucid Emacs.
|
|
153
|
|
154 Rules When Writing New C Code
|
|
155
|
|
156 * General Coding Rules::
|
|
157 * Writing Lisp Primitives::
|
802
|
158 * Writing Good Comments::
|
428
|
159 * Adding Global Lisp Variables::
|
802
|
160 * Proper Use of Unsigned Types::
|
442
|
161 * Coding for Mule::
|
428
|
162 * Techniques for XEmacs Developers::
|
|
163
|
442
|
164 Coding for Mule
|
|
165
|
|
166 * Character-Related Data Types::
|
|
167 * Working With Character and Byte Positions::
|
|
168 * Conversion to and from External Data::
|
|
169 * General Guidelines for Writing Mule-Aware Code::
|
|
170 * An Example of Mule-Aware Code::
|
|
171
|
802
|
172 CVS Techniques
|
|
173
|
|
174 * Merging a Branch into the Trunk::
|
|
175
|
428
|
176 A Summary of the Various XEmacs Modules
|
|
177
|
|
178 * Low-Level Modules::
|
|
179 * Basic Lisp Modules::
|
|
180 * Modules for Standard Editing Operations::
|
|
181 * Editor-Level Control Flow Modules::
|
|
182 * Modules for the Basic Displayable Lisp Objects::
|
|
183 * Modules for other Display-Related Lisp Objects::
|
|
184 * Modules for the Redisplay Mechanism::
|
|
185 * Modules for Interfacing with the File System::
|
|
186 * Modules for Other Aspects of the Lisp Interpreter and Object System::
|
|
187 * Modules for Interfacing with the Operating System::
|
|
188 * Modules for Interfacing with X Windows::
|
|
189 * Modules for Internationalization::
|
|
190
|
|
191 Allocation of Objects in XEmacs Lisp
|
|
192
|
|
193 * Introduction to Allocation::
|
|
194 * Garbage Collection::
|
|
195 * GCPROing::
|
|
196 * Garbage Collection - Step by Step::
|
|
197 * Integers and Characters::
|
|
198 * Allocation from Frob Blocks::
|
|
199 * lrecords::
|
|
200 * Low-level allocation::
|
|
201 * Cons::
|
|
202 * Vector::
|
|
203 * Bit Vector::
|
|
204 * Symbol::
|
|
205 * Marker::
|
|
206 * String::
|
|
207 * Compiled Function::
|
|
208
|
442
|
209 Garbage Collection - Step by Step
|
|
210
|
|
211 * Invocation::
|
|
212 * garbage_collect_1::
|
|
213 * mark_object::
|
|
214 * gc_sweep::
|
|
215 * sweep_lcrecords_1::
|
|
216 * compact_string_chars::
|
|
217 * sweep_strings::
|
|
218 * sweep_bit_vectors_1::
|
|
219
|
|
220 Dumping
|
|
221
|
|
222 * Overview::
|
|
223 * Data descriptions::
|
|
224 * Dumping phase::
|
|
225 * Reloading phase::
|
|
226
|
|
227 Dumping phase
|
|
228
|
|
229 * Object inventory::
|
|
230 * Address allocation::
|
|
231 * The header::
|
|
232 * Data dumping::
|
|
233 * Pointers dumping::
|
|
234
|
428
|
235 Events and the Event Loop
|
|
236
|
|
237 * Introduction to Events::
|
|
238 * Main Loop::
|
|
239 * Specifics of the Event Gathering Mechanism::
|
|
240 * Specifics About the Emacs Event::
|
|
241 * The Event Stream Callback Routines::
|
|
242 * Other Event Loop Functions::
|
|
243 * Converting Events::
|
|
244 * Dispatching Events; The Command Builder::
|
|
245
|
|
246 Evaluation; Stack Frames; Bindings
|
|
247
|
|
248 * Evaluation::
|
|
249 * Dynamic Binding; The specbinding Stack; Unwind-Protects::
|
|
250 * Simple Special Forms::
|
|
251 * Catch and Throw::
|
|
252
|
|
253 Symbols and Variables
|
|
254
|
|
255 * Introduction to Symbols::
|
|
256 * Obarrays::
|
|
257 * Symbol Values::
|
|
258
|
|
259 Buffers and Textual Representation
|
|
260
|
|
261 * Introduction to Buffers:: A buffer holds a block of text such as a file.
|
|
262 * The Text in a Buffer:: Representation of the text in a buffer.
|
|
263 * Buffer Lists:: Keeping track of all buffers.
|
|
264 * Markers and Extents:: Tagging locations within a buffer.
|
|
265 * Bufbytes and Emchars:: Representation of individual characters.
|
|
266 * The Buffer Object:: The Lisp object corresponding to a buffer.
|
|
267
|
|
268 MULE Character Sets and Encodings
|
|
269
|
|
270 * Character Sets::
|
|
271 * Encodings::
|
|
272 * Internal Mule Encodings::
|
442
|
273 * CCL::
|
428
|
274
|
|
275 Encodings
|
|
276
|
|
277 * Japanese EUC (Extended Unix Code)::
|
|
278 * JIS7::
|
|
279
|
|
280 Internal Mule Encodings
|
|
281
|
|
282 * Internal String Encoding::
|
|
283 * Internal Character Encoding::
|
|
284
|
|
285 Lstreams
|
|
286
|
442
|
287 * Creating an Lstream:: Creating an lstream object.
|
|
288 * Lstream Types:: Different sorts of things that are streamed.
|
|
289 * Lstream Functions:: Functions for working with lstreams.
|
|
290 * Lstream Methods:: Creating new lstream types.
|
|
291
|
428
|
292 Consoles; Devices; Frames; Windows
|
|
293
|
|
294 * Introduction to Consoles; Devices; Frames; Windows::
|
|
295 * Point::
|
|
296 * Window Hierarchy::
|
442
|
297 * The Window Object::
|
428
|
298
|
|
299 The Redisplay Mechanism
|
|
300
|
|
301 * Critical Redisplay Sections::
|
|
302 * Line Start Cache::
|
442
|
303 * Redisplay Piece by Piece::
|
428
|
304
|
|
305 Extents
|
|
306
|
|
307 * Introduction to Extents:: Extents are ranges over text, with properties.
|
|
308 * Extent Ordering:: How extents are ordered internally.
|
|
309 * Format of the Extent Info:: The extent information in a buffer or string.
|
|
310 * Zero-Length Extents:: A weird special case.
|
442
|
311 * Mathematics of Extent Ordering:: A rigorous foundation.
|
428
|
312 * Extent Fragments:: Cached information useful for redisplay.
|
|
313
|
442
|
314 @end detailmenu
|
428
|
315 @end menu
|
|
316
|
|
317 @node A History of Emacs, XEmacs From the Outside, Top, Top
|
|
318 @chapter A History of Emacs
|
462
|
319 @cindex history of Emacs, a
|
|
320 @cindex Emacs, a history of
|
428
|
321 @cindex Hackers (Steven Levy)
|
|
322 @cindex Levy, Steven
|
|
323 @cindex ITS (Incompatible Timesharing System)
|
|
324 @cindex Stallman, Richard
|
|
325 @cindex RMS
|
|
326 @cindex MIT
|
|
327 @cindex TECO
|
|
328 @cindex FSF
|
|
329 @cindex Free Software Foundation
|
|
330
|
|
331 XEmacs is a powerful, customizable text editor and development
|
|
332 environment. It began as Lucid Emacs, which was in turn derived from
|
|
333 GNU Emacs, a program written by Richard Stallman of the Free Software
|
|
334 Foundation. GNU Emacs dates back to the 1970's, and was modelled
|
|
335 after a package called ``Emacs'', written in 1976, that was a set of
|
|
336 macros on top of TECO, an old, old text editor written at MIT on the
|
|
337 DEC PDP 10 under one of the earliest time-sharing operating systems,
|
|
338 ITS (Incompatible Timesharing System). (ITS dates back well before
|
|
339 Unix.) ITS, TECO, and Emacs were products of a group of people at MIT
|
|
340 who called themselves ``hackers'', who shared an idealistic belief
|
|
341 system about the free exchange of information and were fanatical in
|
|
342 their devotion to and time spent with computers. (The hacker
|
|
343 subculture dates back to the late 1950's at MIT and is described in
|
|
344 detail in Steven Levy's book @cite{Hackers}. This book also includes
|
|
345 a lot of information about Stallman himself and the development of
|
|
346 Lisp, a programming language developed at MIT that underlies Emacs.)
|
|
347
|
|
348 @menu
|
|
349 * Through Version 18:: Unification prevails.
|
|
350 * Lucid Emacs:: One version 19 Emacs.
|
|
351 * GNU Emacs 19:: The other version 19 Emacs.
|
|
352 * GNU Emacs 20:: The other version 20 Emacs.
|
|
353 * XEmacs:: The continuation of Lucid Emacs.
|
|
354 @end menu
|
|
355
|
462
|
356 @node Through Version 18
|
428
|
357 @section Through Version 18
|
462
|
358 @cindex version 18, through
|
428
|
359 @cindex Gosling, James
|
|
360 @cindex Great Usenet Renaming
|
|
361
|
|
362 Although the history of the early versions of GNU Emacs is unclear,
|
|
363 the history is well-known from the middle of 1985. A time line is:
|
|
364
|
|
365 @itemize @bullet
|
|
366 @item
|
|
367 GNU Emacs version 15 (15.34) was released sometime in 1984 or 1985 and
|
|
368 shared some code with a version of Emacs written by James Gosling (the
|
|
369 same James Gosling who later created the Java language).
|
|
370 @item
|
|
371 GNU Emacs version 16 (first released version was 16.56) was released on
|
|
372 July 15, 1985. All Gosling code was removed due to potential copyright
|
|
373 problems with the code.
|
|
374 @item
|
|
375 version 16.57: released on September 16, 1985.
|
|
376 @item
|
|
377 versions 16.58, 16.59: released on September 17, 1985.
|
|
378 @item
|
|
379 version 16.60: released on September 19, 1985. These later version 16's
|
|
380 incorporated patches from the net, esp. for getting Emacs to work under
|
|
381 System V.
|
|
382 @item
|
|
383 version 17.36 (first official v17 release) released on December 20,
|
|
384 1985. Included a TeX-able user manual. First official unpatched
|
|
385 version that worked on vanilla System V machines.
|
|
386 @item
|
|
387 version 17.43 (second official v17 release) released on January 25,
|
|
388 1986.
|
|
389 @item
|
|
390 version 17.45 released on January 30, 1986.
|
|
391 @item
|
|
392 version 17.46 released on February 4, 1986.
|
|
393 @item
|
|
394 version 17.48 released on February 10, 1986.
|
|
395 @item
|
|
396 version 17.49 released on February 12, 1986.
|
|
397 @item
|
|
398 version 17.55 released on March 18, 1986.
|
|
399 @item
|
|
400 version 17.57 released on March 27, 1986.
|
|
401 @item
|
|
402 version 17.58 released on April 4, 1986.
|
|
403 @item
|
|
404 version 17.61 released on April 12, 1986.
|
|
405 @item
|
|
406 version 17.63 released on May 7, 1986.
|
|
407 @item
|
|
408 version 17.64 released on May 12, 1986.
|
|
409 @item
|
|
410 version 18.24 (a beta version) released on October 2, 1986.
|
|
411 @item
|
|
412 version 18.30 (a beta version) released on November 15, 1986.
|
|
413 @item
|
|
414 version 18.31 (a beta version) released on November 23, 1986.
|
|
415 @item
|
|
416 version 18.32 (a beta version) released on December 7, 1986.
|
|
417 @item
|
|
418 version 18.33 (a beta version) released on December 12, 1986.
|
|
419 @item
|
|
420 version 18.35 (a beta version) released on January 5, 1987.
|
|
421 @item
|
|
422 version 18.36 (a beta version) released on January 21, 1987.
|
|
423 @item
|
|
424 January 27, 1987: The Great Usenet Renaming. net.emacs is now
|
|
425 comp.emacs.
|
|
426 @item
|
|
427 version 18.37 (a beta version) released on February 12, 1987.
|
|
428 @item
|
|
429 version 18.38 (a beta version) released on March 3, 1987.
|
|
430 @item
|
|
431 version 18.39 (a beta version) released on March 14, 1987.
|
|
432 @item
|
|
433 version 18.40 (a beta version) released on March 18, 1987.
|
|
434 @item
|
|
435 version 18.41 (the first ``official'' release) released on March 22,
|
|
436 1987.
|
|
437 @item
|
|
438 version 18.45 released on June 2, 1987.
|
|
439 @item
|
|
440 version 18.46 released on June 9, 1987.
|
|
441 @item
|
|
442 version 18.47 released on June 18, 1987.
|
|
443 @item
|
|
444 version 18.48 released on September 3, 1987.
|
|
445 @item
|
|
446 version 18.49 released on September 18, 1987.
|
|
447 @item
|
|
448 version 18.50 released on February 13, 1988.
|
|
449 @item
|
|
450 version 18.51 released on May 7, 1988.
|
|
451 @item
|
|
452 version 18.52 released on September 1, 1988.
|
|
453 @item
|
|
454 version 18.53 released on February 24, 1989.
|
|
455 @item
|
|
456 version 18.54 released on April 26, 1989.
|
|
457 @item
|
|
458 version 18.55 released on August 23, 1989. This is the earliest version
|
|
459 that is still available by FTP.
|
|
460 @item
|
|
461 version 18.56 released on January 17, 1991.
|
|
462 @item
|
|
463 version 18.57 released late January, 1991.
|
|
464 @item
|
|
465 version 18.58 released ?????.
|
|
466 @item
|
|
467 version 18.59 released October 31, 1992.
|
|
468 @end itemize
|
|
469
|
462
|
470 @node Lucid Emacs
|
428
|
471 @section Lucid Emacs
|
|
472 @cindex Lucid Emacs
|
|
473 @cindex Lucid Inc.
|
|
474 @cindex Energize
|
|
475 @cindex Epoch
|
|
476
|
|
477 Lucid Emacs was developed by the (now-defunct) Lucid Inc., a maker of
|
|
478 C++ and Lisp development environments. It began when Lucid decided they
|
|
479 wanted to use Emacs as the editor and cornerstone of their C++
|
|
480 development environment (called ``Energize''). They needed many features
|
|
481 that were not available in the existing version of GNU Emacs (version
|
|
482 18.5something), in particular good and integrated support for GUI
|
|
483 elements such as mouse support, multiple fonts, multiple window-system
|
|
484 windows, etc. A branch of GNU Emacs called Epoch, written at the
|
|
485 University of Illinois, existed that supplied many of these features;
|
|
486 however, Lucid needed more than what existed in Epoch. At the time, the
|
|
487 Free Software Foundation was working on version 19 of Emacs (this was
|
|
488 sometime around 1991), which was planned to have similar features, and
|
|
489 so Lucid decided to work with the Free Software Foundation. Their plan
|
|
490 was to add features that they needed, and coordinate with the FSF so
|
|
491 that the features would get included back into Emacs version 19.
|
|
492
|
|
493 Delays in the release of version 19 occurred, however (resulting in it
|
|
494 finally being released more than a year after what was initially
|
|
495 planned), and Lucid encountered unexpected technical resistance in
|
|
496 getting their changes merged back into version 19, so they decided to
|
|
497 release their own version of Emacs, which became Lucid Emacs 19.0.
|
|
498
|
|
499 @cindex Zawinski, Jamie
|
|
500 @cindex Sexton, Harlan
|
|
501 @cindex Benson, Eric
|
|
502 @cindex Devin, Matthieu
|
|
503 The initial authors of Lucid Emacs were Matthieu Devin, Harlan Sexton,
|
|
504 and Eric Benson, and the work was later taken over by Jamie Zawinski,
|
|
505 who became ``Mr. Lucid Emacs'' for many releases.
|
|
506
|
464
|
507 A time line for Lucid Emacs is
|
428
|
508
|
|
509 @itemize @bullet
|
|
510 @item
|
|
511 version 19.0 shipped with Energize 1.0, April 1992.
|
|
512 @item
|
|
513 version 19.1 released June 4, 1992.
|
|
514 @item
|
|
515 version 19.2 released June 19, 1992.
|
|
516 @item
|
|
517 version 19.3 released September 9, 1992.
|
|
518 @item
|
|
519 version 19.4 released January 21, 1993.
|
|
520 @item
|
|
521 version 19.5 was a repackaging of 19.4 with a few bug fixes and
|
|
522 shipped with Energize 2.0. Never released to the net.
|
|
523 @item
|
|
524 version 19.6 released April 9, 1993.
|
|
525 @item
|
|
526 version 19.7 was a repackaging of 19.6 with a few bug fixes and
|
|
527 shipped with Energize 2.1. Never released to the net.
|
|
528 @item
|
|
529 version 19.8 released September 6, 1993.
|
|
530 @item
|
|
531 version 19.9 released January 12, 1994.
|
|
532 @item
|
|
533 version 19.10 released May 27, 1994.
|
|
534 @end itemize
|
|
535
|
462
|
536 @node GNU Emacs 19
|
428
|
537 @section GNU Emacs 19
|
|
538 @cindex GNU Emacs 19
|
462
|
539 @cindex Emacs 19, GNU
|
|
540 @cindex version 19, GNU Emacs
|
428
|
541 @cindex FSF Emacs
|
|
542
|
|
543 About a year after the initial release of Lucid Emacs, the FSF
|
|
544 released a beta of their version of Emacs 19 (referred to here as ``GNU
|
|
545 Emacs''). By this time, the current version of Lucid Emacs was
|
|
546 19.6. (Strangely, the first released beta from the FSF was GNU Emacs
|
|
547 19.7.) A time line for GNU Emacs version 19 is
|
|
548
|
|
549 @itemize @bullet
|
|
550 @item
|
|
551 version 19.8 (beta) released May 27, 1993.
|
|
552 @item
|
|
553 version 19.9 (beta) released May 27, 1993.
|
|
554 @item
|
|
555 version 19.10 (beta) released May 30, 1993.
|
|
556 @item
|
|
557 version 19.11 (beta) released June 1, 1993.
|
|
558 @item
|
|
559 version 19.12 (beta) released June 2, 1993.
|
|
560 @item
|
|
561 version 19.13 (beta) released June 8, 1993.
|
|
562 @item
|
|
563 version 19.14 (beta) released June 17, 1993.
|
|
564 @item
|
|
565 version 19.15 (beta) released June 19, 1993.
|
|
566 @item
|
|
567 version 19.16 (beta) released July 6, 1993.
|
|
568 @item
|
|
569 version 19.17 (beta) released late July, 1993.
|
|
570 @item
|
|
571 version 19.18 (beta) released August 9, 1993.
|
|
572 @item
|
|
573 version 19.19 (beta) released August 15, 1993.
|
|
574 @item
|
|
575 version 19.20 (beta) released November 17, 1993.
|
|
576 @item
|
|
577 version 19.21 (beta) released November 17, 1993.
|
|
578 @item
|
|
579 version 19.22 (beta) released November 28, 1993.
|
|
580 @item
|
|
581 version 19.23 (beta) released May 17, 1994.
|
|
582 @item
|
|
583 version 19.24 (beta) released May 16, 1994.
|
|
584 @item
|
|
585 version 19.25 (beta) released June 3, 1994.
|
|
586 @item
|
|
587 version 19.26 (beta) released September 11, 1994.
|
|
588 @item
|
|
589 version 19.27 (beta) released September 14, 1994.
|
|
590 @item
|
|
591 version 19.28 (first ``official'' release) released November 1, 1994.
|
|
592 @item
|
|
593 version 19.29 released June 21, 1995.
|
|
594 @item
|
|
595 version 19.30 released November 24, 1995.
|
|
596 @item
|
|
597 version 19.31 released May 25, 1996.
|
|
598 @item
|
|
599 version 19.32 released July 31, 1996.
|
|
600 @item
|
|
601 version 19.33 released August 11, 1996.
|
|
602 @item
|
|
603 version 19.34 released August 21, 1996.
|
|
604 @item
|
|
605 version 19.34b released September 6, 1996.
|
|
606 @end itemize
|
|
607
|
|
608 @cindex Mlynarik, Richard
|
|
609 In some ways, GNU Emacs 19 was better than Lucid Emacs; in some ways,
|
|
610 worse. Lucid soon began incorporating features from GNU Emacs 19 into
|
|
611 Lucid Emacs; the work was mostly done by Richard Mlynarik, who had been
|
|
612 working on and using GNU Emacs for a long time (back as far as version
|
|
613 16 or 17).
|
|
614
|
462
|
615 @node GNU Emacs 20
|
428
|
616 @section GNU Emacs 20
|
|
617 @cindex GNU Emacs 20
|
462
|
618 @cindex Emacs 20, GNU
|
|
619 @cindex version 20, GNU Emacs
|
428
|
620 @cindex FSF Emacs
|
|
621
|
|
622 On February 2, 1997 work began on GNU Emacs to integrate Mule. The first
|
|
623 release was made in September of that year.
|
|
624
|
|
625 A timeline for Emacs 20 is
|
|
626
|
|
627 @itemize @bullet
|
|
628 @item
|
|
629 version 20.1 released September 17, 1997.
|
|
630 @item
|
|
631 version 20.2 released September 20, 1997.
|
|
632 @item
|
|
633 version 20.3 released August 19, 1998.
|
|
634 @end itemize
|
|
635
|
462
|
636 @node XEmacs
|
428
|
637 @section XEmacs
|
|
638 @cindex XEmacs
|
|
639
|
|
640 @cindex Sun Microsystems
|
|
641 @cindex University of Illinois
|
|
642 @cindex Illinois, University of
|
|
643 @cindex SPARCWorks
|
|
644 @cindex Andreessen, Marc
|
|
645 @cindex Baur, Steve
|
|
646 @cindex Buchholz, Martin
|
|
647 @cindex Kaplan, Simon
|
|
648 @cindex Wing, Ben
|
|
649 @cindex Thompson, Chuck
|
|
650 @cindex Win-Emacs
|
|
651 @cindex Epoch
|
|
652 @cindex Amdahl Corporation
|
|
653 Around the time that Lucid was developing Energize, Sun Microsystems
|
|
654 was developing their own development environment (called ``SPARCWorks'')
|
|
655 and also decided to use Emacs. They joined forces with the Epoch team
|
|
656 at the University of Illinois and later with Lucid. The maintainer of
|
|
657 the last-released version of Epoch was Marc Andreessen, but he dropped
|
|
658 out and the Epoch project, headed by Simon Kaplan, lured Chuck Thompson
|
|
659 away from a system administration job to become the primary Lucid Emacs
|
|
660 author for Epoch and Sun. Chuck's area of specialty became the
|
|
661 redisplay engine (he replaced the old Lucid Emacs redisplay engine with
|
|
662 a ported version from Epoch and then later rewrote it from scratch).
|
|
663 Sun also hired Ben Wing (the author of Win-Emacs, a port of Lucid Emacs
|
|
664 to Microsoft Windows 3.1) in 1993, for what was initially a one-month
|
|
665 contract to fix some event problems but later became a many-year
|
|
666 involvement, punctuated by a six-month contract with Amdahl Corporation.
|
|
667
|
|
668 @cindex rename to XEmacs
|
|
669 In 1994, Sun and Lucid agreed to rename Lucid Emacs to XEmacs (a name
|
|
670 not favorable to either company); the first release called XEmacs was
|
|
671 version 19.11. In June 1994, Lucid folded and Jamie quit to work for
|
|
672 the newly formed Mosaic Communications Corp., later Netscape
|
|
673 Communications Corp. (co-founded by the same Marc Andreessen, who had
|
|
674 quit his Epoch job to work on a graphical browser for the World Wide
|
|
675 Web). Chuck then become the primary maintainer of XEmacs, and put out
|
|
676 versions 19.11 through 19.14 in conjunction with Ben. For 19.12 and
|
|
677 19.13, Chuck added the new redisplay and many other display improvements
|
|
678 and Ben added MULE support (support for Asian and other languages) and
|
|
679 redesigned most of the internal Lisp subsystems to better support the
|
|
680 MULE work and the various other features being added to XEmacs. After
|
|
681 19.14 Chuck retired as primary maintainer and Steve Baur stepped in.
|
|
682
|
|
683 @cindex MULE merged XEmacs appears
|
|
684 Soon after 19.13 was released, work began in earnest on the MULE
|
|
685 internationalization code and the source tree was divided into two
|
|
686 development paths. The MULE version was initially called 19.20, but was
|
|
687 soon renamed to 20.0. In 1996 Martin Buchholz of Sun Microsystems took
|
|
688 over the care and feeding of it and worked on it in parallel with the
|
|
689 19.14 development that was occurring at the same time. After much work
|
|
690 by Martin, it was decided to release 20.0 ahead of 19.15 in February
|
|
691 1997. The source tree remained divided until 20.2 when the version 19
|
|
692 source was finally retired at version 19.16.
|
|
693
|
|
694 @cindex Baur, Steve
|
|
695 @cindex Buchholz, Martin
|
|
696 @cindex Jones, Kyle
|
|
697 @cindex Niksic, Hrvoje
|
|
698 @cindex XEmacs goes it alone
|
|
699 In 1997, Sun finally dropped all pretense of support for XEmacs and
|
|
700 Martin Buchholz left the company in November. Since then, and mostly
|
|
701 for the previous year, because Steve Baur was never paid to work on
|
|
702 XEmacs, XEmacs has existed solely on the contributions of volunteers
|
|
703 from the Free Software Community. Starting from 1997, Hrvoje Niksic and
|
|
704 Kyle Jones have figured prominently in XEmacs development.
|
|
705
|
|
706 @cindex merging attempts
|
|
707 Many attempts have been made to merge XEmacs and GNU Emacs, but they
|
|
708 have consistently failed.
|
|
709
|
|
710 A more detailed history is contained in the XEmacs About page.
|
|
711
|
464
|
712 A time line for XEmacs is
|
|
713
|
|
714 @itemize @bullet
|
|
715 @item
|
|
716 version 19.11 (first XEmacs) released September 13, 1994.
|
|
717 @item
|
|
718 version 19.12 released June 23, 1995.
|
|
719 @item
|
|
720 version 19.13 released September 1, 1995.
|
|
721 @item
|
|
722 version 19.14 released June 23, 1996.
|
|
723 @item
|
|
724 version 20.0 released February 9, 1997.
|
|
725 @item
|
|
726 version 19.15 released March 28, 1997.
|
|
727 @item
|
|
728 version 20.1 (not released to the net) April 15, 1997.
|
|
729 @item
|
|
730 version 20.2 released May 16, 1997.
|
|
731 @item
|
|
732 version 19.16 released October 31, 1997.
|
|
733 @item
|
|
734 version 20.3 (the first stable version of XEmacs 20.x) released November 30,
|
|
735 1997.
|
|
736 @item
|
|
737 version 20.4 released February 28, 1998.
|
|
738 @item
|
|
739 version 21.0.60 released December 10, 1998. (The version naming scheme was
|
|
740 changed at this point: [a] the second version number is odd for stable
|
|
741 versions, even for beta versions; [b] a third version number is added,
|
|
742 replacing the "beta xxx" ending for beta versions and allowing for
|
|
743 periodic maintenance releases for stable versions. Therefore, 21.0 was
|
|
744 never "officially" released; similarly for 21.2, etc.)
|
|
745 @item
|
|
746 version 21.0.61 released January 4, 1999.
|
|
747 @item
|
|
748 version 21.0.63 released February 3, 1999.
|
|
749 @item
|
|
750 version 21.0.64 released March 1, 1999.
|
|
751 @item
|
|
752 version 21.0.65 released March 5, 1999.
|
|
753 @item
|
|
754 version 21.0.66 released March 12, 1999.
|
|
755 @item
|
|
756 version 21.0.67 released March 25, 1999.
|
|
757 @item
|
|
758 version 21.1.2 released May 14, 1999. (This is the followup to 21.0.67.
|
|
759 The second version number was bumped to indicate the beginning of the
|
|
760 "stable" series.)
|
|
761 @item
|
|
762 version 21.1.3 released June 26, 1999.
|
|
763 @item
|
|
764 version 21.1.4 released July 8, 1999.
|
|
765 @item
|
|
766 version 21.1.6 released August 14, 1999. (There was no 21.1.5.)
|
|
767 @item
|
|
768 version 21.1.7 released September 26, 1999.
|
|
769 @item
|
|
770 version 21.1.8 released November 2, 1999.
|
|
771 @item
|
|
772 version 21.1.9 released February 13, 2000.
|
|
773 @item
|
|
774 version 21.1.10 released May 7, 2000.
|
|
775 @item
|
|
776 version 21.1.10a released June 24, 2000.
|
|
777 @item
|
|
778 version 21.1.11 released July 18, 2000.
|
|
779 @item
|
|
780 version 21.1.12 released August 5, 2000.
|
|
781 @item
|
|
782 version 21.1.13 released January 7, 2001.
|
|
783 @item
|
|
784 version 21.1.14 released January 27, 2001.
|
|
785 @item
|
|
786 version 21.2.9 released February 3, 1999.
|
|
787 @item
|
|
788 version 21.2.10 released February 5, 1999.
|
|
789 @item
|
|
790 version 21.2.11 released March 1, 1999.
|
|
791 @item
|
|
792 version 21.2.12 released March 5, 1999.
|
|
793 @item
|
|
794 version 21.2.13 released March 12, 1999.
|
|
795 @item
|
|
796 version 21.2.14 released May 14, 1999.
|
|
797 @item
|
|
798 version 21.2.15 released June 4, 1999.
|
|
799 @item
|
|
800 version 21.2.16 released June 11, 1999.
|
|
801 @item
|
|
802 version 21.2.17 released June 22, 1999.
|
|
803 @item
|
|
804 version 21.2.18 released July 14, 1999.
|
|
805 @item
|
|
806 version 21.2.19 released July 30, 1999.
|
|
807 @item
|
|
808 version 21.2.20 released November 10, 1999.
|
|
809 @item
|
|
810 version 21.2.21 released November 28, 1999.
|
|
811 @item
|
|
812 version 21.2.22 released November 29, 1999.
|
|
813 @item
|
|
814 version 21.2.23 released December 7, 1999.
|
|
815 @item
|
|
816 version 21.2.24 released December 14, 1999.
|
|
817 @item
|
|
818 version 21.2.25 released December 24, 1999.
|
|
819 @item
|
|
820 version 21.2.26 released December 31, 1999.
|
|
821 @item
|
|
822 version 21.2.27 released January 18, 2000.
|
|
823 @item
|
|
824 version 21.2.28 released February 7, 2000.
|
|
825 @item
|
|
826 version 21.2.29 released February 16, 2000.
|
|
827 @item
|
|
828 version 21.2.30 released February 21, 2000.
|
|
829 @item
|
|
830 version 21.2.31 released February 23, 2000.
|
|
831 @item
|
|
832 version 21.2.32 released March 20, 2000.
|
|
833 @item
|
|
834 version 21.2.33 released May 1, 2000.
|
|
835 @item
|
|
836 version 21.2.34 released May 28, 2000.
|
|
837 @item
|
|
838 version 21.2.35 released July 19, 2000.
|
|
839 @item
|
|
840 version 21.2.36 released October 4, 2000.
|
|
841 @item
|
|
842 version 21.2.37 released November 14, 2000.
|
|
843 @item
|
|
844 version 21.2.38 released December 5, 2000.
|
|
845 @item
|
|
846 version 21.2.39 released December 31, 2000.
|
|
847 @item
|
|
848 version 21.2.40 released January 8, 2001.
|
|
849 @item
|
|
850 version 21.2.41 released January 17, 2001.
|
|
851 @item
|
|
852 version 21.2.42 released January 20, 2001.
|
|
853 @item
|
|
854 version 21.2.43 released January 26, 2001.
|
|
855 @item
|
|
856 version 21.2.44 released February 8, 2001.
|
|
857 @item
|
|
858 version 21.2.45 released February 23, 2001.
|
|
859 @item
|
|
860 version 21.2.46 released March 21, 2001.
|
|
861 @end itemize
|
|
862
|
428
|
863 @node XEmacs From the Outside, The Lisp Language, A History of Emacs, Top
|
|
864 @chapter XEmacs From the Outside
|
462
|
865 @cindex XEmacs from the outside
|
|
866 @cindex outside, XEmacs from the
|
428
|
867 @cindex read-eval-print
|
|
868
|
|
869 XEmacs appears to the outside world as an editor, but it is really a
|
|
870 Lisp environment. At its heart is a Lisp interpreter; it also
|
|
871 ``happens'' to contain many specialized object types (e.g. buffers,
|
|
872 windows, frames, events) that are useful for implementing an editor.
|
|
873 Some of these objects (in particular windows and frames) have
|
|
874 displayable representations, and XEmacs provides a function
|
|
875 @code{redisplay()} that ensures that the display of all such objects
|
|
876 matches their internal state. Most of the time, a standard Lisp
|
440
|
877 environment is in a @dfn{read-eval-print} loop---i.e. ``read some Lisp
|
428
|
878 code, execute it, and print the results''. XEmacs has a similar loop:
|
|
879
|
|
880 @itemize @bullet
|
|
881 @item
|
|
882 read an event
|
|
883 @item
|
|
884 dispatch the event (i.e. ``do it'')
|
|
885 @item
|
|
886 redisplay
|
|
887 @end itemize
|
|
888
|
|
889 Reading an event is done using the Lisp function @code{next-event},
|
|
890 which waits for something to happen (typically, the user presses a key
|
|
891 or moves the mouse) and returns an event object describing this.
|
|
892 Dispatching an event is done using the Lisp function
|
|
893 @code{dispatch-event}, which looks up the event in a keymap object (a
|
|
894 particular kind of object that associates an event with a Lisp function)
|
|
895 and calls that function. The function ``does'' what the user has
|
|
896 requested by changing the state of particular frame objects, buffer
|
|
897 objects, etc. Finally, @code{redisplay()} is called, which updates the
|
|
898 display to reflect those changes just made. Thus is an ``editor'' born.
|
|
899
|
|
900 @cindex bridge, playing
|
|
901 @cindex taxes, doing
|
|
902 @cindex pi, calculating
|
|
903 Note that you do not have to use XEmacs as an editor; you could just
|
|
904 as well make it do your taxes, compute pi, play bridge, etc. You'd just
|
|
905 have to write functions to do those operations in Lisp.
|
|
906
|
|
907 @node The Lisp Language, XEmacs From the Perspective of Building, XEmacs From the Outside, Top
|
|
908 @chapter The Lisp Language
|
462
|
909 @cindex Lisp language, the
|
428
|
910 @cindex Lisp vs. C
|
|
911 @cindex C vs. Lisp
|
|
912 @cindex Lisp vs. Java
|
|
913 @cindex Java vs. Lisp
|
|
914 @cindex dynamic scoping
|
|
915 @cindex scoping, dynamic
|
|
916 @cindex dynamic types
|
|
917 @cindex types, dynamic
|
|
918 @cindex Java
|
|
919 @cindex Common Lisp
|
|
920 @cindex Gosling, James
|
|
921
|
|
922 Lisp is a general-purpose language that is higher-level than C and in
|
|
923 many ways more powerful than C. Powerful dialects of Lisp such as
|
|
924 Common Lisp are probably much better languages for writing very large
|
|
925 applications than is C. (Unfortunately, for many non-technical
|
|
926 reasons C and its successor C++ have become the dominant languages for
|
|
927 application development. These languages are both inadequate for
|
|
928 extremely large applications, which is evidenced by the fact that newer,
|
|
929 larger programs are becoming ever harder to write and are requiring ever
|
|
930 more programmers despite great increases in C development environments;
|
|
931 and by the fact that, although hardware speeds and reliability have been
|
|
932 growing at an exponential rate, most software is still generally
|
|
933 considered to be slow and buggy.)
|
|
934
|
|
935 The new Java language holds promise as a better general-purpose
|
|
936 development language than C. Java has many features in common with
|
|
937 Lisp that are not shared by C (this is not a coincidence, since
|
|
938 Java was designed by James Gosling, a former Lisp hacker). This
|
|
939 will be discussed more later.
|
|
940
|
|
941 For those used to C, here is a summary of the basic differences between
|
|
942 C and Lisp:
|
|
943
|
|
944 @enumerate
|
|
945 @item
|
|
946 Lisp has an extremely regular syntax. Every function, expression,
|
|
947 and control statement is written in the form
|
|
948
|
|
949 @example
|
|
950 (@var{func} @var{arg1} @var{arg2} ...)
|
|
951 @end example
|
|
952
|
|
953 This is as opposed to C, which writes functions as
|
|
954
|
|
955 @example
|
|
956 func(@var{arg1}, @var{arg2}, ...)
|
|
957 @end example
|
|
958
|
|
959 but writes expressions involving operators as (e.g.)
|
|
960
|
|
961 @example
|
|
962 @var{arg1} + @var{arg2}
|
|
963 @end example
|
|
964
|
|
965 and writes control statements as (e.g.)
|
|
966
|
|
967 @example
|
|
968 while (@var{expr}) @{ @var{statement1}; @var{statement2}; ... @}
|
|
969 @end example
|
|
970
|
|
971 Lisp equivalents of the latter two would be
|
|
972
|
|
973 @example
|
|
974 (+ @var{arg1} @var{arg2} ...)
|
|
975 @end example
|
|
976
|
|
977 and
|
|
978
|
|
979 @example
|
|
980 (while @var{expr} @var{statement1} @var{statement2} ...)
|
|
981 @end example
|
|
982
|
|
983 @item
|
|
984 Lisp is a safe language. Assuming there are no bugs in the Lisp
|
|
985 interpreter/compiler, it is impossible to write a program that ``core
|
|
986 dumps'' or otherwise causes the machine to execute an illegal
|
|
987 instruction. This is very different from C, where perhaps the most
|
|
988 common outcome of a bug is exactly such a crash. A corollary of this is that
|
|
989 the C operation of casting a pointer is impossible (and unnecessary) in
|
|
990 Lisp, and that it is impossible to access memory outside the bounds of
|
|
991 an array.
|
|
992
|
|
993 @item
|
|
994 Programs and data are written in the same form. The
|
|
995 parenthesis-enclosing form described above for statements is the same
|
|
996 form used for the most common data type in Lisp, the list. Thus, it is
|
|
997 possible to represent any Lisp program using Lisp data types, and for
|
|
998 one program to construct Lisp statements and then dynamically
|
|
999 @dfn{evaluate} them, or cause them to execute.
|
|
1000
|
|
1001 @item
|
|
1002 All objects are @dfn{dynamically typed}. This means that part of every
|
|
1003 object is an indication of what type it is. A Lisp program can
|
|
1004 manipulate an object without knowing what type it is, and can query an
|
|
1005 object to determine its type. This means that, correspondingly,
|
|
1006 variables and function parameters can hold objects of any type and are
|
|
1007 not normally declared as being of any particular type. This is opposed
|
|
1008 to the @dfn{static typing} of C, where variables can hold exactly one
|
|
1009 type of object and must be declared as such, and objects do not contain
|
|
1010 an indication of their type because it's implicit in the variables they
|
|
1011 are stored in. It is possible in C to have a variable hold different
|
|
1012 types of objects (e.g. through the use of @code{void *} pointers or
|
|
1013 variable-argument functions), but the type information must then be
|
|
1014 passed explicitly in some other fashion, leading to additional program
|
|
1015 complexity.
|
|
1016
|
|
1017 @item
|
|
1018 Allocated memory is automatically reclaimed when it is no longer in use.
|
|
1019 This operation is called @dfn{garbage collection} and involves looking
|
|
1020 through all variables to see what memory is being pointed to, and
|
|
1021 reclaiming any memory that is not pointed to and is thus
|
|
1022 ``inaccessible'' and out of use. This is as opposed to C, in which
|
|
1023 allocated memory must be explicitly reclaimed using @code{free()}. If
|
|
1024 you simply drop all pointers to memory without freeing it, it becomes
|
|
1025 ``leaked'' memory that still takes up space. Over a long period of
|
|
1026 time, this can cause your program to grow and grow until it runs out of
|
|
1027 memory.
|
|
1028
|
|
1029 @item
|
|
1030 Lisp has built-in facilities for handling errors and exceptions. In C,
|
|
1031 when an error occurs, usually either the program exits entirely or the
|
|
1032 routine in which the error occurs returns a value indicating this. If
|
|
1033 an error occurs in a deeply-nested routine, then every routine currently
|
|
1034 called must unwind itself normally and return an error value back up to
|
|
1035 the next routine. This means that every routine must explicitly check
|
|
1036 for an error in all the routines it calls; if it does not do so,
|
|
1037 unexpected and often random behavior results. This is an extremely
|
|
1038 common source of bugs in C programs. An alternative would be to do a
|
|
1039 non-local exit using @code{longjmp()}, but that is often very dangerous
|
|
1040 because the routines that were exited past had no opportunity to clean
|
|
1041 up after themselves and may leave things in an inconsistent state,
|
|
1042 causing a crash shortly afterwards.
|
|
1043
|
|
1044 Lisp provides mechanisms to make such non-local exits safe. When an
|
|
1045 error occurs, a routine simply signals that an error of a particular
|
|
1046 class has occurred, and a non-local exit takes place. Any routine can
|
|
1047 trap errors occurring in routines it calls by registering an error
|
|
1048 handler for some or all classes of errors. (If no handler is registered,
|
|
1049 a default handler, generally installed by the top-level event loop, is
|
|
1050 executed; this prints out the error and continues.) Routines can also
|
|
1051 specify cleanup code (called an @dfn{unwind-protect}) that will be
|
|
1052 called when control exits from a block of code, no matter how that exit
|
440
|
1053 occurs---i.e. even if a function deeply nested below it causes a
|
428
|
1054 non-local exit back to the top level.
|
|
1055
|
|
1056 Note that this facility has appeared in some recent vintages of C, in
|
|
1057 particular Visual C++ and other PC compilers written for the Microsoft
|
|
1058 Win32 API.
|
|
1059
|
|
1060 @item
|
|
1061 In Emacs Lisp, local variables are @dfn{dynamically scoped}. This means
|
|
1062 that if you declare a local variable in a particular function, and then
|
|
1063 call another function, that subfunction can ``see'' the local variable
|
|
1064 you declared. This is actually considered a bug in Emacs Lisp and in
|
|
1065 all other early dialects of Lisp, and was corrected in Common Lisp. (In
|
|
1066 Common Lisp, you can still declare dynamically scoped variables if you
|
440
|
1067 want to---they are sometimes useful---but variables by default are
|
428
|
1068 @dfn{lexically scoped} as in C.)
|
|
1069 @end enumerate
|
|
1070
|
|
1071 For those familiar with Lisp, Emacs Lisp is modelled after MacLisp, an
|
|
1072 early dialect of Lisp developed at MIT (no relation to the Macintosh
|
|
1073 computer). There is a Common Lisp compatibility package available for
|
|
1074 Emacs that provides many of the features of Common Lisp.
|
|
1075
|
|
1076 The Java language is derived in many ways from C, and shares a similar
|
|
1077 syntax, but has the following features in common with Lisp (and different
|
|
1078 from C):
|
|
1079
|
|
1080 @enumerate
|
|
1081 @item
|
|
1082 Java is a safe language, like Lisp.
|
|
1083 @item
|
|
1084 Java provides garbage collection, like Lisp.
|
|
1085 @item
|
|
1086 Java has built-in facilities for handling errors and exceptions, like
|
|
1087 Lisp.
|
|
1088 @item
|
|
1089 Java has a type system that combines the best advantages of both static
|
|
1090 and dynamic typing. Objects (except very simple types) are explicitly
|
|
1091 marked with their type, as in dynamic typing; but there is a hierarchy
|
|
1092 of types and functions are declared to accept only certain types, thus
|
|
1093 providing the increased compile-time error-checking of static typing.
|
|
1094 @end enumerate
|
|
1095
|
|
1096 The Java language also has some negative attributes:
|
|
1097
|
|
1098 @enumerate
|
|
1099 @item
|
|
1100 Java uses the edit/compile/run model of software development. This
|
|
1101 makes it hard to use interactively. For example, to use Java like
|
|
1102 @code{bc} it is necessary to write a special purpose, albeit tiny,
|
|
1103 application. In Emacs Lisp, a calculator comes built-in without any
|
|
1104 effort - one can always just type an expression in the @code{*scratch*}
|
|
1105 buffer.
|
|
1106 @item
|
|
1107 Java tries too hard to enforce, not merely enable, portability, making
|
|
1108 ordinary access to standard OS facilities painful. Java has an
|
|
1109 @dfn{agenda}. I think this is why @code{chdir} is not part of standard
|
|
1110 Java, which is inexcusable.
|
|
1111 @end enumerate
|
|
1112
|
|
1113 Unfortunately, there is no perfect language. Static typing allows a
|
|
1114 compiler to catch programmer errors and produce more efficient code, but
|
442
|
1115 makes programming more tedious and less fun. For the foreseeable future,
|
428
|
1116 an Ideal Editing and Programming Environment (and that is what XEmacs
|
|
1117 aspires to) will be programmable in multiple languages: high level ones
|
|
1118 like Lisp for user customization and prototyping, and lower level ones
|
|
1119 for infrastructure and industrial strength applications. If I had my
|
|
1120 way, XEmacs would be friendly towards the Python, Scheme, C++, ML,
|
|
1121 etc... communities. But there are serious technical difficulties to
|
|
1122 achieving that goal.
|
|
1123
|
|
1124 The word @dfn{application} in the previous paragraph was used
|
|
1125 intentionally. XEmacs implements an API for programs written in Lisp
|
|
1126 that makes it a full-fledged application platform, very much like an OS
|
|
1127 inside the real OS.
|
|
1128
|
|
1129 @node XEmacs From the Perspective of Building, XEmacs From the Inside, The Lisp Language, Top
|
|
1130 @chapter XEmacs From the Perspective of Building
|
462
|
1131 @cindex XEmacs from the perspective of building
|
|
1132 @cindex building, XEmacs from the perspective of
|
428
|
1133
|
|
1134 The heart of XEmacs is the Lisp environment, which is written in C.
|
|
1135 This is contained in the @file{src/} subdirectory. Underneath
|
|
1136 @file{src/} are two subdirectories of header files: @file{s/} (header
|
|
1137 files for particular operating systems) and @file{m/} (header files for
|
|
1138 particular machine types). In practice the distinction between the two
|
|
1139 types of header files is blurred. These header files define or undefine
|
|
1140 certain preprocessor constants and macros to indicate particular
|
|
1141 characteristics of the associated machine or operating system. As part
|
|
1142 of the configure process, one @file{s/} file and one @file{m/} file is
|
|
1143 identified for the particular environment in which XEmacs is being
|
|
1144 built.
|
|
1145
|
|
1146 XEmacs also contains a great deal of Lisp code. This implements the
|
|
1147 operations that make XEmacs useful as an editor as well as just a Lisp
|
|
1148 environment, and also contains many add-on packages that allow XEmacs to
|
|
1149 browse directories, act as a mail and Usenet news reader, compile Lisp
|
|
1150 code, etc. There is actually more Lisp code than C code associated with
|
|
1151 XEmacs, but much of the Lisp code is peripheral to the actual operation
|
|
1152 of the editor. The Lisp code all lies in subdirectories underneath the
|
|
1153 @file{lisp/} directory.
|
|
1154
|
|
1155 The @file{lwlib/} directory contains C code that implements a
|
|
1156 generalized interface onto different X widget toolkits and also
|
|
1157 implements some widgets of its own that behave like Motif widgets but
|
|
1158 are faster, free, and in some cases more powerful. The code in this
|
|
1159 directory compiles into a library and is mostly independent from XEmacs.
|
|
1160
|
|
1161 The @file{etc/} directory contains various data files associated with
|
|
1162 XEmacs. Some of them are actually read by XEmacs at startup; others
|
|
1163 merely contain useful information of various sorts.
|
|
1164
|
|
1165 The @file{lib-src/} directory contains C code for various auxiliary
|
|
1166 programs that are used in connection with XEmacs. Some of them are used
|
|
1167 during the build process; others are used to perform certain functions
|
|
1168 that cannot conveniently be placed in the XEmacs executable (e.g. the
|
|
1169 @file{movemail} program for fetching mail out of @file{/var/spool/mail},
|
|
1170 which must be setgid to @file{mail} on many systems; and the
|
|
1171 @file{gnuclient} program, which allows an external script to communicate
|
|
1172 with a running XEmacs process).
|
|
1173
|
|
1174 The @file{man/} directory contains the sources for the XEmacs
|
|
1175 documentation. It is mostly in a form called Texinfo, which can be
|
|
1176 converted into either a printed document (by passing it through @TeX{})
|
|
1177 or into on-line documentation called @dfn{info files}.
|
|
1178
|
|
1179 The @file{info/} directory contains the results of formatting the XEmacs
|
|
1180 documentation as @dfn{info files}, for on-line use. These files are
|
|
1181 used when you enter the Info system using @kbd{C-h i} or through the
|
|
1182 Help menu.
|
|
1183
|
|
1184 The @file{dynodump/} directory contains auxiliary code used to build
|
|
1185 XEmacs on Solaris platforms.
|
|
1186
|
|
1187 The other directories contain various miscellaneous code and information
|
|
1188 that is not normally used or needed.
|
|
1189
|
|
1190 The first step of building involves running the @file{configure} program
|
|
1191 and passing it various parameters to specify any optional features you
|
|
1192 want and compiler arguments and such, as described in the @file{INSTALL}
|
|
1193 file. This determines what the build environment is, chooses the
|
|
1194 appropriate @file{s/} and @file{m/} file, and runs a series of tests to
|
|
1195 determine many details about your environment, such as which library
|
|
1196 functions are available and exactly how they work. The reason for
|
|
1197 running these tests is that it allows XEmacs to be compiled on a much
|
|
1198 wider variety of platforms than those that the XEmacs developers happen
|
|
1199 to be familiar with, including various sorts of hybrid platforms. This
|
|
1200 is especially important now that many operating systems give you a great
|
|
1201 deal of control over exactly what features you want installed, and allow
|
|
1202 for easy upgrading of parts of a system without upgrading the rest. It
|
|
1203 would be impossible to pre-determine and pre-specify the information for
|
|
1204 all possible configurations.
|
|
1205
|
|
1206 In fact, the @file{s/} and @file{m/} files are basically @emph{evil},
|
|
1207 since they contain unmaintainable platform-specific hard-coded
|
|
1208 information. XEmacs has been moving in the direction of having all
|
|
1209 system-specific information be determined dynamically by
|
|
1210 @file{configure}. Perhaps someday we can @code{rm -rf src/s src/m}.
|
|
1211
|
|
1212 When configure is done running, it generates @file{Makefile}s and
|
|
1213 @file{GNUmakefile}s and the file @file{src/config.h} (which describes
|
|
1214 the features of your system) from template files. You then run
|
|
1215 @file{make}, which compiles the auxiliary code and programs in
|
|
1216 @file{lib-src/} and @file{lwlib/} and the main XEmacs executable in
|
|
1217 @file{src/}. The result of compiling and linking is an executable
|
|
1218 called @file{temacs}, which is @emph{not} the final XEmacs executable.
|
|
1219 @file{temacs} by itself is not intended to function as an editor or even
|
|
1220 display any windows on the screen, and if you simply run it, it will
|
|
1221 exit immediately. The @file{Makefile} runs @file{temacs} with certain
|
|
1222 options that cause it to initialize itself, read in a number of basic
|
|
1223 Lisp files, and then dump itself out into a new executable called
|
|
1224 @file{xemacs}. This new executable has been pre-initialized and
|
|
1225 contains pre-digested Lisp code that is necessary for the editor to
|
|
1226 function (this includes most basic editing functions,
|
|
1227 e.g. @code{kill-line}, that can be defined in terms of other Lisp
|
|
1228 primitives; some initialization code that is called when certain
|
|
1229 objects, such as frames, are created; and all of the standard
|
|
1230 keybindings and code for the actions they result in). This executable,
|
|
1231 @file{xemacs}, is the executable that you run to use the XEmacs editor.
|
|
1232
|
|
1233 Although @file{temacs} is not intended to be run as an editor, it can,
|
|
1234 by using the incantation @code{temacs -batch -l loadup.el run-temacs}.
|
|
1235 This is useful when the dumping procedure described above is broken, or
|
|
1236 when using certain program debugging tools such as Purify. These tools
|
|
1237 get mighty confused by the tricks played by the XEmacs build process,
|
|
1238 such as allocation memory in one process, and freeing it in the next.
|
|
1239
|
|
1240 @node XEmacs From the Inside, The XEmacs Object System (Abstractly Speaking), XEmacs From the Perspective of Building, Top
|
|
1241 @chapter XEmacs From the Inside
|
462
|
1242 @cindex XEmacs from the inside
|
|
1243 @cindex inside, XEmacs from the
|
428
|
1244
|
|
1245 Internally, XEmacs is quite complex, and can be very confusing. To
|
|
1246 simplify things, it can be useful to think of XEmacs as containing an
|
|
1247 event loop that ``drives'' everything, and a number of other subsystems,
|
|
1248 such as a Lisp engine and a redisplay mechanism. Each of these other
|
|
1249 subsystems exists simultaneously in XEmacs, and each has a certain
|
|
1250 state. The flow of control continually passes in and out of these
|
|
1251 different subsystems in the course of normal operation of the editor.
|
|
1252
|
|
1253 It is important to keep in mind that, most of the time, the editor is
|
|
1254 ``driven'' by the event loop. Except during initialization and batch
|
|
1255 mode, all subsystems are entered directly or indirectly through the
|
|
1256 event loop, and ultimately, control exits out of all subsystems back up
|
|
1257 to the event loop. This cycle of entering a subsystem, exiting back out
|
|
1258 to the event loop, and starting another iteration of the event loop
|
|
1259 occurs once each keystroke, mouse motion, etc.
|
|
1260
|
|
1261 If you're trying to understand a particular subsystem (other than the
|
|
1262 event loop), think of it as a ``daemon'' process or ``servant'' that is
|
|
1263 responsible for one particular aspect of a larger system, and
|
|
1264 periodically receives commands or environment changes that cause it to
|
|
1265 do something. Ultimately, these commands and environment changes are
|
|
1266 always triggered by the event loop. For example:
|
|
1267
|
|
1268 @itemize @bullet
|
|
1269 @item
|
|
1270 The window and frame mechanism is responsible for keeping track of what
|
|
1271 windows and frames exist, what buffers are in them, etc. It is
|
|
1272 periodically given commands (usually from the user) to make a change to
|
|
1273 the current window/frame state: i.e. create a new frame, delete a
|
|
1274 window, etc.
|
|
1275
|
|
1276 @item
|
|
1277 The buffer mechanism is responsible for keeping track of what buffers
|
|
1278 exist and what text is in them. It is periodically given commands
|
|
1279 (usually from the user) to insert or delete text, create a buffer, etc.
|
|
1280 When it receives a text-change command, it notifies the redisplay
|
|
1281 mechanism.
|
|
1282
|
|
1283 @item
|
|
1284 The redisplay mechanism is responsible for making sure that windows and
|
|
1285 frames are displayed correctly. It is periodically told (by the event
|
|
1286 loop) to actually ``do its job'', i.e. snoop around and see what the
|
|
1287 current state of the environment (mostly of the currently-existing
|
625
|
1288 windows, frames, and buffers) is, and make sure that state matches
|
428
|
1289 what's actually displayed. It keeps lots and lots of information around
|
|
1290 (such as what is actually being displayed currently, and what the
|
|
1291 environment was last time it checked) so that it can minimize the work
|
|
1292 it has to do. It is also helped along in that whenever a relevant
|
|
1293 change to the environment occurs, the redisplay mechanism is told about
|
|
1294 this, so it has a pretty good idea of where it has to look to find
|
|
1295 possible changes and doesn't have to look everywhere.
|
|
1296
|
|
1297 @item
|
|
1298 The Lisp engine is responsible for executing the Lisp code in which most
|
|
1299 user commands are written. It is entered through a call to @code{eval}
|
|
1300 or @code{funcall}, which occurs as a result of dispatching an event from
|
|
1301 the event loop. The functions it calls issue commands to the buffer
|
|
1302 mechanism, the window/frame subsystem, etc.
|
|
1303
|
|
1304 @item
|
|
1305 The Lisp allocation subsystem is responsible for keeping track of Lisp
|
|
1306 objects. It is given commands from the Lisp engine to allocate objects,
|
|
1307 garbage collect, etc.
|
|
1308 @end itemize
|
|
1309
|
|
1310 etc.
|
|
1311
|
|
1312 The important idea here is that there are a number of independent
|
|
1313 subsystems each with its own responsibility and persistent state, just
|
|
1314 like different employees in a company, and each subsystem is
|
|
1315 periodically given commands from other subsystems. Commands can flow
|
|
1316 from any one subsystem to any other, but there is usually some sort of
|
|
1317 hierarchy, with all commands originating from the event subsystem.
|
|
1318
|
|
1319 XEmacs is entered in @code{main()}, which is in @file{emacs.c}. When
|
|
1320 this is called the first time (in a properly-invoked @file{temacs}), it
|
|
1321 does the following:
|
|
1322
|
|
1323 @enumerate
|
|
1324 @item
|
|
1325 It does some very basic environment initializations, such as determining
|
|
1326 where it and its directories (e.g. @file{lisp/} and @file{etc/}) reside
|
|
1327 and setting up signal handlers.
|
|
1328 @item
|
|
1329 It initializes the entire Lisp interpreter.
|
|
1330 @item
|
|
1331 It sets the initial values of many built-in variables (including many
|
|
1332 variables that are visible to Lisp programs), such as the global keymap
|
|
1333 object and the built-in faces (a face is an object that describes the
|
|
1334 display characteristics of text). This involves creating Lisp objects
|
|
1335 and thus is dependent on step (2).
|
|
1336 @item
|
|
1337 It performs various other initializations that are relevant to the
|
|
1338 particular environment it is running in, such as retrieving environment
|
|
1339 variables, determining the current date and the user who is running the
|
|
1340 program, examining its standard input, creating any necessary file
|
|
1341 descriptors, etc.
|
|
1342 @item
|
|
1343 At this point, the C initialization is complete. A Lisp program that
|
|
1344 was specified on the command line (usually @file{loadup.el}) is called
|
|
1345 (temacs is normally invoked as @code{temacs -batch -l loadup.el dump}).
|
|
1346 @file{loadup.el} loads all of the other Lisp files that are needed for
|
|
1347 the operation of the editor, calls the @code{dump-emacs} function to
|
|
1348 write out @file{xemacs}, and then kills the temacs process.
|
|
1349 @end enumerate
|
|
1350
|
|
1351 When @file{xemacs} is then run, it only redoes steps (1) and (4)
|
|
1352 above; all variables already contain the values they were set to when
|
|
1353 the executable was dumped, and all memory that was allocated with
|
|
1354 @code{malloc()} is still around. (XEmacs knows whether it is being run
|
|
1355 as @file{xemacs} or @file{temacs} because it sets the global variable
|
|
1356 @code{initialized} to 1 after step (4) above.) At this point,
|
|
1357 @file{xemacs} calls a Lisp function to do any further initialization,
|
|
1358 which includes parsing the command-line (the C code can only do limited
|
|
1359 command-line parsing, which includes looking for the @samp{-batch} and
|
|
1360 @samp{-l} flags and a few other flags that it needs to know about before
|
|
1361 initialization is complete), creating the first frame (or @dfn{window}
|
|
1362 in standard window-system parlance), running the user's init file
|
|
1363 (usually the file @file{.emacs} in the user's home directory), etc. The
|
|
1364 function to do this is usually called @code{normal-top-level};
|
|
1365 @file{loadup.el} tells the C code about this function by setting its
|
|
1366 name as the value of the Lisp variable @code{top-level}.
|
|
1367
|
|
1368 When the Lisp initialization code is done, the C code enters the event
|
|
1369 loop, and stays there for the duration of the XEmacs process. The code
|
442
|
1370 for the event loop is contained in @file{cmdloop.c}, and is called
|
428
|
1371 @code{Fcommand_loop_1()}. Note that this event loop could very well be
|
|
1372 written in Lisp, and in fact a Lisp version exists; but apparently,
|
|
1373 doing this makes XEmacs run noticeably slower.
|
|
1374
|
|
1375 Notice how much of the initialization is done in Lisp, not in C.
|
|
1376 In general, XEmacs tries to move as much code as is possible
|
|
1377 into Lisp. Code that remains in C is code that implements the
|
|
1378 Lisp interpreter itself, or code that needs to be very fast, or
|
|
1379 code that needs to do system calls or other such stuff that
|
|
1380 needs to be done in C, or code that needs to have access to
|
|
1381 ``forbidden'' structures. (One conscious aspect of the design of
|
|
1382 Lisp under XEmacs is a clean separation between the external
|
|
1383 interface to a Lisp object's functionality and its internal
|
|
1384 implementation. Part of this design is that Lisp programs
|
|
1385 are forbidden from accessing the contents of the object other
|
|
1386 than through using a standard API. In this respect, XEmacs Lisp
|
|
1387 is similar to modern Lisp dialects but differs from GNU Emacs,
|
|
1388 which tends to expose the implementation and allow Lisp
|
|
1389 programs to look at it directly. The major advantage of
|
|
1390 hiding the implementation is that it allows the implementation
|
|
1391 to be redesigned without affecting any Lisp programs, including
|
|
1392 those that might want to be ``clever'' by looking directly at
|
|
1393 the object's contents and possibly manipulating them.)
|
|
1394
|
|
1395 Moving code into Lisp makes the code easier to debug and maintain and
|
|
1396 makes it much easier for people who are not XEmacs developers to
|
|
1397 customize XEmacs, because they can make a change with much less chance
|
|
1398 of obscure and unwanted interactions occurring than if they were to
|
|
1399 change the C code.
|
|
1400
|
|
1401 @node The XEmacs Object System (Abstractly Speaking), How Lisp Objects Are Represented in C, XEmacs From the Inside, Top
|
|
1402 @chapter The XEmacs Object System (Abstractly Speaking)
|
462
|
1403 @cindex XEmacs object system (abstractly speaking), the
|
|
1404 @cindex object system (abstractly speaking), the XEmacs
|
428
|
1405
|
|
1406 At the heart of the Lisp interpreter is its management of objects.
|
|
1407 XEmacs Lisp contains many built-in objects, some of which are
|
|
1408 simple and others of which can be very complex; and some of which
|
|
1409 are very common, and others of which are rarely used or are only
|
|
1410 used internally. (Since the Lisp allocation system, with its
|
|
1411 automatic reclamation of unused storage, is so much more convenient
|
|
1412 than @code{malloc()} and @code{free()}, the C code makes extensive use of it
|
|
1413 in its internal operations.)
|
|
1414
|
|
1415 The basic Lisp objects are
|
|
1416
|
|
1417 @table @code
|
|
1418 @item integer
|
|
1419 28 or 31 bits of precision, or 60 or 63 bits on 64-bit machines; the
|
|
1420 reason for this is described below when the internal Lisp object
|
|
1421 representation is described.
|
|
1422 @item float
|
|
1423 Same precision as a double in C.
|
|
1424 @item cons
|
|
1425 A simple container for two Lisp objects, used to implement lists and
|
|
1426 most other data structures in Lisp.
|
|
1427 @item char
|
|
1428 An object representing a single character of text; chars behave like
|
|
1429 integers in many ways but are logically considered text rather than
|
|
1430 numbers and have a different read syntax. (the read syntax for a char
|
440
|
1431 contains the char itself or some textual encoding of it---for example,
|
428
|
1432 a Japanese Kanji character might be encoded as @samp{^[$(B#&^[(B} using the
|
440
|
1433 ISO-2022 encoding standard---rather than the numerical representation
|
428
|
1434 of the char; this way, if the mapping between chars and integers
|
|
1435 changes, which is quite possible for Kanji characters and other extended
|
|
1436 characters, the same character will still be created. Note that some
|
|
1437 primitives confuse chars and integers. The worst culprit is @code{eq},
|
|
1438 which makes a special exception and considers a char to be @code{eq} to
|
|
1439 its integer equivalent, even though in no other case are objects of two
|
|
1440 different types @code{eq}. The reason for this monstrosity is
|
|
1441 compatibility with existing code; the separation of char from integer
|
|
1442 came fairly recently.)
|
|
1443 @item symbol
|
|
1444 An object that contains Lisp objects and is referred to by name;
|
|
1445 symbols are used to implement variables and named functions
|
|
1446 and to provide the equivalent of preprocessor constants in C.
|
|
1447 @item vector
|
|
1448 A one-dimensional array of Lisp objects providing constant-time access
|
|
1449 to any of the objects; access to an arbitrary object in a vector is
|
|
1450 faster than for lists, but the operations that can be done on a vector
|
|
1451 are more limited.
|
|
1452 @item string
|
|
1453 Self-explanatory; behaves much like a vector of chars
|
|
1454 but has a different read syntax and is stored and manipulated
|
|
1455 more compactly.
|
|
1456 @item bit-vector
|
|
1457 A vector of bits; similar to a string in spirit.
|
|
1458 @item compiled-function
|
|
1459 An object containing compiled Lisp code, known as @dfn{byte code}.
|
|
1460 @item subr
|
|
1461 A Lisp primitive, i.e. a Lisp-callable function implemented in C.
|
|
1462 @end table
|
|
1463
|
|
1464 @cindex closure
|
|
1465 Note that there is no basic ``function'' type, as in more powerful
|
|
1466 versions of Lisp (where it's called a @dfn{closure}). XEmacs Lisp does
|
|
1467 not provide the closure semantics implemented by Common Lisp and Scheme.
|
|
1468 The guts of a function in XEmacs Lisp are represented in one of four
|
|
1469 ways: a symbol specifying another function (when one function is an
|
|
1470 alias for another), a list (whose first element must be the symbol
|
|
1471 @code{lambda}) containing the function's source code, a
|
|
1472 compiled-function object, or a subr object. (In other words, given a
|
|
1473 symbol specifying the name of a function, calling @code{symbol-function}
|
|
1474 to retrieve the contents of the symbol's function cell will return one
|
|
1475 of these types of objects.)
|
|
1476
|
|
1477 XEmacs Lisp also contains numerous specialized objects used to implement
|
|
1478 the editor:
|
|
1479
|
|
1480 @table @code
|
|
1481 @item buffer
|
|
1482 Stores text like a string, but is optimized for insertion and deletion
|
|
1483 and has certain other properties that can be set.
|
|
1484 @item frame
|
|
1485 An object with various properties whose displayable representation is a
|
|
1486 @dfn{window} in window-system parlance.
|
|
1487 @item window
|
|
1488 A section of a frame that displays the contents of a buffer;
|
|
1489 often called a @dfn{pane} in window-system parlance.
|
|
1490 @item window-configuration
|
|
1491 An object that represents a saved configuration of windows in a frame.
|
|
1492 @item device
|
|
1493 An object representing a screen on which frames can be displayed;
|
|
1494 equivalent to a @dfn{display} in the X Window System and a @dfn{TTY} in
|
|
1495 character mode.
|
|
1496 @item face
|
|
1497 An object specifying the appearance of text or graphics; it has
|
|
1498 properties such as font, foreground color, and background color.
|
|
1499 @item marker
|
|
1500 An object that refers to a particular position in a buffer and moves
|
|
1501 around as text is inserted and deleted to stay in the same relative
|
|
1502 position to the text around it.
|
|
1503 @item extent
|
|
1504 Similar to a marker but covers a range of text in a buffer; can also
|
|
1505 specify properties of the text, such as a face in which the text is to
|
|
1506 be displayed, whether the text is invisible or unmodifiable, etc.
|
|
1507 @item event
|
|
1508 Generated by calling @code{next-event} and contains information
|
|
1509 describing a particular event happening in the system, such as the user
|
|
1510 pressing a key or a process terminating.
|
|
1511 @item keymap
|
|
1512 An object that maps from events (described using lists, vectors, and
|
|
1513 symbols rather than with an event object because the mapping is for
|
|
1514 classes of events, rather than individual events) to functions to
|
|
1515 execute or other events to recursively look up; the functions are
|
|
1516 described by name, using a symbol, or using lists to specify the
|
|
1517 function's code.
|
|
1518 @item glyph
|
|
1519 An object that describes the appearance of an image (e.g. pixmap) on
|
|
1520 the screen; glyphs can be attached to the beginning or end of extents
|
|
1521 and in some future version of XEmacs will be able to be inserted
|
|
1522 directly into a buffer.
|
|
1523 @item process
|
|
1524 An object that describes a connection to an externally-running process.
|
|
1525 @end table
|
|
1526
|
|
1527 There are some other, less-commonly-encountered general objects:
|
|
1528
|
|
1529 @table @code
|
|
1530 @item hash-table
|
|
1531 An object that maps from an arbitrary Lisp object to another arbitrary
|
|
1532 Lisp object, using hashing for fast lookup.
|
|
1533 @item obarray
|
|
1534 A limited form of hash-table that maps from strings to symbols; obarrays
|
|
1535 are used to look up a symbol given its name and are not actually their
|
|
1536 own object type but are kludgily represented using vectors with hidden
|
|
1537 fields (this representation derives from GNU Emacs).
|
|
1538 @item specifier
|
|
1539 A complex object used to specify the value of a display property; a
|
|
1540 default value is given and different values can be specified for
|
|
1541 particular frames, buffers, windows, devices, or classes of device.
|
|
1542 @item char-table
|
|
1543 An object that maps from chars or classes of chars to arbitrary Lisp
|
|
1544 objects; internally char tables use a complex nested-vector
|
|
1545 representation that is optimized to the way characters are represented
|
|
1546 as integers.
|
|
1547 @item range-table
|
|
1548 An object that maps from ranges of integers to arbitrary Lisp objects.
|
|
1549 @end table
|
|
1550
|
|
1551 And some strange special-purpose objects:
|
|
1552
|
|
1553 @table @code
|
|
1554 @item charset
|
|
1555 @itemx coding-system
|
|
1556 Objects used when MULE, or multi-lingual/Asian-language, support is
|
|
1557 enabled.
|
|
1558 @item color-instance
|
|
1559 @itemx font-instance
|
|
1560 @itemx image-instance
|
|
1561 An object that encapsulates a window-system resource; instances are
|
|
1562 mostly used internally but are exposed on the Lisp level for cleanness
|
|
1563 of the specifier model and because it's occasionally useful for Lisp
|
|
1564 program to create or query the properties of instances.
|
|
1565 @item subwindow
|
|
1566 An object that encapsulate a @dfn{subwindow} resource, i.e. a
|
|
1567 window-system child window that is drawn into by an external process;
|
|
1568 this object should be integrated into the glyph system but isn't yet,
|
|
1569 and may change form when this is done.
|
|
1570 @item tooltalk-message
|
|
1571 @itemx tooltalk-pattern
|
|
1572 Objects that represent resources used in the ToolTalk interprocess
|
|
1573 communication protocol.
|
|
1574 @item toolbar-button
|
|
1575 An object used in conjunction with the toolbar.
|
|
1576 @end table
|
|
1577
|
|
1578 And objects that are only used internally:
|
|
1579
|
|
1580 @table @code
|
|
1581 @item opaque
|
|
1582 A generic object for encapsulating arbitrary memory; this allows you the
|
|
1583 generality of @code{malloc()} and the convenience of the Lisp object
|
|
1584 system.
|
|
1585 @item lstream
|
|
1586 A buffering I/O stream, used to provide a unified interface to anything
|
|
1587 that can accept output or provide input, such as a file descriptor, a
|
|
1588 stdio stream, a chunk of memory, a Lisp buffer, a Lisp string, etc.;
|
|
1589 it's a Lisp object to make its memory management more convenient.
|
|
1590 @item char-table-entry
|
|
1591 Subsidiary objects in the internal char-table representation.
|
|
1592 @item extent-auxiliary
|
|
1593 @itemx menubar-data
|
|
1594 @itemx toolbar-data
|
|
1595 Various special-purpose objects that are basically just used to
|
|
1596 encapsulate memory for particular subsystems, similar to the more
|
|
1597 general ``opaque'' object.
|
|
1598 @item symbol-value-forward
|
|
1599 @itemx symbol-value-buffer-local
|
|
1600 @itemx symbol-value-varalias
|
|
1601 @itemx symbol-value-lisp-magic
|
|
1602 Special internal-only objects that are placed in the value cell of a
|
|
1603 symbol to indicate that there is something special with this variable --
|
|
1604 e.g. it has no value, it mirrors another variable, or it mirrors some C
|
|
1605 variable; there is really only one kind of object, called a
|
|
1606 @dfn{symbol-value-magic}, but it is sort-of halfway kludged into
|
|
1607 semi-different object types.
|
|
1608 @end table
|
|
1609
|
|
1610 @cindex permanent objects
|
|
1611 @cindex temporary objects
|
|
1612 Some types of objects are @dfn{permanent}, meaning that once created,
|
|
1613 they do not disappear until explicitly destroyed, using a function such
|
|
1614 as @code{delete-buffer}, @code{delete-window}, @code{delete-frame}, etc.
|
|
1615 Others will disappear once they are not longer used, through the garbage
|
|
1616 collection mechanism. Buffers, frames, windows, devices, and processes
|
|
1617 are among the objects that are permanent. Note that some objects can go
|
|
1618 both ways: Faces can be created either way; extents are normally
|
|
1619 permanent, but detached extents (extents not referring to any text, as
|
|
1620 happens to some extents when the text they are referring to is deleted)
|
|
1621 are temporary. Note that some permanent objects, such as faces and
|
|
1622 coding systems, cannot be deleted. Note also that windows are unique in
|
|
1623 that they can be @emph{undeleted} after having previously been
|
|
1624 deleted. (This happens as a result of restoring a window configuration.)
|
|
1625
|
|
1626 @cindex read syntax
|
|
1627 Note that many types of objects have a @dfn{read syntax}, i.e. a way of
|
|
1628 specifying an object of that type in Lisp code. When you load a Lisp
|
|
1629 file, or type in code to be evaluated, what really happens is that the
|
|
1630 function @code{read} is called, which reads some text and creates an object
|
|
1631 based on the syntax of that text; then @code{eval} is called, which
|
|
1632 possibly does something special; then this loop repeats until there's
|
|
1633 no more text to read. (@code{eval} only actually does something special
|
|
1634 with symbols, which causes the symbol's value to be returned,
|
|
1635 similar to referencing a variable; and with conses [i.e. lists],
|
|
1636 which cause a function invocation. All other values are returned
|
|
1637 unchanged.)
|
|
1638
|
|
1639 The read syntax
|
|
1640
|
|
1641 @example
|
|
1642 17297
|
|
1643 @end example
|
|
1644
|
|
1645 converts to an integer whose value is 17297.
|
|
1646
|
|
1647 @example
|
|
1648 1.983e-4
|
|
1649 @end example
|
|
1650
|
|
1651 converts to a float whose value is 1.983e-4, or .0001983.
|
|
1652
|
|
1653 @example
|
|
1654 ?b
|
|
1655 @end example
|
|
1656
|
|
1657 converts to a char that represents the lowercase letter b.
|
|
1658
|
|
1659 @example
|
|
1660 ?^[$(B#&^[(B
|
|
1661 @end example
|
|
1662
|
|
1663 (where @samp{^[} actually is an @samp{ESC} character) converts to a
|
|
1664 particular Kanji character when using an ISO2022-based coding system for
|
|
1665 input. (To decode this goo: @samp{ESC} begins an escape sequence;
|
|
1666 @samp{ESC $ (} is a class of escape sequences meaning ``switch to a
|
|
1667 94x94 character set''; @samp{ESC $ ( B} means ``switch to Japanese
|
|
1668 Kanji''; @samp{#} and @samp{&} collectively index into a 94-by-94 array
|
|
1669 of characters [subtract 33 from the ASCII value of each character to get
|
|
1670 the corresponding index]; @samp{ESC (} is a class of escape sequences
|
|
1671 meaning ``switch to a 94 character set''; @samp{ESC (B} means ``switch
|
|
1672 to US ASCII''. It is a coincidence that the letter @samp{B} is used to
|
|
1673 denote both Japanese Kanji and US ASCII. If the first @samp{B} were
|
|
1674 replaced with an @samp{A}, you'd be requesting a Chinese Hanzi character
|
|
1675 from the GB2312 character set.)
|
|
1676
|
|
1677 @example
|
|
1678 "foobar"
|
|
1679 @end example
|
|
1680
|
|
1681 converts to a string.
|
|
1682
|
|
1683 @example
|
|
1684 foobar
|
|
1685 @end example
|
|
1686
|
|
1687 converts to a symbol whose name is @code{"foobar"}. This is done by
|
|
1688 looking up the string equivalent in the global variable
|
|
1689 @code{obarray}, whose contents should be an obarray. If no symbol
|
|
1690 is found, a new symbol with the name @code{"foobar"} is automatically
|
|
1691 created and added to @code{obarray}; this process is called
|
|
1692 @dfn{interning} the symbol.
|
|
1693 @cindex interning
|
|
1694
|
|
1695 @example
|
|
1696 (foo . bar)
|
|
1697 @end example
|
|
1698
|
|
1699 converts to a cons cell containing the symbols @code{foo} and @code{bar}.
|
|
1700
|
|
1701 @example
|
|
1702 (1 a 2.5)
|
|
1703 @end example
|
|
1704
|
|
1705 converts to a three-element list containing the specified objects
|
|
1706 (note that a list is actually a set of nested conses; see the
|
|
1707 XEmacs Lisp Reference).
|
|
1708
|
|
1709 @example
|
|
1710 [1 a 2.5]
|
|
1711 @end example
|
|
1712
|
|
1713 converts to a three-element vector containing the specified objects.
|
|
1714
|
|
1715 @example
|
|
1716 #[... ... ... ...]
|
|
1717 @end example
|
|
1718
|
|
1719 converts to a compiled-function object (the actual contents are not
|
|
1720 shown since they are not relevant here; look at a file that ends with
|
|
1721 @file{.elc} for examples).
|
|
1722
|
|
1723 @example
|
|
1724 #*01110110
|
|
1725 @end example
|
|
1726
|
|
1727 converts to a bit-vector.
|
|
1728
|
|
1729 @example
|
|
1730 #s(hash-table ... ...)
|
|
1731 @end example
|
|
1732
|
|
1733 converts to a hash table (the actual contents are not shown).
|
|
1734
|
|
1735 @example
|
|
1736 #s(range-table ... ...)
|
|
1737 @end example
|
|
1738
|
|
1739 converts to a range table (the actual contents are not shown).
|
|
1740
|
|
1741 @example
|
|
1742 #s(char-table ... ...)
|
|
1743 @end example
|
|
1744
|
|
1745 converts to a char table (the actual contents are not shown).
|
|
1746
|
|
1747 Note that the @code{#s()} syntax is the general syntax for structures,
|
|
1748 which are not really implemented in XEmacs Lisp but should be.
|
|
1749
|
|
1750 When an object is printed out (using @code{print} or a related
|
|
1751 function), the read syntax is used, so that the same object can be read
|
|
1752 in again.
|
|
1753
|
|
1754 The other objects do not have read syntaxes, usually because it does not
|
|
1755 really make sense to create them in this fashion (i.e. processes, where
|
|
1756 it doesn't make sense to have a subprocess created as a side effect of
|
|
1757 reading some Lisp code), or because they can't be created at all
|
|
1758 (e.g. subrs). Permanent objects, as a rule, do not have a read syntax;
|
|
1759 nor do most complex objects, which contain too much state to be easily
|
|
1760 initialized through a read syntax.
|
|
1761
|
|
1762 @node How Lisp Objects Are Represented in C, Rules When Writing New C Code, The XEmacs Object System (Abstractly Speaking), Top
|
|
1763 @chapter How Lisp Objects Are Represented in C
|
462
|
1764 @cindex Lisp objects are represented in C, how
|
|
1765 @cindex objects are represented in C, how Lisp
|
|
1766 @cindex represented in C, how Lisp objects are
|
428
|
1767
|
|
1768 Lisp objects are represented in C using a 32-bit or 64-bit machine word
|
|
1769 (depending on the processor; i.e. DEC Alphas use 64-bit Lisp objects and
|
|
1770 most other processors use 32-bit Lisp objects). The representation
|
|
1771 stuffs a pointer together with a tag, as follows:
|
|
1772
|
|
1773 @example
|
|
1774 [ 3 3 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 ]
|
|
1775 [ 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 ]
|
|
1776
|
442
|
1777 <---------------------------------------------------------> <->
|
|
1778 a pointer to a structure, or an integer tag
|
|
1779 @end example
|
|
1780
|
|
1781 A tag of 00 is used for all pointer object types, a tag of 10 is used
|
|
1782 for characters, and the other two tags 01 and 11 are joined together to
|
|
1783 form the integer object type. This representation gives us 31 bit
|
|
1784 integers and 30 bit characters, while pointers are represented directly
|
|
1785 without any bit masking or shifting. This representation, though,
|
|
1786 assumes that pointers to structs are always aligned to multiples of 4,
|
|
1787 so the lower 2 bits are always zero.
|
428
|
1788
|
|
1789 Lisp objects use the typedef @code{Lisp_Object}, but the actual C type
|
|
1790 used for the Lisp object can vary. It can be either a simple type
|
|
1791 (@code{long} on the DEC Alpha, @code{int} on other machines) or a
|
|
1792 structure whose fields are bit fields that line up properly (actually, a
|
|
1793 union of structures is used). Generally the simple integral type is
|
|
1794 preferable because it ensures that the compiler will actually use a
|
|
1795 machine word to represent the object (some compilers will use more
|
|
1796 general and less efficient code for unions and structs even if they can
|
|
1797 fit in a machine word). The union type, however, has the advantage of
|
442
|
1798 stricter type checking. If you accidentally pass an integer where a Lisp
|
|
1799 object is desired, you get a compile error. The choice of which type
|
|
1800 to use is determined by the preprocessor constant @code{USE_UNION_TYPE}
|
|
1801 which is defined via the @code{--use-union-type} option to
|
|
1802 @code{configure}.
|
|
1803
|
|
1804 Various macros are used to convert between Lisp_Objects and the
|
|
1805 corresponding C type. Macros of the form @code{XINT()}, @code{XCHAR()},
|
|
1806 @code{XSTRING()}, @code{XSYMBOL()}, do any required bit shifting and/or
|
|
1807 masking and cast it to the appropriate type. @code{XINT()} needs to be
|
|
1808 a bit tricky so that negative numbers are properly sign-extended. Since
|
|
1809 integers are stored left-shifted, if the right-shift operator does an
|
|
1810 arithmetic shift (i.e. it leaves the most-significant bit as-is rather
|
|
1811 than shifting in a zero, so that it mimics a divide-by-two even for
|
|
1812 negative numbers) the shift to remove the tag bit is enough. This is
|
|
1813 the case on all the systems we support.
|
|
1814
|
|
1815 Note that when @code{ERROR_CHECK_TYPECHECK} is defined, the converter
|
440
|
1816 macros become more complicated---they check the tag bits and/or the
|
428
|
1817 type field in the first four bytes of a record type to ensure that the
|
|
1818 object is really of the correct type. This is great for catching places
|
440
|
1819 where an incorrect type is being dereferenced---this typically results
|
428
|
1820 in a pointer being dereferenced as the wrong type of structure, with
|
|
1821 unpredictable (and sometimes not easily traceable) results.
|
|
1822
|
|
1823 There are similar @code{XSET@var{TYPE}()} macros that construct a Lisp
|
|
1824 object. These macros are of the form @code{XSET@var{TYPE}
|
442
|
1825 (@var{lvalue}, @var{result})}, i.e. they have to be a statement rather
|
|
1826 than just used in an expression. The reason for this is that standard C
|
|
1827 doesn't let you ``construct'' a structure (but GCC does). Granted, this
|
|
1828 sometimes isn't too convenient; for the case of integers, at least, you
|
|
1829 can use the function @code{make_int()}, which constructs and
|
|
1830 @emph{returns} an integer Lisp object. Note that the
|
|
1831 @code{XSET@var{TYPE}()} macros are also affected by
|
|
1832 @code{ERROR_CHECK_TYPECHECK} and make sure that the structure is of the
|
|
1833 right type in the case of record types, where the type is contained in
|
|
1834 the structure.
|
428
|
1835
|
|
1836 The C programmer is responsible for @strong{guaranteeing} that a
|
442
|
1837 Lisp_Object is the correct type before using the @code{X@var{TYPE}}
|
428
|
1838 macros. This is especially important in the case of lists. Use
|
|
1839 @code{XCAR} and @code{XCDR} if a Lisp_Object is certainly a cons cell,
|
|
1840 else use @code{Fcar()} and @code{Fcdr()}. Trust other C code, but not
|
|
1841 Lisp code. On the other hand, if XEmacs has an internal logic error,
|
442
|
1842 it's better to crash immediately, so sprinkle @code{assert()}s and
|
|
1843 ``unreachable'' @code{abort()}s liberally about the source code. Where
|
|
1844 performance is an issue, use @code{type_checking_assert},
|
|
1845 @code{bufpos_checking_assert}, and @code{gc_checking_assert}, which do
|
|
1846 nothing unless the corresponding configure error checking flag was
|
|
1847 specified.
|
428
|
1848
|
802
|
1849 @node Rules When Writing New C Code, CVS Techniques, How Lisp Objects Are Represented in C, Top
|
428
|
1850 @chapter Rules When Writing New C Code
|
462
|
1851 @cindex writing new C code, rules when
|
|
1852 @cindex C code, rules when writing new
|
|
1853 @cindex code, rules when writing new C
|
428
|
1854
|
|
1855 The XEmacs C Code is extremely complex and intricate, and there are many
|
|
1856 rules that are more or less consistently followed throughout the code.
|
|
1857 Many of these rules are not obvious, so they are explained here. It is
|
|
1858 of the utmost importance that you follow them. If you don't, you may
|
|
1859 get something that appears to work, but which will crash in odd
|
|
1860 situations, often in code far away from where the actual breakage is.
|
|
1861
|
|
1862 @menu
|
|
1863 * General Coding Rules::
|
|
1864 * Writing Lisp Primitives::
|
462
|
1865 * Writing Good Comments::
|
428
|
1866 * Adding Global Lisp Variables::
|
462
|
1867 * Proper Use of Unsigned Types::
|
428
|
1868 * Coding for Mule::
|
|
1869 * Techniques for XEmacs Developers::
|
|
1870 @end menu
|
|
1871
|
462
|
1872 @node General Coding Rules
|
428
|
1873 @section General Coding Rules
|
462
|
1874 @cindex coding rules, general
|
428
|
1875
|
|
1876 The C code is actually written in a dialect of C called @dfn{Clean C},
|
|
1877 meaning that it can be compiled, mostly warning-free, with either a C or
|
|
1878 C++ compiler. Coding in Clean C has several advantages over plain C.
|
|
1879 C++ compilers are more nit-picking, and a number of coding errors have
|
|
1880 been found by compiling with C++. The ability to use both C and C++
|
|
1881 tools means that a greater variety of development tools are available to
|
|
1882 the developer.
|
|
1883
|
|
1884 Every module includes @file{<config.h>} (angle brackets so that
|
|
1885 @samp{--srcdir} works correctly; @file{config.h} may or may not be in
|
|
1886 the same directory as the C sources) and @file{lisp.h}. @file{config.h}
|
|
1887 must always be included before any other header files (including
|
|
1888 system header files) to ensure that certain tricks played by various
|
|
1889 @file{s/} and @file{m/} files work out correctly.
|
|
1890
|
440
|
1891 When including header files, always use angle brackets, not double
|
442
|
1892 quotes, except when the file to be included is always in the same
|
|
1893 directory as the including file. If either file is a generated file,
|
|
1894 then that is not likely to be the case. In order to understand why we
|
|
1895 have this rule, imagine what happens when you do a build in the source
|
|
1896 directory using @samp{./configure} and another build in another
|
|
1897 directory using @samp{../work/configure}. There will be two different
|
|
1898 @file{config.h} files. Which one will be used if you @samp{#include
|
|
1899 "config.h"}?
|
440
|
1900
|
448
|
1901 Almost every module contains a @code{syms_of_*()} function and a
|
|
1902 @code{vars_of_*()} function. The former declares any Lisp primitives
|
|
1903 you have defined and defines any symbols you will be using. The latter
|
|
1904 declares any global Lisp variables you have added and initializes global
|
|
1905 C variables in the module. @strong{Important}: There are stringent
|
|
1906 requirements on exactly what can go into these functions. See the
|
|
1907 comment in @file{emacs.c}. The reason for this is to avoid obscure
|
|
1908 unwanted interactions during initialization. If you don't follow these
|
|
1909 rules, you'll be sorry! If you want to do anything that isn't allowed,
|
|
1910 create a @code{complex_vars_of_*()} function for it. Doing this is
|
|
1911 tricky, though: you have to make sure your function is called at the
|
|
1912 right time so that all the initialization dependencies work out.
|
|
1913
|
|
1914 Declare each function of these kinds in @file{symsinit.h}. Make sure
|
|
1915 it's called in the appropriate place in @file{emacs.c}. You never need
|
|
1916 to include @file{symsinit.h} directly, because it is included by
|
|
1917 @file{lisp.h}.
|
|
1918
|
428
|
1919 @strong{All global and static variables that are to be modifiable must
|
|
1920 be declared uninitialized.} This means that you may not use the
|
|
1921 ``declare with initializer'' form for these variables, such as @code{int
|
|
1922 some_variable = 0;}. The reason for this has to do with some kludges
|
|
1923 done during the dumping process: If possible, the initialized data
|
|
1924 segment is re-mapped so that it becomes part of the (unmodifiable) code
|
|
1925 segment in the dumped executable. This allows this memory to be shared
|
|
1926 among multiple running XEmacs processes. XEmacs is careful to place as
|
442
|
1927 much constant data as possible into initialized variables during the
|
|
1928 @file{temacs} phase.
|
428
|
1929
|
|
1930 @cindex copy-on-write
|
|
1931 @strong{Please note:} This kludge only works on a few systems nowadays,
|
|
1932 and is rapidly becoming irrelevant because most modern operating systems
|
|
1933 provide @dfn{copy-on-write} semantics. All data is initially shared
|
|
1934 between processes, and a private copy is automatically made (on a
|
|
1935 page-by-page basis) when a process first attempts to write to a page of
|
|
1936 memory.
|
|
1937
|
|
1938 Formerly, there was a requirement that static variables not be declared
|
|
1939 inside of functions. This had to do with another hack along the same
|
|
1940 vein as what was just described: old USG systems put statically-declared
|
|
1941 variables in the initialized data space, so those header files had a
|
|
1942 @code{#define static} declaration. (That way, the data-segment remapping
|
|
1943 described above could still work.) This fails badly on static variables
|
|
1944 inside of functions, which suddenly become automatic variables;
|
|
1945 therefore, you weren't supposed to have any of them. This awful kludge
|
|
1946 has been removed in XEmacs because
|
|
1947
|
|
1948 @enumerate
|
|
1949 @item
|
|
1950 almost all of the systems that used this kludge ended up having
|
|
1951 to disable the data-segment remapping anyway;
|
|
1952 @item
|
|
1953 the only systems that didn't were extremely outdated ones;
|
|
1954 @item
|
|
1955 this hack completely messed up inline functions.
|
|
1956 @end enumerate
|
|
1957
|
|
1958 The C source code makes heavy use of C preprocessor macros. One popular
|
|
1959 macro style is:
|
|
1960
|
|
1961 @example
|
442
|
1962 #define FOO(var, value) do @{ \
|
440
|
1963 Lisp_Object FOO_value = (value); \
|
|
1964 ... /* compute using FOO_value */ \
|
|
1965 (var) = bar; \
|
428
|
1966 @} while (0)
|
|
1967 @end example
|
|
1968
|
|
1969 The @code{do @{...@} while (0)} is a standard trick to allow FOO to have
|
|
1970 statement semantics, so that it can safely be used within an @code{if}
|
|
1971 statement in C, for example. Multiple evaluation is prevented by
|
|
1972 copying a supplied argument into a local variable, so that
|
|
1973 @code{FOO(var,fun(1))} only calls @code{fun} once.
|
|
1974
|
|
1975 Lisp lists are popular data structures in the C code as well as in
|
|
1976 Elisp. There are two sets of macros that iterate over lists.
|
|
1977 @code{EXTERNAL_LIST_LOOP_@var{n}} should be used when the list has been
|
|
1978 supplied by the user, and cannot be trusted to be acyclic and
|
444
|
1979 @code{nil}-terminated. A @code{malformed-list} or @code{circular-list} error
|
428
|
1980 will be generated if the list being iterated over is not entirely
|
|
1981 kosher. @code{LIST_LOOP_@var{n}}, on the other hand, is faster and less
|
|
1982 safe, and can be used only on trusted lists.
|
|
1983
|
|
1984 Related macros are @code{GET_EXTERNAL_LIST_LENGTH} and
|
|
1985 @code{GET_LIST_LENGTH}, which calculate the length of a list, and in the
|
|
1986 case of @code{GET_EXTERNAL_LIST_LENGTH}, validating the properness of
|
|
1987 the list. The macros @code{EXTERNAL_LIST_LOOP_DELETE_IF} and
|
|
1988 @code{LIST_LOOP_DELETE_IF} delete elements from a lisp list satisfying some
|
|
1989 predicate.
|
|
1990
|
462
|
1991 @node Writing Lisp Primitives
|
428
|
1992 @section Writing Lisp Primitives
|
462
|
1993 @cindex writing Lisp primitives
|
|
1994 @cindex Lisp primitives, writing
|
|
1995 @cindex primitives, writing Lisp
|
428
|
1996
|
|
1997 Lisp primitives are Lisp functions implemented in C. The details of
|
|
1998 interfacing the C function so that Lisp can call it are handled by a few
|
|
1999 C macros. The only way to really understand how to write new C code is
|
|
2000 to read the source, but we can explain some things here.
|
|
2001
|
|
2002 An example of a special form is the definition of @code{prog1}, from
|
|
2003 @file{eval.c}. (An ordinary function would have the same general
|
|
2004 appearance.)
|
|
2005
|
|
2006 @cindex garbage collection protection
|
|
2007 @smallexample
|
|
2008 @group
|
|
2009 DEFUN ("prog1", Fprog1, 1, UNEVALLED, 0, /*
|
|
2010 Similar to `progn', but the value of the first form is returned.
|
|
2011 \(prog1 FIRST BODY...): All the arguments are evaluated sequentially.
|
|
2012 The value of FIRST is saved during evaluation of the remaining args,
|
|
2013 whose values are discarded.
|
|
2014 */
|
|
2015 (args))
|
|
2016 @{
|
|
2017 /* This function can GC */
|
|
2018 REGISTER Lisp_Object val, form, tail;
|
|
2019 struct gcpro gcpro1;
|
|
2020
|
|
2021 val = Feval (XCAR (args));
|
|
2022
|
|
2023 GCPRO1 (val);
|
|
2024
|
|
2025 LIST_LOOP_3 (form, XCDR (args), tail)
|
|
2026 Feval (form);
|
|
2027
|
|
2028 UNGCPRO;
|
|
2029 return val;
|
|
2030 @}
|
|
2031 @end group
|
|
2032 @end smallexample
|
|
2033
|
|
2034 Let's start with a precise explanation of the arguments to the
|
|
2035 @code{DEFUN} macro. Here is a template for them:
|
|
2036
|
|
2037 @example
|
|
2038 @group
|
|
2039 DEFUN (@var{lname}, @var{fname}, @var{min_args}, @var{max_args}, @var{interactive}, /*
|
|
2040 @var{docstring}
|
|
2041 */
|
|
2042 (@var{arglist}))
|
|
2043 @end group
|
|
2044 @end example
|
|
2045
|
|
2046 @table @var
|
|
2047 @item lname
|
|
2048 This string is the name of the Lisp symbol to define as the function
|
|
2049 name; in the example above, it is @code{"prog1"}.
|
|
2050
|
|
2051 @item fname
|
|
2052 This is the C function name for this function. This is the name that is
|
|
2053 used in C code for calling the function. The name is, by convention,
|
|
2054 @samp{F} prepended to the Lisp name, with all dashes (@samp{-}) in the
|
|
2055 Lisp name changed to underscores. Thus, to call this function from C
|
|
2056 code, call @code{Fprog1}. Remember that the arguments are of type
|
|
2057 @code{Lisp_Object}; various macros and functions for creating values of
|
|
2058 type @code{Lisp_Object} are declared in the file @file{lisp.h}.
|
|
2059
|
|
2060 Primitives whose names are special characters (e.g. @code{+} or
|
|
2061 @code{<}) are named by spelling out, in some fashion, the special
|
|
2062 character: e.g. @code{Fplus()} or @code{Flss()}. Primitives whose names
|
|
2063 begin with normal alphanumeric characters but also contain special
|
|
2064 characters are spelled out in some creative way, e.g. @code{let*}
|
|
2065 becomes @code{FletX()}.
|
|
2066
|
|
2067 Each function also has an associated structure that holds the data for
|
|
2068 the subr object that represents the function in Lisp. This structure
|
|
2069 conveys the Lisp symbol name to the initialization routine that will
|
|
2070 create the symbol and store the subr object as its definition. The C
|
|
2071 variable name of this structure is always @samp{S} prepended to the
|
|
2072 @var{fname}. You hardly ever need to be aware of the existence of this
|
|
2073 structure, since @code{DEFUN} plus @code{DEFSUBR} takes care of all the
|
|
2074 details.
|
|
2075
|
|
2076 @item min_args
|
|
2077 This is the minimum number of arguments that the function requires. The
|
|
2078 function @code{prog1} allows a minimum of one argument.
|
|
2079
|
|
2080 @item max_args
|
|
2081 This is the maximum number of arguments that the function accepts, if
|
|
2082 there is a fixed maximum. Alternatively, it can be @code{UNEVALLED},
|
|
2083 indicating a special form that receives unevaluated arguments, or
|
|
2084 @code{MANY}, indicating an unlimited number of evaluated arguments (the
|
|
2085 C equivalent of @code{&rest}). Both @code{UNEVALLED} and @code{MANY}
|
|
2086 are macros. If @var{max_args} is a number, it may not be less than
|
|
2087 @var{min_args} and it may not be greater than 8. (If you need to add a
|
|
2088 function with more than 8 arguments, use the @code{MANY} form. Resist
|
|
2089 the urge to edit the definition of @code{DEFUN} in @file{lisp.h}. If
|
|
2090 you do it anyways, make sure to also add another clause to the switch
|
|
2091 statement in @code{primitive_funcall().})
|
|
2092
|
|
2093 @item interactive
|
|
2094 This is an interactive specification, a string such as might be used as
|
|
2095 the argument of @code{interactive} in a Lisp function. In the case of
|
|
2096 @code{prog1}, it is 0 (a null pointer), indicating that @code{prog1}
|
|
2097 cannot be called interactively. A value of @code{""} indicates a
|
|
2098 function that should receive no arguments when called interactively.
|
|
2099
|
|
2100 @item docstring
|
|
2101 This is the documentation string. It is written just like a
|
|
2102 documentation string for a function defined in Lisp; in particular, the
|
|
2103 first line should be a single sentence. Note how the documentation
|
|
2104 string is enclosed in a comment, none of the documentation is placed on
|
|
2105 the same lines as the comment-start and comment-end characters, and the
|
|
2106 comment-start characters are on the same line as the interactive
|
|
2107 specification. @file{make-docfile}, which scans the C files for
|
|
2108 documentation strings, is very particular about what it looks for, and
|
|
2109 will not properly extract the doc string if it's not in this exact format.
|
|
2110
|
|
2111 In order to make both @file{etags} and @file{make-docfile} happy, make
|
|
2112 sure that the @code{DEFUN} line contains the @var{lname} and
|
|
2113 @var{fname}, and that the comment-start characters for the doc string
|
|
2114 are on the same line as the interactive specification, and put a newline
|
|
2115 directly after them (and before the comment-end characters).
|
|
2116
|
|
2117 @item arglist
|
|
2118 This is the comma-separated list of arguments to the C function. For a
|
|
2119 function with a fixed maximum number of arguments, provide a C argument
|
|
2120 for each Lisp argument. In this case, unlike regular C functions, the
|
|
2121 types of the arguments are not declared; they are simply always of type
|
|
2122 @code{Lisp_Object}.
|
|
2123
|
|
2124 The names of the C arguments will be used as the names of the arguments
|
|
2125 to the Lisp primitive as displayed in its documentation, modulo the same
|
|
2126 concerns described above for @code{F...} names (in particular,
|
|
2127 underscores in the C arguments become dashes in the Lisp arguments).
|
|
2128
|
|
2129 There is one additional kludge: A trailing `_' on the C argument is
|
|
2130 discarded when forming the Lisp argument. This allows C language
|
|
2131 reserved words (like @code{default}) or global symbols (like
|
|
2132 @code{dirname}) to be used as argument names without compiler warnings
|
|
2133 or errors.
|
|
2134
|
|
2135 A Lisp function with @w{@var{max_args} = @code{UNEVALLED}} is a
|
|
2136 @w{@dfn{special form}}; its arguments are not evaluated. Instead it
|
|
2137 receives one argument of type @code{Lisp_Object}, a (Lisp) list of the
|
|
2138 unevaluated arguments, conventionally named @code{(args)}.
|
|
2139
|
|
2140 When a Lisp function has no upper limit on the number of arguments,
|
|
2141 specify @w{@var{max_args} = @code{MANY}}. In this case its implementation in
|
|
2142 C actually receives exactly two arguments: the number of Lisp arguments
|
|
2143 (an @code{int}) and the address of a block containing their values (a
|
|
2144 @w{@code{Lisp_Object *}}). In this case only are the C types specified
|
|
2145 in the @var{arglist}: @w{@code{(int nargs, Lisp_Object *args)}}.
|
|
2146
|
|
2147 @end table
|
|
2148
|
|
2149 Within the function @code{Fprog1} itself, note the use of the macros
|
|
2150 @code{GCPRO1} and @code{UNGCPRO}. @code{GCPRO1} is used to ``protect''
|
|
2151 a variable from garbage collection---to inform the garbage collector
|
|
2152 that it must look in that variable and regard the object pointed at by
|
|
2153 its contents as an accessible object. This is necessary whenever you
|
|
2154 call @code{Feval} or anything that can directly or indirectly call
|
|
2155 @code{Feval} (this includes the @code{QUIT} macro!). At such a time,
|
|
2156 any Lisp object that you intend to refer to again must be protected
|
|
2157 somehow. @code{UNGCPRO} cancels the protection of the variables that
|
|
2158 are protected in the current function. It is necessary to do this
|
|
2159 explicitly.
|
|
2160
|
|
2161 The macro @code{GCPRO1} protects just one local variable. If you want
|
|
2162 to protect two, use @code{GCPRO2} instead; repeating @code{GCPRO1} will
|
|
2163 not work. Macros @code{GCPRO3} and @code{GCPRO4} also exist.
|
|
2164
|
|
2165 These macros implicitly use local variables such as @code{gcpro1}; you
|
|
2166 must declare these explicitly, with type @code{struct gcpro}. Thus, if
|
|
2167 you use @code{GCPRO2}, you must declare @code{gcpro1} and @code{gcpro2}.
|
|
2168
|
|
2169 @cindex caller-protects (@code{GCPRO} rule)
|
|
2170 Note also that the general rule is @dfn{caller-protects}; i.e. you are
|
|
2171 only responsible for protecting those Lisp objects that you create. Any
|
|
2172 objects passed to you as arguments should have been protected by whoever
|
|
2173 created them, so you don't in general have to protect them.
|
|
2174
|
|
2175 In particular, the arguments to any Lisp primitive are always
|
|
2176 automatically @code{GCPRO}ed, when called ``normally'' from Lisp code or
|
|
2177 bytecode. So only a few Lisp primitives that are called frequently from
|
|
2178 C code, such as @code{Fprogn} protect their arguments as a service to
|
|
2179 their caller. You don't need to protect your arguments when writing a
|
|
2180 new @code{DEFUN}.
|
|
2181
|
|
2182 @code{GCPRO}ing is perhaps the trickiest and most error-prone part of
|
|
2183 XEmacs coding. It is @strong{extremely} important that you get this
|
|
2184 right and use a great deal of discipline when writing this code.
|
|
2185 @xref{GCPROing, ,@code{GCPRO}ing}, for full details on how to do this.
|
|
2186
|
|
2187 What @code{DEFUN} actually does is declare a global structure of type
|
|
2188 @code{Lisp_Subr} whose name begins with capital @samp{SF} and which
|
|
2189 contains information about the primitive (e.g. a pointer to the
|
|
2190 function, its minimum and maximum allowed arguments, a string describing
|
|
2191 its Lisp name); @code{DEFUN} then begins a normal C function declaration
|
|
2192 using the @code{F...} name. The Lisp subr object that is the function
|
|
2193 definition of a primitive (i.e. the object in the function slot of the
|
|
2194 symbol that names the primitive) actually points to this @samp{SF}
|
|
2195 structure; when @code{Feval} encounters a subr, it looks in the
|
|
2196 structure to find out how to call the C function.
|
|
2197
|
|
2198 Defining the C function is not enough to make a Lisp primitive
|
|
2199 available; you must also create the Lisp symbol for the primitive (the
|
|
2200 symbol is @dfn{interned}; @pxref{Obarrays}) and store a suitable subr
|
|
2201 object in its function cell. (If you don't do this, the primitive won't
|
|
2202 be seen by Lisp code.) The code looks like this:
|
|
2203
|
|
2204 @example
|
|
2205 DEFSUBR (@var{fname});
|
|
2206 @end example
|
|
2207
|
|
2208 @noindent
|
|
2209 Here @var{fname} is the same name you used as the second argument to
|
|
2210 @code{DEFUN}.
|
|
2211
|
|
2212 This call to @code{DEFSUBR} should go in the @code{syms_of_*()} function
|
|
2213 at the end of the module. If no such function exists, create it and
|
|
2214 make sure to also declare it in @file{symsinit.h} and call it from the
|
|
2215 appropriate spot in @code{main()}. @xref{General Coding Rules}.
|
|
2216
|
|
2217 Note that C code cannot call functions by name unless they are defined
|
|
2218 in C. The way to call a function written in Lisp from C is to use
|
|
2219 @code{Ffuncall}, which embodies the Lisp function @code{funcall}. Since
|
|
2220 the Lisp function @code{funcall} accepts an unlimited number of
|
|
2221 arguments, in C it takes two: the number of Lisp-level arguments, and a
|
|
2222 one-dimensional array containing their values. The first Lisp-level
|
|
2223 argument is the Lisp function to call, and the rest are the arguments to
|
|
2224 pass to it. Since @code{Ffuncall} can call the evaluator, you must
|
|
2225 protect pointers from garbage collection around the call to
|
|
2226 @code{Ffuncall}. (However, @code{Ffuncall} explicitly protects all of
|
|
2227 its parameters, so you don't have to protect any pointers passed as
|
|
2228 parameters to it.)
|
|
2229
|
|
2230 The C functions @code{call0}, @code{call1}, @code{call2}, and so on,
|
|
2231 provide handy ways to call a Lisp function conveniently with a fixed
|
|
2232 number of arguments. They work by calling @code{Ffuncall}.
|
|
2233
|
|
2234 @file{eval.c} is a very good file to look through for examples;
|
|
2235 @file{lisp.h} contains the definitions for important macros and
|
|
2236 functions.
|
|
2237
|
462
|
2238 @node Writing Good Comments
|
|
2239 @section Writing Good Comments
|
|
2240 @cindex writing good comments
|
|
2241 @cindex comments, writing good
|
|
2242
|
|
2243 Comments are a lifeline for programmers trying to understand tricky
|
|
2244 code. In general, the less obvious it is what you are doing, the more
|
|
2245 you need a comment, and the more detailed it needs to be. You should
|
|
2246 always be on guard when you're writing code for stuff that's tricky, and
|
|
2247 should constantly be putting yourself in someone else's shoes and asking
|
|
2248 if that person could figure out without much difficulty what's going
|
|
2249 on. (Assume they are a competent programmer who understands the
|
|
2250 essentials of how the XEmacs code is structured but doesn't know much
|
|
2251 about the module you're working on or any algorithms you're using.) If
|
|
2252 you're not sure whether they would be able to, add a comment. Always
|
|
2253 err on the side of more comments, rather than less.
|
|
2254
|
|
2255 Generally, when making comments, there is no need to attribute them with
|
|
2256 your name or initials. This especially goes for small,
|
|
2257 easy-to-understand, non-opinionated ones. Also, comments indicating
|
|
2258 where, when, and by whom a file was changed are @emph{strongly}
|
|
2259 discouraged, and in general will be removed as they are discovered.
|
|
2260 This is exactly what @file{ChangeLogs} are there for. However, it can
|
|
2261 occasionally be useful to mark exactly where (but not when or by whom)
|
|
2262 changes are made, particularly when making small changes to a file
|
|
2263 imported from elsewhere. These marks help when later on a newer version
|
|
2264 of the file is imported and the changes need to be merged. (If
|
|
2265 everything were always kept in CVS, there would be no need for this.
|
|
2266 But in practice, this often doesn't happen, or the CVS repository is
|
|
2267 later on lost or unavailable to the person doing the update.)
|
|
2268
|
|
2269 When putting in an explicit opinion in a comment, you should
|
|
2270 @emph{always} attribute it with your name, and optionally the date.
|
|
2271 This also goes for long, complex comments explaining in detail the
|
|
2272 workings of something -- by putting your name there, you make it
|
|
2273 possible for someone who has questions about how that thing works to
|
|
2274 determine who wrote the comment so they can write to them. Preferably,
|
|
2275 use your actual name and not your initials, unless your initials are
|
|
2276 generally recognized (e.g. @samp{jwz}). You can use only your first
|
|
2277 name if it's obvious who you are; otherwise, give first and last name.
|
|
2278 If you're not a regular contributor, you might consider putting your
|
|
2279 email address in -- it may be in the ChangeLog, but after awhile
|
|
2280 ChangeLogs have a tendency of disappearing or getting
|
|
2281 muddled. (E.g. your comment may get copied somewhere else or even into
|
|
2282 another program, and tracking down the proper ChangeLog may be very
|
|
2283 difficult.)
|
|
2284
|
|
2285 If you come across an opinion that is not or no longer valid, or you
|
|
2286 come across any comment that no longer applies but you want to keep it
|
|
2287 around, enclose it in @samp{[[ } and @samp{ ]]} marks and add a comment
|
|
2288 afterwards explaining why the preceding comment is no longer valid. Put
|
|
2289 your name on this comment, as explained above.
|
|
2290
|
|
2291 Just as comments are a lifeline to programmers, incorrect comments are
|
|
2292 death. If you come across an incorrect comment, @strong{immediately}
|
|
2293 correct it or flag it as incorrect, as described in the previous
|
|
2294 paragraph. Whenever you work on a section of code, @emph{always} make
|
|
2295 sure to update any comments to be correct -- or, at the very least, flag
|
|
2296 them as incorrect.
|
|
2297
|
|
2298 To indicate a "todo" or other problem, use four pound signs --
|
|
2299 i.e. @samp{####}.
|
|
2300
|
|
2301 @node Adding Global Lisp Variables
|
428
|
2302 @section Adding Global Lisp Variables
|
462
|
2303 @cindex global Lisp variables, adding
|
|
2304 @cindex variables, adding global Lisp
|
428
|
2305
|
|
2306 Global variables whose names begin with @samp{Q} are constants whose
|
|
2307 value is a symbol of a particular name. The name of the variable should
|
|
2308 be derived from the name of the symbol using the same rules as for Lisp
|
|
2309 primitives. These variables are initialized using a call to
|
|
2310 @code{defsymbol()} in the @code{syms_of_*()} function. (This call
|
|
2311 interns a symbol, sets the C variable to the resulting Lisp object, and
|
|
2312 calls @code{staticpro()} on the C variable to tell the
|
|
2313 garbage-collection mechanism about this variable. What
|
|
2314 @code{staticpro()} does is add a pointer to the variable to a large
|
|
2315 global array; when garbage-collection happens, all pointers listed in
|
|
2316 the array are used as starting points for marking Lisp objects. This is
|
|
2317 important because it's quite possible that the only current reference to
|
|
2318 the object is the C variable. In the case of symbols, the
|
|
2319 @code{staticpro()} doesn't matter all that much because the symbol is
|
|
2320 contained in @code{obarray}, which is itself @code{staticpro()}ed.
|
|
2321 However, it's possible that a naughty user could do something like
|
|
2322 uninterning the symbol out of @code{obarray} or even setting
|
|
2323 @code{obarray} to a different value [although this is likely to make
|
|
2324 XEmacs crash!].)
|
|
2325
|
|
2326 @strong{Please note:} It is potentially deadly if you declare a
|
|
2327 @samp{Q...} variable in two different modules. The two calls to
|
|
2328 @code{defsymbol()} are no problem, but some linkers will complain about
|
|
2329 multiply-defined symbols. The most insidious aspect of this is that
|
|
2330 often the link will succeed anyway, but then the resulting executable
|
|
2331 will sometimes crash in obscure ways during certain operations! To
|
|
2332 avoid this problem, declare any symbols with common names (such as
|
|
2333 @code{text}) that are not obviously associated with this particular
|
|
2334 module in the module @file{general.c}.
|
|
2335
|
|
2336 Global variables whose names begin with @samp{V} are variables that
|
|
2337 contain Lisp objects. The convention here is that all global variables
|
|
2338 of type @code{Lisp_Object} begin with @samp{V}, and all others don't
|
|
2339 (including integer and boolean variables that have Lisp
|
|
2340 equivalents). Most of the time, these variables have equivalents in
|
|
2341 Lisp, but some don't. Those that do are declared this way by a call to
|
|
2342 @code{DEFVAR_LISP()} in the @code{vars_of_*()} initializer for the
|
|
2343 module. What this does is create a special @dfn{symbol-value-forward}
|
|
2344 Lisp object that contains a pointer to the C variable, intern a symbol
|
|
2345 whose name is as specified in the call to @code{DEFVAR_LISP()}, and set
|
|
2346 its value to the symbol-value-forward Lisp object; it also calls
|
|
2347 @code{staticpro()} on the C variable to tell the garbage-collection
|
|
2348 mechanism about the variable. When @code{eval} (or actually
|
|
2349 @code{symbol-value}) encounters this special object in the process of
|
|
2350 retrieving a variable's value, it follows the indirection to the C
|
|
2351 variable and gets its value. @code{setq} does similar things so that
|
|
2352 the C variable gets changed.
|
|
2353
|
|
2354 Whether or not you @code{DEFVAR_LISP()} a variable, you need to
|
|
2355 initialize it in the @code{vars_of_*()} function; otherwise it will end
|
|
2356 up as all zeroes, which is the integer 0 (@emph{not} @code{nil}), and
|
|
2357 this is probably not what you want. Also, if the variable is not
|
|
2358 @code{DEFVAR_LISP()}ed, @strong{you must call} @code{staticpro()} on the
|
|
2359 C variable in the @code{vars_of_*()} function. Otherwise, the
|
|
2360 garbage-collection mechanism won't know that the object in this variable
|
|
2361 is in use, and will happily collect it and reuse its storage for another
|
|
2362 Lisp object, and you will be the one who's unhappy when you can't figure
|
|
2363 out how your variable got overwritten.
|
|
2364
|
462
|
2365 @node Proper Use of Unsigned Types
|
|
2366 @section Proper Use of Unsigned Types
|
|
2367 @cindex unsigned types, proper use of
|
|
2368 @cindex types, proper use of unsigned
|
|
2369
|
|
2370 Avoid using @code{unsigned int} and @code{unsigned long} whenever
|
|
2371 possible. Unsigned types are viral -- any arithmetic or comparisons
|
|
2372 involving mixed signed and unsigned types are automatically converted to
|
|
2373 unsigned, which is almost certainly not what you want. Many subtle and
|
|
2374 hard-to-find bugs are created by careless use of unsigned types. In
|
|
2375 general, you should almost @emph{never} use an unsigned type to hold a
|
|
2376 regular quantity of any sort. The only exceptions are
|
|
2377
|
|
2378 @enumerate
|
|
2379 @item
|
|
2380 When there's a reasonable possibility you will actually need all 32 or
|
|
2381 64 bits to store the quantity.
|
|
2382 @item
|
|
2383 When calling existing API's that require unsigned types. In this case,
|
|
2384 you should still do all manipulation using signed types, and do the
|
|
2385 conversion at the very threshold of the API call.
|
|
2386 @item
|
|
2387 In existing code that you don't want to modify because you don't
|
|
2388 maintain it.
|
|
2389 @item
|
|
2390 In bit-field structures.
|
|
2391 @end enumerate
|
|
2392
|
|
2393 Other reasonable uses of @code{unsigned int} and @code{unsigned long}
|
|
2394 are representing non-quantities -- e.g. bit-oriented flags and such.
|
|
2395
|
|
2396 @node Coding for Mule
|
428
|
2397 @section Coding for Mule
|
462
|
2398 @cindex coding for Mule
|
|
2399 @cindex Mule, coding for
|
428
|
2400
|
|
2401 Although Mule support is not compiled by default in XEmacs, many people
|
|
2402 are using it, and we consider it crucial that new code works correctly
|
|
2403 with multibyte characters. This is not hard; it is only a matter of
|
|
2404 following several simple user-interface guidelines. Even if you never
|
|
2405 compile with Mule, with a little practice you will find it quite easy
|
|
2406 to code Mule-correctly.
|
|
2407
|
|
2408 Note that these guidelines are not necessarily tied to the current Mule
|
|
2409 implementation; they are also a good idea to follow on the grounds of
|
|
2410 code generalization for future I18N work.
|
|
2411
|
|
2412 @menu
|
|
2413 * Character-Related Data Types::
|
|
2414 * Working With Character and Byte Positions::
|
|
2415 * Conversion to and from External Data::
|
|
2416 * General Guidelines for Writing Mule-Aware Code::
|
|
2417 * An Example of Mule-Aware Code::
|
|
2418 @end menu
|
|
2419
|
462
|
2420 @node Character-Related Data Types
|
428
|
2421 @subsection Character-Related Data Types
|
462
|
2422 @cindex character-related data types
|
|
2423 @cindex data types, character-related
|
428
|
2424
|
|
2425 First, let's review the basic character-related datatypes used by
|
|
2426 XEmacs. Note that the separate @code{typedef}s are not mandatory in the
|
|
2427 current implementation (all of them boil down to @code{unsigned char} or
|
|
2428 @code{int}), but they improve clarity of code a great deal, because one
|
|
2429 glance at the declaration can tell the intended use of the variable.
|
|
2430
|
|
2431 @table @code
|
|
2432 @item Emchar
|
|
2433 @cindex Emchar
|
|
2434 An @code{Emchar} holds a single Emacs character.
|
|
2435
|
|
2436 Obviously, the equality between characters and bytes is lost in the Mule
|
|
2437 world. Characters can be represented by one or more bytes in the
|
|
2438 buffer, and @code{Emchar} is the C type large enough to hold any
|
|
2439 character.
|
|
2440
|
|
2441 Without Mule support, an @code{Emchar} is equivalent to an
|
|
2442 @code{unsigned char}.
|
|
2443
|
|
2444 @item Bufbyte
|
|
2445 @cindex Bufbyte
|
|
2446 The data representing the text in a buffer or string is logically a set
|
|
2447 of @code{Bufbyte}s.
|
|
2448
|
442
|
2449 XEmacs does not work with the same character formats all the time; when
|
|
2450 reading characters from the outside, it decodes them to an internal
|
|
2451 format, and likewise encodes them when writing. @code{Bufbyte} (in fact
|
428
|
2452 @code{unsigned char}) is the basic unit of XEmacs internal buffers and
|
442
|
2453 strings format. A @code{Bufbyte *} is the type that points at text
|
|
2454 encoded in the variable-width internal encoding.
|
428
|
2455
|
|
2456 One character can correspond to one or more @code{Bufbyte}s. In the
|
442
|
2457 current Mule implementation, an ASCII character is represented by the
|
|
2458 same @code{Bufbyte}, and other characters are represented by a sequence
|
|
2459 of two or more @code{Bufbyte}s.
|
|
2460
|
|
2461 Without Mule support, there are exactly 256 characters, implicitly
|
|
2462 Latin-1, and each character is represented using one @code{Bufbyte}, and
|
|
2463 there is a one-to-one correspondence between @code{Bufbyte}s and
|
|
2464 @code{Emchar}s.
|
428
|
2465
|
|
2466 @item Bufpos
|
|
2467 @itemx Charcount
|
|
2468 @cindex Bufpos
|
|
2469 @cindex Charcount
|
|
2470 A @code{Bufpos} represents a character position in a buffer or string.
|
|
2471 A @code{Charcount} represents a number (count) of characters.
|
|
2472 Logically, subtracting two @code{Bufpos} values yields a
|
|
2473 @code{Charcount} value. Although all of these are @code{typedef}ed to
|
442
|
2474 @code{EMACS_INT}, we use them in preference to @code{EMACS_INT} to make
|
|
2475 it clear what sort of position is being used.
|
428
|
2476
|
|
2477 @code{Bufpos} and @code{Charcount} values are the only ones that are
|
|
2478 ever visible to Lisp.
|
|
2479
|
|
2480 @item Bytind
|
|
2481 @itemx Bytecount
|
|
2482 @cindex Bytind
|
|
2483 @cindex Bytecount
|
|
2484 A @code{Bytind} represents a byte position in a buffer or string. A
|
442
|
2485 @code{Bytecount} represents the distance between two positions, in bytes.
|
428
|
2486 The relationship between @code{Bytind} and @code{Bytecount} is the same
|
|
2487 as the relationship between @code{Bufpos} and @code{Charcount}.
|
|
2488
|
|
2489 @item Extbyte
|
|
2490 @itemx Extcount
|
|
2491 @cindex Extbyte
|
|
2492 @cindex Extcount
|
|
2493 When dealing with the outside world, XEmacs works with @code{Extbyte}s,
|
|
2494 which are equivalent to @code{unsigned char}. Obviously, an
|
|
2495 @code{Extcount} is the distance between two @code{Extbyte}s. Extbytes
|
|
2496 and Extcounts are not all that frequent in XEmacs code.
|
|
2497 @end table
|
|
2498
|
462
|
2499 @node Working With Character and Byte Positions
|
428
|
2500 @subsection Working With Character and Byte Positions
|
462
|
2501 @cindex character and byte positions, working with
|
|
2502 @cindex byte positions, working with character and
|
|
2503 @cindex positions, working with character and byte
|
428
|
2504
|
|
2505 Now that we have defined the basic character-related types, we can look
|
|
2506 at the macros and functions designed for work with them and for
|
|
2507 conversion between them. Most of these macros are defined in
|
|
2508 @file{buffer.h}, and we don't discuss all of them here, but only the
|
|
2509 most important ones. Examining the existing code is the best way to
|
|
2510 learn about them.
|
|
2511
|
|
2512 @table @code
|
|
2513 @item MAX_EMCHAR_LEN
|
|
2514 @cindex MAX_EMCHAR_LEN
|
442
|
2515 This preprocessor constant is the maximum number of buffer bytes to
|
|
2516 represent an Emacs character in the variable width internal encoding.
|
|
2517 It is useful when allocating temporary strings to keep a known number of
|
|
2518 characters. For instance:
|
428
|
2519
|
|
2520 @example
|
|
2521 @group
|
|
2522 @{
|
|
2523 Charcount cclen;
|
|
2524 ...
|
|
2525 @{
|
|
2526 /* Allocate place for @var{cclen} characters. */
|
|
2527 Bufbyte *buf = (Bufbyte *)alloca (cclen * MAX_EMCHAR_LEN);
|
|
2528 ...
|
|
2529 @end group
|
|
2530 @end example
|
|
2531
|
|
2532 If you followed the previous section, you can guess that, logically,
|
|
2533 multiplying a @code{Charcount} value with @code{MAX_EMCHAR_LEN} produces
|
|
2534 a @code{Bytecount} value.
|
|
2535
|
|
2536 In the current Mule implementation, @code{MAX_EMCHAR_LEN} equals 4.
|
|
2537 Without Mule, it is 1.
|
|
2538
|
|
2539 @item charptr_emchar
|
|
2540 @itemx set_charptr_emchar
|
|
2541 @cindex charptr_emchar
|
|
2542 @cindex set_charptr_emchar
|
|
2543 The @code{charptr_emchar} macro takes a @code{Bufbyte} pointer and
|
|
2544 returns the @code{Emchar} stored at that position. If it were a
|
|
2545 function, its prototype would be:
|
|
2546
|
|
2547 @example
|
|
2548 Emchar charptr_emchar (Bufbyte *p);
|
|
2549 @end example
|
|
2550
|
|
2551 @code{set_charptr_emchar} stores an @code{Emchar} to the specified byte
|
|
2552 position. It returns the number of bytes stored:
|
|
2553
|
|
2554 @example
|
|
2555 Bytecount set_charptr_emchar (Bufbyte *p, Emchar c);
|
|
2556 @end example
|
|
2557
|
|
2558 It is important to note that @code{set_charptr_emchar} is safe only for
|
|
2559 appending a character at the end of a buffer, not for overwriting a
|
|
2560 character in the middle. This is because the width of characters
|
|
2561 varies, and @code{set_charptr_emchar} cannot resize the string if it
|
|
2562 writes, say, a two-byte character where a single-byte character used to
|
|
2563 reside.
|
|
2564
|
|
2565 A typical use of @code{set_charptr_emchar} can be demonstrated by this
|
|
2566 example, which copies characters from buffer @var{buf} to a temporary
|
|
2567 string of Bufbytes.
|
|
2568
|
|
2569 @example
|
|
2570 @group
|
|
2571 @{
|
|
2572 Bufpos pos;
|
|
2573 for (pos = beg; pos < end; pos++)
|
|
2574 @{
|
|
2575 Emchar c = BUF_FETCH_CHAR (buf, pos);
|
|
2576 p += set_charptr_emchar (buf, c);
|
|
2577 @}
|
|
2578 @}
|
|
2579 @end group
|
|
2580 @end example
|
|
2581
|
|
2582 Note how @code{set_charptr_emchar} is used to store the @code{Emchar}
|
|
2583 and increment the counter, at the same time.
|
|
2584
|
|
2585 @item INC_CHARPTR
|
|
2586 @itemx DEC_CHARPTR
|
|
2587 @cindex INC_CHARPTR
|
|
2588 @cindex DEC_CHARPTR
|
|
2589 These two macros increment and decrement a @code{Bufbyte} pointer,
|
|
2590 respectively. They will adjust the pointer by the appropriate number of
|
|
2591 bytes according to the byte length of the character stored there. Both
|
|
2592 macros assume that the memory address is located at the beginning of a
|
|
2593 valid character.
|
|
2594
|
|
2595 Without Mule support, @code{INC_CHARPTR (p)} and @code{DEC_CHARPTR (p)}
|
|
2596 simply expand to @code{p++} and @code{p--}, respectively.
|
|
2597
|
|
2598 @item bytecount_to_charcount
|
|
2599 @cindex bytecount_to_charcount
|
|
2600 Given a pointer to a text string and a length in bytes, return the
|
|
2601 equivalent length in characters.
|
|
2602
|
|
2603 @example
|
|
2604 Charcount bytecount_to_charcount (Bufbyte *p, Bytecount bc);
|
|
2605 @end example
|
|
2606
|
|
2607 @item charcount_to_bytecount
|
|
2608 @cindex charcount_to_bytecount
|
|
2609 Given a pointer to a text string and a length in characters, return the
|
|
2610 equivalent length in bytes.
|
|
2611
|
|
2612 @example
|
|
2613 Bytecount charcount_to_bytecount (Bufbyte *p, Charcount cc);
|
|
2614 @end example
|
|
2615
|
|
2616 @item charptr_n_addr
|
|
2617 @cindex charptr_n_addr
|
|
2618 Return a pointer to the beginning of the character offset @var{cc} (in
|
|
2619 characters) from @var{p}.
|
|
2620
|
|
2621 @example
|
|
2622 Bufbyte *charptr_n_addr (Bufbyte *p, Charcount cc);
|
|
2623 @end example
|
|
2624 @end table
|
|
2625
|
462
|
2626 @node Conversion to and from External Data
|
428
|
2627 @subsection Conversion to and from External Data
|
462
|
2628 @cindex conversion to and from external data
|
|
2629 @cindex external data, conversion to and from
|
428
|
2630
|
|
2631 When an external function, such as a C library function, returns a
|
|
2632 @code{char} pointer, you should almost never treat it as @code{Bufbyte}.
|
|
2633 This is because these returned strings may contain 8bit characters which
|
|
2634 can be misinterpreted by XEmacs, and cause a crash. Likewise, when
|
|
2635 exporting a piece of internal text to the outside world, you should
|
|
2636 always convert it to an appropriate external encoding, lest the internal
|
|
2637 stuff (such as the infamous \201 characters) leak out.
|
|
2638
|
|
2639 The interface to conversion between the internal and external
|
|
2640 representations of text are the numerous conversion macros defined in
|
442
|
2641 @file{buffer.h}. There used to be a fixed set of external formats
|
|
2642 supported by these macros, but now any coding system can be used with
|
|
2643 these macros. The coding system alias mechanism is used to create the
|
|
2644 following logical coding systems, which replace the fixed external
|
|
2645 formats. The (dontusethis-set-symbol-value-handler) mechanism was
|
|
2646 enhanced to make this possible (more work on that is needed - like
|
|
2647 remove the @code{dontusethis-} prefix).
|
428
|
2648
|
|
2649 @table @code
|
442
|
2650 @item Qbinary
|
|
2651 This is the simplest format and is what we use in the absence of a more
|
|
2652 appropriate format. This converts according to the @code{binary} coding
|
|
2653 system:
|
|
2654
|
|
2655 @enumerate a
|
|
2656 @item
|
|
2657 On input, bytes 0--255 are converted into (implicitly Latin-1)
|
|
2658 characters 0--255. A non-Mule xemacs doesn't really know about
|
|
2659 different character sets and the fonts to display them, so the bytes can
|
|
2660 be treated as text in different 1-byte encodings by simply setting the
|
|
2661 appropriate fonts. So in a sense, non-Mule xemacs is a multi-lingual
|
|
2662 editor if, for example, different fonts are used to display text in
|
|
2663 different buffers, faces, or windows. The specifier mechanism gives the
|
|
2664 user complete control over this kind of behavior.
|
|
2665 @item
|
|
2666 On output, characters 0--255 are converted into bytes 0--255 and other
|
|
2667 characters are converted into `~'.
|
|
2668 @end enumerate
|
|
2669
|
|
2670 @item Qfile_name
|
|
2671 Format used for filenames. This is user-definable via either the
|
|
2672 @code{file-name-coding-system} or @code{pathname-coding-system} (now
|
|
2673 obsolete) variables.
|
|
2674
|
|
2675 @item Qnative
|
|
2676 Format used for the external Unix environment---@code{argv[]}, stuff
|
|
2677 from @code{getenv()}, stuff from the @file{/etc/passwd} file, etc.
|
|
2678 Currently this is the same as Qfile_name. The two should be
|
|
2679 distinguished for clarity and possible future separation.
|
|
2680
|
|
2681 @item Qctext
|
|
2682 Compound--text format. This is the standard X11 format used for data
|
|
2683 stored in properties, selections, and the like. This is an 8-bit
|
|
2684 no-lock-shift ISO2022 coding system. This is a real coding system,
|
|
2685 unlike Qfile_name, which is user-definable.
|
428
|
2686 @end table
|
|
2687
|
442
|
2688 There are two fundamental macros to convert between external and
|
|
2689 internal format.
|
|
2690
|
|
2691 @code{TO_INTERNAL_FORMAT} converts external data to internal format, and
|
|
2692 @code{TO_EXTERNAL_FORMAT} converts the other way around. The arguments
|
|
2693 each of these receives are a source type, a source, a sink type, a sink,
|
|
2694 and a coding system (or a symbol naming a coding system).
|
|
2695
|
|
2696 A typical call looks like
|
|
2697 @example
|
|
2698 TO_EXTERNAL_FORMAT (LISP_STRING, str, C_STRING_MALLOC, ptr, Qfile_name);
|
|
2699 @end example
|
|
2700
|
|
2701 which means that the contents of the lisp string @code{str} are written
|
|
2702 to a malloc'ed memory area which will be pointed to by @code{ptr}, after
|
|
2703 the function returns. The conversion will be done using the
|
|
2704 @code{file-name} coding system, which will be controlled by the user
|
|
2705 indirectly by setting or binding the variable
|
|
2706 @code{file-name-coding-system}.
|
|
2707
|
|
2708 Some sources and sinks require two C variables to specify. We use some
|
|
2709 preprocessor magic to allow different source and sink types, and even
|
|
2710 different numbers of arguments to specify different types of sources and
|
|
2711 sinks.
|
|
2712
|
|
2713 So we can have a call that looks like
|
|
2714 @example
|
|
2715 TO_INTERNAL_FORMAT (DATA, (ptr, len),
|
|
2716 MALLOC, (ptr, len),
|
|
2717 coding_system);
|
|
2718 @end example
|
|
2719
|
|
2720 The parenthesized argument pairs are required to make the preprocessor
|
|
2721 magic work.
|
|
2722
|
|
2723 Here are the different source and sink types:
|
|
2724
|
|
2725 @table @code
|
|
2726 @item @code{DATA, (ptr, len),}
|
|
2727 input data is a fixed buffer of size @var{len} at address @var{ptr}
|
|
2728 @item @code{ALLOCA, (ptr, len),}
|
|
2729 output data is placed in an alloca()ed buffer of size @var{len} pointed to by @var{ptr}
|
|
2730 @item @code{MALLOC, (ptr, len),}
|
|
2731 output data is in a malloc()ed buffer of size @var{len} pointed to by @var{ptr}
|
|
2732 @item @code{C_STRING_ALLOCA, ptr,}
|
|
2733 equivalent to @code{ALLOCA (ptr, len_ignored)} on output.
|
|
2734 @item @code{C_STRING_MALLOC, ptr,}
|
|
2735 equivalent to @code{MALLOC (ptr, len_ignored)} on output
|
|
2736 @item @code{C_STRING, ptr,}
|
|
2737 equivalent to @code{DATA, (ptr, strlen (ptr) + 1)} on input
|
|
2738 @item @code{LISP_STRING, string,}
|
|
2739 input or output is a Lisp_Object of type string
|
|
2740 @item @code{LISP_BUFFER, buffer,}
|
|
2741 output is written to @code{(point)} in lisp buffer @var{buffer}
|
|
2742 @item @code{LISP_LSTREAM, lstream,}
|
|
2743 input or output is a Lisp_Object of type lstream
|
|
2744 @item @code{LISP_OPAQUE, object,}
|
|
2745 input or output is a Lisp_Object of type opaque
|
|
2746 @end table
|
|
2747
|
|
2748 Often, the data is being converted to a '\0'-byte-terminated string,
|
|
2749 which is the format required by many external system C APIs. For these
|
|
2750 purposes, a source type of @code{C_STRING} or a sink type of
|
|
2751 @code{C_STRING_ALLOCA} or @code{C_STRING_MALLOC} is appropriate.
|
|
2752 Otherwise, we should try to keep XEmacs '\0'-byte-clean, which means
|
|
2753 using (ptr, len) pairs.
|
|
2754
|
|
2755 The sinks to be specified must be lvalues, unless they are the lisp
|
|
2756 object types @code{LISP_LSTREAM} or @code{LISP_BUFFER}.
|
|
2757
|
|
2758 For the sink types @code{ALLOCA} and @code{C_STRING_ALLOCA}, the
|
|
2759 resulting text is stored in a stack-allocated buffer, which is
|
|
2760 automatically freed on returning from the function. However, the sink
|
|
2761 types @code{MALLOC} and @code{C_STRING_MALLOC} return @code{xmalloc()}ed
|
|
2762 memory. The caller is responsible for freeing this memory using
|
|
2763 @code{xfree()}.
|
|
2764
|
|
2765 Note that it doesn't make sense for @code{LISP_STRING} to be a source
|
|
2766 for @code{TO_INTERNAL_FORMAT} or a sink for @code{TO_EXTERNAL_FORMAT}.
|
|
2767 You'll get an assertion failure if you try.
|
|
2768
|
|
2769
|
462
|
2770 @node General Guidelines for Writing Mule-Aware Code
|
428
|
2771 @subsection General Guidelines for Writing Mule-Aware Code
|
462
|
2772 @cindex writing Mule-aware code, general guidelines for
|
|
2773 @cindex Mule-aware code, general guidelines for writing
|
|
2774 @cindex code, general guidelines for writing Mule-aware
|
428
|
2775
|
|
2776 This section contains some general guidance on how to write Mule-aware
|
|
2777 code, as well as some pitfalls you should avoid.
|
|
2778
|
|
2779 @table @emph
|
|
2780 @item Never use @code{char} and @code{char *}.
|
|
2781 In XEmacs, the use of @code{char} and @code{char *} is almost always a
|
|
2782 mistake. If you want to manipulate an Emacs character from ``C'', use
|
|
2783 @code{Emchar}. If you want to examine a specific octet in the internal
|
|
2784 format, use @code{Bufbyte}. If you want a Lisp-visible character, use a
|
|
2785 @code{Lisp_Object} and @code{make_char}. If you want a pointer to move
|
|
2786 through the internal text, use @code{Bufbyte *}. Also note that you
|
|
2787 almost certainly do not need @code{Emchar *}.
|
|
2788
|
|
2789 @item Be careful not to confuse @code{Charcount}, @code{Bytecount}, and @code{Bufpos}.
|
|
2790 The whole point of using different types is to avoid confusion about the
|
|
2791 use of certain variables. Lest this effect be nullified, you need to be
|
|
2792 careful about using the right types.
|
|
2793
|
|
2794 @item Always convert external data
|
|
2795 It is extremely important to always convert external data, because
|
|
2796 XEmacs can crash if unexpected 8bit sequences are copied to its internal
|
|
2797 buffers literally.
|
|
2798
|
|
2799 This means that when a system function, such as @code{readdir}, returns
|
442
|
2800 a string, you may need to convert it using one of the conversion macros
|
428
|
2801 described in the previous chapter, before passing it further to Lisp.
|
442
|
2802
|
|
2803 Actually, most of the basic system functions that accept '\0'-terminated
|
|
2804 string arguments, like @code{stat()} and @code{open()}, have been
|
|
2805 @strong{encapsulated} so that they are they @code{always} do internal to
|
|
2806 external conversion themselves. This means you must pass internally
|
|
2807 encoded data, typically the @code{XSTRING_DATA} of a Lisp_String to
|
|
2808 these functions. This is actually a design bug, since it unexpectedly
|
|
2809 changes the semantics of the system functions. A better design would be
|
|
2810 to provide separate versions of these system functions that accepted
|
|
2811 Lisp_Objects which were lisp strings in place of their current
|
|
2812 @code{char *} arguments.
|
|
2813
|
|
2814 @example
|
|
2815 int stat_lisp (Lisp_Object path, struct stat *buf); /* Implement me */
|
|
2816 @end example
|
428
|
2817
|
|
2818 Also note that many internal functions, such as @code{make_string},
|
|
2819 accept Bufbytes, which removes the need for them to convert the data
|
|
2820 they receive. This increases efficiency because that way external data
|
|
2821 needs to be decoded only once, when it is read. After that, it is
|
|
2822 passed around in internal format.
|
|
2823 @end table
|
|
2824
|
462
|
2825 @node An Example of Mule-Aware Code
|
428
|
2826 @subsection An Example of Mule-Aware Code
|
462
|
2827 @cindex code, an example of Mule-aware
|
|
2828 @cindex Mule-aware code, an example of
|
428
|
2829
|
442
|
2830 As an example of Mule-aware code, we will analyze the @code{string}
|
|
2831 function, which conses up a Lisp string from the character arguments it
|
|
2832 receives. Here is the definition, pasted from @code{alloc.c}:
|
428
|
2833
|
|
2834 @example
|
|
2835 @group
|
|
2836 DEFUN ("string", Fstring, 0, MANY, 0, /*
|
|
2837 Concatenate all the argument characters and make the result a string.
|
|
2838 */
|
|
2839 (int nargs, Lisp_Object *args))
|
|
2840 @{
|
|
2841 Bufbyte *storage = alloca_array (Bufbyte, nargs * MAX_EMCHAR_LEN);
|
|
2842 Bufbyte *p = storage;
|
|
2843
|
|
2844 for (; nargs; nargs--, args++)
|
|
2845 @{
|
|
2846 Lisp_Object lisp_char = *args;
|
|
2847 CHECK_CHAR_COERCE_INT (lisp_char);
|
|
2848 p += set_charptr_emchar (p, XCHAR (lisp_char));
|
|
2849 @}
|
|
2850 return make_string (storage, p - storage);
|
|
2851 @}
|
|
2852 @end group
|
|
2853 @end example
|
|
2854
|
|
2855 Now we can analyze the source line by line.
|
|
2856
|
|
2857 Obviously, string will be as long as there are arguments to the
|
|
2858 function. This is why we allocate @code{MAX_EMCHAR_LEN} * @var{nargs}
|
|
2859 bytes on the stack, i.e. the worst-case number of bytes for @var{nargs}
|
|
2860 @code{Emchar}s to fit in the string.
|
|
2861
|
|
2862 Then, the loop checks that each element is a character, converting
|
|
2863 integers in the process. Like many other functions in XEmacs, this
|
|
2864 function silently accepts integers where characters are expected, for
|
|
2865 historical and compatibility reasons. Unless you know what you are
|
|
2866 doing, @code{CHECK_CHAR} will also suffice. @code{XCHAR (lisp_char)}
|
|
2867 extracts the @code{Emchar} from the @code{Lisp_Object}, and
|
|
2868 @code{set_charptr_emchar} stores it to storage, increasing @code{p} in
|
|
2869 the process.
|
|
2870
|
|
2871 Other instructive examples of correct coding under Mule can be found all
|
|
2872 over the XEmacs code. For starters, I recommend
|
|
2873 @code{Fnormalize_menu_item_name} in @file{menubar.c}. After you have
|
|
2874 understood this section of the manual and studied the examples, you can
|
|
2875 proceed writing new Mule-aware code.
|
|
2876
|
462
|
2877 @node Techniques for XEmacs Developers
|
428
|
2878 @section Techniques for XEmacs Developers
|
462
|
2879 @cindex techniques for XEmacs developers
|
|
2880 @cindex developers, techniques for XEmacs
|
|
2881
|
|
2882 @cindex Purify
|
|
2883 @cindex Quantify
|
442
|
2884 To make a purified XEmacs, do: @code{make puremacs}.
|
428
|
2885 To make a quantified XEmacs, do: @code{make quantmacs}.
|
|
2886
|
442
|
2887 You simply can't dump Quantified and Purified images (unless using the
|
|
2888 portable dumper). Purify gets confused when xemacs frees memory in one
|
|
2889 process that was allocated in a @emph{different} process on a different
|
|
2890 machine!. Run it like so:
|
|
2891 @example
|
|
2892 temacs -batch -l loadup.el run-temacs @var{xemacs-args...}
|
|
2893 @end example
|
428
|
2894
|
462
|
2895 @cindex error checking
|
428
|
2896 Before you go through the trouble, are you compiling with all
|
442
|
2897 debugging and error-checking off? If not, try that first. Be warned
|
428
|
2898 that while Quantify is directly responsible for quite a few
|
|
2899 optimizations which have been made to XEmacs, doing a run which
|
|
2900 generates results which can be acted upon is not necessarily a trivial
|
|
2901 task.
|
|
2902
|
|
2903 Also, if you're still willing to do some runs make sure you configure
|
|
2904 with the @samp{--quantify} flag. That will keep Quantify from starting
|
|
2905 to record data until after the loadup is completed and will shut off
|
|
2906 recording right before it shuts down (which generates enough bogus data
|
|
2907 to throw most results off). It also enables three additional elisp
|
|
2908 commands: @code{quantify-start-recording-data},
|
|
2909 @code{quantify-stop-recording-data} and @code{quantify-clear-data}.
|
|
2910
|
|
2911 If you want to make XEmacs faster, target your favorite slow benchmark,
|
|
2912 run a profiler like Quantify, @code{gprof}, or @code{tcov}, and figure
|
|
2913 out where the cycles are going. Specific projects:
|
|
2914
|
|
2915 @itemize @bullet
|
|
2916 @item
|
|
2917 Make the garbage collector faster. Figure out how to write an
|
|
2918 incremental garbage collector.
|
|
2919 @item
|
|
2920 Write a compiler that takes bytecode and spits out C code.
|
|
2921 Unfortunately, you will then need a C compiler and a more fully
|
|
2922 developed module system.
|
|
2923 @item
|
|
2924 Speed up redisplay.
|
|
2925 @item
|
|
2926 Speed up syntax highlighting. Maybe moving some of the syntax
|
|
2927 highlighting capabilities into C would make a difference.
|
|
2928 @item
|
|
2929 Implement tail recursion in Emacs Lisp (hard!).
|
|
2930 @end itemize
|
|
2931
|
|
2932 Unfortunately, Emacs Lisp is slow, and is going to stay slow. Function
|
|
2933 calls in elisp are especially expensive. Iterating over a long list is
|
|
2934 going to be 30 times faster implemented in C than in Elisp.
|
|
2935
|
442
|
2936 Heavily used small code fragments need to be fast. The traditional way
|
|
2937 to implement such code fragments in C is with macros. But macros in C
|
|
2938 are known to be broken.
|
|
2939
|
462
|
2940 @cindex macro hygiene
|
442
|
2941 Macro arguments that are repeatedly evaluated may suffer from repeated
|
|
2942 side effects or suboptimal performance.
|
|
2943
|
|
2944 Variable names used in macros may collide with caller's variables,
|
|
2945 causing (at least) unwanted compiler warnings.
|
|
2946
|
|
2947 In order to solve these problems, and maintain statement semantics, one
|
|
2948 should use the @code{do @{ ... @} while (0)} trick while trying to
|
|
2949 reference macro arguments exactly once using local variables.
|
|
2950
|
|
2951 Let's take a look at this poor macro definition:
|
|
2952
|
|
2953 @example
|
|
2954 #define MARK_OBJECT(obj) \
|
|
2955 if (!marked_p (obj)) mark_object (obj), did_mark = 1
|
|
2956 @end example
|
|
2957
|
|
2958 This macro evaluates its argument twice, and also fails if used like this:
|
|
2959 @example
|
|
2960 if (flag) MARK_OBJECT (obj); else do_something();
|
|
2961 @end example
|
|
2962
|
|
2963 A much better definition is
|
|
2964
|
|
2965 @example
|
|
2966 #define MARK_OBJECT(obj) do @{ \
|
|
2967 Lisp_Object mo_obj = (obj); \
|
|
2968 if (!marked_p (mo_obj)) \
|
|
2969 @{ \
|
|
2970 mark_object (mo_obj); \
|
|
2971 did_mark = 1; \
|
|
2972 @} \
|
|
2973 @} while (0)
|
|
2974 @end example
|
|
2975
|
|
2976 Notice the elimination of double evaluation by using the local variable
|
|
2977 with the obscure name. Writing safe and efficient macros requires great
|
|
2978 care. The one problem with macros that cannot be portably worked around
|
|
2979 is, since a C block has no value, a macro used as an expression rather
|
|
2980 than a statement cannot use the techniques just described to avoid
|
|
2981 multiple evaluation.
|
|
2982
|
462
|
2983 @cindex inline functions
|
442
|
2984 In most cases where a macro has function semantics, an inline function
|
|
2985 is a better implementation technique. Modern compiler optimizers tend
|
|
2986 to inline functions even if they have no @code{inline} keyword, and
|
|
2987 configure magic ensures that the @code{inline} keyword can be safely
|
|
2988 used as an additional compiler hint. Inline functions used in a single
|
|
2989 .c files are easy. The function must already be defined to be
|
|
2990 @code{static}. Just add another @code{inline} keyword to the
|
|
2991 definition.
|
|
2992
|
|
2993 @example
|
|
2994 inline static int
|
|
2995 heavily_used_small_function (int arg)
|
|
2996 @{
|
|
2997 ...
|
|
2998 @}
|
|
2999 @end example
|
|
3000
|
|
3001 Inline functions in header files are trickier, because we would like to
|
|
3002 make the following optimization if the function is @emph{not} inlined
|
|
3003 (for example, because we're compiling for debugging). We would like the
|
|
3004 function to be defined externally exactly once, and each calling
|
|
3005 translation unit would create an external reference to the function,
|
|
3006 instead of including a definition of the inline function in the object
|
|
3007 code of every translation unit that uses it. This optimization is
|
|
3008 currently only available for gcc. But you don't have to worry about the
|
|
3009 trickiness; just define your inline functions in header files using this
|
|
3010 pattern:
|
|
3011
|
|
3012 @example
|
|
3013 INLINE_HEADER int
|
|
3014 i_used_to_be_a_crufty_macro_but_look_at_me_now (int arg);
|
|
3015 INLINE_HEADER int
|
|
3016 i_used_to_be_a_crufty_macro_but_look_at_me_now (int arg)
|
|
3017 @{
|
|
3018 ...
|
|
3019 @}
|
|
3020 @end example
|
|
3021
|
|
3022 The declaration right before the definition is to prevent warnings when
|
|
3023 compiling with @code{gcc -Wmissing-declarations}. I consider issuing
|
|
3024 this warning for inline functions a gcc bug, but the gcc maintainers disagree.
|
|
3025
|
462
|
3026 @cindex inline functions, headers
|
|
3027 @cindex header files, inline functions
|
442
|
3028 Every header which contains inline functions, either directly by using
|
|
3029 @code{INLINE_HEADER} or indirectly by using @code{DECLARE_LRECORD} must
|
|
3030 be added to @file{inline.c}'s includes to make the optimization
|
|
3031 described above work. (Optimization note: if all INLINE_HEADER
|
|
3032 functions are in fact inlined in all translation units, then the linker
|
|
3033 can just discard @code{inline.o}, since it contains only unreferenced code).
|
|
3034
|
438
|
3035 To get started debugging XEmacs, take a look at the @file{.gdbinit} and
|
442
|
3036 @file{.dbxrc} files in the @file{src} directory. See the section in the
|
|
3037 XEmacs FAQ on How to Debug an XEmacs problem with a debugger.
|
428
|
3038
|
|
3039 After making source code changes, run @code{make check} to ensure that
|
442
|
3040 you haven't introduced any regressions. If you want to make xemacs more
|
|
3041 reliable, please improve the test suite in @file{tests/automated}.
|
|
3042
|
|
3043 Did you make sure you didn't introduce any new compiler warnings?
|
|
3044
|
|
3045 Before submitting a patch, please try compiling at least once with
|
|
3046
|
|
3047 @example
|
607
|
3048 configure --with-mule --use-union-type --error-checking=all
|
442
|
3049 @end example
|
428
|
3050
|
|
3051 Here are things to know when you create a new source file:
|
|
3052
|
|
3053 @itemize @bullet
|
|
3054 @item
|
|
3055 All @file{.c} files should @code{#include <config.h>} first. Almost all
|
|
3056 @file{.c} files should @code{#include "lisp.h"} second.
|
|
3057
|
|
3058 @item
|
|
3059 Generated header files should be included using the @code{#include <...>} syntax,
|
|
3060 not the @code{#include "..."} syntax. The generated headers are:
|
|
3061
|
442
|
3062 @file{config.h sheap-adjust.h paths.h Emacs.ad.h}
|
428
|
3063
|
|
3064 The basic rule is that you should assume builds using @code{--srcdir}
|
|
3065 and the @code{#include <...>} syntax needs to be used when the
|
|
3066 to-be-included generated file is in a potentially different directory
|
|
3067 @emph{at compile time}. The non-obvious C rule is that @code{#include "..."}
|
|
3068 means to search for the included file in the same directory as the
|
|
3069 including file, @emph{not} in the current directory.
|
|
3070
|
|
3071 @item
|
|
3072 Header files should @emph{not} include @code{<config.h>} and
|
|
3073 @code{"lisp.h"}. It is the responsibility of the @file{.c} files that
|
|
3074 use it to do so.
|
|
3075
|
|
3076 @end itemize
|
|
3077
|
462
|
3078 @cindex Lisp object types, creating
|
|
3079 @cindex creating Lisp object types
|
|
3080 @cindex object types, creating Lisp
|
442
|
3081 Here is a checklist of things to do when creating a new lisp object type
|
|
3082 named @var{foo}:
|
|
3083
|
|
3084 @enumerate
|
|
3085 @item
|
|
3086 create @var{foo}.h
|
|
3087 @item
|
|
3088 create @var{foo}.c
|
|
3089 @item
|
|
3090 add definitions of @code{syms_of_@var{foo}}, etc. to @file{@var{foo}.c}
|
|
3091 @item
|
|
3092 add declarations of @code{syms_of_@var{foo}}, etc. to @file{symsinit.h}
|
|
3093 @item
|
|
3094 add calls to @code{syms_of_@var{foo}}, etc. to @file{emacs.c}
|
|
3095 @item
|
|
3096 add definitions of macros like @code{CHECK_@var{FOO}} and
|
|
3097 @code{@var{FOO}P} to @file{@var{foo}.h}
|
|
3098 @item
|
|
3099 add the new type index to @code{enum lrecord_type}
|
|
3100 @item
|
|
3101 add a DEFINE_LRECORD_IMPLEMENTATION call to @file{@var{foo}.c}
|
|
3102 @item
|
|
3103 add an INIT_LRECORD_IMPLEMENTATION call to @code{syms_of_@var{foo}.c}
|
|
3104 @end enumerate
|
428
|
3105
|
802
|
3106 @node CVS Techniques, A Summary of the Various XEmacs Modules, Rules When Writing New C Code, Top
|
|
3107 @chapter CVS Techniques
|
|
3108 @cindex CVS techniques
|
|
3109
|
|
3110 @menu
|
|
3111 * Merging a Branch into the Trunk::
|
|
3112 @end menu
|
|
3113
|
|
3114 @node Merging a Branch into the Trunk
|
|
3115 @section Merging a Branch into the Trunk
|
|
3116 @cindex merging a branch into the trunk
|
|
3117
|
|
3118 @enumerate
|
|
3119 @item
|
|
3120 If you haven't already done a merge, you will be merging from the branch
|
|
3121 point; otherwise you'll be merging from the last merge point, which
|
|
3122 should be marked by a tag, e.g. @samp{last-sync-ben-mule-21-5}. In the
|
|
3123 former case, create the last-sync tag, e.g.
|
|
3124
|
|
3125 @example
|
|
3126 crw rtag -r ben-mule-21-5-bp last-sync-ben-mule-21-5 xemacs
|
|
3127 @end example
|
|
3128
|
|
3129 (You did create a branch point tag when you created the branch, didn't
|
|
3130 you?)
|
|
3131
|
|
3132 @item
|
|
3133 Check everything in on your branch.
|
|
3134
|
|
3135 @item
|
|
3136 Tag your branch with a pre-sync tag, e.g.
|
|
3137
|
|
3138 @example
|
|
3139 crw rtag -r ben-mule-21-5 ben-mule-21-5-pre-feb-20-2002-sync xemacs
|
|
3140 @end example
|
|
3141
|
|
3142 Note, you need to use rtag and specify a version with @samp{-r} (use
|
|
3143 @samp{-r HEAD} if necessary) so that removed files are handled correctly
|
|
3144 in some obscure cases. See section 4.8 of the CVS manual.
|
|
3145
|
|
3146 @item
|
|
3147 Tag the trunk so you have a stable place to merge up to in case people
|
|
3148 are asynchronously committing to the trunk, e.g.
|
|
3149
|
|
3150 @example
|
|
3151 crw rtag -r HEAD main-branch-ben-mule-21-5-syncpoint-feb-20-2002 xemacs
|
|
3152 crw rtag -F -r main-branch-ben-mule-21-5-syncpoint-feb-20-2002 next-sync-ben-mule-21-5 xemacs
|
|
3153 @end example
|
|
3154
|
|
3155 Use -F in the second case because the name might already exist, e.g. if
|
|
3156 you've already done a merge. We make two tags because one is a
|
|
3157 permanent mark indicating a syncpoint when merging, and the other is a
|
|
3158 symbolic tag to make other operations easier.
|
|
3159
|
|
3160 @item
|
|
3161 Make a backup of your source tree (not totally necessary but useful for
|
|
3162 reference and peace of mind): Move one level up from the top directory
|
|
3163 of your branch and do, e.g.
|
|
3164
|
|
3165 @example
|
|
3166 cp -a mule mule-backup-2-23-02
|
|
3167 @end example
|
|
3168
|
|
3169 @item
|
|
3170 Now, we're ready to merge! Make sure you're in the top directory of
|
|
3171 your branch and do, e.g.
|
|
3172
|
|
3173 @example
|
|
3174 cvs update -j last-sync-ben-mule-21-5 -j next-sync-ben-mule-21-5
|
|
3175 @end example
|
|
3176
|
|
3177 @item
|
|
3178 Fix all merge conflicts. Get the sucker to compile and run.
|
|
3179
|
|
3180 @item
|
|
3181 Tag your branch with a post-sync tag, e.g.
|
|
3182
|
|
3183 @example
|
|
3184 crw rtag -r ben-mule-21-5 ben-mule-21-5-post-feb-20-2002-sync xemacs
|
|
3185 @end example
|
|
3186
|
|
3187 @item
|
|
3188 Update the last-sync tag, e.g.
|
|
3189
|
|
3190 @example
|
|
3191 crw rtag -F -r next-sync-ben-mule-21-5 last-sync-ben-mule-21-5 xemacs
|
|
3192 @end example
|
|
3193 @end enumerate
|
|
3194
|
|
3195
|
|
3196 @node A Summary of the Various XEmacs Modules, Allocation of Objects in XEmacs Lisp, CVS Techniques, Top
|
428
|
3197 @chapter A Summary of the Various XEmacs Modules
|
462
|
3198 @cindex modules, a summary of the various XEmacs
|
428
|
3199
|
|
3200 This is accurate as of XEmacs 20.0.
|
|
3201
|
|
3202 @menu
|
|
3203 * Low-Level Modules::
|
|
3204 * Basic Lisp Modules::
|
|
3205 * Modules for Standard Editing Operations::
|
|
3206 * Editor-Level Control Flow Modules::
|
|
3207 * Modules for the Basic Displayable Lisp Objects::
|
|
3208 * Modules for other Display-Related Lisp Objects::
|
|
3209 * Modules for the Redisplay Mechanism::
|
|
3210 * Modules for Interfacing with the File System::
|
|
3211 * Modules for Other Aspects of the Lisp Interpreter and Object System::
|
|
3212 * Modules for Interfacing with the Operating System::
|
|
3213 * Modules for Interfacing with X Windows::
|
|
3214 * Modules for Internationalization::
|
|
3215 @end menu
|
|
3216
|
462
|
3217 @node Low-Level Modules
|
428
|
3218 @section Low-Level Modules
|
462
|
3219 @cindex low-level modules
|
|
3220 @cindex modules, low-level
|
428
|
3221
|
|
3222 @example
|
|
3223 config.h
|
|
3224 @end example
|
|
3225
|
|
3226 This is automatically generated from @file{config.h.in} based on the
|
|
3227 results of configure tests and user-selected optional features and
|
|
3228 contains preprocessor definitions specifying the nature of the
|
|
3229 environment in which XEmacs is being compiled.
|
|
3230
|
|
3231
|
|
3232
|
|
3233 @example
|
|
3234 paths.h
|
|
3235 @end example
|
|
3236
|
|
3237 This is automatically generated from @file{paths.h.in} based on supplied
|
|
3238 configure values, and allows for non-standard installed configurations
|
|
3239 of the XEmacs directories. It's currently broken, though.
|
|
3240
|
|
3241
|
|
3242
|
|
3243 @example
|
|
3244 emacs.c
|
|
3245 signal.c
|
|
3246 @end example
|
|
3247
|
|
3248 @file{emacs.c} contains @code{main()} and other code that performs the most
|
|
3249 basic environment initializations and handles shutting down the XEmacs
|
|
3250 process (this includes @code{kill-emacs}, the normal way that XEmacs is
|
|
3251 exited; @code{dump-emacs}, which is used during the build process to
|
|
3252 write out the XEmacs executable; @code{run-emacs-from-temacs}, which can
|
|
3253 be used to start XEmacs directly when temacs has finished loading all
|
|
3254 the Lisp code; and emergency code to handle crashes [XEmacs tries to
|
|
3255 auto-save all files before it crashes]).
|
|
3256
|
|
3257 Low-level code that directly interacts with the Unix signal mechanism,
|
|
3258 however, is in @file{signal.c}. Note that this code does not handle system
|
|
3259 dependencies in interfacing to signals; that is handled using the
|
|
3260 @file{syssignal.h} header file, described in section J below.
|
|
3261
|
|
3262
|
|
3263
|
|
3264 @example
|
|
3265 unexaix.c
|
|
3266 unexalpha.c
|
|
3267 unexapollo.c
|
|
3268 unexconvex.c
|
|
3269 unexec.c
|
|
3270 unexelf.c
|
|
3271 unexelfsgi.c
|
|
3272 unexencap.c
|
|
3273 unexenix.c
|
|
3274 unexfreebsd.c
|
|
3275 unexfx2800.c
|
|
3276 unexhp9k3.c
|
|
3277 unexhp9k800.c
|
|
3278 unexmips.c
|
|
3279 unexnext.c
|
|
3280 unexsol2.c
|
|
3281 unexsunos4.c
|
|
3282 @end example
|
|
3283
|
|
3284 These modules contain code dumping out the XEmacs executable on various
|
|
3285 different systems. (This process is highly machine-specific and
|
|
3286 requires intimate knowledge of the executable format and the memory map
|
|
3287 of the process.) Only one of these modules is actually used; this is
|
|
3288 chosen by @file{configure}.
|
|
3289
|
|
3290
|
|
3291
|
|
3292 @example
|
442
|
3293 ecrt0.c
|
428
|
3294 lastfile.c
|
|
3295 pre-crt0.c
|
|
3296 @end example
|
|
3297
|
|
3298 These modules are used in conjunction with the dump mechanism. On some
|
|
3299 systems, an alternative version of the C startup code (the actual code
|
|
3300 that receives control from the operating system when the process is
|
|
3301 started, and which calls @code{main()}) is required so that the dumping
|
|
3302 process works properly; @file{crt0.c} provides this.
|
|
3303
|
|
3304 @file{pre-crt0.c} and @file{lastfile.c} should be the very first and
|
|
3305 very last file linked, respectively. (Actually, this is not really true.
|
|
3306 @file{lastfile.c} should be after all Emacs modules whose initialized
|
|
3307 data should be made constant, and before all other Emacs files and all
|
|
3308 libraries. In particular, the allocation modules @file{gmalloc.c},
|
|
3309 @file{alloca.c}, etc. are normally placed past @file{lastfile.c}, and
|
|
3310 all of the files that implement Xt widget classes @emph{must} be placed
|
|
3311 after @file{lastfile.c} because they contain various structures that
|
|
3312 must be statically initialized and into which Xt writes at various
|
|
3313 times.) @file{pre-crt0.c} and @file{lastfile.c} contain exported symbols
|
|
3314 that are used to determine the start and end of XEmacs' initialized
|
|
3315 data space when dumping.
|
|
3316
|
|
3317
|
|
3318
|
|
3319 @example
|
|
3320 alloca.c
|
|
3321 free-hook.c
|
|
3322 getpagesize.h
|
|
3323 gmalloc.c
|
|
3324 malloc.c
|
|
3325 mem-limits.h
|
|
3326 ralloc.c
|
|
3327 vm-limit.c
|
|
3328 @end example
|
|
3329
|
|
3330 These handle basic C allocation of memory. @file{alloca.c} is an emulation of
|
|
3331 the stack allocation function @code{alloca()} on machines that lack
|
|
3332 this. (XEmacs makes extensive use of @code{alloca()} in its code.)
|
|
3333
|
|
3334 @file{gmalloc.c} and @file{malloc.c} are two implementations of the standard C
|
|
3335 functions @code{malloc()}, @code{realloc()} and @code{free()}. They are
|
|
3336 often used in place of the standard system-provided @code{malloc()}
|
|
3337 because they usually provide a much faster implementation, at the
|
|
3338 expense of additional memory use. @file{gmalloc.c} is a newer implementation
|
|
3339 that is much more memory-efficient for large allocations than @file{malloc.c},
|
|
3340 and should always be preferred if it works. (At one point, @file{gmalloc.c}
|
|
3341 didn't work on some systems where @file{malloc.c} worked; but this should be
|
|
3342 fixed now.)
|
|
3343
|
|
3344 @cindex relocating allocator
|
|
3345 @file{ralloc.c} is the @dfn{relocating allocator}. It provides
|
|
3346 functions similar to @code{malloc()}, @code{realloc()} and @code{free()}
|
|
3347 that allocate memory that can be dynamically relocated in memory. The
|
|
3348 advantage of this is that allocated memory can be shuffled around to
|
|
3349 place all the free memory at the end of the heap, and the heap can then
|
|
3350 be shrunk, releasing the memory back to the operating system. The use
|
|
3351 of this can be controlled with the configure option @code{--rel-alloc};
|
|
3352 if enabled, memory allocated for buffers will be relocatable, so that if
|
|
3353 a very large file is visited and the buffer is later killed, the memory
|
|
3354 can be released to the operating system. (The disadvantage of this
|
|
3355 mechanism is that it can be very slow. On systems with the
|
|
3356 @code{mmap()} system call, the XEmacs version of @file{ralloc.c} uses
|
|
3357 this to move memory around without actually having to block-copy it,
|
|
3358 which can speed things up; but it can still cause noticeable performance
|
|
3359 degradation.)
|
|
3360
|
|
3361 @file{free-hook.c} contains some debugging functions for checking for invalid
|
|
3362 arguments to @code{free()}.
|
|
3363
|
|
3364 @file{vm-limit.c} contains some functions that warn the user when memory is
|
|
3365 getting low. These are callback functions that are called by @file{gmalloc.c}
|
|
3366 and @file{malloc.c} at appropriate times.
|
|
3367
|
|
3368 @file{getpagesize.h} provides a uniform interface for retrieving the size of a
|
|
3369 page in virtual memory. @file{mem-limits.h} provides a uniform interface for
|
|
3370 retrieving the total amount of available virtual memory. Both are
|
|
3371 similar in spirit to the @file{sys*.h} files described in section J, below.
|
|
3372
|
|
3373
|
|
3374
|
|
3375 @example
|
|
3376 blocktype.c
|
|
3377 blocktype.h
|
|
3378 dynarr.c
|
|
3379 @end example
|
|
3380
|
|
3381 These implement a couple of basic C data types to facilitate memory
|
|
3382 allocation. The @code{Blocktype} type efficiently manages the
|
|
3383 allocation of fixed-size blocks by minimizing the number of times that
|
|
3384 @code{malloc()} and @code{free()} are called. It allocates memory in
|
|
3385 large chunks, subdivides the chunks into blocks of the proper size, and
|
|
3386 returns the blocks as requested. When blocks are freed, they are placed
|
|
3387 onto a linked list, so they can be efficiently reused. This data type
|
|
3388 is not much used in XEmacs currently, because it's a fairly new
|
|
3389 addition.
|
|
3390
|
|
3391 @cindex dynamic array
|
|
3392 The @code{Dynarr} type implements a @dfn{dynamic array}, which is
|
|
3393 similar to a standard C array but has no fixed limit on the number of
|
|
3394 elements it can contain. Dynamic arrays can hold elements of any type,
|
|
3395 and when you add a new element, the array automatically resizes itself
|
|
3396 if it isn't big enough. Dynarrs are extensively used in the redisplay
|
|
3397 mechanism.
|
|
3398
|
|
3399
|
|
3400
|
|
3401 @example
|
|
3402 inline.c
|
|
3403 @end example
|
|
3404
|
|
3405 This module is used in connection with inline functions (available in
|
|
3406 some compilers). Often, inline functions need to have a corresponding
|
|
3407 non-inline function that does the same thing. This module is where they
|
|
3408 reside. It contains no actual code, but defines some special flags that
|
|
3409 cause inline functions defined in header files to be rendered as actual
|
|
3410 functions. It then includes all header files that contain any inline
|
|
3411 function definitions, so that each one gets a real function equivalent.
|
|
3412
|
|
3413
|
|
3414
|
|
3415 @example
|
|
3416 debug.c
|
|
3417 debug.h
|
|
3418 @end example
|
|
3419
|
|
3420 These functions provide a system for doing internal consistency checks
|
|
3421 during code development. This system is not currently used; instead the
|
|
3422 simpler @code{assert()} macro is used along with the various checks
|
|
3423 provided by the @samp{--error-check-*} configuration options.
|
|
3424
|
|
3425
|
|
3426
|
|
3427 @example
|
|
3428 universe.h
|
|
3429 @end example
|
|
3430
|
|
3431 This is not currently used.
|
|
3432
|
|
3433
|
|
3434
|
462
|
3435 @node Basic Lisp Modules
|
428
|
3436 @section Basic Lisp Modules
|
462
|
3437 @cindex Lisp modules, basic
|
|
3438 @cindex modules, basic Lisp
|
428
|
3439
|
|
3440 @example
|
|
3441 lisp-disunion.h
|
|
3442 lisp-union.h
|
|
3443 lisp.h
|
|
3444 lrecord.h
|
|
3445 symsinit.h
|
|
3446 @end example
|
|
3447
|
|
3448 These are the basic header files for all XEmacs modules. Each module
|
|
3449 includes @file{lisp.h}, which brings the other header files in.
|
|
3450 @file{lisp.h} contains the definitions of the structures and extractor
|
|
3451 and constructor macros for the basic Lisp objects and various other
|
|
3452 basic definitions for the Lisp environment, as well as some
|
|
3453 general-purpose definitions (e.g. @code{min()} and @code{max()}).
|
|
3454 @file{lisp.h} includes either @file{lisp-disunion.h} or
|
|
3455 @file{lisp-union.h}, depending on whether @code{USE_UNION_TYPE} is
|
|
3456 defined. These files define the typedef of the Lisp object itself (as
|
|
3457 described above) and the low-level macros that hide the actual
|
|
3458 implementation of the Lisp object. All extractor and constructor macros
|
|
3459 for particular types of Lisp objects are defined in terms of these
|
|
3460 low-level macros.
|
|
3461
|
|
3462 As a general rule, all typedefs should go into the typedefs section of
|
|
3463 @file{lisp.h} rather than into a module-specific header file even if the
|
|
3464 structure is defined elsewhere. This allows function prototypes that
|
|
3465 use the typedef to be placed into other header files. Forward structure
|
|
3466 declarations (i.e. a simple declaration like @code{struct foo;} where
|
|
3467 the structure itself is defined elsewhere) should be placed into the
|
|
3468 typedefs section as necessary.
|
|
3469
|
|
3470 @file{lrecord.h} contains the basic structures and macros that implement
|
440
|
3471 all record-type Lisp objects---i.e. all objects whose type is a field
|
428
|
3472 in their C structure, which includes all objects except the few most
|
|
3473 basic ones.
|
|
3474
|
|
3475 @file{lisp.h} contains prototypes for most of the exported functions in
|
|
3476 the various modules. Lisp primitives defined using @code{DEFUN} that
|
|
3477 need to be called by C code should be declared using @code{EXFUN}.
|
|
3478 Other function prototypes should be placed either into the appropriate
|
|
3479 section of @code{lisp.h}, or into a module-specific header file,
|
|
3480 depending on how general-purpose the function is and whether it has
|
|
3481 special-purpose argument types requiring definitions not in
|
|
3482 @file{lisp.h}.) All initialization functions are prototyped in
|
|
3483 @file{symsinit.h}.
|
|
3484
|
|
3485
|
|
3486
|
|
3487 @example
|
|
3488 alloc.c
|
|
3489 @end example
|
|
3490
|
|
3491 The large module @file{alloc.c} implements all of the basic allocation and
|
|
3492 garbage collection for Lisp objects. The most commonly used Lisp
|
|
3493 objects are allocated in chunks, similar to the Blocktype data type
|
|
3494 described above; others are allocated in individually @code{malloc()}ed
|
|
3495 blocks. This module provides the foundation on which all other aspects
|
|
3496 of the Lisp environment sit, and is the first module initialized at
|
|
3497 startup.
|
|
3498
|
|
3499 Note that @file{alloc.c} provides a series of generic functions that are
|
|
3500 not dependent on any particular object type, and interfaces to
|
|
3501 particular types of objects using a standardized interface of
|
|
3502 type-specific methods. This scheme is a fundamental principle of
|
|
3503 object-oriented programming and is heavily used throughout XEmacs. The
|
|
3504 great advantage of this is that it allows for a clean separation of
|
440
|
3505 functionality into different modules---new classes of Lisp objects, new
|
428
|
3506 event interfaces, new device types, new stream interfaces, etc. can be
|
|
3507 added transparently without affecting code anywhere else in XEmacs.
|
|
3508 Because the different subsystems are divided into general and specific
|
|
3509 code, adding a new subtype within a subsystem will in general not
|
|
3510 require changes to the generic subsystem code or affect any of the other
|
|
3511 subtypes in the subsystem; this provides a great deal of robustness to
|
|
3512 the XEmacs code.
|
|
3513
|
|
3514
|
|
3515 @example
|
|
3516 eval.c
|
|
3517 backtrace.h
|
|
3518 @end example
|
|
3519
|
|
3520 This module contains all of the functions to handle the flow of control.
|
|
3521 This includes the mechanisms of defining functions, calling functions,
|
|
3522 traversing stack frames, and binding variables; the control primitives
|
|
3523 and other special forms such as @code{while}, @code{if}, @code{eval},
|
|
3524 @code{let}, @code{and}, @code{or}, @code{progn}, etc.; handling of
|
|
3525 non-local exits, unwind-protects, and exception handlers; entering the
|
|
3526 debugger; methods for the subr Lisp object type; etc. It does
|
|
3527 @emph{not} include the @code{read} function, the @code{print} function,
|
|
3528 or the handling of symbols and obarrays.
|
|
3529
|
|
3530 @file{backtrace.h} contains some structures related to stack frames and the
|
|
3531 flow of control.
|
|
3532
|
|
3533
|
|
3534
|
|
3535 @example
|
|
3536 lread.c
|
|
3537 @end example
|
|
3538
|
|
3539 This module implements the Lisp reader and the @code{read} function,
|
|
3540 which converts text into Lisp objects, according to the read syntax of
|
|
3541 the objects, as described above. This is similar to the parser that is
|
|
3542 a part of all compilers.
|
|
3543
|
|
3544
|
|
3545
|
|
3546 @example
|
|
3547 print.c
|
|
3548 @end example
|
|
3549
|
|
3550 This module implements the Lisp print mechanism and the @code{print}
|
|
3551 function and related functions. This is the inverse of the Lisp reader
|
|
3552 -- it converts Lisp objects to a printed, textual representation.
|
|
3553 (Hopefully something that can be read back in using @code{read} to get
|
|
3554 an equivalent object.)
|
|
3555
|
|
3556
|
|
3557
|
|
3558 @example
|
|
3559 general.c
|
|
3560 symbols.c
|
|
3561 symeval.h
|
|
3562 @end example
|
|
3563
|
|
3564 @file{symbols.c} implements the handling of symbols, obarrays, and
|
|
3565 retrieving the values of symbols. Much of the code is devoted to
|
|
3566 handling the special @dfn{symbol-value-magic} objects that define
|
440
|
3567 special types of variables---this includes buffer-local variables,
|
428
|
3568 variable aliases, variables that forward into C variables, etc. This
|
|
3569 module is initialized extremely early (right after @file{alloc.c}),
|
|
3570 because it is here that the basic symbols @code{t} and @code{nil} are
|
|
3571 created, and those symbols are used everywhere throughout XEmacs.
|
|
3572
|
|
3573 @file{symeval.h} contains the definitions of symbol structures and the
|
|
3574 @code{DEFVAR_LISP()} and related macros for declaring variables.
|
|
3575
|
|
3576
|
|
3577
|
|
3578 @example
|
|
3579 data.c
|
|
3580 floatfns.c
|
|
3581 fns.c
|
|
3582 @end example
|
|
3583
|
|
3584 These modules implement the methods and standard Lisp primitives for all
|
|
3585 the basic Lisp object types other than symbols (which are described
|
|
3586 above). @file{data.c} contains all the predicates (primitives that return
|
|
3587 whether an object is of a particular type); the integer arithmetic
|
|
3588 functions; and the basic accessor and mutator primitives for the various
|
|
3589 object types. @file{fns.c} contains all the standard predicates for working
|
|
3590 with sequences (where, abstractly speaking, a sequence is an ordered set
|
|
3591 of objects, and can be represented by a list, string, vector, or
|
|
3592 bit-vector); it also contains @code{equal}, perhaps on the grounds that
|
|
3593 bulk of the operation of @code{equal} is comparing sequences.
|
|
3594 @file{floatfns.c} contains methods and primitives for floats and floating-point
|
|
3595 arithmetic.
|
|
3596
|
|
3597
|
|
3598
|
|
3599 @example
|
|
3600 bytecode.c
|
|
3601 bytecode.h
|
|
3602 @end example
|
|
3603
|
|
3604 @file{bytecode.c} implements the byte-code interpreter and
|
|
3605 compiled-function objects, and @file{bytecode.h} contains associated
|
|
3606 structures. Note that the byte-code @emph{compiler} is written in Lisp.
|
|
3607
|
|
3608
|
|
3609
|
|
3610
|
462
|
3611 @node Modules for Standard Editing Operations
|
428
|
3612 @section Modules for Standard Editing Operations
|
462
|
3613 @cindex modules for standard editing operations
|
|
3614 @cindex editing operations, modules for standard
|
428
|
3615
|
|
3616 @example
|
|
3617 buffer.c
|
|
3618 buffer.h
|
|
3619 bufslots.h
|
|
3620 @end example
|
|
3621
|
|
3622 @file{buffer.c} implements the @dfn{buffer} Lisp object type. This
|
|
3623 includes functions that create and destroy buffers; retrieve buffers by
|
|
3624 name or by other properties; manipulate lists of buffers (remember that
|
|
3625 buffers are permanent objects and stored in various ordered lists);
|
|
3626 retrieve or change buffer properties; etc. It also contains the
|
|
3627 definitions of all the built-in buffer-local variables (which can be
|
|
3628 viewed as buffer properties). It does @emph{not} contain code to
|
|
3629 manipulate buffer-local variables (that's in @file{symbols.c}, described
|
|
3630 above); or code to manipulate the text in a buffer.
|
|
3631
|
|
3632 @file{buffer.h} defines the structures associated with a buffer and the various
|
|
3633 macros for retrieving text from a buffer and special buffer positions
|
|
3634 (e.g. @code{point}, the default location for text insertion). It also
|
|
3635 contains macros for working with buffer positions and converting between
|
|
3636 their representations as character offsets and as byte offsets (under
|
|
3637 MULE, they are different, because characters can be multi-byte). It is
|
|
3638 one of the largest header files.
|
|
3639
|
|
3640 @file{bufslots.h} defines the fields in the buffer structure that correspond to
|
|
3641 the built-in buffer-local variables. It is its own header file because
|
|
3642 it is included many times in @file{buffer.c}, as a way of iterating over all
|
|
3643 the built-in buffer-local variables.
|
|
3644
|
|
3645
|
|
3646
|
|
3647 @example
|
|
3648 insdel.c
|
|
3649 insdel.h
|
|
3650 @end example
|
|
3651
|
|
3652 @file{insdel.c} contains low-level functions for inserting and deleting text in
|
|
3653 a buffer, keeping track of changed regions for use by redisplay, and
|
|
3654 calling any before-change and after-change functions that may have been
|
|
3655 registered for the buffer. It also contains the actual functions that
|
|
3656 convert between byte offsets and character offsets.
|
|
3657
|
|
3658 @file{insdel.h} contains associated headers.
|
|
3659
|
|
3660
|
|
3661
|
|
3662 @example
|
|
3663 marker.c
|
|
3664 @end example
|
|
3665
|
|
3666 This module implements the @dfn{marker} Lisp object type, which
|
|
3667 conceptually is a pointer to a text position in a buffer that moves
|
|
3668 around as text is inserted and deleted, so as to remain in the same
|
|
3669 relative position. This module doesn't actually move the markers around
|
|
3670 -- that's handled in @file{insdel.c}. This module just creates them and
|
|
3671 implements the primitives for working with them. As markers are simple
|
|
3672 objects, this does not entail much.
|
|
3673
|
|
3674 Note that the standard arithmetic primitives (e.g. @code{+}) accept
|
|
3675 markers in place of integers and automatically substitute the value of
|
|
3676 @code{marker-position} for the marker, i.e. an integer describing the
|
|
3677 current buffer position of the marker.
|
|
3678
|
|
3679
|
|
3680
|
|
3681 @example
|
|
3682 extents.c
|
|
3683 extents.h
|
|
3684 @end example
|
|
3685
|
|
3686 This module implements the @dfn{extent} Lisp object type, which is like
|
|
3687 a marker that works over a range of text rather than a single position.
|
|
3688 Extents are also much more complex and powerful than markers and have a
|
|
3689 more efficient (and more algorithmically complex) implementation. The
|
|
3690 implementation is described in detail in comments in @file{extents.c}.
|
|
3691
|
|
3692 The code in @file{extents.c} works closely with @file{insdel.c} so that
|
|
3693 extents are properly moved around as text is inserted and deleted.
|
|
3694 There is also code in @file{extents.c} that provides information needed
|
|
3695 by the redisplay mechanism for efficient operation. (Remember that
|
|
3696 extents can have display properties that affect [sometimes drastically,
|
|
3697 as in the @code{invisible} property] the display of the text they
|
|
3698 cover.)
|
|
3699
|
|
3700
|
|
3701
|
|
3702 @example
|
|
3703 editfns.c
|
|
3704 @end example
|
|
3705
|
|
3706 @file{editfns.c} contains the standard Lisp primitives for working with
|
|
3707 a buffer's text, and calls the low-level functions in @file{insdel.c}.
|
|
3708 It also contains primitives for working with @code{point} (the default
|
|
3709 buffer insertion location).
|
|
3710
|
|
3711 @file{editfns.c} also contains functions for retrieving various
|
|
3712 characteristics from the external environment: the current time, the
|
|
3713 process ID of the running XEmacs process, the name of the user who ran
|
|
3714 this XEmacs process, etc. It's not clear why this code is in
|
|
3715 @file{editfns.c}.
|
|
3716
|
|
3717
|
|
3718
|
|
3719 @example
|
|
3720 callint.c
|
|
3721 cmds.c
|
|
3722 commands.h
|
|
3723 @end example
|
|
3724
|
|
3725 @cindex interactive
|
|
3726 These modules implement the basic @dfn{interactive} commands,
|
|
3727 i.e. user-callable functions. Commands, as opposed to other functions,
|
|
3728 have special ways of getting their parameters interactively (by querying
|
|
3729 the user), as opposed to having them passed in a normal function
|
|
3730 invocation. Many commands are not really meant to be called from other
|
|
3731 Lisp functions, because they modify global state in a way that's often
|
|
3732 undesired as part of other Lisp functions.
|
|
3733
|
|
3734 @file{callint.c} implements the mechanism for querying the user for
|
|
3735 parameters and calling interactive commands. The bulk of this module is
|
|
3736 code that parses the interactive spec that is supplied with an
|
|
3737 interactive command.
|
|
3738
|
|
3739 @file{cmds.c} implements the basic, most commonly used editing commands:
|
|
3740 commands to move around the current buffer and insert and delete
|
|
3741 characters. These commands are implemented using the Lisp primitives
|
|
3742 defined in @file{editfns.c}.
|
|
3743
|
|
3744 @file{commands.h} contains associated structure definitions and prototypes.
|
|
3745
|
|
3746
|
|
3747
|
|
3748 @example
|
|
3749 regex.c
|
|
3750 regex.h
|
|
3751 search.c
|
|
3752 @end example
|
|
3753
|
|
3754 @file{search.c} implements the Lisp primitives for searching for text in
|
|
3755 a buffer, and some of the low-level algorithms for doing this. In
|
|
3756 particular, the fast fixed-string Boyer-Moore search algorithm is
|
|
3757 implemented in @file{search.c}. The low-level algorithms for doing
|
|
3758 regular-expression searching, however, are implemented in @file{regex.c}
|
|
3759 and @file{regex.h}. These two modules are largely independent of
|
|
3760 XEmacs, and are similar to (and based upon) the regular-expression
|
|
3761 routines used in @file{grep} and other GNU utilities.
|
|
3762
|
|
3763
|
|
3764
|
|
3765 @example
|
|
3766 doprnt.c
|
|
3767 @end example
|
|
3768
|
|
3769 @file{doprnt.c} implements formatted-string processing, similar to
|
|
3770 @code{printf()} command in C.
|
|
3771
|
|
3772
|
|
3773
|
|
3774 @example
|
|
3775 undo.c
|
|
3776 @end example
|
|
3777
|
|
3778 This module implements the undo mechanism for tracking buffer changes.
|
|
3779 Most of this could be implemented in Lisp.
|
|
3780
|
|
3781
|
|
3782
|
462
|
3783 @node Editor-Level Control Flow Modules
|
428
|
3784 @section Editor-Level Control Flow Modules
|
462
|
3785 @cindex control flow modules, editor-level
|
|
3786 @cindex modules, editor-level control flow
|
428
|
3787
|
|
3788 @example
|
|
3789 event-Xt.c
|
442
|
3790 event-msw.c
|
428
|
3791 event-stream.c
|
|
3792 event-tty.c
|
442
|
3793 events-mod.h
|
|
3794 gpmevent.c
|
|
3795 gpmevent.h
|
428
|
3796 events.c
|
|
3797 events.h
|
|
3798 @end example
|
|
3799
|
|
3800 These implement the handling of events (user input and other system
|
|
3801 notifications).
|
|
3802
|
|
3803 @file{events.c} and @file{events.h} define the @dfn{event} Lisp object
|
|
3804 type and primitives for manipulating it.
|
|
3805
|
|
3806 @file{event-stream.c} implements the basic functions for working with
|
|
3807 event queues, dispatching an event by looking it up in relevant keymaps
|
|
3808 and such, and handling timeouts; this includes the primitives
|
|
3809 @code{next-event} and @code{dispatch-event}, as well as related
|
|
3810 primitives such as @code{sit-for}, @code{sleep-for}, and
|
|
3811 @code{accept-process-output}. (@file{event-stream.c} is one of the
|
|
3812 hairiest and trickiest modules in XEmacs. Beware! You can easily mess
|
|
3813 things up here.)
|
|
3814
|
|
3815 @file{event-Xt.c} and @file{event-tty.c} implement the low-level
|
|
3816 interfaces onto retrieving events from Xt (the X toolkit) and from TTY's
|
|
3817 (using @code{read()} and @code{select()}), respectively. The event
|
|
3818 interface enforces a clean separation between the specific code for
|
|
3819 interfacing with the operating system and the generic code for working
|
|
3820 with events, by defining an API of basic, low-level event methods;
|
|
3821 @file{event-Xt.c} and @file{event-tty.c} are two different
|
|
3822 implementations of this API. To add support for a new operating system
|
|
3823 (e.g. NeXTstep), one merely needs to provide another implementation of
|
|
3824 those API functions.
|
|
3825
|
|
3826 Note that the choice of whether to use @file{event-Xt.c} or
|
|
3827 @file{event-tty.c} is made at compile time! Or at the very latest, it
|
|
3828 is made at startup time. @file{event-Xt.c} handles events for
|
|
3829 @emph{both} X and TTY frames; @file{event-tty.c} is only used when X
|
|
3830 support is not compiled into XEmacs. The reason for this is that there
|
|
3831 is only one event loop in XEmacs: thus, it needs to be able to receive
|
|
3832 events from all different kinds of frames.
|
|
3833
|
|
3834
|
|
3835
|
|
3836 @example
|
|
3837 keymap.c
|
|
3838 keymap.h
|
|
3839 @end example
|
|
3840
|
|
3841 @file{keymap.c} and @file{keymap.h} define the @dfn{keymap} Lisp object
|
|
3842 type and associated methods and primitives. (Remember that keymaps are
|
|
3843 objects that associate event descriptions with functions to be called to
|
|
3844 ``execute'' those events; @code{dispatch-event} looks up events in the
|
|
3845 relevant keymaps.)
|
|
3846
|
|
3847
|
|
3848
|
|
3849 @example
|
442
|
3850 cmdloop.c
|
|
3851 @end example
|
|
3852
|
|
3853 @file{cmdloop.c} contains functions that implement the actual editor
|
440
|
3854 command loop---i.e. the event loop that cyclically retrieves and
|
428
|
3855 dispatches events. This code is also rather tricky, just like
|
|
3856 @file{event-stream.c}.
|
|
3857
|
|
3858
|
|
3859
|
|
3860 @example
|
|
3861 macros.c
|
|
3862 macros.h
|
|
3863 @end example
|
|
3864
|
|
3865 These two modules contain the basic code for defining keyboard macros.
|
|
3866 These functions don't actually do much; most of the code that handles keyboard
|
|
3867 macros is mixed in with the event-handling code in @file{event-stream.c}.
|
|
3868
|
|
3869
|
|
3870
|
|
3871 @example
|
|
3872 minibuf.c
|
|
3873 @end example
|
|
3874
|
|
3875 This contains some miscellaneous code related to the minibuffer (most of
|
|
3876 the minibuffer code was moved into Lisp by Richard Mlynarik). This
|
|
3877 includes the primitives for completion (although filename completion is
|
|
3878 in @file{dired.c}), the lowest-level interface to the minibuffer (if the
|
|
3879 command loop were cleaned up, this too could be in Lisp), and code for
|
|
3880 dealing with the echo area (this, too, was mostly moved into Lisp, and
|
|
3881 the only code remaining is code to call out to Lisp or provide simple
|
|
3882 bootstrapping implementations early in temacs, before the echo-area Lisp
|
|
3883 code is loaded).
|
|
3884
|
|
3885
|
|
3886
|
462
|
3887 @node Modules for the Basic Displayable Lisp Objects
|
428
|
3888 @section Modules for the Basic Displayable Lisp Objects
|
462
|
3889 @cindex modules for the basic displayable Lisp objects
|
|
3890 @cindex displayable Lisp objects, modules for the basic
|
|
3891 @cindex Lisp objects, modules for the basic displayable
|
|
3892 @cindex objects, modules for the basic displayable Lisp
|
428
|
3893
|
|
3894 @example
|
442
|
3895 console-msw.c
|
|
3896 console-msw.h
|
|
3897 console-stream.c
|
|
3898 console-stream.h
|
|
3899 console-tty.c
|
|
3900 console-tty.h
|
|
3901 console-x.c
|
|
3902 console-x.h
|
|
3903 console.c
|
|
3904 console.h
|
|
3905 @end example
|
|
3906
|
|
3907 These modules implement the @dfn{console} Lisp object type. A console
|
|
3908 contains multiple display devices, but only one keyboard and mouse.
|
|
3909 Most of the time, a console will contain exactly one device.
|
|
3910
|
|
3911 Consoles are the top of a lisp object inclusion hierarchy. Consoles
|
|
3912 contain devices, which contain frames, which contain windows.
|
|
3913
|
|
3914
|
|
3915
|
|
3916 @example
|
|
3917 device-msw.c
|
428
|
3918 device-tty.c
|
|
3919 device-x.c
|
|
3920 device.c
|
|
3921 device.h
|
|
3922 @end example
|
|
3923
|
|
3924 These modules implement the @dfn{device} Lisp object type. This
|
|
3925 abstracts a particular screen or connection on which frames are
|
|
3926 displayed. As with Lisp objects, event interfaces, and other
|
|
3927 subsystems, the device code is separated into a generic component that
|
|
3928 contains a standardized interface (in the form of a set of methods) onto
|
|
3929 particular device types.
|
|
3930
|
|
3931 The device subsystem defines all the methods and provides method
|
|
3932 services for not only device operations but also for the frame, window,
|
|
3933 menubar, scrollbar, toolbar, and other displayable-object subsystems.
|
|
3934 The reason for this is that all of these subsystems have the same
|
|
3935 subtypes (X, TTY, NeXTstep, Microsoft Windows, etc.) as devices do.
|
|
3936
|
|
3937
|
|
3938
|
|
3939 @example
|
442
|
3940 frame-msw.c
|
428
|
3941 frame-tty.c
|
|
3942 frame-x.c
|
|
3943 frame.c
|
|
3944 frame.h
|
|
3945 @end example
|
|
3946
|
|
3947 Each device contains one or more frames in which objects (e.g. text) are
|
|
3948 displayed. A frame corresponds to a window in the window system;
|
|
3949 usually this is a top-level window but it could potentially be one of a
|
|
3950 number of overlapping child windows within a top-level window, using the
|
|
3951 MDI (Multiple Document Interface) protocol in Microsoft Windows or a
|
|
3952 similar scheme.
|
|
3953
|
|
3954 The @file{frame-*} files implement the @dfn{frame} Lisp object type and
|
|
3955 provide the generic and device-type-specific operations on frames
|
|
3956 (e.g. raising, lowering, resizing, moving, etc.).
|
|
3957
|
|
3958
|
|
3959
|
|
3960 @example
|
|
3961 window.c
|
|
3962 window.h
|
|
3963 @end example
|
|
3964
|
|
3965 @cindex window (in Emacs)
|
|
3966 @cindex pane
|
|
3967 Each frame consists of one or more non-overlapping @dfn{windows} (better
|
|
3968 known as @dfn{panes} in standard window-system terminology) in which a
|
|
3969 buffer's text can be displayed. Windows can also have scrollbars
|
|
3970 displayed around their edges.
|
|
3971
|
|
3972 @file{window.c} and @file{window.h} implement the @dfn{window} Lisp
|
|
3973 object type and provide code to manage windows. Since windows have no
|
|
3974 associated resources in the window system (the window system knows only
|
|
3975 about the frame; no child windows or anything are used for XEmacs
|
|
3976 windows), there is no device-type-specific code here; all of that code
|
|
3977 is part of the redisplay mechanism or the code for particular object
|
|
3978 types such as scrollbars.
|
|
3979
|
|
3980
|
|
3981
|
462
|
3982 @node Modules for other Display-Related Lisp Objects
|
428
|
3983 @section Modules for other Display-Related Lisp Objects
|
462
|
3984 @cindex modules for other display-related Lisp objects
|
|
3985 @cindex display-related Lisp objects, modules for other
|
|
3986 @cindex Lisp objects, modules for other display-related
|
428
|
3987
|
|
3988 @example
|
|
3989 faces.c
|
|
3990 faces.h
|
|
3991 @end example
|
|
3992
|
|
3993
|
|
3994
|
|
3995 @example
|
|
3996 bitmaps.h
|
442
|
3997 glyphs-eimage.c
|
|
3998 glyphs-msw.c
|
|
3999 glyphs-msw.h
|
|
4000 glyphs-widget.c
|
428
|
4001 glyphs-x.c
|
|
4002 glyphs-x.h
|
|
4003 glyphs.c
|
|
4004 glyphs.h
|
|
4005 @end example
|
|
4006
|
|
4007
|
|
4008
|
|
4009 @example
|
442
|
4010 objects-msw.c
|
|
4011 objects-msw.h
|
428
|
4012 objects-tty.c
|
|
4013 objects-tty.h
|
|
4014 objects-x.c
|
|
4015 objects-x.h
|
|
4016 objects.c
|
|
4017 objects.h
|
|
4018 @end example
|
|
4019
|
|
4020
|
|
4021
|
|
4022 @example
|
442
|
4023 menubar-msw.c
|
|
4024 menubar-msw.h
|
428
|
4025 menubar-x.c
|
|
4026 menubar.c
|
442
|
4027 menubar.h
|
|
4028 @end example
|
|
4029
|
|
4030
|
|
4031
|
|
4032 @example
|
|
4033 scrollbar-msw.c
|
|
4034 scrollbar-msw.h
|
428
|
4035 scrollbar-x.c
|
|
4036 scrollbar-x.h
|
|
4037 scrollbar.c
|
|
4038 scrollbar.h
|
|
4039 @end example
|
|
4040
|
|
4041
|
|
4042
|
|
4043 @example
|
442
|
4044 toolbar-msw.c
|
428
|
4045 toolbar-x.c
|
|
4046 toolbar.c
|
|
4047 toolbar.h
|
|
4048 @end example
|
|
4049
|
|
4050
|
|
4051
|
|
4052 @example
|
|
4053 font-lock.c
|
|
4054 @end example
|
|
4055
|
440
|
4056 This file provides C support for syntax highlighting---i.e.
|
428
|
4057 highlighting different syntactic constructs of a source file in
|
|
4058 different colors, for easy reading. The C support is provided so that
|
|
4059 this is fast.
|
|
4060
|
|
4061
|
|
4062
|
|
4063 @example
|
|
4064 dgif_lib.c
|
|
4065 gif_err.c
|
|
4066 gif_lib.h
|
|
4067 gifalloc.c
|
|
4068 @end example
|
|
4069
|
|
4070 These modules decode GIF-format image files, for use with glyphs.
|
442
|
4071 These files were removed due to Unisys patent infringement concerns.
|
|
4072
|
|
4073
|
|
4074
|
462
|
4075 @node Modules for the Redisplay Mechanism
|
428
|
4076 @section Modules for the Redisplay Mechanism
|
462
|
4077 @cindex modules for the redisplay mechanism
|
|
4078 @cindex redisplay mechanism, modules for the
|
428
|
4079
|
|
4080 @example
|
|
4081 redisplay-output.c
|
442
|
4082 redisplay-msw.c
|
428
|
4083 redisplay-tty.c
|
|
4084 redisplay-x.c
|
|
4085 redisplay.c
|
|
4086 redisplay.h
|
|
4087 @end example
|
|
4088
|
|
4089 These files provide the redisplay mechanism. As with many other
|
|
4090 subsystems in XEmacs, there is a clean separation between the general
|
|
4091 and device-specific support.
|
|
4092
|
|
4093 @file{redisplay.c} contains the bulk of the redisplay engine. These
|
|
4094 functions update the redisplay structures (which describe how the screen
|
|
4095 is to appear) to reflect any changes made to the state of any
|
|
4096 displayable objects (buffer, frame, window, etc.) since the last time
|
|
4097 that redisplay was called. These functions are highly optimized to
|
|
4098 avoid doing more work than necessary (since redisplay is called
|
|
4099 extremely often and is potentially a huge time sink), and depend heavily
|
|
4100 on notifications from the objects themselves that changes have occurred,
|
|
4101 so that redisplay doesn't explicitly have to check each possible object.
|
|
4102 The redisplay mechanism also contains a great deal of caching to further
|
|
4103 speed things up; some of this caching is contained within the various
|
|
4104 displayable objects.
|
|
4105
|
|
4106 @file{redisplay-output.c} goes through the redisplay structures and converts
|
|
4107 them into calls to device-specific methods to actually output the screen
|
|
4108 changes.
|
|
4109
|
|
4110 @file{redisplay-x.c} and @file{redisplay-tty.c} are two implementations
|
|
4111 of these redisplay output methods, for X frames and TTY frames,
|
|
4112 respectively.
|
|
4113
|
|
4114
|
|
4115
|
|
4116 @example
|
|
4117 indent.c
|
|
4118 @end example
|
|
4119
|
|
4120 This module contains various functions and Lisp primitives for
|
|
4121 converting between buffer positions and screen positions. These
|
|
4122 functions call the redisplay mechanism to do most of the work, and then
|
|
4123 examine the redisplay structures to get the necessary information. This
|
|
4124 module needs work.
|
|
4125
|
|
4126
|
|
4127
|
|
4128 @example
|
|
4129 termcap.c
|
|
4130 terminfo.c
|
|
4131 tparam.c
|
|
4132 @end example
|
|
4133
|
|
4134 These files contain functions for working with the termcap (BSD-style)
|
|
4135 and terminfo (System V style) databases of terminal capabilities and
|
|
4136 escape sequences, used when XEmacs is displaying in a TTY.
|
|
4137
|
|
4138
|
|
4139
|
|
4140 @example
|
|
4141 cm.c
|
|
4142 cm.h
|
|
4143 @end example
|
|
4144
|
|
4145 These files provide some miscellaneous TTY-output functions and should
|
|
4146 probably be merged into @file{redisplay-tty.c}.
|
|
4147
|
|
4148
|
|
4149
|
462
|
4150 @node Modules for Interfacing with the File System
|
428
|
4151 @section Modules for Interfacing with the File System
|
462
|
4152 @cindex modules for interfacing with the file system
|
|
4153 @cindex interfacing with the file system, modules for
|
|
4154 @cindex file system, modules for interfacing with the
|
428
|
4155
|
|
4156 @example
|
|
4157 lstream.c
|
|
4158 lstream.h
|
|
4159 @end example
|
|
4160
|
|
4161 These modules implement the @dfn{stream} Lisp object type. This is an
|
|
4162 internal-only Lisp object that implements a generic buffering stream.
|
|
4163 The idea is to provide a uniform interface onto all sources and sinks of
|
|
4164 data, including file descriptors, stdio streams, chunks of memory, Lisp
|
|
4165 buffers, Lisp strings, etc. That way, I/O functions can be written to
|
|
4166 the stream interface and can transparently handle all possible sources
|
|
4167 and sinks. (For example, the @code{read} function can read data from a
|
|
4168 file, a string, a buffer, or even a function that is called repeatedly
|
|
4169 to return data, without worrying about where the data is coming from or
|
|
4170 what-size chunks it is returned in.)
|
|
4171
|
|
4172 @cindex lstream
|
|
4173 Note that in the C code, streams are called @dfn{lstreams} (for ``Lisp
|
|
4174 streams'') to distinguish them from other kinds of streams, e.g. stdio
|
|
4175 streams and C++ I/O streams.
|
|
4176
|
|
4177 Similar to other subsystems in XEmacs, lstreams are separated into
|
|
4178 generic functions and a set of methods for the different types of
|
|
4179 lstreams. @file{lstream.c} provides implementations of many different
|
442
|
4180 types of streams; others are provided, e.g., in @file{file-coding.c}.
|
428
|
4181
|
|
4182
|
|
4183
|
|
4184 @example
|
|
4185 fileio.c
|
|
4186 @end example
|
|
4187
|
|
4188 This implements the basic primitives for interfacing with the file
|
|
4189 system. This includes primitives for reading files into buffers,
|
|
4190 writing buffers into files, checking for the presence or accessibility
|
|
4191 of files, canonicalizing file names, etc. Note that these primitives
|
|
4192 are usually not invoked directly by the user: There is a great deal of
|
|
4193 higher-level Lisp code that implements the user commands such as
|
|
4194 @code{find-file} and @code{save-buffer}. This is similar to the
|
|
4195 distinction between the lower-level primitives in @file{editfns.c} and
|
|
4196 the higher-level user commands in @file{commands.c} and
|
|
4197 @file{simple.el}.
|
|
4198
|
|
4199
|
|
4200
|
|
4201 @example
|
|
4202 filelock.c
|
|
4203 @end example
|
|
4204
|
|
4205 This file provides functions for detecting clashes between different
|
|
4206 processes (e.g. XEmacs and some external process, or two different
|
|
4207 XEmacs processes) modifying the same file. (XEmacs can optionally use
|
|
4208 the @file{lock/} subdirectory to provide a form of ``locking'' between
|
|
4209 different XEmacs processes.) This module is also used by the low-level
|
|
4210 functions in @file{insdel.c} to ensure that, if the first modification
|
|
4211 is being made to a buffer whose corresponding file has been externally
|
|
4212 modified, the user is made aware of this so that the buffer can be
|
|
4213 synched up with the external changes if necessary.
|
|
4214
|
|
4215
|
|
4216 @example
|
|
4217 filemode.c
|
|
4218 @end example
|
|
4219
|
|
4220 This file provides some miscellaneous functions that construct a
|
|
4221 @samp{rwxr-xr-x}-type permissions string (as might appear in an
|
|
4222 @file{ls}-style directory listing) given the information returned by the
|
|
4223 @code{stat()} system call.
|
|
4224
|
|
4225
|
|
4226
|
|
4227 @example
|
|
4228 dired.c
|
|
4229 ndir.h
|
|
4230 @end example
|
|
4231
|
|
4232 These files implement the XEmacs interface to directory searching. This
|
|
4233 includes a number of primitives for determining the files in a directory
|
|
4234 and for doing filename completion. (Remember that generic completion is
|
|
4235 handled by a different mechanism, in @file{minibuf.c}.)
|
|
4236
|
|
4237 @file{ndir.h} is a header file used for the directory-searching
|
|
4238 emulation functions provided in @file{sysdep.c} (see section J below),
|
|
4239 for systems that don't provide any directory-searching functions. (On
|
|
4240 those systems, directories can be read directly as files, and parsed.)
|
|
4241
|
|
4242
|
|
4243
|
|
4244 @example
|
|
4245 realpath.c
|
|
4246 @end example
|
|
4247
|
|
4248 This file provides an implementation of the @code{realpath()} function
|
|
4249 for expanding symbolic links, on systems that don't implement it or have
|
|
4250 a broken implementation.
|
|
4251
|
|
4252
|
|
4253
|
462
|
4254 @node Modules for Other Aspects of the Lisp Interpreter and Object System
|
428
|
4255 @section Modules for Other Aspects of the Lisp Interpreter and Object System
|
462
|
4256 @cindex modules for other aspects of the Lisp interpreter and object system
|
|
4257 @cindex Lisp interpreter and object system, modules for other aspects of the
|
|
4258 @cindex interpreter and object system, modules for other aspects of the Lisp
|
|
4259 @cindex object system, modules for other aspects of the Lisp interpreter and
|
428
|
4260
|
|
4261 @example
|
|
4262 elhash.c
|
|
4263 elhash.h
|
|
4264 hash.c
|
|
4265 hash.h
|
|
4266 @end example
|
|
4267
|
|
4268 These files provide two implementations of hash tables. Files
|
|
4269 @file{hash.c} and @file{hash.h} provide a generic C implementation of
|
|
4270 hash tables which can stand independently of XEmacs. Files
|
|
4271 @file{elhash.c} and @file{elhash.h} provide a separate implementation of
|
|
4272 hash tables that can store only Lisp objects, and knows about Lispy
|
|
4273 things like garbage collection, and implement the @dfn{hash-table} Lisp
|
|
4274 object type.
|
|
4275
|
|
4276
|
|
4277 @example
|
|
4278 specifier.c
|
|
4279 specifier.h
|
|
4280 @end example
|
|
4281
|
|
4282 This module implements the @dfn{specifier} Lisp object type. This is
|
|
4283 primarily used for displayable properties, and allows for values that
|
|
4284 are specific to a particular buffer, window, frame, device, or device
|
|
4285 class, as well as a default value existing. This is used, for example,
|
|
4286 to control the height of the horizontal scrollbar or the appearance of
|
|
4287 the @code{default}, @code{bold}, or other faces. The specifier object
|
|
4288 consists of a number of specifications, each of which maps from a
|
|
4289 buffer, window, etc. to a value. The function @code{specifier-instance}
|
|
4290 looks up a value given a window (from which a buffer, frame, and device
|
|
4291 can be derived).
|
|
4292
|
|
4293
|
|
4294 @example
|
|
4295 chartab.c
|
|
4296 chartab.h
|
|
4297 casetab.c
|
|
4298 @end example
|
|
4299
|
|
4300 @file{chartab.c} and @file{chartab.h} implement the @dfn{char table}
|
|
4301 Lisp object type, which maps from characters or certain sorts of
|
|
4302 character ranges to Lisp objects. The implementation of this object
|
|
4303 type is optimized for the internal representation of characters. Char
|
|
4304 tables come in different types, which affect the allowed object types to
|
|
4305 which a character can be mapped and also dictate certain other
|
|
4306 properties of the char table.
|
|
4307
|
|
4308 @cindex case table
|
|
4309 @file{casetab.c} implements one sort of char table, the @dfn{case
|
|
4310 table}, which maps characters to other characters of possibly different
|
|
4311 case. These are used by XEmacs to implement case-changing primitives
|
|
4312 and to do case-insensitive searching.
|
|
4313
|
|
4314
|
|
4315
|
|
4316 @example
|
|
4317 syntax.c
|
|
4318 syntax.h
|
|
4319 @end example
|
|
4320
|
|
4321 @cindex scanner
|
|
4322 This module implements @dfn{syntax tables}, another sort of char table
|
|
4323 that maps characters into syntax classes that define the syntax of these
|
|
4324 characters (e.g. a parenthesis belongs to a class of @samp{open}
|
|
4325 characters that have corresponding @samp{close} characters and can be
|
|
4326 nested). This module also implements the Lisp @dfn{scanner}, a set of
|
|
4327 primitives for scanning over text based on syntax tables. This is used,
|
|
4328 for example, to find the matching parenthesis in a command such as
|
|
4329 @code{forward-sexp}, and by @file{font-lock.c} to locate quoted strings,
|
|
4330 comments, etc.
|
|
4331
|
|
4332
|
|
4333
|
|
4334 @example
|
|
4335 casefiddle.c
|
|
4336 @end example
|
|
4337
|
|
4338 This module implements various Lisp primitives for upcasing, downcasing
|
|
4339 and capitalizing strings or regions of buffers.
|
|
4340
|
|
4341
|
|
4342
|
|
4343 @example
|
|
4344 rangetab.c
|
|
4345 @end example
|
|
4346
|
|
4347 This module implements the @dfn{range table} Lisp object type, which
|
|
4348 provides for a mapping from ranges of integers to arbitrary Lisp
|
|
4349 objects.
|
|
4350
|
|
4351
|
|
4352
|
|
4353 @example
|
|
4354 opaque.c
|
|
4355 opaque.h
|
|
4356 @end example
|
|
4357
|
|
4358 This module implements the @dfn{opaque} Lisp object type, an
|
|
4359 internal-only Lisp object that encapsulates an arbitrary block of memory
|
|
4360 so that it can be managed by the Lisp allocation system. To create an
|
|
4361 opaque object, you call @code{make_opaque()}, passing a pointer to a
|
|
4362 block of memory. An object is created that is big enough to hold the
|
|
4363 memory, which is copied into the object's storage. The object will then
|
|
4364 stick around as long as you keep pointers to it, after which it will be
|
|
4365 automatically reclaimed.
|
|
4366
|
|
4367 @cindex mark method
|
|
4368 Opaque objects can also have an arbitrary @dfn{mark method} associated
|
|
4369 with them, in case the block of memory contains other Lisp objects that
|
|
4370 need to be marked for garbage-collection purposes. (If you need other
|
|
4371 object methods, such as a finalize method, you should just go ahead and
|
440
|
4372 create a new Lisp object type---it's not hard.)
|
428
|
4373
|
|
4374
|
|
4375
|
|
4376 @example
|
|
4377 abbrev.c
|
|
4378 @end example
|
|
4379
|
|
4380 This function provides a few primitives for doing dynamic abbreviation
|
|
4381 expansion. In XEmacs, most of the code for this has been moved into
|
|
4382 Lisp. Some C code remains for speed and because the primitive
|
|
4383 @code{self-insert-command} (which is executed for all self-inserting
|
|
4384 characters) hooks into the abbrev mechanism. (@code{self-insert-command}
|
|
4385 is itself in C only for speed.)
|
|
4386
|
|
4387
|
|
4388
|
|
4389 @example
|
|
4390 doc.c
|
|
4391 @end example
|
|
4392
|
|
4393 This function provides primitives for retrieving the documentation
|
|
4394 strings of functions and variables. These documentation strings contain
|
|
4395 certain special markers that get dynamically expanded (e.g. a
|
|
4396 reverse-lookup is performed on some named functions to retrieve their
|
|
4397 current key bindings). Some documentation strings (in particular, for
|
|
4398 the built-in primitives and pre-loaded Lisp functions) are stored
|
|
4399 externally in a file @file{DOC} in the @file{lib-src/} directory and
|
|
4400 need to be fetched from that file. (Part of the build stage involves
|
|
4401 building this file, and another part involves constructing an index for
|
|
4402 this file and embedding it into the executable, so that the functions in
|
|
4403 @file{doc.c} do not have to search the entire @file{DOC} file to find
|
|
4404 the appropriate documentation string.)
|
|
4405
|
|
4406
|
|
4407
|
|
4408 @example
|
|
4409 md5.c
|
|
4410 @end example
|
|
4411
|
|
4412 This function provides a Lisp primitive that implements the MD5 secure
|
|
4413 hashing scheme, used to create a large hash value of a string of data such that
|
|
4414 the data cannot be derived from the hash value. This is used for
|
|
4415 various security applications on the Internet.
|
|
4416
|
|
4417
|
|
4418
|
|
4419
|
462
|
4420 @node Modules for Interfacing with the Operating System
|
428
|
4421 @section Modules for Interfacing with the Operating System
|
462
|
4422 @cindex modules for interfacing with the operating system
|
|
4423 @cindex interfacing with the operating system, modules for
|
|
4424 @cindex operating system, modules for interfacing with the
|
428
|
4425
|
|
4426 @example
|
|
4427 callproc.c
|
|
4428 process.c
|
|
4429 process.h
|
|
4430 @end example
|
|
4431
|
|
4432 These modules allow XEmacs to spawn and communicate with subprocesses
|
|
4433 and network connections.
|
|
4434
|
|
4435 @cindex synchronous subprocesses
|
|
4436 @cindex subprocesses, synchronous
|
|
4437 @file{callproc.c} implements (through the @code{call-process}
|
|
4438 primitive) what are called @dfn{synchronous subprocesses}. This means
|
|
4439 that XEmacs runs a program, waits till it's done, and retrieves its
|
|
4440 output. A typical example might be calling the @file{ls} program to get
|
|
4441 a directory listing.
|
|
4442
|
|
4443 @cindex asynchronous subprocesses
|
|
4444 @cindex subprocesses, asynchronous
|
|
4445 @file{process.c} and @file{process.h} implement @dfn{asynchronous
|
|
4446 subprocesses}. This means that XEmacs starts a program and then
|
|
4447 continues normally, not waiting for the process to finish. Data can be
|
|
4448 sent to the process or retrieved from it as it's running. This is used
|
|
4449 for the @code{shell} command (which provides a front end onto a shell
|
|
4450 program such as @file{csh}), the mail and news readers implemented in
|
|
4451 XEmacs, etc. The result of calling @code{start-process} to start a
|
|
4452 subprocess is a process object, a particular kind of object used to
|
|
4453 communicate with the subprocess. You can send data to the process by
|
|
4454 passing the process object and the data to @code{send-process}, and you
|
|
4455 can specify what happens to data retrieved from the process by setting
|
|
4456 properties of the process object. (When the process sends data, XEmacs
|
|
4457 receives a process event, which says that there is data ready. When
|
|
4458 @code{dispatch-event} is called on this event, it reads the data from
|
|
4459 the process and does something with it, as specified by the process
|
|
4460 object's properties. Typically, this means inserting the data into a
|
|
4461 buffer or calling a function.) Another property of the process object is
|
|
4462 called the @dfn{sentinel}, which is a function that is called when the
|
|
4463 process terminates.
|
|
4464
|
|
4465 @cindex network connections
|
|
4466 Process objects are also used for network connections (connections to a
|
|
4467 process running on another machine). Network connections are started
|
|
4468 with @code{open-network-stream} but otherwise work just like
|
|
4469 subprocesses.
|
|
4470
|
|
4471
|
|
4472
|
|
4473 @example
|
|
4474 sysdep.c
|
|
4475 sysdep.h
|
|
4476 @end example
|
|
4477
|
|
4478 These modules implement most of the low-level, messy operating-system
|
|
4479 interface code. This includes various device control (ioctl) operations
|
|
4480 for file descriptors, TTY's, pseudo-terminals, etc. (usually this stuff
|
|
4481 is fairly system-dependent; thus the name of this module), and emulation
|
|
4482 of standard library functions and system calls on systems that don't
|
|
4483 provide them or have broken versions.
|
|
4484
|
|
4485
|
|
4486
|
|
4487 @example
|
|
4488 sysdir.h
|
|
4489 sysfile.h
|
|
4490 sysfloat.h
|
|
4491 sysproc.h
|
|
4492 syspwd.h
|
|
4493 syssignal.h
|
|
4494 systime.h
|
|
4495 systty.h
|
|
4496 syswait.h
|
|
4497 @end example
|
|
4498
|
|
4499 These header files provide consistent interfaces onto system-dependent
|
|
4500 header files and system calls. The idea is that, instead of including a
|
|
4501 standard header file like @file{<sys/param.h>} (which may or may not
|
|
4502 exist on various systems) or having to worry about whether all system
|
|
4503 provide a particular preprocessor constant, or having to deal with the
|
|
4504 four different paradigms for manipulating signals, you just include the
|
|
4505 appropriate @file{sys*.h} header file, which includes all the right
|
|
4506 system header files, defines and missing preprocessor constants,
|
|
4507 provides a uniform interface onto system calls, etc.
|
|
4508
|
|
4509 @file{sysdir.h} provides a uniform interface onto directory-querying
|
|
4510 functions. (In some cases, this is in conjunction with emulation
|
|
4511 functions in @file{sysdep.c}.)
|
|
4512
|
|
4513 @file{sysfile.h} includes all the necessary header files for standard
|
|
4514 system calls (e.g. @code{read()}), ensures that all necessary
|
|
4515 @code{open()} and @code{stat()} preprocessor constants are defined, and
|
|
4516 possibly (usually) substitutes sugared versions of @code{read()},
|
|
4517 @code{write()}, etc. that automatically restart interrupted I/O
|
|
4518 operations.
|
|
4519
|
|
4520 @file{sysfloat.h} includes the necessary header files for floating-point
|
|
4521 operations.
|
|
4522
|
|
4523 @file{sysproc.h} includes the necessary header files for calling
|
|
4524 @code{select()}, @code{fork()}, @code{execve()}, socket operations, and
|
|
4525 the like, and ensures that the @code{FD_*()} macros for descriptor-set
|
|
4526 manipulations are available.
|
|
4527
|
|
4528 @file{syspwd.h} includes the necessary header files for obtaining
|
|
4529 information from @file{/etc/passwd} (the functions are emulated under
|
|
4530 VMS).
|
|
4531
|
|
4532 @file{syssignal.h} includes the necessary header files for
|
|
4533 signal-handling and provides a uniform interface onto the different
|
|
4534 signal-handling and signal-blocking paradigms.
|
|
4535
|
|
4536 @file{systime.h} includes the necessary header files and provides
|
|
4537 uniform interfaces for retrieving the time of day, setting file
|
|
4538 access/modification times, getting the amount of time used by the XEmacs
|
|
4539 process, etc.
|
|
4540
|
|
4541 @file{systty.h} buffers against the infinitude of different ways of
|
|
4542 controlling TTY's.
|
|
4543
|
|
4544 @file{syswait.h} provides a uniform way of retrieving the exit status
|
|
4545 from a @code{wait()}ed-on process (some systems use a union, others use
|
|
4546 an int).
|
|
4547
|
|
4548
|
|
4549
|
|
4550 @example
|
|
4551 hpplay.c
|
|
4552 libsst.c
|
|
4553 libsst.h
|
|
4554 libst.h
|
|
4555 linuxplay.c
|
|
4556 nas.c
|
|
4557 sgiplay.c
|
|
4558 sound.c
|
|
4559 sunplay.c
|
|
4560 @end example
|
|
4561
|
|
4562 These files implement the ability to play various sounds on some types
|
|
4563 of computers. You have to configure your XEmacs with sound support in
|
|
4564 order to get this capability.
|
|
4565
|
|
4566 @file{sound.c} provides the generic interface. It implements various
|
|
4567 Lisp primitives and variables that let you specify which sounds should
|
|
4568 be played in certain conditions. (The conditions are identified by
|
|
4569 symbols, which are passed to @code{ding} to make a sound. Various
|
|
4570 standard functions call this function at certain times; if sound support
|
|
4571 does not exist, a simple beep results.
|
|
4572
|
|
4573 @cindex native sound
|
|
4574 @cindex sound, native
|
|
4575 @file{sgiplay.c}, @file{sunplay.c}, @file{hpplay.c}, and
|
|
4576 @file{linuxplay.c} interface to the machine's speaker for various
|
|
4577 different kind of machines. This is called @dfn{native} sound.
|
|
4578
|
|
4579 @cindex sound, network
|
|
4580 @cindex network sound
|
|
4581 @cindex NAS
|
|
4582 @file{nas.c} interfaces to a computer somewhere else on the network
|
|
4583 using the NAS (Network Audio Server) protocol, playing sounds on that
|
|
4584 machine. This allows you to run XEmacs on a remote machine, with its
|
|
4585 display set to your local machine, and have the sounds be made on your
|
|
4586 local machine, provided that you have a NAS server running on your local
|
|
4587 machine.
|
|
4588
|
|
4589 @file{libsst.c}, @file{libsst.h}, and @file{libst.h} provide some
|
|
4590 additional functions for playing sound on a Sun SPARC but are not
|
|
4591 currently in use.
|
|
4592
|
|
4593
|
|
4594
|
|
4595 @example
|
|
4596 tooltalk.c
|
|
4597 tooltalk.h
|
|
4598 @end example
|
|
4599
|
|
4600 These two modules implement an interface to the ToolTalk protocol, which
|
|
4601 is an interprocess communication protocol implemented on some versions
|
|
4602 of Unix. ToolTalk is a high-level protocol that allows processes to
|
|
4603 register themselves as providers of particular services; other processes
|
|
4604 can then request a service without knowing or caring exactly who is
|
|
4605 providing the service. It is similar in spirit to the DDE protocol
|
|
4606 provided under Microsoft Windows. ToolTalk is a part of the new CDE
|
|
4607 (Common Desktop Environment) specification and is used to connect the
|
|
4608 parts of the SPARCWorks development environment.
|
|
4609
|
|
4610
|
|
4611
|
|
4612 @example
|
|
4613 getloadavg.c
|
|
4614 @end example
|
|
4615
|
|
4616 This module provides the ability to retrieve the system's current load
|
|
4617 average. (The way to do this is highly system-specific, unfortunately,
|
|
4618 and requires a lot of special-case code.)
|
|
4619
|
|
4620
|
|
4621
|
|
4622 @example
|
|
4623 sunpro.c
|
|
4624 @end example
|
|
4625
|
|
4626 This module provides a small amount of code used internally at Sun to
|
|
4627 keep statistics on the usage of XEmacs.
|
|
4628
|
|
4629
|
|
4630
|
|
4631 @example
|
|
4632 broken-sun.h
|
|
4633 strcmp.c
|
|
4634 strcpy.c
|
|
4635 sunOS-fix.c
|
|
4636 @end example
|
|
4637
|
|
4638 These files provide replacement functions and prototypes to fix numerous
|
|
4639 bugs in early releases of SunOS 4.1.
|
|
4640
|
|
4641
|
|
4642
|
|
4643 @example
|
|
4644 hftctl.c
|
|
4645 @end example
|
|
4646
|
|
4647 This module provides some terminal-control code necessary on versions of
|
|
4648 AIX prior to 4.1.
|
|
4649
|
|
4650
|
|
4651
|
462
|
4652 @node Modules for Interfacing with X Windows
|
428
|
4653 @section Modules for Interfacing with X Windows
|
462
|
4654 @cindex modules for interfacing with X Windows
|
|
4655 @cindex interfacing with X Windows, modules for
|
|
4656 @cindex X Windows, modules for interfacing with
|
428
|
4657
|
|
4658 @example
|
|
4659 Emacs.ad.h
|
|
4660 @end example
|
|
4661
|
|
4662 A file generated from @file{Emacs.ad}, which contains XEmacs-supplied
|
|
4663 fallback resources (so that XEmacs has pretty defaults).
|
|
4664
|
|
4665
|
|
4666
|
|
4667 @example
|
|
4668 EmacsFrame.c
|
|
4669 EmacsFrame.h
|
|
4670 EmacsFrameP.h
|
|
4671 @end example
|
|
4672
|
|
4673 These modules implement an Xt widget class that encapsulates a frame.
|
|
4674 This is for ease in integrating with Xt. The EmacsFrame widget covers
|
|
4675 the entire X window except for the menubar; the scrollbars are
|
|
4676 positioned on top of the EmacsFrame widget.
|
|
4677
|
|
4678 @strong{Warning:} Abandon hope, all ye who enter here. This code took
|
|
4679 an ungodly amount of time to get right, and is likely to fall apart
|
|
4680 mercilessly at the slightest change. Such is life under Xt.
|
|
4681
|
|
4682
|
|
4683
|
|
4684 @example
|
|
4685 EmacsManager.c
|
|
4686 EmacsManager.h
|
|
4687 EmacsManagerP.h
|
|
4688 @end example
|
|
4689
|
|
4690 These modules implement a simple Xt manager (i.e. composite) widget
|
|
4691 class that simply lets its children set whatever geometry they want.
|
|
4692 It's amazing that Xt doesn't provide this standardly, but on second
|
|
4693 thought, it makes sense, considering how amazingly broken Xt is.
|
|
4694
|
|
4695
|
|
4696 @example
|
|
4697 EmacsShell-sub.c
|
|
4698 EmacsShell.c
|
|
4699 EmacsShell.h
|
|
4700 EmacsShellP.h
|
|
4701 @end example
|
|
4702
|
|
4703 These modules implement two Xt widget classes that are subclasses of
|
|
4704 the TopLevelShell and TransientShell classes. This is necessary to deal
|
|
4705 with more brokenness that Xt has sadistically thrust onto the backs of
|
|
4706 developers.
|
|
4707
|
|
4708
|
|
4709
|
|
4710 @example
|
|
4711 xgccache.c
|
|
4712 xgccache.h
|
|
4713 @end example
|
|
4714
|
|
4715 These modules provide functions for maintenance and caching of GC's
|
|
4716 (graphics contexts) under the X Window System. This code is junky and
|
|
4717 needs to be rewritten.
|
|
4718
|
|
4719
|
|
4720
|
|
4721 @example
|
442
|
4722 select-msw.c
|
|
4723 select-x.c
|
|
4724 select.c
|
|
4725 select.h
|
428
|
4726 @end example
|
|
4727
|
|
4728 @cindex selections
|
|
4729 This module provides an interface to the X Window System's concept of
|
|
4730 @dfn{selections}, the standard way for X applications to communicate
|
|
4731 with each other.
|
|
4732
|
|
4733
|
|
4734
|
|
4735 @example
|
|
4736 xintrinsic.h
|
|
4737 xintrinsicp.h
|
|
4738 xmmanagerp.h
|
|
4739 xmprimitivep.h
|
|
4740 @end example
|
|
4741
|
|
4742 These header files are similar in spirit to the @file{sys*.h} files and buffer
|
|
4743 against different implementations of Xt and Motif.
|
|
4744
|
|
4745 @itemize @bullet
|
|
4746 @item
|
|
4747 @file{xintrinsic.h} should be included in place of @file{<Intrinsic.h>}.
|
|
4748 @item
|
|
4749 @file{xintrinsicp.h} should be included in place of @file{<IntrinsicP.h>}.
|
|
4750 @item
|
|
4751 @file{xmmanagerp.h} should be included in place of @file{<XmManagerP.h>}.
|
|
4752 @item
|
|
4753 @file{xmprimitivep.h} should be included in place of @file{<XmPrimitiveP.h>}.
|
|
4754 @end itemize
|
|
4755
|
|
4756
|
|
4757
|
|
4758 @example
|
|
4759 xmu.c
|
|
4760 xmu.h
|
|
4761 @end example
|
|
4762
|
|
4763 These files provide an emulation of the Xmu library for those systems
|
|
4764 (i.e. HPUX) that don't provide it as a standard part of X.
|
|
4765
|
|
4766
|
|
4767
|
|
4768 @example
|
|
4769 ExternalClient-Xlib.c
|
|
4770 ExternalClient.c
|
|
4771 ExternalClient.h
|
|
4772 ExternalClientP.h
|
|
4773 ExternalShell.c
|
|
4774 ExternalShell.h
|
|
4775 ExternalShellP.h
|
|
4776 extw-Xlib.c
|
|
4777 extw-Xlib.h
|
|
4778 extw-Xt.c
|
|
4779 extw-Xt.h
|
|
4780 @end example
|
|
4781
|
|
4782 @cindex external widget
|
|
4783 These files provide the @dfn{external widget} interface, which allows an
|
|
4784 XEmacs frame to appear as a widget in another application. To do this,
|
|
4785 you have to configure with @samp{--external-widget}.
|
|
4786
|
|
4787 @file{ExternalShell*} provides the server (XEmacs) side of the
|
|
4788 connection.
|
|
4789
|
|
4790 @file{ExternalClient*} provides the client (other application) side of
|
|
4791 the connection. These files are not compiled into XEmacs but are
|
|
4792 compiled into libraries that are then linked into your application.
|
|
4793
|
|
4794 @file{extw-*} is common code that is used for both the client and server.
|
|
4795
|
|
4796 Don't touch this code; something is liable to break if you do.
|
|
4797
|
|
4798
|
|
4799
|
462
|
4800 @node Modules for Internationalization
|
428
|
4801 @section Modules for Internationalization
|
462
|
4802 @cindex modules for internationalization
|
|
4803 @cindex internationalization, modules for
|
428
|
4804
|
|
4805 @example
|
|
4806 mule-canna.c
|
|
4807 mule-ccl.c
|
|
4808 mule-charset.c
|
|
4809 mule-charset.h
|
442
|
4810 file-coding.c
|
|
4811 file-coding.h
|
428
|
4812 mule-mcpath.c
|
|
4813 mule-mcpath.h
|
|
4814 mule-wnnfns.c
|
|
4815 mule.c
|
|
4816 @end example
|
|
4817
|
|
4818 These files implement the MULE (Asian-language) support. Note that MULE
|
|
4819 actually provides a general interface for all sorts of languages, not
|
|
4820 just Asian languages (although they are generally the most complicated
|
|
4821 to support). This code is still in beta.
|
|
4822
|
442
|
4823 @file{mule-charset.*} and @file{file-coding.*} provide the heart of the
|
428
|
4824 XEmacs MULE support. @file{mule-charset.*} implements the @dfn{charset}
|
|
4825 Lisp object type, which encapsulates a character set (an ordered one- or
|
|
4826 two-dimensional set of characters, such as US ASCII or JISX0208 Japanese
|
|
4827 Kanji).
|
|
4828
|
442
|
4829 @file{file-coding.*} implements the @dfn{coding-system} Lisp object
|
428
|
4830 type, which encapsulates a method of converting between different
|
|
4831 encodings. An encoding is a representation of a stream of characters,
|
|
4832 possibly from multiple character sets, using a stream of bytes or words,
|
|
4833 and defines (e.g.) which escape sequences are used to specify particular
|
|
4834 character sets, how the indices for a character are converted into bytes
|
|
4835 (sometimes this involves setting the high bit; sometimes complicated
|
|
4836 rearranging of the values takes place, as in the Shift-JIS encoding),
|
|
4837 etc.
|
|
4838
|
|
4839 @file{mule-ccl.c} provides the CCL (Code Conversion Language)
|
|
4840 interpreter. CCL is similar in spirit to Lisp byte code and is used to
|
|
4841 implement converters for custom encodings.
|
|
4842
|
|
4843 @file{mule-canna.c} and @file{mule-wnnfns.c} implement interfaces to
|
|
4844 external programs used to implement the Canna and WNN input methods,
|
|
4845 respectively. This is currently in beta.
|
|
4846
|
|
4847 @file{mule-mcpath.c} provides some functions to allow for pathnames
|
|
4848 containing extended characters. This code is fragmentary, obsolete, and
|
|
4849 completely non-working. Instead, @var{pathname-coding-system} is used
|
|
4850 to specify conversions of names of files and directories. The standard
|
|
4851 C I/O functions like @samp{open()} are wrapped so that conversion occurs
|
|
4852 automatically.
|
|
4853
|
|
4854 @file{mule.c} provides a few miscellaneous things that should probably
|
|
4855 be elsewhere.
|
|
4856
|
|
4857
|
|
4858
|
|
4859 @example
|
|
4860 intl.c
|
|
4861 @end example
|
|
4862
|
|
4863 This provides some miscellaneous internationalization code for
|
|
4864 implementing message translation and interfacing to the Ximp input
|
|
4865 method. None of this code is currently working.
|
|
4866
|
|
4867
|
|
4868
|
|
4869 @example
|
|
4870 iso-wide.h
|
|
4871 @end example
|
|
4872
|
|
4873 This contains leftover code from an earlier implementation of
|
|
4874 Asian-language support, and is not currently used.
|
|
4875
|
|
4876
|
|
4877
|
|
4878
|
442
|
4879 @node Allocation of Objects in XEmacs Lisp, Dumping, A Summary of the Various XEmacs Modules, Top
|
428
|
4880 @chapter Allocation of Objects in XEmacs Lisp
|
462
|
4881 @cindex allocation of objects in XEmacs Lisp
|
|
4882 @cindex objects in XEmacs Lisp, allocation of
|
|
4883 @cindex Lisp objects, allocation of in XEmacs
|
428
|
4884
|
|
4885 @menu
|
|
4886 * Introduction to Allocation::
|
|
4887 * Garbage Collection::
|
|
4888 * GCPROing::
|
|
4889 * Garbage Collection - Step by Step::
|
|
4890 * Integers and Characters::
|
|
4891 * Allocation from Frob Blocks::
|
|
4892 * lrecords::
|
|
4893 * Low-level allocation::
|
|
4894 * Cons::
|
|
4895 * Vector::
|
|
4896 * Bit Vector::
|
|
4897 * Symbol::
|
|
4898 * Marker::
|
|
4899 * String::
|
|
4900 * Compiled Function::
|
|
4901 @end menu
|
|
4902
|
462
|
4903 @node Introduction to Allocation
|
428
|
4904 @section Introduction to Allocation
|
462
|
4905 @cindex allocation, introduction to
|
428
|
4906
|
|
4907 Emacs Lisp, like all Lisps, has garbage collection. This means that
|
|
4908 the programmer never has to explicitly free (destroy) an object; it
|
|
4909 happens automatically when the object becomes inaccessible. Most
|
|
4910 experts agree that garbage collection is a necessity in a modern,
|
|
4911 high-level language. Its omission from C stems from the fact that C was
|
|
4912 originally designed to be a nice abstract layer on top of assembly
|
|
4913 language, for writing kernels and basic system utilities rather than
|
|
4914 large applications.
|
|
4915
|
|
4916 Lisp objects can be created by any of a number of Lisp primitives.
|
|
4917 Most object types have one or a small number of basic primitives
|
|
4918 for creating objects. For conses, the basic primitive is @code{cons};
|
|
4919 for vectors, the primitives are @code{make-vector} and @code{vector}; for
|
|
4920 symbols, the primitives are @code{make-symbol} and @code{intern}; etc.
|
|
4921 Some Lisp objects, especially those that are primarily used internally,
|
|
4922 have no corresponding Lisp primitives. Every Lisp object, though,
|
|
4923 has at least one C primitive for creating it.
|
|
4924
|
442
|
4925 Recall from section (VII) that a Lisp object, as stored in a 32-bit or
|
|
4926 64-bit word, has a few tag bits, and a ``value'' that occupies the
|
|
4927 remainder of the bits. We can separate the different Lisp object types
|
|
4928 into three broad categories:
|
428
|
4929
|
|
4930 @itemize @bullet
|
|
4931 @item
|
|
4932 (a) Those for whom the value directly represents the contents of the
|
|
4933 Lisp object. Only two types are in this category: integers and
|
|
4934 characters. No special allocation or garbage collection is necessary
|
|
4935 for such objects. Lisp objects of these types do not need to be
|
|
4936 @code{GCPRO}ed.
|
|
4937 @end itemize
|
|
4938
|
442
|
4939 In the remaining two categories, the type is stored in the object
|
|
4940 itself. The tag for all such objects is the generic @dfn{lrecord}
|
|
4941 (Lisp_Type_Record) tag. The first bytes of the object's structure are an
|
|
4942 integer (actually a char) characterising the object's type and some
|
|
4943 flags, in particular the mark bit used for garbage collection. A
|
|
4944 structure describing the type is accessible thru the
|
|
4945 lrecord_implementation_table indexed with said integer. This structure
|
|
4946 includes the method pointers and a pointer to a string naming the type.
|
428
|
4947
|
|
4948 @itemize @bullet
|
|
4949 @item
|
442
|
4950 (b) Those lrecords that are allocated in frob blocks (see above). This
|
428
|
4951 includes the objects that are most common and relatively small, and
|
442
|
4952 includes conses, strings, subrs, floats, compiled functions, symbols,
|
428
|
4953 extents, events, and markers. With the cleanup of frob blocks done in
|
|
4954 19.12, it's not terribly hard to add more objects to this category, but
|
442
|
4955 it's a bit trickier than adding an object type to type (c) (esp. if the
|
428
|
4956 object needs a finalization method), and is not likely to save much
|
|
4957 space unless the object is small and there are many of them. (In fact,
|
|
4958 if there are very few of them, it might actually waste space.)
|
|
4959 @item
|
442
|
4960 (c) Those lrecords that are individually @code{malloc()}ed. These are
|
428
|
4961 called @dfn{lcrecords}. All other types are in this category. Adding a
|
|
4962 new type to this category is comparatively easy, and all types added
|
|
4963 since 19.8 (when the current allocation scheme was devised, by Richard
|
|
4964 Mlynarik), with the exception of the character type, have been in this
|
|
4965 category.
|
|
4966 @end itemize
|
|
4967
|
|
4968 Note that bit vectors are a bit of a special case. They are
|
442
|
4969 simple lrecords as in category (b), but are individually @code{malloc()}ed
|
428
|
4970 like vectors. You can basically view them as exactly like vectors
|
|
4971 except that their type is stored in lrecord fashion rather than
|
|
4972 in directly-tagged fashion.
|
|
4973
|
442
|
4974
|
462
|
4975 @node Garbage Collection
|
428
|
4976 @section Garbage Collection
|
|
4977 @cindex garbage collection
|
|
4978
|
|
4979 @cindex mark and sweep
|
|
4980 Garbage collection is simple in theory but tricky to implement.
|
|
4981 Emacs Lisp uses the oldest garbage collection method, called
|
|
4982 @dfn{mark and sweep}. Garbage collection begins by starting with
|
|
4983 all accessible locations (i.e. all variables and other slots where
|
|
4984 Lisp objects might occur) and recursively traversing all objects
|
|
4985 accessible from those slots, marking each one that is found.
|
|
4986 We then go through all of memory and free each object that is
|
|
4987 not marked, and unmarking each object that is marked. Note
|
|
4988 that ``all of memory'' means all currently allocated objects.
|
|
4989 Traversing all these objects means traversing all frob blocks,
|
|
4990 all vectors (which are chained in one big list), and all
|
|
4991 lcrecords (which are likewise chained).
|
|
4992
|
442
|
4993 Garbage collection can be invoked explicitly by calling
|
|
4994 @code{garbage-collect} but is also called automatically by @code{eval},
|
|
4995 once a certain amount of memory has been allocated since the last
|
|
4996 garbage collection (according to @code{gc-cons-threshold}).
|
|
4997
|
|
4998
|
462
|
4999 @node GCPROing
|
428
|
5000 @section @code{GCPRO}ing
|
462
|
5001 @cindex @code{GCPRO}ing
|
|
5002 @cindex garbage collection protection
|
|
5003 @cindex protection, garbage collection
|
428
|
5004
|
|
5005 @code{GCPRO}ing is one of the ugliest and trickiest parts of Emacs
|
|
5006 internals. The basic idea is that whenever garbage collection
|
|
5007 occurs, all in-use objects must be reachable somehow or
|
|
5008 other from one of the roots of accessibility. The roots
|
|
5009 of accessibility are:
|
|
5010
|
|
5011 @enumerate
|
|
5012 @item
|
442
|
5013 All objects that have been @code{staticpro()}d or
|
|
5014 @code{staticpro_nodump()}ed. This is used for any global C variables
|
|
5015 that hold Lisp objects. A call to @code{staticpro()} happens implicitly
|
|
5016 as a result of any symbols declared with @code{defsymbol()} and any
|
|
5017 variables declared with @code{DEFVAR_FOO()}. You need to explicitly
|
|
5018 call @code{staticpro()} (in the @code{vars_of_foo()} method of a module)
|
|
5019 for other global C variables holding Lisp objects. (This typically
|
|
5020 includes internal lists and such things.). Use
|
|
5021 @code{staticpro_nodump()} only in the rare cases when you do not want
|
|
5022 the pointed variable to be saved at dump time but rather recompute it at
|
|
5023 startup.
|
428
|
5024
|
|
5025 Note that @code{obarray} is one of the @code{staticpro()}d things.
|
|
5026 Therefore, all functions and variables get marked through this.
|
|
5027 @item
|
|
5028 Any shadowed bindings that are sitting on the @code{specpdl} stack.
|
|
5029 @item
|
|
5030 Any objects sitting in currently active (Lisp) stack frames,
|
|
5031 catches, and condition cases.
|
|
5032 @item
|
|
5033 A couple of special-case places where active objects are
|
|
5034 located.
|
|
5035 @item
|
|
5036 Anything currently marked with @code{GCPRO}.
|
|
5037 @end enumerate
|
|
5038
|
|
5039 Marking with @code{GCPRO} is necessary because some C functions (quite
|
|
5040 a lot, in fact), allocate objects during their operation. Quite
|
|
5041 frequently, there will be no other pointer to the object while the
|
|
5042 function is running, and if a garbage collection occurs and the object
|
|
5043 needs to be referenced again, bad things will happen. The solution is
|
|
5044 to mark those objects with @code{GCPRO}. Unfortunately this is easy to
|
|
5045 forget, and there is basically no way around this problem. Here are
|
|
5046 some rules, though:
|
|
5047
|
|
5048 @enumerate
|
|
5049 @item
|
|
5050 For every @code{GCPRO@var{n}}, there have to be declarations of
|
|
5051 @code{struct gcpro gcpro1, gcpro2}, etc.
|
|
5052
|
|
5053 @item
|
|
5054 You @emph{must} @code{UNGCPRO} anything that's @code{GCPRO}ed, and you
|
|
5055 @emph{must not} @code{UNGCPRO} if you haven't @code{GCPRO}ed. Getting
|
|
5056 either of these wrong will lead to crashes, often in completely random
|
|
5057 places unrelated to where the problem lies.
|
|
5058
|
|
5059 @item
|
|
5060 The way this actually works is that all currently active @code{GCPRO}s
|
|
5061 are chained through the @code{struct gcpro} local variables, with the
|
|
5062 variable @samp{gcprolist} pointing to the head of the list and the nth
|
|
5063 local @code{gcpro} variable pointing to the first @code{gcpro} variable
|
|
5064 in the next enclosing stack frame. Each @code{GCPRO}ed thing is an
|
|
5065 lvalue, and the @code{struct gcpro} local variable contains a pointer to
|
|
5066 this lvalue. This is why things will mess up badly if you don't pair up
|
440
|
5067 the @code{GCPRO}s and @code{UNGCPRO}s---you will end up with
|
428
|
5068 @code{gcprolist}s containing pointers to @code{struct gcpro}s or local
|
|
5069 @code{Lisp_Object} variables in no-longer-active stack frames.
|
|
5070
|
|
5071 @item
|
|
5072 It is actually possible for a single @code{struct gcpro} to
|
|
5073 protect a contiguous array of any number of values, rather than
|
|
5074 just a single lvalue. To effect this, call @code{GCPRO@var{n}} as usual on
|
|
5075 the first object in the array and then set @code{gcpro@var{n}.nvars}.
|
|
5076
|
|
5077 @item
|
|
5078 @strong{Strings are relocated.} What this means in practice is that the
|
|
5079 pointer obtained using @code{XSTRING_DATA()} is liable to change at any
|
|
5080 time, and you should never keep it around past any function call, or
|
|
5081 pass it as an argument to any function that might cause a garbage
|
|
5082 collection. This is why a number of functions accept either a
|
|
5083 ``non-relocatable'' @code{char *} pointer or a relocatable Lisp string,
|
|
5084 and only access the Lisp string's data at the very last minute. In some
|
|
5085 cases, you may end up having to @code{alloca()} some space and copy the
|
|
5086 string's data into it.
|
|
5087
|
|
5088 @item
|
|
5089 By convention, if you have to nest @code{GCPRO}'s, use @code{NGCPRO@var{n}}
|
|
5090 (along with @code{struct gcpro ngcpro1, ngcpro2}, etc.), @code{NNGCPRO@var{n}},
|
|
5091 etc. This avoids compiler warnings about shadowed locals.
|
|
5092
|
|
5093 @item
|
|
5094 It is @emph{always} better to err on the side of extra @code{GCPRO}s
|
|
5095 rather than too few. The extra cycles spent on this are
|
|
5096 almost never going to make a whit of difference in the
|
|
5097 speed of anything.
|
|
5098
|
|
5099 @item
|
|
5100 The general rule to follow is that caller, not callee, @code{GCPRO}s.
|
|
5101 That is, you should not have to explicitly @code{GCPRO} any Lisp objects
|
|
5102 that are passed in as parameters.
|
|
5103
|
|
5104 One exception from this rule is if you ever plan to change the parameter
|
|
5105 value, and store a new object in it. In that case, you @emph{must}
|
|
5106 @code{GCPRO} the parameter, because otherwise the new object will not be
|
|
5107 protected.
|
|
5108
|
|
5109 So, if you create any Lisp objects (remember, this happens in all sorts
|
|
5110 of circumstances, e.g. with @code{Fcons()}, etc.), you are responsible
|
|
5111 for @code{GCPRO}ing them, unless you are @emph{absolutely sure} that
|
|
5112 there's no possibility that a garbage-collection can occur while you
|
|
5113 need to use the object. Even then, consider @code{GCPRO}ing.
|
|
5114
|
|
5115 @item
|
|
5116 A garbage collection can occur whenever anything calls @code{Feval}, or
|
|
5117 whenever a QUIT can occur where execution can continue past
|
|
5118 this. (Remember, this is almost anywhere.)
|
|
5119
|
|
5120 @item
|
|
5121 If you have the @emph{least smidgeon of doubt} about whether
|
|
5122 you need to @code{GCPRO}, you should @code{GCPRO}.
|
|
5123
|
|
5124 @item
|
|
5125 Beware of @code{GCPRO}ing something that is uninitialized. If you have
|
|
5126 any shade of doubt about this, initialize all your variables to @code{Qnil}.
|
|
5127
|
|
5128 @item
|
|
5129 Be careful of traps, like calling @code{Fcons()} in the argument to
|
|
5130 another function. By the ``caller protects'' law, you should be
|
|
5131 @code{GCPRO}ing the newly-created cons, but you aren't. A certain
|
|
5132 number of functions that are commonly called on freshly created stuff
|
|
5133 (e.g. @code{nconc2()}, @code{Fsignal()}), break the ``caller protects''
|
|
5134 law and go ahead and @code{GCPRO} their arguments so as to simplify
|
|
5135 things, but make sure and check if it's OK whenever doing something like
|
|
5136 this.
|
|
5137
|
|
5138 @item
|
|
5139 Once again, remember to @code{GCPRO}! Bugs resulting from insufficient
|
|
5140 @code{GCPRO}ing are intermittent and extremely difficult to track down,
|
|
5141 often showing up in crashes inside of @code{garbage-collect} or in
|
|
5142 weirdly corrupted objects or even in incorrect values in a totally
|
|
5143 different section of code.
|
|
5144 @end enumerate
|
|
5145
|
|
5146 @cindex garbage collection, conservative
|
|
5147 @cindex conservative garbage collection
|
|
5148 Given the extremely error-prone nature of the @code{GCPRO} scheme, and
|
|
5149 the difficulties in tracking down, it should be considered a deficiency
|
|
5150 in the XEmacs code. A solution to this problem would involve
|
|
5151 implementing so-called @dfn{conservative} garbage collection for the C
|
|
5152 stack. That involves looking through all of stack memory and treating
|
|
5153 anything that looks like a reference to an object as a reference. This
|
|
5154 will result in a few objects not getting collected when they should, but
|
|
5155 it obviates the need for @code{GCPRO}ing, and allows garbage collection
|
|
5156 to happen at any point at all, such as during object allocation.
|
|
5157
|
462
|
5158 @node Garbage Collection - Step by Step
|
428
|
5159 @section Garbage Collection - Step by Step
|
462
|
5160 @cindex garbage collection - step by step
|
428
|
5161
|
|
5162 @menu
|
|
5163 * Invocation::
|
|
5164 * garbage_collect_1::
|
|
5165 * mark_object::
|
|
5166 * gc_sweep::
|
|
5167 * sweep_lcrecords_1::
|
|
5168 * compact_string_chars::
|
|
5169 * sweep_strings::
|
|
5170 * sweep_bit_vectors_1::
|
|
5171 @end menu
|
|
5172
|
462
|
5173 @node Invocation
|
428
|
5174 @subsection Invocation
|
|
5175 @cindex garbage collection, invocation
|
|
5176
|
|
5177 The first thing that anyone should know about garbage collection is:
|
442
|
5178 when and how the garbage collector is invoked. One might think that this
|
428
|
5179 could happen every time new memory is allocated, e.g. new objects are
|
|
5180 created, but this is @emph{not} the case. Instead, we have the following
|
|
5181 situation:
|
|
5182
|
|
5183 The entry point of any process of garbage collection is an invocation
|
|
5184 of the function @code{garbage_collect_1} in file @code{alloc.c}. The
|
|
5185 invocation can occur @emph{explicitly} by calling the function
|
|
5186 @code{Fgarbage_collect} (in addition this function provides information
|
442
|
5187 about the freed memory), or can occur @emph{implicitly} in four different
|
428
|
5188 situations:
|
|
5189 @enumerate
|
|
5190 @item
|
|
5191 In function @code{main_1} in file @code{emacs.c}. This function is called
|
|
5192 at each startup of xemacs. The garbage collection is invoked after all
|
|
5193 initial creations are completed, but only if a special internal error
|
|
5194 checking-constant @code{ERROR_CHECK_GC} is defined.
|
|
5195 @item
|
|
5196 In function @code{disksave_object_finalization} in file
|
|
5197 @code{alloc.c}. The only purpose of this function is to clear the
|
442
|
5198 objects from memory which need not be stored with xemacs when we dump out
|
428
|
5199 an executable. This is only done by @code{Fdump_emacs} or by
|
|
5200 @code{Fdump_emacs_data} respectively (both in @code{emacs.c}). The
|
|
5201 actual clearing is accomplished by making these objects unreachable and
|
|
5202 starting a garbage collection. The function is only used while building
|
|
5203 xemacs.
|
|
5204 @item
|
|
5205 In function @code{Feval / eval} in file @code{eval.c}. Each time the
|
|
5206 well known and often used function eval is called to evaluate a form,
|
|
5207 one of the first things that could happen, is a potential call of
|
|
5208 @code{garbage_collect_1}. There exist three global variables,
|
|
5209 @code{consing_since_gc} (counts the created cons-cells since the last
|
|
5210 garbage collection), @code{gc_cons_threshold} (a specified threshold
|
|
5211 after which a garbage collection occurs) and @code{always_gc}. If
|
|
5212 @code{always_gc} is set or if the threshold is exceeded, the garbage
|
|
5213 collection will start.
|
|
5214 @item
|
|
5215 In function @code{Ffuncall / funcall} in file @code{eval.c}. This
|
|
5216 function evaluates calls of elisp functions and works according to
|
|
5217 @code{Feval}.
|
|
5218 @end enumerate
|
|
5219
|
|
5220 The upshot is that garbage collection can basically occur everywhere
|
|
5221 @code{Feval}, respectively @code{Ffuncall}, is used - either directly or
|
442
|
5222 through another function. Since calls to these two functions are hidden
|
|
5223 in various other functions, many calls to @code{garbage_collect_1} are
|
|
5224 not obviously foreseeable, and therefore unexpected. Instances where
|
|
5225 they are used that are worth remembering are various elisp commands, as
|
|
5226 for example @code{or}, @code{and}, @code{if}, @code{cond}, @code{while},
|
|
5227 @code{setq}, etc., miscellaneous @code{gui_item_...} functions,
|
|
5228 everything related to @code{eval} (@code{Feval_buffer}, @code{call0},
|
|
5229 ...) and inside @code{Fsignal}. The latter is used to handle signals, as
|
444
|
5230 for example the ones raised by every @code{QUIT}-macro triggered after
|
442
|
5231 pressing Ctrl-g.
|
|
5232
|
462
|
5233 @node garbage_collect_1
|
428
|
5234 @subsection @code{garbage_collect_1}
|
|
5235 @cindex @code{garbage_collect_1}
|
|
5236
|
|
5237 We can now describe exactly what happens after the invocation takes
|
|
5238 place.
|
|
5239 @enumerate
|
|
5240 @item
|
442
|
5241 There are several cases in which the garbage collector is left immediately:
|
428
|
5242 when we are already garbage collecting (@code{gc_in_progress}), when
|
|
5243 the garbage collection is somehow forbidden
|
|
5244 (@code{gc_currently_forbidden}), when we are currently displaying something
|
|
5245 (@code{in_display}) or when we are preparing for the armageddon of the
|
|
5246 whole system (@code{preparing_for_armageddon}).
|
|
5247 @item
|
|
5248 Next the correct frame in which to put
|
|
5249 all the output occurring during garbage collecting is determined. In
|
|
5250 order to be able to restore the old display's state after displaying the
|
|
5251 message, some data about the current cursor position has to be
|
442
|
5252 saved. The variables @code{pre_gc_cursor} and @code{cursor_changed} take
|
428
|
5253 care of that.
|
|
5254 @item
|
|
5255 The state of @code{gc_currently_forbidden} must be restored after
|
|
5256 the garbage collection, no matter what happens during the process. We
|
|
5257 accomplish this by @code{record_unwind_protect}ing the suitable function
|
|
5258 @code{restore_gc_inhibit} together with the current value of
|
442
|
5259 @code{gc_currently_forbidden}.
|
428
|
5260 @item
|
|
5261 If we are concurrently running an interactive xemacs session, the next step
|
|
5262 is simply to show the garbage collector's cursor/message.
|
|
5263 @item
|
|
5264 The following steps are the intrinsic steps of the garbage collector,
|
|
5265 therefore @code{gc_in_progress} is set.
|
|
5266 @item
|
|
5267 For debugging purposes, it is possible to copy the current C stack
|
|
5268 frame. However, this seems to be a currently unused feature.
|
|
5269 @item
|
|
5270 Before actually starting to go over all live objects, references to
|
|
5271 objects that are no longer used are pruned. We only have to do this for events
|
|
5272 (@code{clear_event_resource}) and for specifiers
|
442
|
5273 (@code{cleanup_specifiers}).
|
428
|
5274 @item
|
|
5275 Now the mark phase begins and marks all accessible elements. In order to
|
|
5276 start from
|
|
5277 all slots that serve as roots of accessibility, the function
|
|
5278 @code{mark_object} is called for each root individually to go out from
|
|
5279 there to mark all reachable objects. All roots that are traversed are
|
|
5280 shown in their processed order:
|
|
5281 @itemize @bullet
|
|
5282 @item
|
|
5283 all constant symbols and static variables that are registered via
|
452
|
5284 @code{staticpro}@ in the dynarr @code{staticpros}.
|
442
|
5285 @xref{Adding Global Lisp Variables}.
|
428
|
5286 @item
|
|
5287 all Lisp objects that are created in C functions and that must be
|
|
5288 protected from freeing them. They are registered in the global
|
|
5289 list @code{gcprolist}.
|
|
5290 @xref{GCPROing}.
|
442
|
5291 @item
|
428
|
5292 all local variables (i.e. their name fields @code{symbol} and old
|
|
5293 values @code{old_values}) that are bound during the evaluation by the Lisp
|
|
5294 engine. They are stored in @code{specbinding} structs pushed on a stack
|
|
5295 called @code{specpdl}.
|
|
5296 @xref{Dynamic Binding; The specbinding Stack; Unwind-Protects}.
|
|
5297 @item
|
|
5298 all catch blocks that the Lisp engine encounters during the evaluation
|
|
5299 cause the creation of structs @code{catchtag} inserted in the list
|
|
5300 @code{catchlist}. Their tag (@code{tag}) and value (@code{val} fields
|
|
5301 are freshly created objects and therefore have to be marked.
|
|
5302 @xref{Catch and Throw}.
|
|
5303 @item
|
442
|
5304 every function application pushes new structs @code{backtrace}
|
|
5305 on the call stack of the Lisp engine (@code{backtrace_list}). The unique
|
428
|
5306 parts that have to be marked are the fields for each function
|
|
5307 (@code{function}) and all their arguments (@code{args}).
|
|
5308 @xref{Evaluation}.
|
|
5309 @item
|
442
|
5310 all objects that are used by the redisplay engine that must not be freed
|
428
|
5311 are marked by a special function called @code{mark_redisplay} (in
|
|
5312 @code{redisplay.c}).
|
|
5313 @item
|
|
5314 all objects created for profiling purposes are allocated by C functions
|
|
5315 instead of using the lisp allocation mechanisms. In order to receive the
|
|
5316 right ones during the sweep phase, they also have to be marked
|
|
5317 manually. That is done by the function @code{mark_profiling_info}
|
|
5318 @end itemize
|
|
5319 @item
|
436
|
5320 Hash tables in XEmacs belong to a kind of special objects that
|
428
|
5321 make use of a concept often called 'weak pointers'.
|
|
5322 To make a long story short, these kind of pointers are not followed
|
|
5323 during the estimation of the live objects during garbage collection.
|
|
5324 Any object referenced only by weak pointers is collected
|
|
5325 anyway, and the reference to it is cleared. In hash tables there are
|
|
5326 different usage patterns of them, manifesting in different types of hash
|
|
5327 tables, namely 'non-weak', 'weak', 'key-weak' and 'value-weak'
|
442
|
5328 (internally also 'key-car-weak' and 'value-car-weak') hash tables, each
|
|
5329 clearing entries depending on different conditions. More information can
|
428
|
5330 be found in the documentation to the function @code{make-hash-table}.
|
|
5331
|
|
5332 Because there are complicated dependency rules about when and what to
|
|
5333 mark while processing weak hash tables, the standard @code{marker}
|
|
5334 method is only active if it is marking non-weak hash tables. As soon as
|
|
5335 a weak component is in the table, the hash table entries are ignored
|
|
5336 while marking. Instead their marking is done each separately by the
|
|
5337 function @code{finish_marking_weak_hash_tables}. This function iterates
|
|
5338 over each hash table entry @code{hentries} for each weak hash table in
|
|
5339 @code{Vall_weak_hash_tables}. Depending on the type of a table, the
|
442
|
5340 appropriate action is performed.
|
428
|
5341 If a table is acting as @code{HASH_TABLE_KEY_WEAK}, and a key already marked,
|
442
|
5342 everything reachable from the @code{value} component is marked. If it is
|
428
|
5343 acting as a @code{HASH_TABLE_VALUE_WEAK} and the value component is
|
442
|
5344 already marked, the marking starts beginning only from the
|
428
|
5345 @code{key} component.
|
442
|
5346 If it is a @code{HASH_TABLE_KEY_CAR_WEAK} and the car
|
428
|
5347 of the key entry is already marked, we mark both the @code{key} and
|
|
5348 @code{value} components.
|
|
5349 Finally, if the table is of the type @code{HASH_TABLE_VALUE_CAR_WEAK}
|
|
5350 and the car of the value components is already marked, again both the
|
|
5351 @code{key} and the @code{value} components get marked.
|
|
5352
|
|
5353 Again, there are lists with comparable properties called weak
|
|
5354 lists. There exist different peculiarities of their types called
|
|
5355 @code{simple}, @code{assoc}, @code{key-assoc} and
|
|
5356 @code{value-assoc}. You can find further details about them in the
|
|
5357 description to the function @code{make-weak-list}. The scheme of their
|
442
|
5358 marking is similar: all weak lists are listed in @code{Qall_weak_lists},
|
428
|
5359 therefore we iterate over them. The marking is advanced until we hit an
|
442
|
5360 already marked pair. Then we know that during a former run all
|
428
|
5361 the rest has been marked completely. Again, depending on the special
|
|
5362 type of the weak list, our jobs differ. If it is a @code{WEAK_LIST_SIMPLE}
|
|
5363 and the elem is marked, we mark the @code{cons} part. If it is a
|
|
5364 @code{WEAK_LIST_ASSOC} and not a pair or a pair with both marked car and
|
|
5365 cdr, we mark the @code{cons} and the @code{elem}. If it is a
|
|
5366 @code{WEAK_LIST_KEY_ASSOC} and not a pair or a pair with a marked car of
|
|
5367 the elem, we mark the @code{cons} and the @code{elem}. Finally, if it is
|
|
5368 a @code{WEAK_LIST_VALUE_ASSOC} and not a pair or a pair with a marked
|
|
5369 cdr of the elem, we mark both the @code{cons} and the @code{elem}.
|
|
5370
|
|
5371 Since, by marking objects in reach from weak hash tables and weak lists,
|
|
5372 other objects could get marked, this perhaps implies further marking of
|
442
|
5373 other weak objects, both finishing functions are redone as long as
|
428
|
5374 yet unmarked objects get freshly marked.
|
|
5375
|
|
5376 @item
|
|
5377 After completing the special marking for the weak hash tables and for the weak
|
|
5378 lists, all entries that point to objects that are going to be swept in
|
|
5379 the further process are useless, and therefore have to be removed from
|
|
5380 the table or the list.
|
|
5381
|
|
5382 The function @code{prune_weak_hash_tables} does the job for weak hash
|
|
5383 tables. Totally unmarked hash tables are removed from the list
|
|
5384 @code{Vall_weak_hash_tables}. The other ones are treated more carefully
|
442
|
5385 by scanning over all entries and removing one as soon as one of
|
428
|
5386 the components @code{key} and @code{value} is unmarked.
|
|
5387
|
|
5388 The same idea applies to the weak lists. It is accomplished by
|
|
5389 @code{prune_weak_lists}: An unmarked list is pruned from
|
|
5390 @code{Vall_weak_lists} immediately. A marked list is treated more
|
|
5391 carefully by going over it and removing just the unmarked pairs.
|
|
5392
|
|
5393 @item
|
|
5394 The function @code{prune_specifiers} checks all listed specifiers held
|
442
|
5395 in @code{Vall_specifiers} and removes the ones from the lists that are
|
428
|
5396 unmarked.
|
|
5397
|
|
5398 @item
|
|
5399 All syntax tables are stored in a list called
|
442
|
5400 @code{Vall_syntax_tables}. The function @code{prune_syntax_tables} walks
|
428
|
5401 through it and unlinks the tables that are unmarked.
|
|
5402
|
|
5403 @item
|
|
5404 Next, we will attack the complete sweeping - the function
|
|
5405 @code{gc_sweep} which holds the predominance.
|
|
5406 @item
|
|
5407 First, all the variables with respect to garbage collection are
|
442
|
5408 reset. @code{consing_since_gc} - the counter of the created cells since
|
428
|
5409 the last garbage collection - is set back to 0, and
|
|
5410 @code{gc_in_progress} is not @code{true} anymore.
|
|
5411 @item
|
442
|
5412 In case the session is interactive, the displayed cursor and message are
|
428
|
5413 removed again.
|
|
5414 @item
|
|
5415 The state of @code{gc_inhibit} is restored to the former value by
|
|
5416 unwinding the stack.
|
|
5417 @item
|
|
5418 A small memory reserve is always held back that can be reached by
|
|
5419 @code{breathing_space}. If nothing more is left, we create a new reserve
|
442
|
5420 and exit.
|
428
|
5421 @end enumerate
|
|
5422
|
462
|
5423 @node mark_object
|
428
|
5424 @subsection @code{mark_object}
|
|
5425 @cindex @code{mark_object}
|
|
5426
|
|
5427 The first thing that is checked while marking an object is whether the
|
|
5428 object is a real Lisp object @code{Lisp_Type_Record} or just an integer
|
|
5429 or a character. Integers and characters are the only two types that are
|
|
5430 stored directly - without another level of indirection, and therefore they
|
442
|
5431 don't have to be marked and collected.
|
428
|
5432 @xref{How Lisp Objects Are Represented in C}.
|
|
5433
|
|
5434 The second case is the one we have to handle. It is the one when we are
|
|
5435 dealing with a pointer to a Lisp object. But, there exist also three
|
|
5436 possibilities, that prevent us from doing anything while marking: The
|
|
5437 object is read only which prevents it from being garbage collected,
|
|
5438 i.e. marked (@code{C_READONLY_RECORD_HEADER}). The object in question is
|
|
5439 already marked, and need not be marked for the second time (checked by
|
|
5440 @code{MARKED_RECORD_HEADER_P}). If it is a special, unmarkable object
|
|
5441 (@code{UNMARKABLE_RECORD_HEADER_P}, apparently, these are objects that
|
442
|
5442 sit in some const space, and can therefore not be marked, see
|
428
|
5443 @code{this_one_is_unmarkable} in @code{alloc.c}).
|
|
5444
|
|
5445 Now, the actual marking is feasible. We do so by once using the macro
|
|
5446 @code{MARK_RECORD_HEADER} to mark the object itself (actually the
|
|
5447 special flag in the lrecord header), and calling its special marker
|
|
5448 "method" @code{marker} if available. The marker method marks every
|
442
|
5449 other object that is in reach from our current object. Note, that these
|
428
|
5450 marker methods should not call @code{mark_object} recursively, but
|
|
5451 instead should return the next object from where further marking has to
|
|
5452 be performed.
|
|
5453
|
|
5454 In case another object was returned, as mentioned before, we reiterate
|
|
5455 the whole @code{mark_object} process beginning with this next object.
|
|
5456
|
462
|
5457 @node gc_sweep
|
428
|
5458 @subsection @code{gc_sweep}
|
|
5459 @cindex @code{gc_sweep}
|
|
5460
|
442
|
5461 The job of this function is to free all unmarked records from memory. As
|
428
|
5462 we know, there are different types of objects implemented and managed, and
|
|
5463 consequently different ways to free them from memory.
|
|
5464 @xref{Introduction to Allocation}.
|
|
5465
|
|
5466 We start with all objects stored through @code{lcrecords}. All
|
|
5467 bulkier objects are allocated and handled using that scheme of
|
|
5468 @code{lcrecords}. Each object is @code{malloc}ed separately
|
|
5469 instead of placing it in one of the contiguous frob blocks. All types
|
442
|
5470 that are currently stored
|
438
|
5471 using @code{lcrecords}'s @code{alloc_lcrecord} and
|
428
|
5472 @code{make_lcrecord_list} are the types: vectors, buffers,
|
|
5473 char-table, char-table-entry, console, weak-list, database, device,
|
|
5474 ldap, hash-table, command-builder, extent-auxiliary, extent-info, face,
|
|
5475 coding-system, frame, image-instance, glyph, popup-data, gui-item,
|
|
5476 keymap, charset, color_instance, font_instance, opaque, opaque-list,
|
|
5477 process, range-table, specifier, symbol-value-buffer-local,
|
|
5478 symbol-value-lisp-magic, symbol-value-varalias, toolbar-button,
|
|
5479 tooltalk-message, tooltalk-pattern, window, and window-configuration. We
|
|
5480 take care of them in the fist place
|
|
5481 in order to be able to handle and to finalize items stored in them more
|
|
5482 easily. The function @code{sweep_lcrecords_1} as described below is
|
|
5483 doing the whole job for us.
|
|
5484 For a description about the internals: @xref{lrecords}.
|
|
5485
|
|
5486 Our next candidates are the other objects that behave quite differently
|
|
5487 than everything else: the strings. They consists of two parts, a
|
442
|
5488 fixed-size portion (@code{struct Lisp_String}) holding the string's
|
428
|
5489 length, its property list and a pointer to the second part, and the
|
|
5490 actual string data, which is stored in string-chars blocks comparable to
|
|
5491 frob blocks. In this block, the data is not only freed, but also a
|
|
5492 compression of holes is made, i.e. all strings are relocated together.
|
|
5493 @xref{String}. This compacting phase is performed by the function
|
|
5494 @code{compact_string_chars}, the actual sweeping by the function
|
|
5495 @code{sweep_strings} is described below.
|
|
5496
|
|
5497 After that, the other types are swept step by step using functions
|
|
5498 @code{sweep_conses}, @code{sweep_bit_vectors_1},
|
|
5499 @code{sweep_compiled_functions}, @code{sweep_floats},
|
|
5500 @code{sweep_symbols}, @code{sweep_extents}, @code{sweep_markers} and
|
|
5501 @code{sweep_extents}. They are the fixed-size types cons, floats,
|
|
5502 compiled-functions, symbol, marker, extent, and event stored in
|
|
5503 so-called "frob blocks", and therefore we can basically do the same on
|
|
5504 every type objects, using the same macros, especially defined only to
|
442
|
5505 handle everything with respect to fixed-size blocks. The only fixed-size
|
428
|
5506 type that is not handled here are the fixed-size portion of strings,
|
|
5507 because we took special care of them earlier.
|
|
5508
|
|
5509 The only big exceptions are bit vectors stored differently and
|
442
|
5510 therefore treated differently by the function @code{sweep_bit_vectors_1}
|
428
|
5511 described later.
|
|
5512
|
|
5513 At first, we need some brief information about how
|
|
5514 these fixed-size types are managed in general, in order to understand
|
|
5515 how the sweeping is done. They have all a fixed size, and are therefore
|
|
5516 stored in big blocks of memory - allocated at once - that can hold a
|
|
5517 certain amount of objects of one type. The macro
|
|
5518 @code{DECLARE_FIXED_TYPE_ALLOC} creates the suitable structures for
|
442
|
5519 every type. More precisely, we have the block struct
|
428
|
5520 (holding a pointer to the previous block @code{prev} and the
|
|
5521 objects in @code{block[]}), a pointer to current block
|
|
5522 (@code{current_..._block)}) and its last index
|
|
5523 (@code{current_..._block_index}), and a pointer to the free list that
|
|
5524 will be created. Also a macro @code{FIXED_TYPE_FROM_BLOCK} plus some
|
|
5525 related macros exists that are used to obtain a new object, either from
|
|
5526 the free list @code{ALLOCATE_FIXED_TYPE_1} if there is an unused object
|
|
5527 of that type stored or by allocating a completely new block using
|
|
5528 @code{ALLOCATE_FIXED_TYPE_FROM_BLOCK}.
|
|
5529
|
|
5530 The rest works as follows: all of them define a
|
|
5531 macro @code{UNMARK_...} that is used to unmark the object. They define a
|
|
5532 macro @code{ADDITIONAL_FREE_...} that defines additional work that has
|
|
5533 to be done when converting an object from in use to not in use (so far,
|
|
5534 only markers use it in order to unchain them). Then, they all call
|
442
|
5535 the macro @code{SWEEP_FIXED_TYPE_BLOCK} instantiated with their type name
|
428
|
5536 and their struct name.
|
|
5537
|
|
5538 This call in particular does the following: we go over all blocks
|
|
5539 starting with the current moving towards the oldest.
|
|
5540 For each block, we look at every object in it. If the object already
|
|
5541 freed (checked with @code{FREE_STRUCT_P} using the first pointer of the
|
442
|
5542 object), or if it is
|
428
|
5543 set to read only (@code{C_READONLY_RECORD_HEADER_P}, nothing must be
|
|
5544 done. If it is unmarked (checked with @code{MARKED_RECORD_HEADER_P}), it
|
|
5545 is put in the free list and set free (using the macro
|
442
|
5546 @code{FREE_FIXED_TYPE}, otherwise it stays in the block, but is unmarked
|
428
|
5547 (by @code{UNMARK_...}). While going through one block, we note if the
|
|
5548 whole block is empty. If so, the whole block is freed (using
|
|
5549 @code{xfree}) and the free list state is set to the state it had before
|
|
5550 handling this block.
|
|
5551
|
462
|
5552 @node sweep_lcrecords_1
|
428
|
5553 @subsection @code{sweep_lcrecords_1}
|
|
5554 @cindex @code{sweep_lcrecords_1}
|
|
5555
|
|
5556 After nullifying the complete lcrecord statistics, we go over all
|
442
|
5557 lcrecords two separate times. They are all chained together in a list with
|
|
5558 a head called @code{all_lcrecords}.
|
|
5559
|
|
5560 The first loop calls for each object its @code{finalizer} method, but only
|
428
|
5561 in the case that it is not read only
|
|
5562 (@code{C_READONLY_RECORD_HEADER_P)}, it is not already marked
|
|
5563 (@code{MARKED_RECORD_HEADER_P}), it is not already in a free list (list of
|
|
5564 freed objects, field @code{free}) and finally it owns a finalizer
|
|
5565 method.
|
442
|
5566
|
|
5567 The second loop actually frees the appropriate objects again by iterating
|
|
5568 through the whole list. In case an object is read only or marked, it
|
428
|
5569 has to persist, otherwise it is manually freed by calling
|
|
5570 @code{xfree}. During this loop, the lcrecord statistics are kept up to
|
442
|
5571 date by calling @code{tick_lcrecord_stats} with the right arguments,
|
|
5572
|
462
|
5573 @node compact_string_chars
|
428
|
5574 @subsection @code{compact_string_chars}
|
|
5575 @cindex @code{compact_string_chars}
|
|
5576
|
|
5577 The purpose of this function is to compact all the data parts of the
|
|
5578 strings that are held in so-called @code{string_chars_block}, i.e. the
|
|
5579 strings that do not exceed a certain maximal length.
|
|
5580
|
|
5581 The procedure with which this is done is as follows. We are keeping two
|
|
5582 positions in the @code{string_chars_block}s using two pointer/integer
|
|
5583 pairs, namely @code{from_sb}/@code{from_pos} and
|
|
5584 @code{to_sb}/@code{to_pos}. They stand for the actual positions, from
|
442
|
5585 where to where, to copy the actually handled string.
|
428
|
5586
|
|
5587 While going over all chained @code{string_char_block}s and their held
|
|
5588 strings, staring at @code{first_string_chars_block}, both pointers
|
|
5589 are advanced and eventually a string is copied from @code{from_sb} to
|
|
5590 @code{to_sb}, depending on the status of the pointed at strings.
|
|
5591
|
|
5592 More precisely, we can distinguish between the following actions.
|
|
5593 @itemize @bullet
|
|
5594 @item
|
|
5595 The string at @code{from_sb}'s position could be marked as free, which
|
442
|
5596 is indicated by an invalid pointer to the pointer that should point back
|
428
|
5597 to the fixed size string object, and which is checked by
|
|
5598 @code{FREE_STRUCT_P}. In this case, the @code{from_sb}/@code{from_pos}
|
|
5599 is advanced to the next string, and nothing has to be copied.
|
|
5600 @item
|
|
5601 Also, if a string object itself is unmarked, nothing has to be
|
|
5602 copied. We likewise advance the @code{from_sb}/@code{from_pos}
|
|
5603 pair as described above.
|
|
5604 @item
|
442
|
5605 In all other cases, we have a marked string at hand. The string data
|
428
|
5606 must be moved from the from-position to the to-position. In case
|
|
5607 there is not enough space in the actual @code{to_sb}-block, we advance
|
|
5608 this pointer to the beginning of the next block before copying. In case the
|
|
5609 from and to positions are different, we perform the
|
|
5610 actual copying using the library function @code{memmove}.
|
|
5611 @end itemize
|
|
5612
|
|
5613 After compacting, the pointer to the current
|
|
5614 @code{string_chars_block}, sitting in @code{current_string_chars_block},
|
|
5615 is reset on the last block to which we moved a string,
|
|
5616 i.e. @code{to_block}, and all remaining blocks (we know that they just
|
|
5617 carry garbage) are explicitly @code{xfree}d.
|
|
5618
|
462
|
5619 @node sweep_strings
|
428
|
5620 @subsection @code{sweep_strings}
|
|
5621 @cindex @code{sweep_strings}
|
|
5622
|
|
5623 The sweeping for the fixed sized string objects is essentially exactly
|
|
5624 the same as it is for all other fixed size types. As before, the freeing
|
|
5625 into the suitable free list is done by using the macro
|
|
5626 @code{SWEEP_FIXED_SIZE_BLOCK} after defining the right macros
|
|
5627 @code{UNMARK_string} and @code{ADDITIONAL_FREE_string}. These two
|
|
5628 definitions are a little bit special compared to the ones used
|
|
5629 for the other fixed size types.
|
|
5630
|
442
|
5631 @code{UNMARK_string} is defined the same way except some additional code
|
428
|
5632 used for updating the bookkeeping information.
|
|
5633
|
|
5634 For strings, @code{ADDITIONAL_FREE_string} has to do something in
|
|
5635 addition: in case, the string was not allocated in a
|
|
5636 @code{string_chars_block} because it exceeded the maximal length, and
|
|
5637 therefore it was @code{malloc}ed separately, we know also @code{xfree}
|
|
5638 it explicitly.
|
|
5639
|
462
|
5640 @node sweep_bit_vectors_1
|
428
|
5641 @subsection @code{sweep_bit_vectors_1}
|
|
5642 @cindex @code{sweep_bit_vectors_1}
|
|
5643
|
|
5644 Bit vectors are also one of the rare types that are @code{malloc}ed
|
|
5645 individually. Consequently, while sweeping, all further needless
|
|
5646 bit vectors must be freed by hand. This is done, as one might imagine,
|
|
5647 the expected way: since they are all registered in a list called
|
|
5648 @code{all_bit_vectors}, all elements of that list are traversed,
|
442
|
5649 all unmarked bit vectors are unlinked by calling @code{xfree} and all of
|
428
|
5650 them become unmarked.
|
442
|
5651 In addition, the bookkeeping information used for garbage
|
428
|
5652 collector's output purposes is updated.
|
|
5653
|
462
|
5654 @node Integers and Characters
|
428
|
5655 @section Integers and Characters
|
462
|
5656 @cindex integers and characters
|
|
5657 @cindex characters, integers and
|
428
|
5658
|
|
5659 Integer and character Lisp objects are created from integers using the
|
|
5660 macros @code{XSETINT()} and @code{XSETCHAR()} or the equivalent
|
|
5661 functions @code{make_int()} and @code{make_char()}. (These are actually
|
|
5662 macros on most systems.) These functions basically just do some moving
|
|
5663 of bits around, since the integral value of the object is stored
|
|
5664 directly in the @code{Lisp_Object}.
|
|
5665
|
|
5666 @code{XSETINT()} and the like will truncate values given to them that
|
|
5667 are too big; i.e. you won't get the value you expected but the tag bits
|
|
5668 will at least be correct.
|
|
5669
|
462
|
5670 @node Allocation from Frob Blocks
|
428
|
5671 @section Allocation from Frob Blocks
|
462
|
5672 @cindex allocation from frob blocks
|
|
5673 @cindex frob blocks, allocation from
|
428
|
5674
|
|
5675 The uninitialized memory required by a @code{Lisp_Object} of a particular type
|
|
5676 is allocated using
|
|
5677 @code{ALLOCATE_FIXED_TYPE()}. This only occurs inside of the
|
|
5678 lowest-level object-creating functions in @file{alloc.c}:
|
|
5679 @code{Fcons()}, @code{make_float()}, @code{Fmake_byte_code()},
|
|
5680 @code{Fmake_symbol()}, @code{allocate_extent()},
|
|
5681 @code{allocate_event()}, @code{Fmake_marker()}, and
|
|
5682 @code{make_uninit_string()}. The idea is that, for each type, there are
|
|
5683 a number of frob blocks (each 2K in size); each frob block is divided up
|
|
5684 into object-sized chunks. Each frob block will have some of these
|
|
5685 chunks that are currently assigned to objects, and perhaps some that are
|
|
5686 free. (If a frob block has nothing but free chunks, it is freed at the
|
|
5687 end of the garbage collection cycle.) The free chunks are stored in a
|
|
5688 free list, which is chained by storing a pointer in the first four bytes
|
|
5689 of the chunk. (Except for the free chunks at the end of the last frob
|
|
5690 block, which are handled using an index which points past the end of the
|
|
5691 last-allocated chunk in the last frob block.)
|
|
5692 @code{ALLOCATE_FIXED_TYPE()} first tries to retrieve a chunk from the
|
|
5693 free list; if that fails, it calls
|
|
5694 @code{ALLOCATE_FIXED_TYPE_FROM_BLOCK()}, which looks at the end of the
|
|
5695 last frob block for space, and creates a new frob block if there is
|
|
5696 none. (There are actually two versions of these macros, one of which is
|
|
5697 more defensive but less efficient and is used for error-checking.)
|
|
5698
|
462
|
5699 @node lrecords
|
428
|
5700 @section lrecords
|
462
|
5701 @cindex lrecords
|
428
|
5702
|
|
5703 [see @file{lrecord.h}]
|
|
5704
|
|
5705 All lrecords have at the beginning of their structure a @code{struct
|
442
|
5706 lrecord_header}. This just contains a type number and some flags,
|
|
5707 including the mark bit. All builtin type numbers are defined as
|
|
5708 constants in @code{enum lrecord_type}, to allow the compiler to generate
|
|
5709 more efficient code for @code{@var{type}P}. The type number, thru the
|
|
5710 @code{lrecord_implementation_table}, gives access to a @code{struct
|
428
|
5711 lrecord_implementation}, which is a structure containing method pointers
|
|
5712 and such. There is one of these for each type, and it is a global,
|
|
5713 constant, statically-declared structure that is declared in the
|
442
|
5714 @code{DEFINE_LRECORD_IMPLEMENTATION()} macro.
|
|
5715
|
|
5716 Simple lrecords (of type (b) above) just have a @code{struct
|
428
|
5717 lrecord_header} at their beginning. lcrecords, however, actually have a
|
|
5718 @code{struct lcrecord_header}. This, in turn, has a @code{struct
|
|
5719 lrecord_header} at its beginning, so sanity is preserved; but it also
|
|
5720 has a pointer used to chain all lcrecords together, and a special ID
|
|
5721 field used to distinguish one lcrecord from another. (This field is used
|
|
5722 only for debugging and could be removed, but the space gain is not
|
|
5723 significant.)
|
|
5724
|
|
5725 Simple lrecords are created using @code{ALLOCATE_FIXED_TYPE()}, just
|
|
5726 like for other frob blocks. The only change is that the implementation
|
|
5727 pointer must be initialized correctly. (The implementation structure for
|
|
5728 an lrecord, or rather the pointer to it, is named @code{lrecord_float},
|
|
5729 @code{lrecord_extent}, @code{lrecord_buffer}, etc.)
|
|
5730
|
|
5731 lcrecords are created using @code{alloc_lcrecord()}. This takes a
|
|
5732 size to allocate and an implementation pointer. (The size needs to be
|
|
5733 passed because some lcrecords, such as window configurations, are of
|
|
5734 variable size.) This basically just @code{malloc()}s the storage,
|
|
5735 initializes the @code{struct lcrecord_header}, and chains the lcrecord
|
|
5736 onto the head of the list of all lcrecords, which is stored in the
|
|
5737 variable @code{all_lcrecords}. The calls to @code{alloc_lcrecord()}
|
|
5738 generally occur in the lowest-level allocation function for each lrecord
|
|
5739 type.
|
|
5740
|
|
5741 Whenever you create an lrecord, you need to call either
|
|
5742 @code{DEFINE_LRECORD_IMPLEMENTATION()} or
|
|
5743 @code{DEFINE_LRECORD_SEQUENCE_IMPLEMENTATION()}. This needs to be
|
442
|
5744 specified in a @file{.c} file, at the top level. What this actually
|
|
5745 does is define and initialize the implementation structure for the
|
|
5746 lrecord. (And possibly declares a function @code{error_check_foo()} that
|
|
5747 implements the @code{XFOO()} macro when error-checking is enabled.) The
|
|
5748 arguments to the macros are the actual type name (this is used to
|
|
5749 construct the C variable name of the lrecord implementation structure
|
|
5750 and related structures using the @samp{##} macro concatenation
|
|
5751 operator), a string that names the type on the Lisp level (this may not
|
|
5752 be the same as the C type name; typically, the C type name has
|
|
5753 underscores, while the Lisp string has dashes), various method pointers,
|
|
5754 and the name of the C structure that contains the object. The methods
|
|
5755 are used to encapsulate type-specific information about the object, such
|
|
5756 as how to print it or mark it for garbage collection, so that it's easy
|
|
5757 to add new object types without having to add a specific case for each
|
|
5758 new type in a bunch of different places.
|
428
|
5759
|
|
5760 The difference between @code{DEFINE_LRECORD_IMPLEMENTATION()} and
|
|
5761 @code{DEFINE_LRECORD_SEQUENCE_IMPLEMENTATION()} is that the former is
|
|
5762 used for fixed-size object types and the latter is for variable-size
|
|
5763 object types. Most object types are fixed-size; some complex
|
|
5764 types, however (e.g. window configurations), are variable-size.
|
|
5765 Variable-size object types have an extra method, which is called
|
|
5766 to determine the actual size of a particular object of that type.
|
|
5767 (Currently this is only used for keeping allocation statistics.)
|
|
5768
|
|
5769 For the purpose of keeping allocation statistics, the allocation
|
|
5770 engine keeps a list of all the different types that exist. Note that,
|
|
5771 since @code{DEFINE_LRECORD_IMPLEMENTATION()} is a macro that is
|
442
|
5772 specified at top-level, there is no way for it to initialize the global
|
|
5773 data structures containing type information, like
|
|
5774 @code{lrecord_implementations_table}. For this reason a call to
|
|
5775 @code{INIT_LRECORD_IMPLEMENTATION} must be added to the same source file
|
|
5776 containing @code{DEFINE_LRECORD_IMPLEMENTATION}, but instead of to the
|
|
5777 top level, to one of the init functions, typically
|
|
5778 @code{syms_of_@var{foo}.c}. @code{INIT_LRECORD_IMPLEMENTATION} must be
|
|
5779 called before an object of this type is used.
|
|
5780
|
|
5781 The type number is also used to index into an array holding the number
|
|
5782 of objects of each type and the total memory allocated for objects of
|
|
5783 that type. The statistics in this array are computed during the sweep
|
|
5784 stage. These statistics are returned by the call to
|
|
5785 @code{garbage-collect}.
|
428
|
5786
|
|
5787 Note that for every type defined with a @code{DEFINE_LRECORD_*()}
|
|
5788 macro, there needs to be a @code{DECLARE_LRECORD_IMPLEMENTATION()}
|
|
5789 somewhere in a @file{.h} file, and this @file{.h} file needs to be
|
|
5790 included by @file{inline.c}.
|
|
5791
|
|
5792 Furthermore, there should generally be a set of @code{XFOOBAR()},
|
|
5793 @code{FOOBARP()}, etc. macros in a @file{.h} (or occasionally @file{.c})
|
|
5794 file. To create one of these, copy an existing model and modify as
|
|
5795 necessary.
|
|
5796
|
442
|
5797 @strong{Please note:} If you define an lrecord in an external
|
|
5798 dynamically-loaded module, you must use @code{DECLARE_EXTERNAL_LRECORD},
|
|
5799 @code{DEFINE_EXTERNAL_LRECORD_IMPLEMENTATION}, and
|
|
5800 @code{DEFINE_EXTERNAL_LRECORD_SEQUENCE_IMPLEMENTATION} instead of the
|
|
5801 non-EXTERNAL forms. These macros will dynamically add new type numbers
|
|
5802 to the global enum that records them, whereas the non-EXTERNAL forms
|
|
5803 assume that the programmer has already inserted the correct type numbers
|
|
5804 into the enum's code at compile-time.
|
|
5805
|
428
|
5806 The various methods in the lrecord implementation structure are:
|
|
5807
|
|
5808 @enumerate
|
|
5809 @item
|
|
5810 @cindex mark method
|
|
5811 A @dfn{mark} method. This is called during the marking stage and passed
|
|
5812 a function pointer (usually the @code{mark_object()} function), which is
|
|
5813 used to mark an object. All Lisp objects that are contained within the
|
|
5814 object need to be marked by applying this function to them. The mark
|
444
|
5815 method should also return a Lisp object, which should be either @code{nil} or
|
428
|
5816 an object to mark. (This can be used in lieu of calling
|
|
5817 @code{mark_object()} on the object, to reduce the recursion depth, and
|
|
5818 consequently should be the most heavily nested sub-object, such as a
|
|
5819 long list.)
|
|
5820
|
|
5821 @strong{Please note:} When the mark method is called, garbage collection
|
|
5822 is in progress, and special precautions need to be taken when accessing
|
|
5823 objects; see section (B) above.
|
|
5824
|
|
5825 If your mark method does not need to do anything, it can be
|
|
5826 @code{NULL}.
|
|
5827
|
|
5828 @item
|
|
5829 A @dfn{print} method. This is called to create a printed representation
|
|
5830 of the object, whenever @code{princ}, @code{prin1}, or the like is
|
|
5831 called. It is passed the object, a stream to which the output is to be
|
|
5832 directed, and an @code{escapeflag} which indicates whether the object's
|
|
5833 printed representation should be @dfn{escaped} so that it is
|
|
5834 readable. (This corresponds to the difference between @code{princ} and
|
|
5835 @code{prin1}.) Basically, @dfn{escaped} means that strings will have
|
|
5836 quotes around them and confusing characters in the strings such as
|
|
5837 quotes, backslashes, and newlines will be backslashed; and that special
|
|
5838 care will be taken to make symbols print in a readable fashion
|
|
5839 (e.g. symbols that look like numbers will be backslashed). Other
|
|
5840 readable objects should perhaps pass @code{escapeflag} on when
|
|
5841 sub-objects are printed, so that readability is preserved when necessary
|
|
5842 (or if not, always pass in a 1 for @code{escapeflag}). Non-readable
|
|
5843 objects should in general ignore @code{escapeflag}, except that some use
|
|
5844 it as an indication that more verbose output should be given.
|
|
5845
|
|
5846 Sub-objects are printed using @code{print_internal()}, which takes
|
|
5847 exactly the same arguments as are passed to the print method.
|
|
5848
|
|
5849 Literal C strings should be printed using @code{write_c_string()},
|
|
5850 or @code{write_string_1()} for non-null-terminated strings.
|
|
5851
|
|
5852 Functions that do not have a readable representation should check the
|
|
5853 @code{print_readably} flag and signal an error if it is set.
|
|
5854
|
|
5855 If you specify NULL for the print method, the
|
|
5856 @code{default_object_printer()} will be used.
|
|
5857
|
|
5858 @item
|
|
5859 A @dfn{finalize} method. This is called at the beginning of the sweep
|
|
5860 stage on lcrecords that are about to be freed, and should be used to
|
|
5861 perform any extra object cleanup. This typically involves freeing any
|
|
5862 extra @code{malloc()}ed memory associated with the object, releasing any
|
|
5863 operating-system and window-system resources associated with the object
|
|
5864 (e.g. pixmaps, fonts), etc.
|
|
5865
|
|
5866 The finalize method can be NULL if nothing needs to be done.
|
|
5867
|
|
5868 WARNING #1: The finalize method is also called at the end of the dump
|
|
5869 phase; this time with the for_disksave parameter set to non-zero. The
|
|
5870 object is @emph{not} about to disappear, so you have to make sure to
|
|
5871 @emph{not} free any extra @code{malloc()}ed memory if you're going to
|
|
5872 need it later. (Also, signal an error if there are any operating-system
|
|
5873 and window-system resources here, because they can't be dumped.)
|
|
5874
|
|
5875 Finalize methods should, as a rule, set to zero any pointers after
|
|
5876 they've been freed, and check to make sure pointers are not zero before
|
|
5877 freeing. Although I'm pretty sure that finalize methods are not called
|
|
5878 twice on the same object (except for the @code{for_disksave} proviso),
|
|
5879 we've gotten nastily burned in some cases by not doing this.
|
|
5880
|
|
5881 WARNING #2: The finalize method is @emph{only} called for
|
|
5882 lcrecords, @emph{not} for simply lrecords. If you need a
|
|
5883 finalize method for simple lrecords, you have to stick
|
|
5884 it in the @code{ADDITIONAL_FREE_foo()} macro in @file{alloc.c}.
|
|
5885
|
|
5886 WARNING #3: Things are in an @emph{extremely} bizarre state
|
|
5887 when @code{ADDITIONAL_FREE_foo()} is called, so you have to
|
|
5888 be incredibly careful when writing one of these functions.
|
|
5889 See the comment in @code{gc_sweep()}. If you ever have to add
|
|
5890 one of these, consider using an lcrecord or dealing with
|
|
5891 the problem in a different fashion.
|
|
5892
|
|
5893 @item
|
|
5894 An @dfn{equal} method. This compares the two objects for similarity,
|
|
5895 when @code{equal} is called. It should compare the contents of the
|
|
5896 objects in some reasonable fashion. It is passed the two objects and a
|
|
5897 @dfn{depth} value, which is used to catch circular objects. To compare
|
|
5898 sub-Lisp-objects, call @code{internal_equal()} and bump the depth value
|
|
5899 by one. If this value gets too high, a @code{circular-object} error
|
|
5900 will be signaled.
|
|
5901
|
|
5902 If this is NULL, objects are @code{equal} only when they are @code{eq},
|
|
5903 i.e. identical.
|
|
5904
|
|
5905 @item
|
|
5906 A @dfn{hash} method. This is used to hash objects when they are to be
|
|
5907 compared with @code{equal}. The rule here is that if two objects are
|
|
5908 @code{equal}, they @emph{must} hash to the same value; i.e. your hash
|
|
5909 function should use some subset of the sub-fields of the object that are
|
|
5910 compared in the ``equal'' method. If you specify this method as
|
|
5911 @code{NULL}, the object's pointer will be used as the hash, which will
|
|
5912 @emph{fail} if the object has an @code{equal} method, so don't do this.
|
|
5913
|
|
5914 To hash a sub-Lisp-object, call @code{internal_hash()}. Bump the
|
|
5915 depth by one, just like in the ``equal'' method.
|
|
5916
|
|
5917 To convert a Lisp object directly into a hash value (using
|
|
5918 its pointer), use @code{LISP_HASH()}. This is what happens when
|
|
5919 the hash method is NULL.
|
|
5920
|
|
5921 To hash two or more values together into a single value, use
|
|
5922 @code{HASH2()}, @code{HASH3()}, @code{HASH4()}, etc.
|
|
5923
|
|
5924 @item
|
|
5925 @dfn{getprop}, @dfn{putprop}, @dfn{remprop}, and @dfn{plist} methods.
|
|
5926 These are used for object types that have properties. I don't feel like
|
|
5927 documenting them here. If you create one of these objects, you have to
|
|
5928 use different macros to define them,
|
|
5929 i.e. @code{DEFINE_LRECORD_IMPLEMENTATION_WITH_PROPS()} or
|
|
5930 @code{DEFINE_LRECORD_SEQUENCE_IMPLEMENTATION_WITH_PROPS()}.
|
|
5931
|
|
5932 @item
|
|
5933 A @dfn{size_in_bytes} method, when the object is of variable-size.
|
|
5934 (i.e. declared with a @code{_SEQUENCE_IMPLEMENTATION} macro.) This should
|
|
5935 simply return the object's size in bytes, exactly as you might expect.
|
|
5936 For an example, see the methods for window configurations and opaques.
|
|
5937 @end enumerate
|
|
5938
|
462
|
5939 @node Low-level allocation
|
428
|
5940 @section Low-level allocation
|
462
|
5941 @cindex low-level allocation
|
|
5942 @cindex allocation, low-level
|
428
|
5943
|
|
5944 Memory that you want to allocate directly should be allocated using
|
|
5945 @code{xmalloc()} rather than @code{malloc()}. This implements
|
|
5946 error-checking on the return value, and once upon a time did some more
|
|
5947 vital stuff (i.e. @code{BLOCK_INPUT}, which is no longer necessary).
|
|
5948 Free using @code{xfree()}, and realloc using @code{xrealloc()}. Note
|
|
5949 that @code{xmalloc()} will do a non-local exit if the memory can't be
|
|
5950 allocated. (Many functions, however, do not expect this, and thus XEmacs
|
|
5951 will likely crash if this happens. @strong{This is a bug.} If you can,
|
|
5952 you should strive to make your function handle this OK. However, it's
|
|
5953 difficult in the general circumstance, perhaps requiring extra
|
|
5954 unwind-protects and such.)
|
|
5955
|
|
5956 Note that XEmacs provides two separate replacements for the standard
|
|
5957 @code{malloc()} library function. These are called @dfn{old GNU malloc}
|
|
5958 (@file{malloc.c}) and @dfn{new GNU malloc} (@file{gmalloc.c}),
|
|
5959 respectively. New GNU malloc is better in pretty much every way than
|
|
5960 old GNU malloc, and should be used if possible. (It used to be that on
|
|
5961 some systems, the old one worked but the new one didn't. I think this
|
|
5962 was due specifically to a bug in SunOS, which the new one now works
|
|
5963 around; so I don't think the old one ever has to be used any more.) The
|
|
5964 primary difference between both of these mallocs and the standard system
|
|
5965 malloc is that they are much faster, at the expense of increased space.
|
|
5966 The basic idea is that memory is allocated in fixed chunks of powers of
|
|
5967 two. This allows for basically constant malloc time, since the various
|
|
5968 chunks can just be kept on a number of free lists. (The standard system
|
|
5969 malloc typically allocates arbitrary-sized chunks and has to spend some
|
|
5970 time, sometimes a significant amount of time, walking the heap looking
|
|
5971 for a free block to use and cleaning things up.) The new GNU malloc
|
|
5972 improves on things by allocating large objects in chunks of 4096 bytes
|
|
5973 rather than in ever larger powers of two, which results in ever larger
|
|
5974 wastage. There is a slight speed loss here, but it's of doubtful
|
|
5975 significance.
|
|
5976
|
|
5977 NOTE: Apparently there is a third-generation GNU malloc that is
|
|
5978 significantly better than the new GNU malloc, and should probably
|
|
5979 be included in XEmacs.
|
|
5980
|
|
5981 There is also the relocating allocator, @file{ralloc.c}. This actually
|
|
5982 moves blocks of memory around so that the @code{sbrk()} pointer shrunk
|
|
5983 and virtual memory released back to the system. On some systems,
|
|
5984 this is a big win. On all systems, it causes a noticeable (and
|
|
5985 sometimes huge) speed penalty, so I turn it off by default.
|
|
5986 @file{ralloc.c} only works with the new GNU malloc in @file{gmalloc.c}.
|
|
5987 There are also two versions of @file{ralloc.c}, one that uses @code{mmap()}
|
|
5988 rather than block copies to move data around. This purports to
|
|
5989 be faster, although that depends on the amount of data that would
|
|
5990 have had to be block copied and the system-call overhead for
|
|
5991 @code{mmap()}. I don't know exactly how this works, except that the
|
|
5992 relocating-allocation routines are pretty much used only for
|
|
5993 the memory allocated for a buffer, which is the biggest consumer
|
|
5994 of space, esp. of space that may get freed later.
|
|
5995
|
|
5996 Note that the GNU mallocs have some ``memory warning'' facilities.
|
|
5997 XEmacs taps into them and issues a warning through the standard
|
|
5998 warning system, when memory gets to 75%, 85%, and 95% full.
|
|
5999 (On some systems, the memory warnings are not functional.)
|
|
6000
|
|
6001 Allocated memory that is going to be used to make a Lisp object
|
442
|
6002 is created using @code{allocate_lisp_storage()}. This just calls
|
|
6003 @code{xmalloc()}. It used to verify that the pointer to the memory can
|
|
6004 fit into a Lisp word, before the current Lisp object representation was
|
|
6005 introduced. @code{allocate_lisp_storage()} is called by
|
|
6006 @code{alloc_lcrecord()}, @code{ALLOCATE_FIXED_TYPE()}, and the vector
|
|
6007 and bit-vector creation routines. These routines also call
|
|
6008 @code{INCREMENT_CONS_COUNTER()} at the appropriate times; this keeps
|
|
6009 statistics on how much memory is allocated, so that garbage-collection
|
|
6010 can be invoked when the threshold is reached.
|
|
6011
|
462
|
6012 @node Cons
|
428
|
6013 @section Cons
|
462
|
6014 @cindex cons
|
428
|
6015
|
|
6016 Conses are allocated in standard frob blocks. The only thing to
|
|
6017 note is that conses can be explicitly freed using @code{free_cons()}
|
|
6018 and associated functions @code{free_list()} and @code{free_alist()}. This
|
|
6019 immediately puts the conses onto the cons free list, and decrements
|
|
6020 the statistics on memory allocation appropriately. This is used
|
|
6021 to good effect by some extremely commonly-used code, to avoid
|
|
6022 generating extra objects and thereby triggering GC sooner.
|
|
6023 However, you have to be @emph{extremely} careful when doing this.
|
|
6024 If you mess this up, you will get BADLY BURNED, and it has happened
|
|
6025 before.
|
|
6026
|
462
|
6027 @node Vector
|
428
|
6028 @section Vector
|
462
|
6029 @cindex vector
|
428
|
6030
|
|
6031 As mentioned above, each vector is @code{malloc()}ed individually, and
|
|
6032 all are threaded through the variable @code{all_vectors}. Vectors are
|
|
6033 marked strangely during garbage collection, by kludging the size field.
|
|
6034 Note that the @code{struct Lisp_Vector} is declared with its
|
|
6035 @code{contents} field being a @emph{stretchy} array of one element. It
|
|
6036 is actually @code{malloc()}ed with the right size, however, and access
|
|
6037 to any element through the @code{contents} array works fine.
|
|
6038
|
462
|
6039 @node Bit Vector
|
428
|
6040 @section Bit Vector
|
462
|
6041 @cindex bit vector
|
|
6042 @cindex vector, bit
|
428
|
6043
|
|
6044 Bit vectors work exactly like vectors, except for more complicated
|
|
6045 code to access an individual bit, and except for the fact that bit
|
|
6046 vectors are lrecords while vectors are not. (The only difference here is
|
|
6047 that there's an lrecord implementation pointer at the beginning and the
|
|
6048 tag field in bit vector Lisp words is ``lrecord'' rather than
|
|
6049 ``vector''.)
|
|
6050
|
462
|
6051 @node Symbol
|
428
|
6052 @section Symbol
|
462
|
6053 @cindex symbol
|
428
|
6054
|
442
|
6055 Symbols are also allocated in frob blocks. Symbols in the awful
|
|
6056 horrible obarray structure are chained through their @code{next} field.
|
428
|
6057
|
|
6058 Remember that @code{intern} looks up a symbol in an obarray, creating
|
|
6059 one if necessary.
|
|
6060
|
462
|
6061 @node Marker
|
428
|
6062 @section Marker
|
462
|
6063 @cindex marker
|
428
|
6064
|
|
6065 Markers are allocated in frob blocks, as usual. They are kept
|
|
6066 in a buffer unordered, but in a doubly-linked list so that they
|
|
6067 can easily be removed. (Formerly this was a singly-linked list,
|
|
6068 but in some cases garbage collection took an extraordinarily
|
|
6069 long time due to the O(N^2) time required to remove lots of
|
|
6070 markers from a buffer.) Markers are removed from a buffer in
|
|
6071 the finalize stage, in @code{ADDITIONAL_FREE_marker()}.
|
|
6072
|
462
|
6073 @node String
|
428
|
6074 @section String
|
462
|
6075 @cindex string
|
428
|
6076
|
|
6077 As mentioned above, strings are a special case. A string is logically
|
|
6078 two parts, a fixed-size object (containing the length, property list,
|
|
6079 and a pointer to the actual data), and the actual data in the string.
|
|
6080 The fixed-size object is a @code{struct Lisp_String} and is allocated in
|
|
6081 frob blocks, as usual. The actual data is stored in special
|
|
6082 @dfn{string-chars blocks}, which are 8K blocks of memory.
|
|
6083 Currently-allocated strings are simply laid end to end in these
|
|
6084 string-chars blocks, with a pointer back to the @code{struct Lisp_String}
|
|
6085 stored before each string in the string-chars block. When a new string
|
|
6086 needs to be allocated, the remaining space at the end of the last
|
|
6087 string-chars block is used if there's enough, and a new string-chars
|
|
6088 block is created otherwise.
|
|
6089
|
|
6090 There are never any holes in the string-chars blocks due to the string
|
|
6091 compaction and relocation that happens at the end of garbage collection.
|
|
6092 During the sweep stage of garbage collection, when objects are
|
|
6093 reclaimed, the garbage collector goes through all string-chars blocks,
|
|
6094 looking for unused strings. Each chunk of string data is preceded by a
|
|
6095 pointer to the corresponding @code{struct Lisp_String}, which indicates
|
|
6096 both whether the string is used and how big the string is, i.e. how to
|
|
6097 get to the next chunk of string data. Holes are compressed by
|
|
6098 block-copying the next string into the empty space and relocating the
|
|
6099 pointer stored in the corresponding @code{struct Lisp_String}.
|
|
6100 @strong{This means you have to be careful with strings in your code.}
|
|
6101 See the section above on @code{GCPRO}ing.
|
|
6102
|
|
6103 Note that there is one situation not handled: a string that is too big
|
|
6104 to fit into a string-chars block. Such strings, called @dfn{big
|
|
6105 strings}, are all @code{malloc()}ed as their own block. (#### Although it
|
|
6106 would make more sense for the threshold for big strings to be somewhat
|
|
6107 lower, e.g. 1/2 or 1/4 the size of a string-chars block. It seems that
|
440
|
6108 this was indeed the case formerly---indeed, the threshold was set at
|
|
6109 1/8---but Mly forgot about this when rewriting things for 19.8.)
|
428
|
6110
|
|
6111 Note also that the string data in string-chars blocks is padded as
|
|
6112 necessary so that proper alignment constraints on the @code{struct
|
|
6113 Lisp_String} back pointers are maintained.
|
|
6114
|
|
6115 Finally, strings can be resized. This happens in Mule when a
|
|
6116 character is substituted with a different-length character, or during
|
|
6117 modeline frobbing. (You could also export this to Lisp, but it's not
|
|
6118 done so currently.) Resizing a string is a potentially tricky process.
|
|
6119 If the change is small enough that the padding can absorb it, nothing
|
|
6120 other than a simple memory move needs to be done. Keep in mind,
|
|
6121 however, that the string can't shrink too much because the offset to the
|
|
6122 next string in the string-chars block is computed by looking at the
|
|
6123 length and rounding to the nearest multiple of four or eight. If the
|
|
6124 string would shrink or expand beyond the correct padding, new string
|
|
6125 data needs to be allocated at the end of the last string-chars block and
|
|
6126 the data moved appropriately. This leaves some dead string data, which
|
|
6127 is marked by putting a special marker of 0xFFFFFFFF in the @code{struct
|
|
6128 Lisp_String} pointer before the data (there's no real @code{struct
|
|
6129 Lisp_String} to point to and relocate), and storing the size of the dead
|
|
6130 string data (which would normally be obtained from the now-non-existent
|
|
6131 @code{struct Lisp_String}) at the beginning of the dead string data gap.
|
|
6132 The string compactor recognizes this special 0xFFFFFFFF marker and
|
|
6133 handles it correctly.
|
|
6134
|
462
|
6135 @node Compiled Function
|
428
|
6136 @section Compiled Function
|
462
|
6137 @cindex compiled function
|
|
6138 @cindex function, compiled
|
428
|
6139
|
|
6140 Not yet documented.
|
|
6141
|
442
|
6142
|
|
6143 @node Dumping, Events and the Event Loop, Allocation of Objects in XEmacs Lisp, Top
|
|
6144 @chapter Dumping
|
462
|
6145 @cindex dumping
|
442
|
6146
|
|
6147 @section What is dumping and its justification
|
462
|
6148 @cindex dumping and its justification, what is
|
442
|
6149
|
|
6150 The C code of XEmacs is just a Lisp engine with a lot of built-in
|
|
6151 primitives useful for writing an editor. The editor itself is written
|
|
6152 mostly in Lisp, and represents around 100K lines of code. Loading and
|
|
6153 executing the initialization of all this code takes a bit a time (five
|
|
6154 to ten times the usual startup time of current xemacs) and requires
|
|
6155 having all the lisp source files around. Having to reload them each
|
|
6156 time the editor is started would not be acceptable.
|
|
6157
|
|
6158 The traditional solution to this problem is called dumping: the build
|
|
6159 process first creates the lisp engine under the name @file{temacs}, then
|
|
6160 runs it until it has finished loading and initializing all the lisp
|
|
6161 code, and eventually creates a new executable called @file{xemacs}
|
|
6162 including both the object code in @file{temacs} and all the contents of
|
|
6163 the memory after the initialization.
|
|
6164
|
|
6165 This solution, while working, has a huge problem: the creation of the
|
|
6166 new executable from the actual contents of memory is an extremely
|
|
6167 system-specific process, quite error-prone, and which interferes with a
|
|
6168 lot of system libraries (like malloc). It is even getting worse
|
|
6169 nowadays with libraries using constructors which are automatically
|
|
6170 called when the program is started (even before main()) which tend to
|
|
6171 crash when they are called multiple times, once before dumping and once
|
|
6172 after (IRIX 6.x libz.so pulls in some C++ image libraries thru
|
|
6173 dependencies which have this problem). Writing the dumper is also one
|
|
6174 of the most difficult parts of porting XEmacs to a new operating system.
|
|
6175 Basically, `dumping' is an operation that is just not officially
|
|
6176 supported on many operating systems.
|
|
6177
|
|
6178 The aim of the portable dumper is to solve the same problem as the
|
|
6179 system-specific dumper, that is to be able to reload quickly, using only
|
|
6180 a small number of files, the fully initialized lisp part of the editor,
|
|
6181 without any system-specific hacks.
|
|
6182
|
|
6183 @menu
|
|
6184 * Overview::
|
|
6185 * Data descriptions::
|
|
6186 * Dumping phase::
|
|
6187 * Reloading phase::
|
|
6188 * Remaining issues::
|
|
6189 @end menu
|
|
6190
|
462
|
6191 @node Overview
|
442
|
6192 @section Overview
|
462
|
6193 @cindex dumping overview
|
442
|
6194
|
|
6195 The portable dumping system has to:
|
|
6196
|
|
6197 @enumerate
|
|
6198 @item
|
|
6199 At dump time, write all initialized, non-quickly-rebuildable data to a
|
|
6200 file [Note: currently named @file{xemacs.dmp}, but the name will
|
|
6201 change], along with all informations needed for the reloading.
|
|
6202
|
|
6203 @item
|
|
6204 When starting xemacs, reload the dump file, relocate it to its new
|
|
6205 starting address if needed, and reinitialize all pointers to this
|
|
6206 data. Also, rebuild all the quickly rebuildable data.
|
|
6207 @end enumerate
|
|
6208
|
462
|
6209 @node Data descriptions
|
442
|
6210 @section Data descriptions
|
462
|
6211 @cindex dumping data descriptions
|
442
|
6212
|
|
6213 The more complex task of the dumper is to be able to write lisp objects
|
|
6214 (lrecords) and C structs to disk and reload them at a different address,
|
|
6215 updating all the pointers they include in the process. This is done by
|
|
6216 using external data descriptions that give information about the layout
|
|
6217 of the structures in memory.
|
|
6218
|
|
6219 The specification of these descriptions is in lrecord.h. A description
|
|
6220 of an lrecord is an array of struct lrecord_description. Each of these
|
|
6221 structs include a type, an offset in the structure and some optional
|
|
6222 parameters depending on the type. For instance, here is the string
|
|
6223 description:
|
|
6224
|
|
6225 @example
|
|
6226 static const struct lrecord_description string_description[] = @{
|
|
6227 @{ XD_BYTECOUNT, offsetof (Lisp_String, size) @},
|
|
6228 @{ XD_OPAQUE_DATA_PTR, offsetof (Lisp_String, data), XD_INDIRECT(0, 1) @},
|
|
6229 @{ XD_LISP_OBJECT, offsetof (Lisp_String, plist) @},
|
|
6230 @{ XD_END @}
|
|
6231 @};
|
|
6232 @end example
|
|
6233
|
|
6234 The first line indicates a member of type Bytecount, which is used by
|
|
6235 the next, indirect directive. The second means "there is a pointer to
|
|
6236 some opaque data in the field @code{data}". The length of said data is
|
|
6237 given by the expression @code{XD_INDIRECT(0, 1)}, which means "the value
|
|
6238 in the 0th line of the description (welcome to C) plus one". The third
|
|
6239 line means "there is a Lisp_Object member @code{plist} in the Lisp_String
|
|
6240 structure". @code{XD_END} then ends the description.
|
|
6241
|
|
6242 This gives us all the information we need to move around what is pointed
|
|
6243 to by a structure (C or lrecord) and, by transitivity, everything that
|
|
6244 it points to. The only missing information for dumping is the size of
|
|
6245 the structure. For lrecords, this is part of the
|
|
6246 lrecord_implementation, so we don't need to duplicate it. For C
|
|
6247 structures we use a struct struct_description, which includes a size
|
|
6248 field and a pointer to an associated array of lrecord_description.
|
|
6249
|
462
|
6250 @node Dumping phase
|
442
|
6251 @section Dumping phase
|
462
|
6252 @cindex dumping phase
|
442
|
6253
|
|
6254 Dumping is done by calling the function pdump() (in dumper.c) which is
|
|
6255 invoked from Fdump_emacs (in emacs.c). This function performs a number
|
|
6256 of tasks.
|
|
6257
|
|
6258 @menu
|
|
6259 * Object inventory::
|
|
6260 * Address allocation::
|
|
6261 * The header::
|
|
6262 * Data dumping::
|
|
6263 * Pointers dumping::
|
|
6264 @end menu
|
|
6265
|
462
|
6266 @node Object inventory
|
442
|
6267 @subsection Object inventory
|
462
|
6268 @cindex dumping object inventory
|
442
|
6269
|
|
6270 The first task is to build the list of the objects to dump. This
|
|
6271 includes:
|
|
6272
|
|
6273 @itemize @bullet
|
|
6274 @item lisp objects
|
|
6275 @item C structures
|
|
6276 @end itemize
|
|
6277
|
|
6278 We end up with one @code{pdump_entry_list_elmt} per object group (arrays
|
|
6279 of C structs are kept together) which includes a pointer to the first
|
|
6280 object of the group, the per-object size and the count of objects in the
|
|
6281 group, along with some other information which is initialized later.
|
|
6282
|
|
6283 These entries are linked together in @code{pdump_entry_list} structures
|
|
6284 and can be enumerated thru either:
|
|
6285
|
|
6286 @enumerate
|
|
6287 @item
|
|
6288 the @code{pdump_object_table}, an array of @code{pdump_entry_list}, one
|
|
6289 per lrecord type, indexed by type number.
|
|
6290
|
|
6291 @item
|
|
6292 the @code{pdump_opaque_data_list}, used for the opaque data which does
|
|
6293 not include pointers, and hence does not need descriptions.
|
|
6294
|
|
6295 @item
|
|
6296 the @code{pdump_struct_table}, which is a vector of
|
|
6297 @code{struct_description}/@code{pdump_entry_list} pairs, used for
|
|
6298 non-opaque C structures.
|
|
6299 @end enumerate
|
|
6300
|
|
6301 This uses a marking strategy similar to the garbage collector. Some
|
|
6302 differences though:
|
|
6303
|
|
6304 @enumerate
|
|
6305 @item
|
|
6306 We do not use the mark bit (which does not exist for C structures
|
448
|
6307 anyway); we use a big hash table instead.
|
442
|
6308
|
|
6309 @item
|
|
6310 We do not use the mark function of lrecords but instead rely on the
|
|
6311 external descriptions. This happens essentially because we need to
|
|
6312 follow pointers to C structures and opaque data in addition to
|
|
6313 Lisp_Object members.
|
|
6314 @end enumerate
|
|
6315
|
452
|
6316 This is done by @code{pdump_register_object()}, which handles Lisp_Object
|
|
6317 variables, and @code{pdump_register_struct()} which handles C structures,
|
|
6318 which both delegate the description management to @code{pdump_register_sub()}.
|
442
|
6319
|
|
6320 The hash table doubles as a map object to pdump_entry_list_elmt (i.e.
|
|
6321 allows us to look up a pdump_entry_list_elmt with the object it points
|
|
6322 to). Entries are added with @code{pdump_add_entry()} and looked up with
|
|
6323 @code{pdump_get_entry()}. There is no need for entry removal. The hash
|
448
|
6324 value is computed quite simply from the object pointer by
|
442
|
6325 @code{pdump_make_hash()}.
|
|
6326
|
|
6327 The roots for the marking are:
|
|
6328
|
|
6329 @enumerate
|
|
6330 @item
|
|
6331 the @code{staticpro}'ed variables (there is a special @code{staticpro_nodump()}
|
|
6332 call for protected variables we do not want to dump).
|
|
6333
|
|
6334 @item
|
452
|
6335 the variables registered via @code{dump_add_root_object}
|
|
6336 (@code{staticpro()} is equivalent to @code{staticpro_nodump()} +
|
|
6337 @code{dump_add_root_object()}).
|
|
6338
|
|
6339 @item
|
|
6340 the variables registered via @code{dump_add_root_struct_ptr}, each of
|
|
6341 which points to a C structure.
|
442
|
6342 @end enumerate
|
|
6343
|
|
6344 This does not include the GCPRO'ed variables, the specbinds, the
|
|
6345 catchtags, the backlist, the redisplay or the profiling info, since we
|
|
6346 do not want to rebuild the actual chain of lisp calls which end up to
|
|
6347 the dump-emacs call, only the global variables.
|
|
6348
|
|
6349 Weak lists and weak hash tables are dumped as if they were their
|
|
6350 non-weak equivalent (without changing their type, of course). This has
|
|
6351 not yet been a problem.
|
|
6352
|
462
|
6353 @node Address allocation
|
442
|
6354 @subsection Address allocation
|
462
|
6355 @cindex dumping address allocation
|
442
|
6356
|
|
6357
|
|
6358 The next step is to allocate the offsets of each of the objects in the
|
|
6359 final dump file. This is done by @code{pdump_allocate_offset()} which
|
|
6360 is called indirectly by @code{pdump_scan_by_alignment()}.
|
|
6361
|
|
6362 The strategy to deal with alignment problems uses these facts:
|
|
6363
|
|
6364 @enumerate
|
|
6365 @item
|
|
6366 real world alignment requirements are powers of two.
|
|
6367
|
|
6368 @item
|
|
6369 the C compiler is required to adjust the size of a struct so that you
|
448
|
6370 can have an array of them next to each other. This means you can have an
|
442
|
6371 upper bound of the alignment requirements of a given structure by
|
|
6372 looking at which power of two its size is a multiple.
|
|
6373
|
|
6374 @item
|
|
6375 the non-variant part of variable size lrecords has an alignment
|
|
6376 requirement of 4.
|
|
6377 @end enumerate
|
|
6378
|
|
6379 Hence, for each lrecord type, C struct type or opaque data block the
|
|
6380 alignment requirement is computed as a power of two, with a minimum of
|
|
6381 2^2 for lrecords. @code{pdump_scan_by_alignment()} then scans all the
|
|
6382 @code{pdump_entry_list_elmt}'s, the ones with the highest requirements
|
|
6383 first. This ensures the best packing.
|
|
6384
|
|
6385 The maximum alignment requirement we take into account is 2^8.
|
|
6386
|
|
6387 @code{pdump_allocate_offset()} only has to do a linear allocation,
|
448
|
6388 starting at offset 256 (this leaves room for the header and keeps the
|
442
|
6389 alignments happy).
|
|
6390
|
462
|
6391 @node The header
|
442
|
6392 @subsection The header
|
462
|
6393 @cindex dumping, the header
|
442
|
6394
|
|
6395 The next step creates the file and writes a header with a signature and
|
452
|
6396 some random information in it. The @code{reloc_address} field, which
|
|
6397 indicates at which address the file should be loaded if we want to avoid
|
|
6398 post-reload relocation, is set to 0. It then seeks to offset 256 (base
|
|
6399 offset for the objects).
|
442
|
6400
|
462
|
6401 @node Data dumping
|
442
|
6402 @subsection Data dumping
|
462
|
6403 @cindex data dumping
|
|
6404 @cindex dumping, data
|
442
|
6405
|
|
6406 The data is dumped in the same order as the addresses were allocated by
|
|
6407 @code{pdump_dump_data()}, called from @code{pdump_scan_by_alignment()}.
|
|
6408 This function copies the data to a temporary buffer, relocates all
|
|
6409 pointers in the object to the addresses allocated in step Address
|
|
6410 Allocation, and writes it to the file. Using the same order means that,
|
|
6411 if we are careful with lrecords whose size is not a multiple of 4, we
|
|
6412 are ensured that the object is always written at the offset in the file
|
|
6413 allocated in step Address Allocation.
|
|
6414
|
462
|
6415 @node Pointers dumping
|
442
|
6416 @subsection Pointers dumping
|
462
|
6417 @cindex pointers dumping
|
|
6418 @cindex dumping, pointers
|
442
|
6419
|
|
6420 A bunch of tables needed to reassign properly the global pointers are
|
|
6421 then written. They are:
|
|
6422
|
|
6423 @enumerate
|
|
6424 @item
|
452
|
6425 the pdump_root_struct_ptrs dynarr
|
|
6426 @item
|
|
6427 the pdump_opaques dynarr
|
442
|
6428 @item
|
|
6429 a vector of all the offsets to the objects in the file that include a
|
|
6430 description (for faster relocation at reload time)
|
|
6431 @item
|
452
|
6432 the pdump_root_objects and pdump_weak_object_chains dynarrs.
|
442
|
6433 @end enumerate
|
|
6434
|
452
|
6435 For each of the dynarrs we write both the pointer to the variables and
|
442
|
6436 the relocated offset of the object they point to. Since these variables
|
|
6437 are global, the pointers are still valid when restarting the program and
|
|
6438 are used to regenerate the global pointers.
|
|
6439
|
452
|
6440 The @code{pdump_weak_object_chains} dynarr is a special case. The
|
|
6441 variables it points to are the head of weak linked lists of lisp objects
|
|
6442 of the same type. Not all objects of this list are dumped so the
|
|
6443 relocated pointer we associate with them points to the first dumped
|
|
6444 object of the list, or Qnil if none is available. This is also the
|
|
6445 reason why they are not used as roots for the purpose of object
|
|
6446 enumeration.
|
|
6447
|
|
6448 Some very important information like the @code{staticpros} and
|
|
6449 @code{lrecord_implementations_table} are handled indirectly using
|
|
6450 @code{dump_add_opaque} or @code{dump_add_root_struct_ptr}.
|
442
|
6451
|
|
6452 This is the end of the dumping part.
|
|
6453
|
462
|
6454 @node Reloading phase
|
442
|
6455 @section Reloading phase
|
462
|
6456 @cindex reloading phase
|
|
6457 @cindex dumping, reloading phase
|
442
|
6458
|
|
6459 @subsection File loading
|
462
|
6460 @cindex dumping, file loading
|
442
|
6461
|
|
6462 The file is mmap'ed in memory (which ensures a PAGESIZE alignment, at
|
|
6463 least 4096), or if mmap is unavailable or fails, a 256-bytes aligned
|
|
6464 malloc is done and the file is loaded.
|
|
6465
|
|
6466 Some variables are reinitialized from the values found in the header.
|
|
6467
|
|
6468 The difference between the actual loading address and the reloc_address
|
|
6469 is computed and will be used for all the relocations.
|
|
6470
|
|
6471
|
452
|
6472 @subsection Putting back the pdump_opaques
|
462
|
6473 @cindex dumping, putting back the pdump_opaques
|
452
|
6474
|
|
6475 The memory contents are restored in the obvious and trivial way.
|
|
6476
|
|
6477
|
|
6478 @subsection Putting back the pdump_root_struct_ptrs
|
462
|
6479 @cindex dumping, putting back the pdump_root_struct_ptrs
|
452
|
6480
|
|
6481 The variables pointed to by pdump_root_struct_ptrs in the dump phase are
|
|
6482 reset to the right relocated object addresses.
|
442
|
6483
|
|
6484
|
|
6485 @subsection Object relocation
|
462
|
6486 @cindex dumping, object relocation
|
442
|
6487
|
|
6488 All the objects are relocated using their description and their offset
|
|
6489 by @code{pdump_reloc_one}. This step is unnecessary if the
|
|
6490 reloc_address is equal to the file loading address.
|
|
6491
|
|
6492
|
452
|
6493 @subsection Putting back the pdump_root_objects and pdump_weak_object_chains
|
462
|
6494 @cindex dumping, putting back the pdump_root_objects and pdump_weak_object_chains
|
452
|
6495
|
|
6496 Same as Putting back the pdump_root_struct_ptrs.
|
442
|
6497
|
|
6498
|
|
6499 @subsection Reorganize the hash tables
|
462
|
6500 @cindex dumping, reorganize the hash tables
|
442
|
6501
|
|
6502 Since some of the hash values in the lisp hash tables are
|
|
6503 address-dependent, their layout is now wrong. So we go through each of
|
|
6504 them and have them resorted by calling @code{pdump_reorganize_hash_table}.
|
|
6505
|
462
|
6506 @node Remaining issues
|
442
|
6507 @section Remaining issues
|
462
|
6508 @cindex dumping, remaining issues
|
442
|
6509
|
|
6510 The build process will have to start a post-dump xemacs, ask it the
|
|
6511 loading address (which will, hopefully, be always the same between
|
|
6512 different xemacs invocations) and relocate the file to the new address.
|
|
6513 This way the object relocation phase will not have to be done, which
|
|
6514 means no writes in the objects and that, because of the use of mmap, the
|
|
6515 dumped data will be shared between all the xemacs running on the
|
|
6516 computer.
|
|
6517
|
|
6518 Some executable signature will be necessary to ensure that a given dump
|
|
6519 file is really associated with a given executable, or random crashes
|
|
6520 will occur. Maybe a random number set at compile or configure time thru
|
|
6521 a define. This will also allow for having differently-compiled xemacsen
|
|
6522 on the same system (mule and no-mule comes to mind).
|
|
6523
|
|
6524 The DOC file contents should probably end up in the dump file.
|
|
6525
|
|
6526
|
|
6527 @node Events and the Event Loop, Evaluation; Stack Frames; Bindings, Dumping, Top
|
428
|
6528 @chapter Events and the Event Loop
|
462
|
6529 @cindex events and the event loop
|
|
6530 @cindex event loop, events and the
|
428
|
6531
|
|
6532 @menu
|
|
6533 * Introduction to Events::
|
|
6534 * Main Loop::
|
|
6535 * Specifics of the Event Gathering Mechanism::
|
|
6536 * Specifics About the Emacs Event::
|
|
6537 * The Event Stream Callback Routines::
|
|
6538 * Other Event Loop Functions::
|
|
6539 * Converting Events::
|
|
6540 * Dispatching Events; The Command Builder::
|
|
6541 @end menu
|
|
6542
|
462
|
6543 @node Introduction to Events
|
428
|
6544 @section Introduction to Events
|
462
|
6545 @cindex events, introduction to
|
428
|
6546
|
|
6547 An event is an object that encapsulates information about an
|
|
6548 interesting occurrence in the operating system. Events are
|
|
6549 generated either by user action, direct (e.g. typing on the
|
|
6550 keyboard or moving the mouse) or indirect (moving another
|
|
6551 window, thereby generating an expose event on an Emacs frame),
|
|
6552 or as a result of some other typically asynchronous action happening,
|
|
6553 such as output from a subprocess being ready or a timer expiring.
|
|
6554 Events come into the system in an asynchronous fashion (typically
|
|
6555 through a callback being called) and are converted into a
|
|
6556 synchronous event queue (first-in, first-out) in a process that
|
|
6557 we will call @dfn{collection}.
|
|
6558
|
|
6559 Note that each application has its own event queue. (It is
|
|
6560 immaterial whether the collection process directly puts the
|
|
6561 events in the proper application's queue, or puts them into
|
|
6562 a single system queue, which is later split up.)
|
|
6563
|
|
6564 The most basic level of event collection is done by the
|
|
6565 operating system or window system. Typically, XEmacs does
|
|
6566 its own event collection as well. Often there are multiple
|
|
6567 layers of collection in XEmacs, with events from various
|
|
6568 sources being collected into a queue, which is then combined
|
|
6569 with other sources to go into another queue (i.e. a second
|
|
6570 level of collection), with perhaps another level on top of
|
|
6571 this, etc.
|
|
6572
|
|
6573 XEmacs has its own types of events (called @dfn{Emacs events}),
|
|
6574 which provides an abstract layer on top of the system-dependent
|
|
6575 nature of the most basic events that are received. Part of the
|
|
6576 complex nature of the XEmacs event collection process involves
|
|
6577 converting from the operating-system events into the proper
|
440
|
6578 Emacs events---there may not be a one-to-one correspondence.
|
428
|
6579
|
|
6580 Emacs events are documented in @file{events.h}; I'll discuss them
|
|
6581 later.
|
|
6582
|
462
|
6583 @node Main Loop
|
428
|
6584 @section Main Loop
|
462
|
6585 @cindex main loop
|
|
6586 @cindex events, main loop
|
428
|
6587
|
|
6588 The @dfn{command loop} is the top-level loop that the editor is always
|
|
6589 running. It loops endlessly, calling @code{next-event} to retrieve an
|
|
6590 event and @code{dispatch-event} to execute it. @code{dispatch-event} does
|
|
6591 the appropriate thing with non-user events (process, timeout,
|
|
6592 magic, eval, mouse motion); this involves calling a Lisp handler
|
|
6593 function, redrawing a newly-exposed part of a frame, reading
|
|
6594 subprocess output, etc. For user events, @code{dispatch-event}
|
|
6595 looks up the event in relevant keymaps or menubars; when a
|
|
6596 full key sequence or menubar selection is reached, the appropriate
|
|
6597 function is executed. @code{dispatch-event} may have to keep state
|
|
6598 across calls; this is done in the ``command-builder'' structure
|
|
6599 associated with each console (remember, there's usually only
|
|
6600 one console), and the engine that looks up keystrokes and
|
|
6601 constructs full key sequences is called the @dfn{command builder}.
|
|
6602 This is documented elsewhere.
|
|
6603
|
|
6604 The guts of the command loop are in @code{command_loop_1()}. This
|
440
|
6605 function doesn't catch errors, though---that's the job of
|
428
|
6606 @code{command_loop_2()}, which is a condition-case (i.e. error-trapping)
|
|
6607 wrapper around @code{command_loop_1()}. @code{command_loop_1()} never
|
|
6608 returns, but may get thrown out of.
|
|
6609
|
|
6610 When an error occurs, @code{cmd_error()} is called, which usually
|
|
6611 invokes the Lisp error handler in @code{command-error}; however, a
|
|
6612 default error handler is provided if @code{command-error} is @code{nil}
|
|
6613 (e.g. during startup). The purpose of the error handler is simply to
|
|
6614 display the error message and do associated cleanup; it does not need to
|
|
6615 throw anywhere. When the error handler finishes, the condition-case in
|
|
6616 @code{command_loop_2()} will finish and @code{command_loop_2()} will
|
|
6617 reinvoke @code{command_loop_1()}.
|
|
6618
|
|
6619 @code{command_loop_2()} is invoked from three places: from
|
|
6620 @code{initial_command_loop()} (called from @code{main()} at the end of
|
|
6621 internal initialization), from the Lisp function @code{recursive-edit},
|
|
6622 and from @code{call_command_loop()}.
|
|
6623
|
|
6624 @code{call_command_loop()} is called when a macro is started and when
|
|
6625 the minibuffer is entered; normal termination of the macro or minibuffer
|
|
6626 causes a throw out of the recursive command loop. (To
|
|
6627 @code{execute-kbd-macro} for macros and @code{exit} for minibuffers.
|
|
6628 Note also that the low-level minibuffer-entering function,
|
|
6629 @code{read-minibuffer-internal}, provides its own error handling and
|
|
6630 does not need @code{command_loop_2()}'s error encapsulation; so it tells
|
|
6631 @code{call_command_loop()} to invoke @code{command_loop_1()} directly.)
|
|
6632
|
|
6633 Note that both read-minibuffer-internal and recursive-edit set up a
|
|
6634 catch for @code{exit}; this is why @code{abort-recursive-edit}, which
|
|
6635 throws to this catch, exits out of either one.
|
|
6636
|
|
6637 @code{initial_command_loop()}, called from @code{main()}, sets up a
|
|
6638 catch for @code{top-level} when invoking @code{command_loop_2()},
|
|
6639 allowing functions to throw all the way to the top level if they really
|
|
6640 need to. Before invoking @code{command_loop_2()},
|
|
6641 @code{initial_command_loop()} calls @code{top_level_1()}, which handles
|
|
6642 all of the startup stuff (creating the initial frame, handling the
|
|
6643 command-line options, loading the user's @file{.emacs} file, etc.). The
|
|
6644 function that actually does this is in Lisp and is pointed to by the
|
|
6645 variable @code{top-level}; normally this function is
|
|
6646 @code{normal-top-level}. @code{top_level_1()} is just an error-handling
|
|
6647 wrapper similar to @code{command_loop_2()}. Note also that
|
|
6648 @code{initial_command_loop()} sets up a catch for @code{top-level} when
|
|
6649 invoking @code{top_level_1()}, just like when it invokes
|
|
6650 @code{command_loop_2()}.
|
|
6651
|
462
|
6652 @node Specifics of the Event Gathering Mechanism
|
428
|
6653 @section Specifics of the Event Gathering Mechanism
|
462
|
6654 @cindex event gathering mechanism, specifics of the
|
428
|
6655
|
|
6656 Here is an approximate diagram of the collection processes
|
|
6657 at work in XEmacs, under TTY's (TTY's are simpler than X
|
|
6658 so we'll look at this first):
|
|
6659
|
|
6660 @noindent
|
|
6661 @example
|
|
6662 asynch. asynch. asynch. asynch. [Collectors in
|
|
6663 kbd events kbd events process process the OS]
|
|
6664 | | output output
|
|
6665 | | | |
|
|
6666 | | | | SIGINT, [signal handlers
|
|
6667 | | | | SIGQUIT, in XEmacs]
|
|
6668 V V V V SIGWINCH,
|
|
6669 file file file file SIGALRM
|
|
6670 desc. desc. desc. desc. |
|
|
6671 (TTY) (TTY) (pipe) (pipe) |
|
|
6672 | | | | fake timeouts
|
|
6673 | | | | file |
|
|
6674 | | | | desc. |
|
|
6675 | | | | (pipe) |
|
|
6676 | | | | | |
|
|
6677 | | | | | |
|
|
6678 | | | | | |
|
|
6679 V V V V V V
|
|
6680 ------>-----------<----------------<----------------
|
|
6681 |
|
|
6682 |
|
|
6683 | [collected using select() in emacs_tty_next_event()
|
|
6684 | and converted to the appropriate Emacs event]
|
|
6685 |
|
|
6686 |
|
|
6687 V (above this line is TTY-specific)
|
|
6688 Emacs -----------------------------------------------
|
|
6689 event (below this line is the generic event mechanism)
|
|
6690 |
|
|
6691 |
|
|
6692 was there if not, call
|
|
6693 a SIGINT? emacs_tty_next_event()
|
|
6694 | |
|
|
6695 | |
|
|
6696 | |
|
|
6697 V V
|
|
6698 --->------<----
|
|
6699 |
|
|
6700 | [collected in event_stream_next_event();
|
|
6701 | SIGINT is converted using maybe_read_quit_event()]
|
|
6702 V
|
|
6703 Emacs
|
|
6704 event
|
|
6705 |
|
|
6706 \---->------>----- maybe_kbd_translate() ---->---\
|
|
6707 |
|
|
6708 |
|
|
6709 |
|
|
6710 command event queue |
|
|
6711 if not from command
|
|
6712 (contains events that were event queue, call
|
|
6713 read earlier but not processed, event_stream_next_event()
|
|
6714 typically when waiting in a |
|
|
6715 sit-for, sleep-for, etc. for |
|
|
6716 a particular event to be received) |
|
|
6717 | |
|
|
6718 | |
|
|
6719 V V
|
|
6720 ---->------------------------------------<----
|
|
6721 |
|
|
6722 | [collected in
|
|
6723 | next_event_internal()]
|
|
6724 |
|
|
6725 unread- unread- event from |
|
|
6726 command- command- keyboard else, call
|
|
6727 events event macro next_event_internal()
|
|
6728 | | | |
|
|
6729 | | | |
|
|
6730 | | | |
|
|
6731 V V V V
|
|
6732 --------->----------------------<------------
|
|
6733 |
|
|
6734 | [collected in `next-event', which may loop
|
|
6735 | more than once if the event it gets is on
|
|
6736 | a dead frame, device, etc.]
|
|
6737 |
|
|
6738 |
|
|
6739 V
|
|
6740 feed into top-level event loop,
|
|
6741 which repeatedly calls `next-event'
|
|
6742 and then dispatches the event
|
|
6743 using `dispatch-event'
|
|
6744 @end example
|
|
6745
|
|
6746 Notice the separation between TTY-specific and generic event mechanism.
|
|
6747 When using the Xt-based event loop, the TTY-specific stuff is replaced
|
|
6748 but the rest stays the same.
|
|
6749
|
|
6750 It's also important to realize that only one different kind of
|
|
6751 system-specific event loop can be operating at a time, and must be able
|
|
6752 to receive all kinds of events simultaneously. For the two existing
|
|
6753 event loops (implemented in @file{event-tty.c} and @file{event-Xt.c},
|
|
6754 respectively), the TTY event loop @emph{only} handles TTY consoles,
|
|
6755 while the Xt event loop handles @emph{both} TTY and X consoles. This
|
|
6756 situation is different from all of the output handlers, where you simply
|
|
6757 have one per console type.
|
|
6758
|
|
6759 Here's the Xt Event Loop Diagram (notice that below a certain point,
|
|
6760 it's the same as the above diagram):
|
|
6761
|
|
6762 @example
|
|
6763 asynch. asynch. asynch. asynch. [Collectors in
|
|
6764 kbd kbd process process the OS]
|
|
6765 events events output output
|
|
6766 | | | |
|
|
6767 | | | | asynch. asynch. [Collectors in the
|
|
6768 | | | | X X OS and X Window System]
|
|
6769 | | | | events events
|
|
6770 | | | | | |
|
|
6771 | | | | | |
|
|
6772 | | | | | | SIGINT, [signal handlers
|
|
6773 | | | | | | SIGQUIT, in XEmacs]
|
|
6774 | | | | | | SIGWINCH,
|
|
6775 | | | | | | SIGALRM
|
|
6776 | | | | | | |
|
|
6777 | | | | | | |
|
|
6778 | | | | | | | timeouts
|
|
6779 | | | | | | | |
|
|
6780 | | | | | | | |
|
|
6781 | | | | | | V |
|
|
6782 V V V V V V fake |
|
|
6783 file file file file file file file |
|
|
6784 desc. desc. desc. desc. desc. desc. desc. |
|
|
6785 (TTY) (TTY) (pipe) (pipe) (socket) (socket) (pipe) |
|
|
6786 | | | | | | | |
|
|
6787 | | | | | | | |
|
|
6788 | | | | | | | |
|
|
6789 V V V V V V V V
|
|
6790 --->----------------------------------------<---------<------
|
|
6791 | | |
|
|
6792 | | |[collected using select() in
|
|
6793 | | | _XtWaitForSomething(), called
|
|
6794 | | | from XtAppProcessEvent(), called
|
|
6795 | | | in emacs_Xt_next_event();
|
|
6796 | | | dispatched to various callbacks]
|
|
6797 | | |
|
|
6798 | | |
|
|
6799 emacs_Xt_ p_s_callback(), | [popup_selection_callback]
|
|
6800 event_handler() x_u_v_s_callback(),| [x_update_vertical_scrollbar_
|
|
6801 | x_u_h_s_callback(),| callback]
|
|
6802 | search_callback() | [x_update_horizontal_scrollbar_
|
|
6803 | | | callback]
|
|
6804 | | |
|
|
6805 | | |
|
|
6806 enqueue_Xt_ signal_special_ |
|
|
6807 dispatch_event() Xt_user_event() |
|
|
6808 [maybe multiple | |
|
|
6809 times, maybe 0 | |
|
|
6810 times] | |
|
|
6811 | enqueue_Xt_ |
|
|
6812 | dispatch_event() |
|
|
6813 | | |
|
|
6814 | | |
|
|
6815 V V |
|
|
6816 -->----------<-- |
|
|
6817 | |
|
|
6818 | |
|
|
6819 dispatch Xt_what_callback()
|
|
6820 event sets flags
|
|
6821 queue |
|
|
6822 | |
|
|
6823 | |
|
|
6824 | |
|
|
6825 | |
|
|
6826 ---->-----------<--------
|
|
6827 |
|
|
6828 |
|
|
6829 | [collected and converted as appropriate in
|
|
6830 | emacs_Xt_next_event()]
|
|
6831 |
|
|
6832 |
|
|
6833 V (above this line is Xt-specific)
|
|
6834 Emacs ------------------------------------------------
|
|
6835 event (below this line is the generic event mechanism)
|
|
6836 |
|
|
6837 |
|
|
6838 was there if not, call
|
|
6839 a SIGINT? emacs_Xt_next_event()
|
|
6840 | |
|
|
6841 | |
|
|
6842 | |
|
|
6843 V V
|
|
6844 --->-------<----
|
|
6845 |
|
|
6846 | [collected in event_stream_next_event();
|
|
6847 | SIGINT is converted using maybe_read_quit_event()]
|
|
6848 V
|
|
6849 Emacs
|
|
6850 event
|
|
6851 |
|
|
6852 \---->------>----- maybe_kbd_translate() -->-----\
|
|
6853 |
|
|
6854 |
|
|
6855 |
|
|
6856 command event queue |
|
|
6857 if not from command
|
|
6858 (contains events that were event queue, call
|
|
6859 read earlier but not processed, event_stream_next_event()
|
|
6860 typically when waiting in a |
|
|
6861 sit-for, sleep-for, etc. for |
|
|
6862 a particular event to be received) |
|
|
6863 | |
|
|
6864 | |
|
|
6865 V V
|
|
6866 ---->----------------------------------<------
|
|
6867 |
|
|
6868 | [collected in
|
|
6869 | next_event_internal()]
|
|
6870 |
|
|
6871 unread- unread- event from |
|
|
6872 command- command- keyboard else, call
|
|
6873 events event macro next_event_internal()
|
|
6874 | | | |
|
|
6875 | | | |
|
|
6876 | | | |
|
|
6877 V V V V
|
|
6878 --------->----------------------<------------
|
|
6879 |
|
|
6880 | [collected in `next-event', which may loop
|
|
6881 | more than once if the event it gets is on
|
|
6882 | a dead frame, device, etc.]
|
|
6883 |
|
|
6884 |
|
|
6885 V
|
|
6886 feed into top-level event loop,
|
|
6887 which repeatedly calls `next-event'
|
|
6888 and then dispatches the event
|
|
6889 using `dispatch-event'
|
|
6890 @end example
|
|
6891
|
462
|
6892 @node Specifics About the Emacs Event
|
428
|
6893 @section Specifics About the Emacs Event
|
462
|
6894 @cindex event, specifics about the Lisp object
|
|
6895
|
|
6896 @node The Event Stream Callback Routines
|
428
|
6897 @section The Event Stream Callback Routines
|
462
|
6898 @cindex event stream callback routines, the
|
|
6899 @cindex callback routines, the event stream
|
|
6900
|
|
6901 @node Other Event Loop Functions
|
428
|
6902 @section Other Event Loop Functions
|
462
|
6903 @cindex event loop functions, other
|
428
|
6904
|
|
6905 @code{detect_input_pending()} and @code{input-pending-p} look for
|
|
6906 input by calling @code{event_stream->event_pending_p} and looking in
|
|
6907 @code{[V]unread-command-event} and the @code{command_event_queue} (they
|
|
6908 do not check for an executing keyboard macro, though).
|
|
6909
|
|
6910 @code{discard-input} cancels any command events pending (and any
|
|
6911 keyboard macros currently executing), and puts the others onto the
|
|
6912 @code{command_event_queue}. There is a comment about a ``race
|
|
6913 condition'', which is not a good sign.
|
|
6914
|
|
6915 @code{next-command-event} and @code{read-char} are higher-level
|
|
6916 interfaces to @code{next-event}. @code{next-command-event} gets the
|
|
6917 next @dfn{command} event (i.e. keypress, mouse event, menu selection,
|
|
6918 or scrollbar action), calling @code{dispatch-event} on any others.
|
|
6919 @code{read-char} calls @code{next-command-event} and uses
|
|
6920 @code{event_to_character()} to return the character equivalent. With
|
|
6921 the right kind of input method support, it is possible for (read-char)
|
|
6922 to return a Kanji character.
|
|
6923
|
462
|
6924 @node Converting Events
|
428
|
6925 @section Converting Events
|
462
|
6926 @cindex converting events
|
|
6927 @cindex events, converting
|
428
|
6928
|
|
6929 @code{character_to_event()}, @code{event_to_character()},
|
|
6930 @code{event-to-character}, and @code{character-to-event} convert between
|
|
6931 characters and keypress events corresponding to the characters. If the
|
|
6932 event was not a keypress, @code{event_to_character()} returns -1 and
|
|
6933 @code{event-to-character} returns @code{nil}. These functions convert
|
|
6934 between character representation and the split-up event representation
|
|
6935 (keysym plus mod keys).
|
|
6936
|
462
|
6937 @node Dispatching Events; The Command Builder
|
428
|
6938 @section Dispatching Events; The Command Builder
|
462
|
6939 @cindex dispatching events; the command builder
|
|
6940 @cindex events; the command builder, dispatching
|
|
6941 @cindex command builder, dispatching events; the
|
428
|
6942
|
|
6943 Not yet documented.
|
|
6944
|
|
6945 @node Evaluation; Stack Frames; Bindings, Symbols and Variables, Events and the Event Loop, Top
|
|
6946 @chapter Evaluation; Stack Frames; Bindings
|
462
|
6947 @cindex evaluation; stack frames; bindings
|
|
6948 @cindex stack frames; bindings, evaluation;
|
|
6949 @cindex bindings, evaluation; stack frames;
|
428
|
6950
|
|
6951 @menu
|
|
6952 * Evaluation::
|
|
6953 * Dynamic Binding; The specbinding Stack; Unwind-Protects::
|
|
6954 * Simple Special Forms::
|
|
6955 * Catch and Throw::
|
|
6956 @end menu
|
|
6957
|
462
|
6958 @node Evaluation
|
428
|
6959 @section Evaluation
|
462
|
6960 @cindex evaluation
|
428
|
6961
|
|
6962 @code{Feval()} evaluates the form (a Lisp object) that is passed to
|
|
6963 it. Note that evaluation is only non-trivial for two types of objects:
|
|
6964 symbols and conses. A symbol is evaluated simply by calling
|
|
6965 @code{symbol-value} on it and returning the value.
|
|
6966
|
|
6967 Evaluating a cons means calling a function. First, @code{eval} checks
|
|
6968 to see if garbage-collection is necessary, and calls
|
|
6969 @code{garbage_collect_1()} if so. It then increases the evaluation
|
|
6970 depth by 1 (@code{lisp_eval_depth}, which is always less than
|
|
6971 @code{max_lisp_eval_depth}) and adds an element to the linked list of
|
|
6972 @code{struct backtrace}'s (@code{backtrace_list}). Each such structure
|
|
6973 contains a pointer to the function being called plus a list of the
|
|
6974 function's arguments. Originally these values are stored unevalled, and
|
|
6975 as they are evaluated, the backtrace structure is updated. Garbage
|
|
6976 collection pays attention to the objects pointed to in the backtrace
|
|
6977 structures (garbage collection might happen while a function is being
|
|
6978 called or while an argument is being evaluated, and there could easily
|
|
6979 be no other references to the arguments in the argument list; once an
|
|
6980 argument is evaluated, however, the unevalled version is not needed by
|
|
6981 eval, and so the backtrace structure is changed).
|
|
6982
|
|
6983 At this point, the function to be called is determined by looking at
|
|
6984 the car of the cons (if this is a symbol, its function definition is
|
|
6985 retrieved and the process repeated). The function should then consist
|
|
6986 of either a @code{Lisp_Subr} (built-in function written in C), a
|
|
6987 @code{Lisp_Compiled_Function} object, or a cons whose car is one of the
|
|
6988 symbols @code{autoload}, @code{macro} or @code{lambda}.
|
|
6989
|
|
6990 If the function is a @code{Lisp_Subr}, the lisp object points to a
|
|
6991 @code{struct Lisp_Subr} (created by @code{DEFUN()}), which contains a
|
|
6992 pointer to the C function, a minimum and maximum number of arguments
|
|
6993 (or possibly the special constants @code{MANY} or @code{UNEVALLED}), a
|
|
6994 pointer to the symbol referring to that subr, and a couple of other
|
|
6995 things. If the subr wants its arguments @code{UNEVALLED}, they are
|
|
6996 passed raw as a list. Otherwise, an array of evaluated arguments is
|
|
6997 created and put into the backtrace structure, and either passed whole
|
|
6998 (@code{MANY}) or each argument is passed as a C argument.
|
|
6999
|
|
7000 If the function is a @code{Lisp_Compiled_Function},
|
|
7001 @code{funcall_compiled_function()} is called. If the function is a
|
|
7002 lambda list, @code{funcall_lambda()} is called. If the function is a
|
|
7003 macro, [..... fill in] is done. If the function is an autoload,
|
|
7004 @code{do_autoload()} is called to load the definition and then eval
|
|
7005 starts over [explain this more].
|
|
7006
|
|
7007 When @code{Feval()} exits, the evaluation depth is reduced by one, the
|
|
7008 debugger is called if appropriate, and the current backtrace structure
|
|
7009 is removed from the list.
|
|
7010
|
|
7011 Both @code{funcall_compiled_function()} and @code{funcall_lambda()} need
|
|
7012 to go through the list of formal parameters to the function and bind
|
|
7013 them to the actual arguments, checking for @code{&rest} and
|
|
7014 @code{&optional} symbols in the formal parameters and making sure the
|
|
7015 number of actual arguments is correct.
|
|
7016 @code{funcall_compiled_function()} can do this a little more
|
|
7017 efficiently, since the formal parameter list can be checked for sanity
|
|
7018 when the compiled function object is created.
|
|
7019
|
|
7020 @code{funcall_lambda()} simply calls @code{Fprogn} to execute the code
|
|
7021 in the lambda list.
|
|
7022
|
|
7023 @code{funcall_compiled_function()} calls the real byte-code interpreter
|
|
7024 @code{execute_optimized_program()} on the byte-code instructions, which
|
|
7025 are converted into an internal form for faster execution.
|
|
7026
|
|
7027 When a compiled function is executed for the first time by
|
442
|
7028 @code{funcall_compiled_function()}, or during the dump phase of building
|
|
7029 XEmacs, the byte-code instructions are converted from a
|
|
7030 @code{Lisp_String} (which is inefficient to access, especially in the
|
|
7031 presence of MULE) into a @code{Lisp_Opaque} object containing an array
|
|
7032 of unsigned char, which can be directly executed by the byte-code
|
|
7033 interpreter. At this time the byte code is also analyzed for validity
|
|
7034 and transformed into a more optimized form, so that
|
428
|
7035 @code{execute_optimized_program()} can really fly.
|
|
7036
|
|
7037 Here are some of the optimizations performed by the internal byte-code
|
|
7038 transformer:
|
|
7039 @enumerate
|
|
7040 @item
|
|
7041 References to the @code{constants} array are checked for out-of-range
|
|
7042 indices, so that the byte interpreter doesn't have to.
|
|
7043 @item
|
|
7044 References to the @code{constants} array that will be used as a Lisp
|
|
7045 variable are checked for being correct non-constant (i.e. not @code{t},
|
|
7046 @code{nil}, or @code{keywordp}) symbols, so that the byte interpreter
|
|
7047 doesn't have to.
|
|
7048 @item
|
442
|
7049 The maximum number of variable bindings in the byte-code is
|
428
|
7050 pre-computed, so that space on the @code{specpdl} stack can be
|
|
7051 pre-reserved once for the whole function execution.
|
|
7052 @item
|
|
7053 All byte-code jumps are relative to the current program counter instead
|
|
7054 of the start of the program, thereby saving a register.
|
|
7055 @item
|
|
7056 One-byte relative jumps are converted from the byte-code form of unsigned
|
|
7057 chars offset by 127 to machine-friendly signed chars.
|
|
7058 @end enumerate
|
|
7059
|
|
7060 Of course, this transformation of the @code{instructions} should not be
|
|
7061 visible to the user, so @code{Fcompiled_function_instructions()} needs
|
|
7062 to know how to convert the optimized opaque object back into a Lisp
|
|
7063 string that is identical to the original string from the @file{.elc}
|
|
7064 file. (Actually, the resulting string may (rarely) contain slightly
|
|
7065 different, yet equivalent, byte code.)
|
|
7066
|
|
7067 @code{Ffuncall()} implements Lisp @code{funcall}. @code{(funcall fun
|
|
7068 x1 x2 x3 ...)} is equivalent to @code{(eval (list fun (quote x1) (quote
|
|
7069 x2) (quote x3) ...))}. @code{Ffuncall()} contains its own code to do
|
|
7070 the evaluation, however, and is very similar to @code{Feval()}.
|
|
7071
|
|
7072 From the performance point of view, it is worth knowing that most of the
|
|
7073 time in Lisp evaluation is spent executing @code{Lisp_Subr} and
|
|
7074 @code{Lisp_Compiled_Function} objects via @code{Ffuncall()} (not
|
|
7075 @code{Feval()}).
|
|
7076
|
|
7077 @code{Fapply()} implements Lisp @code{apply}, which is very similar to
|
|
7078 @code{funcall} except that if the last argument is a list, the result is the
|
|
7079 same as if each of the arguments in the list had been passed separately.
|
|
7080 @code{Fapply()} does some business to expand the last argument if it's a
|
|
7081 list, then calls @code{Ffuncall()} to do the work.
|
|
7082
|
|
7083 @code{apply1()}, @code{call0()}, @code{call1()}, @code{call2()}, and
|
|
7084 @code{call3()} call a function, passing it the argument(s) given (the
|
|
7085 arguments are given as separate C arguments rather than being passed as
|
|
7086 an array). @code{apply1()} uses @code{Fapply()} while the others use
|
|
7087 @code{Ffuncall()} to do the real work.
|
|
7088
|
462
|
7089 @node Dynamic Binding; The specbinding Stack; Unwind-Protects
|
428
|
7090 @section Dynamic Binding; The specbinding Stack; Unwind-Protects
|
462
|
7091 @cindex dynamic binding; the specbinding stack; unwind-protects
|
|
7092 @cindex binding; the specbinding stack; unwind-protects, dynamic
|
|
7093 @cindex specbinding stack; unwind-protects, dynamic binding; the
|
|
7094 @cindex unwind-protects, dynamic binding; the specbinding stack;
|
428
|
7095
|
|
7096 @example
|
|
7097 struct specbinding
|
|
7098 @{
|
|
7099 Lisp_Object symbol;
|
|
7100 Lisp_Object old_value;
|
|
7101 Lisp_Object (*func) (Lisp_Object); /* for unwind-protect */
|
|
7102 @};
|
|
7103 @end example
|
|
7104
|
|
7105 @code{struct specbinding} is used for local-variable bindings and
|
|
7106 unwind-protects. @code{specpdl} holds an array of @code{struct specbinding}'s,
|
|
7107 @code{specpdl_ptr} points to the beginning of the free bindings in the
|
|
7108 array, @code{specpdl_size} specifies the total number of binding slots
|
|
7109 in the array, and @code{max_specpdl_size} specifies the maximum number
|
|
7110 of bindings the array can be expanded to hold. @code{grow_specpdl()}
|
|
7111 increases the size of the @code{specpdl} array, multiplying its size by
|
|
7112 2 but never exceeding @code{max_specpdl_size} (except that if this
|
|
7113 number is less than 400, it is first set to 400).
|
|
7114
|
|
7115 @code{specbind()} binds a symbol to a value and is used for local
|
|
7116 variables and @code{let} forms. The symbol and its old value (which
|
|
7117 might be @code{Qunbound}, indicating no prior value) are recorded in the
|
|
7118 specpdl array, and @code{specpdl_size} is increased by 1.
|
|
7119
|
|
7120 @code{record_unwind_protect()} implements an @dfn{unwind-protect},
|
|
7121 which, when placed around a section of code, ensures that some specified
|
|
7122 cleanup routine will be executed even if the code exits abnormally
|
|
7123 (e.g. through a @code{throw} or quit). @code{record_unwind_protect()}
|
|
7124 simply adds a new specbinding to the @code{specpdl} array and stores the
|
|
7125 appropriate information in it. The cleanup routine can either be a C
|
|
7126 function, which is stored in the @code{func} field, or a @code{progn}
|
|
7127 form, which is stored in the @code{old_value} field.
|
|
7128
|
|
7129 @code{unbind_to()} removes specbindings from the @code{specpdl} array
|
|
7130 until the specified position is reached. Each specbinding can be one of
|
|
7131 three types:
|
|
7132
|
|
7133 @enumerate
|
|
7134 @item
|
|
7135 an unwind-protect with a C cleanup function (@code{func} is not 0, and
|
|
7136 @code{old_value} holds an argument to be passed to the function);
|
|
7137 @item
|
|
7138 an unwind-protect with a Lisp form (@code{func} is 0, @code{symbol}
|
|
7139 is @code{nil}, and @code{old_value} holds the form to be executed with
|
|
7140 @code{Fprogn()}); or
|
|
7141 @item
|
|
7142 a local-variable binding (@code{func} is 0, @code{symbol} is not
|
|
7143 @code{nil}, and @code{old_value} holds the old value, which is stored as
|
|
7144 the symbol's value).
|
|
7145 @end enumerate
|
|
7146
|
462
|
7147 @node Simple Special Forms
|
428
|
7148 @section Simple Special Forms
|
462
|
7149 @cindex special forms, simple
|
428
|
7150
|
|
7151 @code{or}, @code{and}, @code{if}, @code{cond}, @code{progn},
|
|
7152 @code{prog1}, @code{prog2}, @code{setq}, @code{quote}, @code{function},
|
|
7153 @code{let*}, @code{let}, @code{while}
|
|
7154
|
|
7155 All of these are very simple and work as expected, calling
|
|
7156 @code{Feval()} or @code{Fprogn()} as necessary and (in the case of
|
|
7157 @code{let} and @code{let*}) using @code{specbind()} to create bindings
|
|
7158 and @code{unbind_to()} to undo the bindings when finished.
|
|
7159
|
442
|
7160 Note that, with the exception of @code{Fprogn}, these functions are
|
428
|
7161 typically called in real life only in interpreted code, since the byte
|
|
7162 compiler knows how to convert calls to these functions directly into
|
|
7163 byte code.
|
|
7164
|
462
|
7165 @node Catch and Throw
|
428
|
7166 @section Catch and Throw
|
462
|
7167 @cindex catch and throw
|
|
7168 @cindex throw, catch and
|
428
|
7169
|
|
7170 @example
|
|
7171 struct catchtag
|
|
7172 @{
|
|
7173 Lisp_Object tag;
|
|
7174 Lisp_Object val;
|
|
7175 struct catchtag *next;
|
|
7176 struct gcpro *gcpro;
|
|
7177 jmp_buf jmp;
|
|
7178 struct backtrace *backlist;
|
|
7179 int lisp_eval_depth;
|
|
7180 int pdlcount;
|
|
7181 @};
|
|
7182 @end example
|
|
7183
|
|
7184 @code{catch} is a Lisp function that places a catch around a body of
|
|
7185 code. A catch is a means of non-local exit from the code. When a catch
|
|
7186 is created, a tag is specified, and executing a @code{throw} to this tag
|
|
7187 will exit from the body of code caught with this tag, and its value will
|
|
7188 be the value given in the call to @code{throw}. If there is no such
|
|
7189 call, the code will be executed normally.
|
|
7190
|
|
7191 Information pertaining to a catch is held in a @code{struct catchtag},
|
|
7192 which is placed at the head of a linked list pointed to by
|
|
7193 @code{catchlist}. @code{internal_catch()} is passed a C function to
|
|
7194 call (@code{Fprogn()} when Lisp @code{catch} is called) and arguments to
|
|
7195 give it, and places a catch around the function. Each @code{struct
|
|
7196 catchtag} is held in the stack frame of the @code{internal_catch()}
|
|
7197 instance that created the catch.
|
|
7198
|
|
7199 @code{internal_catch()} is fairly straightforward. It stores into the
|
|
7200 @code{struct catchtag} the tag name and the current values of
|
|
7201 @code{backtrace_list}, @code{lisp_eval_depth}, @code{gcprolist}, and the
|
|
7202 offset into the @code{specpdl} array, sets a jump point with @code{_setjmp()}
|
|
7203 (storing the jump point into the @code{struct catchtag}), and calls the
|
|
7204 function. Control will return to @code{internal_catch()} either when
|
|
7205 the function exits normally or through a @code{_longjmp()} to this jump
|
|
7206 point. In the latter case, @code{throw} will store the value to be
|
|
7207 returned into the @code{struct catchtag} before jumping. When it's
|
|
7208 done, @code{internal_catch()} removes the @code{struct catchtag} from
|
|
7209 the catchlist and returns the proper value.
|
|
7210
|
|
7211 @code{Fthrow()} goes up through the catchlist until it finds one with
|
|
7212 a matching tag. It then calls @code{unbind_catch()} to restore
|
|
7213 everything to what it was when the appropriate catch was set, stores the
|
|
7214 return value in the @code{struct catchtag}, and jumps (with
|
|
7215 @code{_longjmp()}) to its jump point.
|
|
7216
|
|
7217 @code{unbind_catch()} removes all catches from the catchlist until it
|
|
7218 finds the correct one. Some of the catches might have been placed for
|
|
7219 error-trapping, and if so, the appropriate entries on the handlerlist
|
|
7220 must be removed (see ``errors''). @code{unbind_catch()} also restores
|
|
7221 the values of @code{gcprolist}, @code{backtrace_list}, and
|
|
7222 @code{lisp_eval}, and calls @code{unbind_to()} to undo any specbindings
|
|
7223 created since the catch.
|
|
7224
|
|
7225
|
|
7226 @node Symbols and Variables, Buffers and Textual Representation, Evaluation; Stack Frames; Bindings, Top
|
|
7227 @chapter Symbols and Variables
|
462
|
7228 @cindex symbols and variables
|
|
7229 @cindex variables, symbols and
|
428
|
7230
|
|
7231 @menu
|
|
7232 * Introduction to Symbols::
|
|
7233 * Obarrays::
|
|
7234 * Symbol Values::
|
|
7235 @end menu
|
|
7236
|
462
|
7237 @node Introduction to Symbols
|
428
|
7238 @section Introduction to Symbols
|
462
|
7239 @cindex symbols, introduction to
|
428
|
7240
|
|
7241 A symbol is basically just an object with four fields: a name (a
|
|
7242 string), a value (some Lisp object), a function (some Lisp object), and
|
|
7243 a property list (usually a list of alternating keyword/value pairs).
|
|
7244 What makes symbols special is that there is usually only one symbol with
|
|
7245 a given name, and the symbol is referred to by name. This makes a
|
|
7246 symbol a convenient way of calling up data by name, i.e. of implementing
|
|
7247 variables. (The variable's value is stored in the @dfn{value slot}.)
|
|
7248 Similarly, functions are referenced by name, and the definition of the
|
|
7249 function is stored in a symbol's @dfn{function slot}. This means that
|
|
7250 there can be a distinct function and variable with the same name. The
|
|
7251 property list is used as a more general mechanism of associating
|
|
7252 additional values with particular names, and once again the namespace is
|
|
7253 independent of the function and variable namespaces.
|
|
7254
|
462
|
7255 @node Obarrays
|
428
|
7256 @section Obarrays
|
462
|
7257 @cindex obarrays
|
428
|
7258
|
|
7259 The identity of symbols with their names is accomplished through a
|
|
7260 structure called an obarray, which is just a poorly-implemented hash
|
|
7261 table mapping from strings to symbols whose name is that string. (I say
|
|
7262 ``poorly implemented'' because an obarray appears in Lisp as a vector
|
|
7263 with some hidden fields rather than as its own opaque type. This is an
|
|
7264 Emacs Lisp artifact that should be fixed.)
|
|
7265
|
|
7266 Obarrays are implemented as a vector of some fixed size (which should
|
|
7267 be a prime for best results), where each ``bucket'' of the vector
|
|
7268 contains one or more symbols, threaded through a hidden @code{next}
|
|
7269 field in the symbol. Lookup of a symbol in an obarray, and adding a
|
|
7270 symbol to an obarray, is accomplished through standard hash-table
|
|
7271 techniques.
|
|
7272
|
|
7273 The standard Lisp function for working with symbols and obarrays is
|
|
7274 @code{intern}. This looks up a symbol in an obarray given its name; if
|
|
7275 it's not found, a new symbol is automatically created with the specified
|
|
7276 name, added to the obarray, and returned. This is what happens when the
|
|
7277 Lisp reader encounters a symbol (or more precisely, encounters the name
|
|
7278 of a symbol) in some text that it is reading. There is a standard
|
|
7279 obarray called @code{obarray} that is used for this purpose, although
|
|
7280 the Lisp programmer is free to create his own obarrays and @code{intern}
|
|
7281 symbols in them.
|
|
7282
|
|
7283 Note that, once a symbol is in an obarray, it stays there until
|
|
7284 something is done about it, and the standard obarray @code{obarray}
|
|
7285 always stays around, so once you use any particular variable name, a
|
|
7286 corresponding symbol will stay around in @code{obarray} until you exit
|
|
7287 XEmacs.
|
|
7288
|
|
7289 Note that @code{obarray} itself is a variable, and as such there is a
|
|
7290 symbol in @code{obarray} whose name is @code{"obarray"} and which
|
|
7291 contains @code{obarray} as its value.
|
|
7292
|
|
7293 Note also that this call to @code{intern} occurs only when in the Lisp
|
|
7294 reader, not when the code is executed (at which point the symbol is
|
|
7295 already around, stored as such in the definition of the function).
|
|
7296
|
|
7297 You can create your own obarray using @code{make-vector} (this is
|
|
7298 horrible but is an artifact) and intern symbols into that obarray.
|
|
7299 Doing that will result in two or more symbols with the same name.
|
|
7300 However, at most one of these symbols is in the standard @code{obarray}:
|
|
7301 You cannot have two symbols of the same name in any particular obarray.
|
|
7302 Note that you cannot add a symbol to an obarray in any fashion other
|
|
7303 than using @code{intern}: i.e. you can't take an existing symbol and put
|
|
7304 it in an existing obarray. Nor can you change the name of an existing
|
|
7305 symbol. (Since obarrays are vectors, you can violate the consistency of
|
|
7306 things by storing directly into the vector, but let's ignore that
|
|
7307 possibility.)
|
|
7308
|
|
7309 Usually symbols are created by @code{intern}, but if you really want,
|
|
7310 you can explicitly create a symbol using @code{make-symbol}, giving it
|
|
7311 some name. The resulting symbol is not in any obarray (i.e. it is
|
|
7312 @dfn{uninterned}), and you can't add it to any obarray. Therefore its
|
|
7313 primary purpose is as a symbol to use in macros to avoid namespace
|
|
7314 pollution. It can also be used as a carrier of information, but cons
|
|
7315 cells could probably be used just as well.
|
|
7316
|
|
7317 You can also use @code{intern-soft} to look up a symbol but not create
|
|
7318 a new one, and @code{unintern} to remove a symbol from an obarray. This
|
|
7319 returns the removed symbol. (Remember: You can't put the symbol back
|
|
7320 into any obarray.) Finally, @code{mapatoms} maps over all of the symbols
|
|
7321 in an obarray.
|
|
7322
|
462
|
7323 @node Symbol Values
|
428
|
7324 @section Symbol Values
|
462
|
7325 @cindex symbol values
|
|
7326 @cindex values, symbol
|
428
|
7327
|
|
7328 The value field of a symbol normally contains a Lisp object. However,
|
|
7329 a symbol can be @dfn{unbound}, meaning that it logically has no value.
|
|
7330 This is internally indicated by storing a special Lisp object, called
|
|
7331 @dfn{the unbound marker} and stored in the global variable
|
|
7332 @code{Qunbound}. The unbound marker is of a special Lisp object type
|
|
7333 called @dfn{symbol-value-magic}. It is impossible for the Lisp
|
|
7334 programmer to directly create or access any object of this type.
|
|
7335
|
|
7336 @strong{You must not let any ``symbol-value-magic'' object escape to
|
|
7337 the Lisp level.} Printing any of these objects will cause the message
|
|
7338 @samp{INTERNAL EMACS BUG} to appear as part of the print representation.
|
|
7339 (You may see this normally when you call @code{debug_print()} from the
|
|
7340 debugger on a Lisp object.) If you let one of these objects escape to
|
|
7341 the Lisp level, you will violate a number of assumptions contained in
|
|
7342 the C code and make the unbound marker not function right.
|
|
7343
|
|
7344 When a symbol is created, its value field (and function field) are set
|
|
7345 to @code{Qunbound}. The Lisp programmer can restore these conditions
|
|
7346 later using @code{makunbound} or @code{fmakunbound}, and can query to
|
|
7347 see whether the value of function fields are @dfn{bound} (i.e. have a
|
|
7348 value other than @code{Qunbound}) using @code{boundp} and
|
|
7349 @code{fboundp}. The fields are set to a normal Lisp object using
|
|
7350 @code{set} (or @code{setq}) and @code{fset}.
|
|
7351
|
|
7352 Other symbol-value-magic objects are used as special markers to
|
|
7353 indicate variables that have non-normal properties. This includes any
|
|
7354 variables that are tied into C variables (setting the variable magically
|
|
7355 sets some global variable in the C code, and likewise for retrieving the
|
|
7356 variable's value), variables that magically tie into slots in the
|
|
7357 current buffer, variables that are buffer-local, etc. The
|
|
7358 symbol-value-magic object is stored in the value cell in place of
|
|
7359 a normal object, and the code to retrieve a symbol's value
|
|
7360 (i.e. @code{symbol-value}) knows how to do special things with them.
|
|
7361 This means that you should not just fetch the value cell directly if you
|
|
7362 want a symbol's value.
|
|
7363
|
|
7364 The exact workings of this are rather complex and involved and are
|
|
7365 well-documented in comments in @file{buffer.c}, @file{symbols.c}, and
|
|
7366 @file{lisp.h}.
|
|
7367
|
|
7368 @node Buffers and Textual Representation, MULE Character Sets and Encodings, Symbols and Variables, Top
|
|
7369 @chapter Buffers and Textual Representation
|
462
|
7370 @cindex buffers and textual representation
|
|
7371 @cindex textual representation, buffers and
|
428
|
7372
|
|
7373 @menu
|
|
7374 * Introduction to Buffers:: A buffer holds a block of text such as a file.
|
|
7375 * The Text in a Buffer:: Representation of the text in a buffer.
|
|
7376 * Buffer Lists:: Keeping track of all buffers.
|
|
7377 * Markers and Extents:: Tagging locations within a buffer.
|
|
7378 * Bufbytes and Emchars:: Representation of individual characters.
|
|
7379 * The Buffer Object:: The Lisp object corresponding to a buffer.
|
|
7380 @end menu
|
|
7381
|
462
|
7382 @node Introduction to Buffers
|
428
|
7383 @section Introduction to Buffers
|
462
|
7384 @cindex buffers, introduction to
|
428
|
7385
|
|
7386 A buffer is logically just a Lisp object that holds some text.
|
|
7387 In this, it is like a string, but a buffer is optimized for
|
|
7388 frequent insertion and deletion, while a string is not. Furthermore:
|
|
7389
|
|
7390 @enumerate
|
|
7391 @item
|
|
7392 Buffers are @dfn{permanent} objects, i.e. once you create them, they
|
|
7393 remain around, and need to be explicitly deleted before they go away.
|
|
7394 @item
|
|
7395 Each buffer has a unique name, which is a string. Buffers are
|
|
7396 normally referred to by name. In this respect, they are like
|
|
7397 symbols.
|
|
7398 @item
|
|
7399 Buffers have a default insertion position, called @dfn{point}.
|
|
7400 Inserting text (unless you explicitly give a position) goes at point,
|
|
7401 and moves point forward past the text. This is what is going on when
|
|
7402 you type text into Emacs.
|
|
7403 @item
|
|
7404 Buffers have lots of extra properties associated with them.
|
|
7405 @item
|
|
7406 Buffers can be @dfn{displayed}. What this means is that there
|
|
7407 exist a number of @dfn{windows}, which are objects that correspond
|
|
7408 to some visible section of your display, and each window has
|
|
7409 an associated buffer, and the current contents of the buffer
|
|
7410 are shown in that section of the display. The redisplay mechanism
|
|
7411 (which takes care of doing this) knows how to look at the
|
|
7412 text of a buffer and come up with some reasonable way of displaying
|
|
7413 this. Many of the properties of a buffer control how the
|
|
7414 buffer's text is displayed.
|
|
7415 @item
|
|
7416 One buffer is distinguished and called the @dfn{current buffer}. It is
|
|
7417 stored in the variable @code{current_buffer}. Buffer operations operate
|
|
7418 on this buffer by default. When you are typing text into a buffer, the
|
|
7419 buffer you are typing into is always @code{current_buffer}. Switching
|
|
7420 to a different window changes the current buffer. Note that Lisp code
|
|
7421 can temporarily change the current buffer using @code{set-buffer} (often
|
|
7422 enclosed in a @code{save-excursion} so that the former current buffer
|
|
7423 gets restored when the code is finished). However, calling
|
|
7424 @code{set-buffer} will NOT cause a permanent change in the current
|
|
7425 buffer. The reason for this is that the top-level event loop sets
|
|
7426 @code{current_buffer} to the buffer of the selected window, each time
|
|
7427 it finishes executing a user command.
|
|
7428 @end enumerate
|
|
7429
|
|
7430 Make sure you understand the distinction between @dfn{current buffer}
|
|
7431 and @dfn{buffer of the selected window}, and the distinction between
|
|
7432 @dfn{point} of the current buffer and @dfn{window-point} of the selected
|
|
7433 window. (This latter distinction is explained in detail in the section
|
|
7434 on windows.)
|
|
7435
|
462
|
7436 @node The Text in a Buffer
|
428
|
7437 @section The Text in a Buffer
|
462
|
7438 @cindex text in a buffer, the
|
|
7439 @cindex buffer, the text in a
|
428
|
7440
|
|
7441 The text in a buffer consists of a sequence of zero or more
|
|
7442 characters. A @dfn{character} is an integer that logically represents
|
|
7443 a letter, number, space, or other unit of text. Most of the characters
|
|
7444 that you will typically encounter belong to the ASCII set of characters,
|
|
7445 but there are also characters for various sorts of accented letters,
|
|
7446 special symbols, Chinese and Japanese ideograms (i.e. Kanji, Katakana,
|
|
7447 etc.), Cyrillic and Greek letters, etc. The actual number of possible
|
|
7448 characters is quite large.
|
|
7449
|
|
7450 For now, we can view a character as some non-negative integer that
|
|
7451 has some shape that defines how it typically appears (e.g. as an
|
|
7452 uppercase A). (The exact way in which a character appears depends on the
|
|
7453 font used to display the character.) The internal type of characters in
|
|
7454 the C code is an @code{Emchar}; this is just an @code{int}, but using a
|
|
7455 symbolic type makes the code clearer.
|
|
7456
|
|
7457 Between every character in a buffer is a @dfn{buffer position} or
|
|
7458 @dfn{character position}. We can speak of the character before or after
|
|
7459 a particular buffer position, and when you insert a character at a
|
|
7460 particular position, all characters after that position end up at new
|
|
7461 positions. When we speak of the character @dfn{at} a position, we
|
|
7462 really mean the character after the position. (This schizophrenia
|
|
7463 between a buffer position being ``between'' a character and ``on'' a
|
|
7464 character is rampant in Emacs.)
|
|
7465
|
|
7466 Buffer positions are numbered starting at 1. This means that
|
|
7467 position 1 is before the first character, and position 0 is not
|
|
7468 valid. If there are N characters in a buffer, then buffer
|
|
7469 position N+1 is after the last one, and position N+2 is not valid.
|
|
7470
|
|
7471 The internal makeup of the Emchar integer varies depending on whether
|
|
7472 we have compiled with MULE support. If not, the Emchar integer is an
|
|
7473 8-bit integer with possible values from 0 - 255. 0 - 127 are the
|
|
7474 standard ASCII characters, while 128 - 255 are the characters from the
|
|
7475 ISO-8859-1 character set. If we have compiled with MULE support, an
|
|
7476 Emchar is a 19-bit integer, with the various bits having meanings
|
|
7477 according to a complex scheme that will be detailed later. The
|
|
7478 characters numbered 0 - 255 still have the same meanings as for the
|
|
7479 non-MULE case, though.
|
|
7480
|
|
7481 Internally, the text in a buffer is represented in a fairly simple
|
|
7482 fashion: as a contiguous array of bytes, with a @dfn{gap} of some size
|
|
7483 in the middle. Although the gap is of some substantial size in bytes,
|
|
7484 there is no text contained within it: From the perspective of the text
|
|
7485 in the buffer, it does not exist. The gap logically sits at some buffer
|
|
7486 position, between two characters (or possibly at the beginning or end of
|
|
7487 the buffer). Insertion of text in a buffer at a particular position is
|
|
7488 always accomplished by first moving the gap to that position
|
|
7489 (i.e. through some block moving of text), then writing the text into the
|
|
7490 beginning of the gap, thereby shrinking the gap. If the gap shrinks
|
|
7491 down to nothing, a new gap is created. (What actually happens is that a
|
|
7492 new gap is ``created'' at the end of the buffer's text, which requires
|
|
7493 nothing more than changing a couple of indices; then the gap is
|
|
7494 ``moved'' to the position where the insertion needs to take place by
|
|
7495 moving up in memory all the text after that position.) Similarly,
|
|
7496 deletion occurs by moving the gap to the place where the text is to be
|
|
7497 deleted, and then simply expanding the gap to include the deleted text.
|
|
7498 (@dfn{Expanding} and @dfn{shrinking} the gap as just described means
|
|
7499 just that the internal indices that keep track of where the gap is
|
|
7500 located are changed.)
|
|
7501
|
|
7502 Note that the total amount of memory allocated for a buffer text never
|
|
7503 decreases while the buffer is live. Therefore, if you load up a
|
|
7504 20-megabyte file and then delete all but one character, there will be a
|
|
7505 20-megabyte gap, which won't get any smaller (except by inserting
|
|
7506 characters back again). Once the buffer is killed, the memory allocated
|
|
7507 for the buffer text will be freed, but it will still be sitting on the
|
|
7508 heap, taking up virtual memory, and will not be released back to the
|
|
7509 operating system. (However, if you have compiled XEmacs with rel-alloc,
|
|
7510 the situation is different. In this case, the space @emph{will} be
|
|
7511 released back to the operating system. However, this tends to result in a
|
|
7512 noticeable speed penalty.)
|
|
7513
|
|
7514 Astute readers may notice that the text in a buffer is represented as
|
|
7515 an array of @emph{bytes}, while (at least in the MULE case) an Emchar is
|
|
7516 a 19-bit integer, which clearly cannot fit in a byte. This means (of
|
|
7517 course) that the text in a buffer uses a different representation from
|
|
7518 an Emchar: specifically, the 19-bit Emchar becomes a series of one to
|
|
7519 four bytes. The conversion between these two representations is complex
|
|
7520 and will be described later.
|
|
7521
|
|
7522 In the non-MULE case, everything is very simple: An Emchar
|
|
7523 is an 8-bit value, which fits neatly into one byte.
|
|
7524
|
|
7525 If we are given a buffer position and want to retrieve the
|
|
7526 character at that position, we need to follow these steps:
|
|
7527
|
|
7528 @enumerate
|
|
7529 @item
|
|
7530 Pretend there's no gap, and convert the buffer position into a @dfn{byte
|
|
7531 index} that indexes to the appropriate byte in the buffer's stream of
|
|
7532 textual bytes. By convention, byte indices begin at 1, just like buffer
|
|
7533 positions. In the non-MULE case, byte indices and buffer positions are
|
|
7534 identical, since one character equals one byte.
|
|
7535 @item
|
|
7536 Convert the byte index into a @dfn{memory index}, which takes the gap
|
|
7537 into account. The memory index is a direct index into the block of
|
|
7538 memory that stores the text of a buffer. This basically just involves
|
|
7539 checking to see if the byte index is past the gap, and if so, adding the
|
|
7540 size of the gap to it. By convention, memory indices begin at 1, just
|
|
7541 like buffer positions and byte indices, and when referring to the
|
|
7542 position that is @dfn{at} the gap, we always use the memory position at
|
|
7543 the @emph{beginning}, not at the end, of the gap.
|
|
7544 @item
|
|
7545 Fetch the appropriate bytes at the determined memory position.
|
|
7546 @item
|
|
7547 Convert these bytes into an Emchar.
|
|
7548 @end enumerate
|
|
7549
|
|
7550 In the non-Mule case, (3) and (4) boil down to a simple one-byte
|
|
7551 memory access.
|
|
7552
|
|
7553 Note that we have defined three types of positions in a buffer:
|
|
7554
|
|
7555 @enumerate
|
|
7556 @item
|
|
7557 @dfn{buffer positions} or @dfn{character positions}, typedef @code{Bufpos}
|
|
7558 @item
|
|
7559 @dfn{byte indices}, typedef @code{Bytind}
|
|
7560 @item
|
|
7561 @dfn{memory indices}, typedef @code{Memind}
|
|
7562 @end enumerate
|
|
7563
|
|
7564 All three typedefs are just @code{int}s, but defining them this way makes
|
|
7565 things a lot clearer.
|
|
7566
|
|
7567 Most code works with buffer positions. In particular, all Lisp code
|
|
7568 that refers to text in a buffer uses buffer positions. Lisp code does
|
|
7569 not know that byte indices or memory indices exist.
|
|
7570
|
|
7571 Finally, we have a typedef for the bytes in a buffer. This is a
|
|
7572 @code{Bufbyte}, which is an unsigned char. Referring to them as
|
|
7573 Bufbytes underscores the fact that we are working with a string of bytes
|
|
7574 in the internal Emacs buffer representation rather than in one of a
|
|
7575 number of possible alternative representations (e.g. EUC-encoded text,
|
|
7576 etc.).
|
|
7577
|
462
|
7578 @node Buffer Lists
|
428
|
7579 @section Buffer Lists
|
462
|
7580 @cindex buffer lists
|
428
|
7581
|
|
7582 Recall earlier that buffers are @dfn{permanent} objects, i.e. that
|
|
7583 they remain around until explicitly deleted. This entails that there is
|
|
7584 a list of all the buffers in existence. This list is actually an
|
|
7585 assoc-list (mapping from the buffer's name to the buffer) and is stored
|
|
7586 in the global variable @code{Vbuffer_alist}.
|
|
7587
|
|
7588 The order of the buffers in the list is important: the buffers are
|
|
7589 ordered approximately from most-recently-used to least-recently-used.
|
|
7590 Switching to a buffer using @code{switch-to-buffer},
|
|
7591 @code{pop-to-buffer}, etc. and switching windows using
|
|
7592 @code{other-window}, etc. usually brings the new current buffer to the
|
|
7593 front of the list. @code{switch-to-buffer}, @code{other-buffer},
|
|
7594 etc. look at the beginning of the list to find an alternative buffer to
|
|
7595 suggest. You can also explicitly move a buffer to the end of the list
|
|
7596 using @code{bury-buffer}.
|
|
7597
|
|
7598 In addition to the global ordering in @code{Vbuffer_alist}, each frame
|
|
7599 has its own ordering of the list. These lists always contain the same
|
|
7600 elements as in @code{Vbuffer_alist} although possibly in a different
|
|
7601 order. @code{buffer-list} normally returns the list for the selected
|
|
7602 frame. This allows you to work in separate frames without things
|
|
7603 interfering with each other.
|
|
7604
|
|
7605 The standard way to look up a buffer given a name is
|
|
7606 @code{get-buffer}, and the standard way to create a new buffer is
|
|
7607 @code{get-buffer-create}, which looks up a buffer with a given name,
|
|
7608 creating a new one if necessary. These operations correspond exactly
|
|
7609 with the symbol operations @code{intern-soft} and @code{intern},
|
|
7610 respectively. You can also force a new buffer to be created using
|
|
7611 @code{generate-new-buffer}, which takes a name and (if necessary) makes
|
|
7612 a unique name from this by appending a number, and then creates the
|
|
7613 buffer. This is basically like the symbol operation @code{gensym}.
|
|
7614
|
462
|
7615 @node Markers and Extents
|
428
|
7616 @section Markers and Extents
|
462
|
7617 @cindex markers and extents
|
|
7618 @cindex extents, markers and
|
428
|
7619
|
|
7620 Among the things associated with a buffer are things that are
|
|
7621 logically attached to certain buffer positions. This can be used to
|
|
7622 keep track of a buffer position when text is inserted and deleted, so
|
|
7623 that it remains at the same spot relative to the text around it; to
|
|
7624 assign properties to particular sections of text; etc. There are two
|
|
7625 such objects that are useful in this regard: they are @dfn{markers} and
|
|
7626 @dfn{extents}.
|
|
7627
|
|
7628 A @dfn{marker} is simply a flag placed at a particular buffer
|
|
7629 position, which is moved around as text is inserted and deleted.
|
|
7630 Markers are used for all sorts of purposes, such as the @code{mark} that
|
|
7631 is the other end of textual regions to be cut, copied, etc.
|
|
7632
|
|
7633 An @dfn{extent} is similar to two markers plus some associated
|
|
7634 properties, and is used to keep track of regions in a buffer as text is
|
|
7635 inserted and deleted, and to add properties (e.g. fonts) to particular
|
|
7636 regions of text. The external interface of extents is explained
|
|
7637 elsewhere.
|
|
7638
|
|
7639 The important thing here is that markers and extents simply contain
|
|
7640 buffer positions in them as integers, and every time text is inserted or
|
|
7641 deleted, these positions must be updated. In order to minimize the
|
|
7642 amount of shuffling that needs to be done, the positions in markers and
|
442
|
7643 extents (there's one per marker, two per extent) are stored in Meminds.
|
428
|
7644 This means that they only need to be moved when the text is physically
|
|
7645 moved in memory; since the gap structure tries to minimize this, it also
|
|
7646 minimizes the number of marker and extent indices that need to be
|
|
7647 adjusted. Look in @file{insdel.c} for the details of how this works.
|
|
7648
|
|
7649 One other important distinction is that markers are @dfn{temporary}
|
|
7650 while extents are @dfn{permanent}. This means that markers disappear as
|
|
7651 soon as there are no more pointers to them, and correspondingly, there
|
|
7652 is no way to determine what markers are in a buffer if you are just
|
|
7653 given the buffer. Extents remain in a buffer until they are detached
|
|
7654 (which could happen as a result of text being deleted) or the buffer is
|
|
7655 deleted, and primitives do exist to enumerate the extents in a buffer.
|
|
7656
|
462
|
7657 @node Bufbytes and Emchars
|
428
|
7658 @section Bufbytes and Emchars
|
462
|
7659 @cindex Bufbytes and Emchars
|
|
7660 @cindex Emchars, Bufbytes and
|
428
|
7661
|
|
7662 Not yet documented.
|
|
7663
|
462
|
7664 @node The Buffer Object
|
428
|
7665 @section The Buffer Object
|
462
|
7666 @cindex buffer object, the
|
|
7667 @cindex object, the buffer
|
428
|
7668
|
|
7669 Buffers contain fields not directly accessible by the Lisp programmer.
|
|
7670 We describe them here, naming them by the names used in the C code.
|
|
7671 Many are accessible indirectly in Lisp programs via Lisp primitives.
|
|
7672
|
|
7673 @table @code
|
|
7674 @item name
|
|
7675 The buffer name is a string that names the buffer. It is guaranteed to
|
446
|
7676 be unique. @xref{Buffer Names,,, lispref, XEmacs Lisp Reference
|
428
|
7677 Manual}.
|
|
7678
|
|
7679 @item save_modified
|
|
7680 This field contains the time when the buffer was last saved, as an
|
446
|
7681 integer. @xref{Buffer Modification,,, lispref, XEmacs Lisp Reference
|
428
|
7682 Manual}.
|
|
7683
|
|
7684 @item modtime
|
|
7685 This field contains the modification time of the visited file. It is
|
|
7686 set when the file is written or read. Every time the buffer is written
|
|
7687 to the file, this field is compared to the modification time of the
|
446
|
7688 file. @xref{Buffer Modification,,, lispref, XEmacs Lisp Reference
|
428
|
7689 Manual}.
|
|
7690
|
|
7691 @item auto_save_modified
|
|
7692 This field contains the time when the buffer was last auto-saved.
|
|
7693
|
|
7694 @item last_window_start
|
|
7695 This field contains the @code{window-start} position in the buffer as of
|
|
7696 the last time the buffer was displayed in a window.
|
|
7697
|
|
7698 @item undo_list
|
|
7699 This field points to the buffer's undo list. @xref{Undo,,, lispref,
|
446
|
7700 XEmacs Lisp Reference Manual}.
|
428
|
7701
|
|
7702 @item syntax_table_v
|
|
7703 This field contains the syntax table for the buffer. @xref{Syntax
|
446
|
7704 Tables,,, lispref, XEmacs Lisp Reference Manual}.
|
428
|
7705
|
|
7706 @item downcase_table
|
|
7707 This field contains the conversion table for converting text to lower
|
446
|
7708 case. @xref{Case Tables,,, lispref, XEmacs Lisp Reference Manual}.
|
428
|
7709
|
|
7710 @item upcase_table
|
|
7711 This field contains the conversion table for converting text to upper
|
446
|
7712 case. @xref{Case Tables,,, lispref, XEmacs Lisp Reference Manual}.
|
428
|
7713
|
|
7714 @item case_canon_table
|
|
7715 This field contains the conversion table for canonicalizing text for
|
|
7716 case-folding search. @xref{Case Tables,,, lispref, XEmacs Lisp
|
446
|
7717 Reference Manual}.
|
428
|
7718
|
|
7719 @item case_eqv_table
|
|
7720 This field contains the equivalence table for case-folding search.
|
446
|
7721 @xref{Case Tables,,, lispref, XEmacs Lisp Reference Manual}.
|
428
|
7722
|
|
7723 @item display_table
|
|
7724 This field contains the buffer's display table, or @code{nil} if it
|
|
7725 doesn't have one. @xref{Display Tables,,, lispref, XEmacs Lisp
|
446
|
7726 Reference Manual}.
|
428
|
7727
|
|
7728 @item markers
|
|
7729 This field contains the chain of all markers that currently point into
|
|
7730 the buffer. Deletion of text in the buffer, and motion of the buffer's
|
|
7731 gap, must check each of these markers and perhaps update it.
|
446
|
7732 @xref{Markers,,, lispref, XEmacs Lisp Reference Manual}.
|
428
|
7733
|
|
7734 @item backed_up
|
|
7735 This field is a flag that tells whether a backup file has been made for
|
|
7736 the visited file of this buffer.
|
|
7737
|
|
7738 @item mark
|
|
7739 This field contains the mark for the buffer. The mark is a marker,
|
|
7740 hence it is also included on the list @code{markers}. @xref{The Mark,,,
|
446
|
7741 lispref, XEmacs Lisp Reference Manual}.
|
428
|
7742
|
|
7743 @item mark_active
|
|
7744 This field is non-@code{nil} if the buffer's mark is active.
|
|
7745
|
|
7746 @item local_var_alist
|
|
7747 This field contains the association list describing the variables local
|
|
7748 in this buffer, and their values, with the exception of local variables
|
|
7749 that have special slots in the buffer object. (Those slots are omitted
|
|
7750 from this table.) @xref{Buffer-Local Variables,,, lispref, XEmacs Lisp
|
446
|
7751 Reference Manual}.
|
428
|
7752
|
|
7753 @item modeline_format
|
|
7754 This field contains a Lisp object which controls how to display the mode
|
|
7755 line for this buffer. @xref{Modeline Format,,, lispref, XEmacs Lisp
|
446
|
7756 Reference Manual}.
|
428
|
7757
|
|
7758 @item base_buffer
|
|
7759 This field holds the buffer's base buffer (if it is an indirect buffer),
|
|
7760 or @code{nil}.
|
|
7761 @end table
|
|
7762
|
|
7763 @node MULE Character Sets and Encodings, The Lisp Reader and Compiler, Buffers and Textual Representation, Top
|
|
7764 @chapter MULE Character Sets and Encodings
|
462
|
7765 @cindex Mule character sets and encodings
|
|
7766 @cindex character sets and encodings, Mule
|
|
7767 @cindex encodings, Mule character sets and
|
428
|
7768
|
|
7769 Recall that there are two primary ways that text is represented in
|
|
7770 XEmacs. The @dfn{buffer} representation sees the text as a series of
|
|
7771 bytes (Bufbytes), with a variable number of bytes used per character.
|
|
7772 The @dfn{character} representation sees the text as a series of integers
|
|
7773 (Emchars), one per character. The character representation is a cleaner
|
|
7774 representation from a theoretical standpoint, and is thus used in many
|
|
7775 cases when lots of manipulations on a string need to be done. However,
|
|
7776 the buffer representation is the standard representation used in both
|
|
7777 Lisp strings and buffers, and because of this, it is the ``default''
|
|
7778 representation that text comes in. The reason for using this
|
|
7779 representation is that it's compact and is compatible with ASCII.
|
|
7780
|
|
7781 @menu
|
|
7782 * Character Sets::
|
|
7783 * Encodings::
|
|
7784 * Internal Mule Encodings::
|
|
7785 * CCL::
|
|
7786 @end menu
|
|
7787
|
462
|
7788 @node Character Sets
|
428
|
7789 @section Character Sets
|
462
|
7790 @cindex character sets
|
428
|
7791
|
|
7792 A character set (or @dfn{charset}) is an ordered set of characters. A
|
|
7793 particular character in a charset is indexed using one or more
|
|
7794 @dfn{position codes}, which are non-negative integers. The number of
|
|
7795 position codes needed to identify a particular character in a charset is
|
|
7796 called the @dfn{dimension} of the charset. In XEmacs/Mule, all charsets
|
|
7797 have dimension 1 or 2, and the size of all charsets (except for a few
|
|
7798 special cases) is either 94, 96, 94 by 94, or 96 by 96. The range of
|
|
7799 position codes used to index characters from any of these types of
|
|
7800 character sets is as follows:
|
|
7801
|
|
7802 @example
|
|
7803 Charset type Position code 1 Position code 2
|
|
7804 ------------------------------------------------------------
|
|
7805 94 33 - 126 N/A
|
|
7806 96 32 - 127 N/A
|
|
7807 94x94 33 - 126 33 - 126
|
|
7808 96x96 32 - 127 32 - 127
|
|
7809 @end example
|
|
7810
|
|
7811 Note that in the above cases position codes do not start at an
|
|
7812 expected value such as 0 or 1. The reason for this will become clear
|
|
7813 later.
|
|
7814
|
|
7815 For example, Latin-1 is a 96-character charset, and JISX0208 (the
|
|
7816 Japanese national character set) is a 94x94-character charset.
|
|
7817
|
|
7818 [Note that, although the ranges above define the @emph{valid} position
|
|
7819 codes for a charset, some of the slots in a particular charset may in
|
|
7820 fact be empty. This is the case for JISX0208, for example, where (e.g.)
|
|
7821 all the slots whose first position code is in the range 118 - 127 are
|
|
7822 empty.]
|
|
7823
|
|
7824 There are three charsets that do not follow the above rules. All of
|
|
7825 them have one dimension, and have ranges of position codes as follows:
|
|
7826
|
|
7827 @example
|
|
7828 Charset name Position code 1
|
|
7829 ------------------------------------
|
|
7830 ASCII 0 - 127
|
|
7831 Control-1 0 - 31
|
|
7832 Composite 0 - some large number
|
|
7833 @end example
|
|
7834
|
|
7835 (The upper bound of the position code for composite characters has not
|
|
7836 yet been determined, but it will probably be at least 16,383).
|
|
7837
|
|
7838 ASCII is the union of two subsidiary character sets: Printing-ASCII
|
|
7839 (the printing ASCII character set, consisting of position codes 33 -
|
|
7840 126, like for a standard 94-character charset) and Control-ASCII (the
|
|
7841 non-printing characters that would appear in a binary file with codes 0
|
|
7842 - 32 and 127).
|
|
7843
|
|
7844 Control-1 contains the non-printing characters that would appear in a
|
|
7845 binary file with codes 128 - 159.
|
|
7846
|
|
7847 Composite contains characters that are generated by overstriking one
|
|
7848 or more characters from other charsets.
|
|
7849
|
|
7850 Note that some characters in ASCII, and all characters in Control-1,
|
|
7851 are @dfn{control} (non-printing) characters. These have no printed
|
|
7852 representation but instead control some other function of the printing
|
|
7853 (e.g. TAB or 8 moves the current character position to the next tab
|
|
7854 stop). All other characters in all charsets are @dfn{graphic}
|
|
7855 (printing) characters.
|
|
7856
|
|
7857 When a binary file is read in, the bytes in the file are assigned to
|
|
7858 character sets as follows:
|
|
7859
|
|
7860 @example
|
|
7861 Bytes Character set Range
|
|
7862 --------------------------------------------------
|
|
7863 0 - 127 ASCII 0 - 127
|
|
7864 128 - 159 Control-1 0 - 31
|
|
7865 160 - 255 Latin-1 32 - 127
|
|
7866 @end example
|
|
7867
|
|
7868 This is a bit ad-hoc but gets the job done.
|
|
7869
|
462
|
7870 @node Encodings
|
428
|
7871 @section Encodings
|
462
|
7872 @cindex encodings, Mule
|
|
7873 @cindex Mule encodings
|
428
|
7874
|
|
7875 An @dfn{encoding} is a way of numerically representing characters from
|
|
7876 one or more character sets. If an encoding only encompasses one
|
|
7877 character set, then the position codes for the characters in that
|
|
7878 character set could be used directly. This is not possible, however, if
|
|
7879 more than one character set is to be used in the encoding.
|
|
7880
|
|
7881 For example, the conversion detailed above between bytes in a binary
|
|
7882 file and characters is effectively an encoding that encompasses the
|
|
7883 three character sets ASCII, Control-1, and Latin-1 in a stream of 8-bit
|
|
7884 bytes.
|
|
7885
|
|
7886 Thus, an encoding can be viewed as a way of encoding characters from a
|
|
7887 specified group of character sets using a stream of bytes, each of which
|
|
7888 contains a fixed number of bits (but not necessarily 8, as in the common
|
|
7889 usage of ``byte'').
|
|
7890
|
|
7891 Here are descriptions of a couple of common
|
|
7892 encodings:
|
|
7893
|
|
7894 @menu
|
|
7895 * Japanese EUC (Extended Unix Code)::
|
|
7896 * JIS7::
|
|
7897 @end menu
|
|
7898
|
462
|
7899 @node Japanese EUC (Extended Unix Code)
|
428
|
7900 @subsection Japanese EUC (Extended Unix Code)
|
462
|
7901 @cindex Japanese EUC (Extended Unix Code)
|
|
7902 @cindex EUC (Extended Unix Code), Japanese
|
|
7903 @cindex Extended Unix Code, Japanese EUC
|
428
|
7904
|
|
7905 This encompasses the character sets Printing-ASCII, Japanese-JISX0201,
|
|
7906 and Japanese-JISX0208-Kana (half-width katakana, the right half of
|
|
7907 JISX0201). It uses 8-bit bytes.
|
|
7908
|
|
7909 Note that Printing-ASCII and Japanese-JISX0201-Kana are 94-character
|
|
7910 charsets, while Japanese-JISX0208 is a 94x94-character charset.
|
|
7911
|
|
7912 The encoding is as follows:
|
|
7913
|
|
7914 @example
|
|
7915 Character set Representation (PC=position-code)
|
|
7916 ------------- --------------
|
|
7917 Printing-ASCII PC1
|
|
7918 Japanese-JISX0201-Kana 0x8E | PC1 + 0x80
|
|
7919 Japanese-JISX0208 PC1 + 0x80 | PC2 + 0x80
|
|
7920 Japanese-JISX0212 PC1 + 0x80 | PC2 + 0x80
|
|
7921 @end example
|
|
7922
|
|
7923
|
462
|
7924 @node JIS7
|
428
|
7925 @subsection JIS7
|
462
|
7926 @cindex JIS7
|
428
|
7927
|
|
7928 This encompasses the character sets Printing-ASCII,
|
|
7929 Japanese-JISX0201-Roman (the left half of JISX0201; this character set
|
|
7930 is very similar to Printing-ASCII and is a 94-character charset),
|
|
7931 Japanese-JISX0208, and Japanese-JISX0201-Kana. It uses 7-bit bytes.
|
|
7932
|
|
7933 Unlike Japanese EUC, this is a @dfn{modal} encoding, which
|
|
7934 means that there are multiple states that the encoding can
|
|
7935 be in, which affect how the bytes are to be interpreted.
|
|
7936 Special sequences of bytes (called @dfn{escape sequences})
|
|
7937 are used to change states.
|
|
7938
|
|
7939 The encoding is as follows:
|
|
7940
|
|
7941 @example
|
|
7942 Character set Representation (PC=position-code)
|
|
7943 ------------- --------------
|
|
7944 Printing-ASCII PC1
|
|
7945 Japanese-JISX0201-Roman PC1
|
|
7946 Japanese-JISX0201-Kana PC1
|
|
7947 Japanese-JISX0208 PC1 PC2
|
|
7948
|
|
7949
|
|
7950 Escape sequence ASCII equivalent Meaning
|
|
7951 --------------- ---------------- -------
|
|
7952 0x1B 0x28 0x4A ESC ( J invoke Japanese-JISX0201-Roman
|
|
7953 0x1B 0x28 0x49 ESC ( I invoke Japanese-JISX0201-Kana
|
|
7954 0x1B 0x24 0x42 ESC $ B invoke Japanese-JISX0208
|
|
7955 0x1B 0x28 0x42 ESC ( B invoke Printing-ASCII
|
|
7956 @end example
|
|
7957
|
|
7958 Initially, Printing-ASCII is invoked.
|
|
7959
|
462
|
7960 @node Internal Mule Encodings
|
428
|
7961 @section Internal Mule Encodings
|
462
|
7962 @cindex internal Mule encodings
|
|
7963 @cindex Mule encodings, internal
|
|
7964 @cindex encodings, internal Mule
|
428
|
7965
|
|
7966 In XEmacs/Mule, each character set is assigned a unique number, called a
|
|
7967 @dfn{leading byte}. This is used in the encodings of a character.
|
|
7968 Leading bytes are in the range 0x80 - 0xFF (except for ASCII, which has
|
|
7969 a leading byte of 0), although some leading bytes are reserved.
|
|
7970
|
|
7971 Charsets whose leading byte is in the range 0x80 - 0x9F are called
|
|
7972 @dfn{official} and are used for built-in charsets. Other charsets are
|
|
7973 called @dfn{private} and have leading bytes in the range 0xA0 - 0xFF;
|
|
7974 these are user-defined charsets.
|
|
7975
|
|
7976 More specifically:
|
|
7977
|
|
7978 @example
|
|
7979 Character set Leading byte
|
|
7980 ------------- ------------
|
|
7981 ASCII 0
|
|
7982 Composite 0x80
|
|
7983 Dimension-1 Official 0x81 - 0x8D
|
|
7984 (0x8E is free)
|
|
7985 Control-1 0x8F
|
|
7986 Dimension-2 Official 0x90 - 0x99
|
|
7987 (0x9A - 0x9D are free;
|
|
7988 0x9E and 0x9F are reserved)
|
|
7989 Dimension-1 Private 0xA0 - 0xEF
|
|
7990 Dimension-2 Private 0xF0 - 0xFF
|
|
7991 @end example
|
|
7992
|
|
7993 There are two internal encodings for characters in XEmacs/Mule. One is
|
|
7994 called @dfn{string encoding} and is an 8-bit encoding that is used for
|
|
7995 representing characters in a buffer or string. It uses 1 to 4 bytes per
|
|
7996 character. The other is called @dfn{character encoding} and is a 19-bit
|
|
7997 encoding that is used for representing characters individually in a
|
|
7998 variable.
|
|
7999
|
|
8000 (In the following descriptions, we'll ignore composite characters for
|
|
8001 the moment. We also give a general (structural) overview first,
|
|
8002 followed later by the exact details.)
|
|
8003
|
|
8004 @menu
|
|
8005 * Internal String Encoding::
|
|
8006 * Internal Character Encoding::
|
|
8007 @end menu
|
|
8008
|
462
|
8009 @node Internal String Encoding
|
428
|
8010 @subsection Internal String Encoding
|
462
|
8011 @cindex internal string encoding
|
|
8012 @cindex string encoding, internal
|
|
8013 @cindex encoding, internal string
|
428
|
8014
|
|
8015 ASCII characters are encoded using their position code directly. Other
|
|
8016 characters are encoded using their leading byte followed by their
|
|
8017 position code(s) with the high bit set. Characters in private character
|
|
8018 sets have their leading byte prefixed with a @dfn{leading byte prefix},
|
|
8019 which is either 0x9E or 0x9F. (No character sets are ever assigned these
|
|
8020 leading bytes.) Specifically:
|
|
8021
|
|
8022 @example
|
|
8023 Character set Encoding (PC=position-code, LB=leading-byte)
|
|
8024 ------------- --------
|
|
8025 ASCII PC-1 |
|
|
8026 Control-1 LB | PC1 + 0xA0 |
|
|
8027 Dimension-1 official LB | PC1 + 0x80 |
|
|
8028 Dimension-1 private 0x9E | LB | PC1 + 0x80 |
|
|
8029 Dimension-2 official LB | PC1 + 0x80 | PC2 + 0x80 |
|
|
8030 Dimension-2 private 0x9F | LB | PC1 + 0x80 | PC2 + 0x80
|
|
8031 @end example
|
|
8032
|
|
8033 The basic characteristic of this encoding is that the first byte
|
|
8034 of all characters is in the range 0x00 - 0x9F, and the second and
|
|
8035 following bytes of all characters is in the range 0xA0 - 0xFF.
|
|
8036 This means that it is impossible to get out of sync, or more
|
|
8037 specifically:
|
|
8038
|
|
8039 @enumerate
|
|
8040 @item
|
|
8041 Given any byte position, the beginning of the character it is
|
|
8042 within can be determined in constant time.
|
|
8043 @item
|
|
8044 Given any byte position at the beginning of a character, the
|
|
8045 beginning of the next character can be determined in constant
|
|
8046 time.
|
|
8047 @item
|
|
8048 Given any byte position at the beginning of a character, the
|
|
8049 beginning of the previous character can be determined in constant
|
|
8050 time.
|
|
8051 @item
|
|
8052 Textual searches can simply treat encoded strings as if they
|
|
8053 were encoded in a one-byte-per-character fashion rather than
|
|
8054 the actual multi-byte encoding.
|
|
8055 @end enumerate
|
|
8056
|
|
8057 None of the standard non-modal encodings meet all of these
|
|
8058 conditions. For example, EUC satisfies only (2) and (3), while
|
|
8059 Shift-JIS and Big5 (not yet described) satisfy only (2). (All
|
|
8060 non-modal encodings must satisfy (2), in order to be unambiguous.)
|
|
8061
|
462
|
8062 @node Internal Character Encoding
|
428
|
8063 @subsection Internal Character Encoding
|
462
|
8064 @cindex internal character encoding
|
|
8065 @cindex character encoding, internal
|
|
8066 @cindex encoding, internal character
|
428
|
8067
|
|
8068 One 19-bit word represents a single character. The word is
|
|
8069 separated into three fields:
|
|
8070
|
|
8071 @example
|
|
8072 Bit number: 18 17 16 15 14 13 12 11 10 09 08 07 06 05 04 03 02 01 00
|
|
8073 <------------> <------------------> <------------------>
|
|
8074 Field: 1 2 3
|
|
8075 @end example
|
|
8076
|
|
8077 Note that fields 2 and 3 hold 7 bits each, while field 1 holds 5 bits.
|
|
8078
|
|
8079 @example
|
|
8080 Character set Field 1 Field 2 Field 3
|
|
8081 ------------- ------- ------- -------
|
|
8082 ASCII 0 0 PC1
|
|
8083 range: (00 - 7F)
|
|
8084 Control-1 0 1 PC1
|
|
8085 range: (00 - 1F)
|
|
8086 Dimension-1 official 0 LB - 0x80 PC1
|
|
8087 range: (01 - 0D) (20 - 7F)
|
|
8088 Dimension-1 private 0 LB - 0x80 PC1
|
|
8089 range: (20 - 6F) (20 - 7F)
|
|
8090 Dimension-2 official LB - 0x8F PC1 PC2
|
|
8091 range: (01 - 0A) (20 - 7F) (20 - 7F)
|
|
8092 Dimension-2 private LB - 0xE1 PC1 PC2
|
|
8093 range: (0F - 1E) (20 - 7F) (20 - 7F)
|
|
8094 Composite 0x1F ? ?
|
|
8095 @end example
|
|
8096
|
|
8097 Note that character codes 0 - 255 are the same as the ``binary encoding''
|
|
8098 described above.
|
|
8099
|
462
|
8100 @node CCL
|
428
|
8101 @section CCL
|
462
|
8102 @cindex CCL
|
428
|
8103
|
|
8104 @example
|
|
8105 CCL PROGRAM SYNTAX:
|
|
8106 CCL_PROGRAM := (CCL_MAIN_BLOCK
|
|
8107 [ CCL_EOF_BLOCK ])
|
|
8108
|
|
8109 CCL_MAIN_BLOCK := CCL_BLOCK
|
|
8110 CCL_EOF_BLOCK := CCL_BLOCK
|
|
8111
|
|
8112 CCL_BLOCK := STATEMENT | (STATEMENT [STATEMENT ...])
|
|
8113 STATEMENT :=
|
|
8114 SET | IF | BRANCH | LOOP | REPEAT | BREAK
|
|
8115 | READ | WRITE
|
|
8116
|
|
8117 SET := (REG = EXPRESSION) | (REG SELF_OP EXPRESSION)
|
|
8118 | INT-OR-CHAR
|
|
8119
|
|
8120 EXPRESSION := ARG | (EXPRESSION OP ARG)
|
|
8121
|
|
8122 IF := (if EXPRESSION CCL_BLOCK CCL_BLOCK)
|
|
8123 BRANCH := (branch EXPRESSION CCL_BLOCK [CCL_BLOCK ...])
|
|
8124 LOOP := (loop STATEMENT [STATEMENT ...])
|
|
8125 BREAK := (break)
|
|
8126 REPEAT := (repeat)
|
|
8127 | (write-repeat [REG | INT-OR-CHAR | string])
|
|
8128 | (write-read-repeat REG [INT-OR-CHAR | string | ARRAY]?)
|
|
8129 READ := (read REG) | (read REG REG)
|
|
8130 | (read-if REG ARITH_OP ARG CCL_BLOCK CCL_BLOCK)
|
|
8131 | (read-branch REG CCL_BLOCK [CCL_BLOCK ...])
|
|
8132 WRITE := (write REG) | (write REG REG)
|
|
8133 | (write INT-OR-CHAR) | (write STRING) | STRING
|
|
8134 | (write REG ARRAY)
|
|
8135 END := (end)
|
|
8136
|
|
8137 REG := r0 | r1 | r2 | r3 | r4 | r5 | r6 | r7
|
|
8138 ARG := REG | INT-OR-CHAR
|
|
8139 OP := + | - | * | / | % | & | '|' | ^ | << | >> | <8 | >8 | //
|
|
8140 | < | > | == | <= | >= | !=
|
|
8141 SELF_OP :=
|
|
8142 += | -= | *= | /= | %= | &= | '|=' | ^= | <<= | >>=
|
|
8143 ARRAY := '[' INT-OR-CHAR ... ']'
|
|
8144 INT-OR-CHAR := INT | CHAR
|
|
8145
|
|
8146 MACHINE CODE:
|
|
8147
|
|
8148 The machine code consists of a vector of 32-bit words.
|
|
8149 The first such word specifies the start of the EOF section of the code;
|
|
8150 this is the code executed to handle any stuff that needs to be done
|
|
8151 (e.g. designating back to ASCII and left-to-right mode) after all
|
|
8152 other encoded/decoded data has been written out. This is not used for
|
|
8153 charset CCL programs.
|
|
8154
|
442
|
8155 REGISTER: 0..7 -- referred by RRR or rrr
|
428
|
8156
|
|
8157 OPERATOR BIT FIELD (27-bit): XXXXXXXXXXXXXXX RRR TTTTT
|
|
8158 TTTTT (5-bit): operator type
|
|
8159 RRR (3-bit): register number
|
|
8160 XXXXXXXXXXXXXXXX (15-bit):
|
|
8161 CCCCCCCCCCCCCCC: constant or address
|
|
8162 000000000000rrr: register number
|
|
8163
|
|
8164 AAAA: 00000 +
|
|
8165 00001 -
|
|
8166 00010 *
|
|
8167 00011 /
|
|
8168 00100 %
|
|
8169 00101 &
|
|
8170 00110 |
|
|
8171 00111 ~
|
|
8172
|
|
8173 01000 <<
|
|
8174 01001 >>
|
|
8175 01010 <8
|
|
8176 01011 >8
|
|
8177 01100 //
|
|
8178 01101 not used
|
|
8179 01110 not used
|
|
8180 01111 not used
|
|
8181
|
|
8182 10000 <
|
|
8183 10001 >
|
|
8184 10010 ==
|
|
8185 10011 <=
|
|
8186 10100 >=
|
|
8187 10101 !=
|
|
8188
|
|
8189 OPERATORS: TTTTT RRR XX..
|
|
8190
|
|
8191 SetCS: 00000 RRR C...C RRR = C...C
|
|
8192 SetCL: 00001 RRR ..... RRR = c...c
|
|
8193 c.............c
|
|
8194 SetR: 00010 RRR ..rrr RRR = rrr
|
|
8195 SetA: 00011 RRR ..rrr RRR = array[rrr]
|
|
8196 C.............C size of array = C...C
|
|
8197 c.............c contents = c...c
|
|
8198
|
|
8199 Jump: 00100 000 c...c jump to c...c
|
|
8200 JumpCond: 00101 RRR c...c if (!RRR) jump to c...c
|
|
8201 WriteJump: 00110 RRR c...c Write1 RRR, jump to c...c
|
|
8202 WriteReadJump: 00111 RRR c...c Write1, Read1 RRR, jump to c...c
|
|
8203 WriteCJump: 01000 000 c...c Write1 C...C, jump to c...c
|
|
8204 C...C
|
|
8205 WriteCReadJump: 01001 RRR c...c Write1 C...C, Read1 RRR,
|
|
8206 C.............C and jump to c...c
|
|
8207 WriteSJump: 01010 000 c...c WriteS, jump to c...c
|
|
8208 C.............C
|
|
8209 S.............S
|
|
8210 ...
|
|
8211 WriteSReadJump: 01011 RRR c...c WriteS, Read1 RRR, jump to c...c
|
|
8212 C.............C
|
|
8213 S.............S
|
|
8214 ...
|
|
8215 WriteAReadJump: 01100 RRR c...c WriteA, Read1 RRR, jump to c...c
|
|
8216 C.............C size of array = C...C
|
|
8217 c.............c contents = c...c
|
|
8218 ...
|
|
8219 Branch: 01101 RRR C...C if (RRR >= 0 && RRR < C..)
|
|
8220 c.............c branch to (RRR+1)th address
|
|
8221 Read1: 01110 RRR ... read 1-byte to RRR
|
|
8222 Read2: 01111 RRR ..rrr read 2-byte to RRR and rrr
|
|
8223 ReadBranch: 10000 RRR C...C Read1 and Branch
|
|
8224 c.............c
|
|
8225 ...
|
|
8226 Write1: 10001 RRR ..... write 1-byte RRR
|
|
8227 Write2: 10010 RRR ..rrr write 2-byte RRR and rrr
|
|
8228 WriteC: 10011 000 ..... write 1-char C...CC
|
|
8229 C.............C
|
|
8230 WriteS: 10100 000 ..... write C..-byte of string
|
|
8231 C.............C
|
|
8232 S.............S
|
|
8233 ...
|
|
8234 WriteA: 10101 RRR ..... write array[RRR]
|
|
8235 C.............C size of array = C...C
|
|
8236 c.............c contents = c...c
|
|
8237 ...
|
|
8238 End: 10110 000 ..... terminate the execution
|
|
8239
|
|
8240 SetSelfCS: 10111 RRR C...C RRR AAAAA= C...C
|
|
8241 ..........AAAAA
|
|
8242 SetSelfCL: 11000 RRR ..... RRR AAAAA= c...c
|
|
8243 c.............c
|
|
8244 ..........AAAAA
|
|
8245 SetSelfR: 11001 RRR ..Rrr RRR AAAAA= rrr
|
|
8246 ..........AAAAA
|
|
8247 SetExprCL: 11010 RRR ..Rrr RRR = rrr AAAAA c...c
|
|
8248 c.............c
|
|
8249 ..........AAAAA
|
|
8250 SetExprR: 11011 RRR ..rrr RRR = rrr AAAAA Rrr
|
|
8251 ............Rrr
|
|
8252 ..........AAAAA
|
|
8253 JumpCondC: 11100 RRR c...c if !(RRR AAAAA C..) jump to c...c
|
|
8254 C.............C
|
|
8255 ..........AAAAA
|
|
8256 JumpCondR: 11101 RRR c...c if !(RRR AAAAA rrr) jump to c...c
|
|
8257 ............rrr
|
|
8258 ..........AAAAA
|
|
8259 ReadJumpCondC: 11110 RRR c...c Read1 and JumpCondC
|
|
8260 C.............C
|
|
8261 ..........AAAAA
|
|
8262 ReadJumpCondR: 11111 RRR c...c Read1 and JumpCondR
|
|
8263 ............rrr
|
|
8264 ..........AAAAA
|
|
8265 @end example
|
|
8266
|
|
8267 @node The Lisp Reader and Compiler, Lstreams, MULE Character Sets and Encodings, Top
|
|
8268 @chapter The Lisp Reader and Compiler
|
462
|
8269 @cindex Lisp reader and compiler, the
|
|
8270 @cindex reader and compiler, the Lisp
|
|
8271 @cindex compiler, the Lisp reader and
|
428
|
8272
|
|
8273 Not yet documented.
|
|
8274
|
|
8275 @node Lstreams, Consoles; Devices; Frames; Windows, The Lisp Reader and Compiler, Top
|
|
8276 @chapter Lstreams
|
462
|
8277 @cindex lstreams
|
428
|
8278
|
|
8279 An @dfn{lstream} is an internal Lisp object that provides a generic
|
|
8280 buffering stream implementation. Conceptually, you send data to the
|
|
8281 stream or read data from the stream, not caring what's on the other end
|
|
8282 of the stream. The other end could be another stream, a file
|
|
8283 descriptor, a stdio stream, a fixed block of memory, a reallocating
|
|
8284 block of memory, etc. The main purpose of the stream is to provide a
|
|
8285 standard interface and to do buffering. Macros are defined to read or
|
|
8286 write characters, so the calling functions do not have to worry about
|
|
8287 blocking data together in order to achieve efficiency.
|
|
8288
|
|
8289 @menu
|
|
8290 * Creating an Lstream:: Creating an lstream object.
|
|
8291 * Lstream Types:: Different sorts of things that are streamed.
|
|
8292 * Lstream Functions:: Functions for working with lstreams.
|
|
8293 * Lstream Methods:: Creating new lstream types.
|
|
8294 @end menu
|
|
8295
|
462
|
8296 @node Creating an Lstream
|
428
|
8297 @section Creating an Lstream
|
462
|
8298 @cindex lstream, creating an
|
428
|
8299
|
|
8300 Lstreams come in different types, depending on what is being interfaced
|
|
8301 to. Although the primitive for creating new lstreams is
|
|
8302 @code{Lstream_new()}, generally you do not call this directly. Instead,
|
|
8303 you call some type-specific creation function, which creates the lstream
|
|
8304 and initializes it as appropriate for the particular type.
|
|
8305
|
|
8306 All lstream creation functions take a @var{mode} argument, specifying
|
|
8307 what mode the lstream should be opened as. This controls whether the
|
|
8308 lstream is for input and output, and optionally whether data should be
|
|
8309 blocked up in units of MULE characters. Note that some types of
|
|
8310 lstreams can only be opened for input; others only for output; and
|
|
8311 others can be opened either way. #### Richard Mlynarik thinks that
|
|
8312 there should be a strict separation between input and output streams,
|
|
8313 and he's probably right.
|
|
8314
|
|
8315 @var{mode} is a string, one of
|
|
8316
|
|
8317 @table @code
|
|
8318 @item "r"
|
|
8319 Open for reading.
|
|
8320 @item "w"
|
|
8321 Open for writing.
|
|
8322 @item "rc"
|
|
8323 Open for reading, but ``read'' never returns partial MULE characters.
|
|
8324 @item "wc"
|
|
8325 Open for writing, but never writes partial MULE characters.
|
|
8326 @end table
|
|
8327
|
462
|
8328 @node Lstream Types
|
428
|
8329 @section Lstream Types
|
462
|
8330 @cindex lstream types
|
|
8331 @cindex types, lstream
|
428
|
8332
|
|
8333 @table @asis
|
|
8334 @item stdio
|
|
8335
|
|
8336 @item filedesc
|
|
8337
|
|
8338 @item lisp-string
|
|
8339
|
|
8340 @item fixed-buffer
|
|
8341
|
|
8342 @item resizing-buffer
|
|
8343
|
|
8344 @item dynarr
|
|
8345
|
|
8346 @item lisp-buffer
|
|
8347
|
|
8348 @item print
|
|
8349
|
|
8350 @item decoding
|
|
8351
|
|
8352 @item encoding
|
|
8353 @end table
|
|
8354
|
462
|
8355 @node Lstream Functions
|
428
|
8356 @section Lstream Functions
|
462
|
8357 @cindex lstream functions
|
428
|
8358
|
442
|
8359 @deftypefun {Lstream *} Lstream_new (Lstream_implementation *@var{imp}, const char *@var{mode})
|
428
|
8360 Allocate and return a new Lstream. This function is not really meant to
|
|
8361 be called directly; rather, each stream type should provide its own
|
|
8362 stream creation function, which creates the stream and does any other
|
|
8363 necessary creation stuff (e.g. opening a file).
|
|
8364 @end deftypefun
|
|
8365
|
|
8366 @deftypefun void Lstream_set_buffering (Lstream *@var{lstr}, Lstream_buffering @var{buffering}, int @var{buffering_size})
|
|
8367 Change the buffering of a stream. See @file{lstream.h}. By default the
|
|
8368 buffering is @code{STREAM_BLOCK_BUFFERED}.
|
|
8369 @end deftypefun
|
|
8370
|
|
8371 @deftypefun int Lstream_flush (Lstream *@var{lstr})
|
|
8372 Flush out any pending unwritten data in the stream. Clear any buffered
|
|
8373 input data. Returns 0 on success, -1 on error.
|
|
8374 @end deftypefun
|
|
8375
|
|
8376 @deftypefn Macro int Lstream_putc (Lstream *@var{stream}, int @var{c})
|
|
8377 Write out one byte to the stream. This is a macro and so it is very
|
|
8378 efficient. The @var{c} argument is only evaluated once but the @var{stream}
|
|
8379 argument is evaluated more than once. Returns 0 on success, -1 on
|
|
8380 error.
|
|
8381 @end deftypefn
|
|
8382
|
|
8383 @deftypefn Macro int Lstream_getc (Lstream *@var{stream})
|
|
8384 Read one byte from the stream. This is a macro and so it is very
|
|
8385 efficient. The @var{stream} argument is evaluated more than once. Return
|
|
8386 value is -1 for EOF or error.
|
|
8387 @end deftypefn
|
|
8388
|
|
8389 @deftypefn Macro void Lstream_ungetc (Lstream *@var{stream}, int @var{c})
|
|
8390 Push one byte back onto the input queue. This will be the next byte
|
|
8391 read from the stream. Any number of bytes can be pushed back and will
|
440
|
8392 be read in the reverse order they were pushed back---most recent
|
|
8393 first. (This is necessary for consistency---if there are a number of
|
428
|
8394 bytes that have been unread and I read and unread a byte, it needs to be
|
|
8395 the first to be read again.) This is a macro and so it is very
|
|
8396 efficient. The @var{c} argument is only evaluated once but the @var{stream}
|
|
8397 argument is evaluated more than once.
|
|
8398 @end deftypefn
|
|
8399
|
|
8400 @deftypefun int Lstream_fputc (Lstream *@var{stream}, int @var{c})
|
|
8401 @deftypefunx int Lstream_fgetc (Lstream *@var{stream})
|
|
8402 @deftypefunx void Lstream_fungetc (Lstream *@var{stream}, int @var{c})
|
|
8403 Function equivalents of the above macros.
|
|
8404 @end deftypefun
|
|
8405
|
|
8406 @deftypefun ssize_t Lstream_read (Lstream *@var{stream}, void *@var{data}, size_t @var{size})
|
|
8407 Read @var{size} bytes of @var{data} from the stream. Return the number
|
|
8408 of bytes read. 0 means EOF. -1 means an error occurred and no bytes
|
|
8409 were read.
|
|
8410 @end deftypefun
|
|
8411
|
|
8412 @deftypefun ssize_t Lstream_write (Lstream *@var{stream}, void *@var{data}, size_t @var{size})
|
|
8413 Write @var{size} bytes of @var{data} to the stream. Return the number
|
|
8414 of bytes written. -1 means an error occurred and no bytes were written.
|
|
8415 @end deftypefun
|
|
8416
|
|
8417 @deftypefun void Lstream_unread (Lstream *@var{stream}, void *@var{data}, size_t @var{size})
|
|
8418 Push back @var{size} bytes of @var{data} onto the input queue. The next
|
|
8419 call to @code{Lstream_read()} with the same size will read the same
|
|
8420 bytes back. Note that this will be the case even if there is other
|
|
8421 pending unread data.
|
|
8422 @end deftypefun
|
|
8423
|
|
8424 @deftypefun int Lstream_close (Lstream *@var{stream})
|
|
8425 Close the stream. All data will be flushed out.
|
|
8426 @end deftypefun
|
|
8427
|
|
8428 @deftypefun void Lstream_reopen (Lstream *@var{stream})
|
|
8429 Reopen a closed stream. This enables I/O on it again. This is not
|
|
8430 meant to be called except from a wrapper routine that reinitializes
|
440
|
8431 variables and such---the close routine may well have freed some
|
428
|
8432 necessary storage structures, for example.
|
|
8433 @end deftypefun
|
|
8434
|
|
8435 @deftypefun void Lstream_rewind (Lstream *@var{stream})
|
|
8436 Rewind the stream to the beginning.
|
|
8437 @end deftypefun
|
|
8438
|
462
|
8439 @node Lstream Methods
|
428
|
8440 @section Lstream Methods
|
462
|
8441 @cindex lstream methods
|
428
|
8442
|
|
8443 @deftypefn {Lstream Method} ssize_t reader (Lstream *@var{stream}, unsigned char *@var{data}, size_t @var{size})
|
|
8444 Read some data from the stream's end and store it into @var{data}, which
|
|
8445 can hold @var{size} bytes. Return the number of bytes read. A return
|
|
8446 value of 0 means no bytes can be read at this time. This may be because
|
|
8447 of an EOF, or because there is a granularity greater than one byte that
|
|
8448 the stream imposes on the returned data, and @var{size} is less than
|
|
8449 this granularity. (This will happen frequently for streams that need to
|
|
8450 return whole characters, because @code{Lstream_read()} calls the reader
|
|
8451 function repeatedly until it has the number of bytes it wants or until 0
|
|
8452 is returned.) The lstream functions do not treat a 0 return as EOF or
|
|
8453 do anything special; however, the calling function will interpret any 0
|
|
8454 it gets back as EOF. This will normally not happen unless the caller
|
|
8455 calls @code{Lstream_read()} with a very small size.
|
|
8456
|
|
8457 This function can be @code{NULL} if the stream is output-only.
|
|
8458 @end deftypefn
|
|
8459
|
442
|
8460 @deftypefn {Lstream Method} ssize_t writer (Lstream *@var{stream}, const unsigned char *@var{data}, size_t @var{size})
|
428
|
8461 Send some data to the stream's end. Data to be sent is in @var{data}
|
|
8462 and is @var{size} bytes. Return the number of bytes sent. This
|
|
8463 function can send and return fewer bytes than is passed in; in that
|
|
8464 case, the function will just be called again until there is no data left
|
|
8465 or 0 is returned. A return value of 0 means that no more data can be
|
|
8466 currently stored, but there is no error; the data will be squirreled
|
|
8467 away until the writer can accept data. (This is useful, e.g., if you're
|
|
8468 dealing with a non-blocking file descriptor and are getting
|
|
8469 @code{EWOULDBLOCK} errors.) This function can be @code{NULL} if the
|
|
8470 stream is input-only.
|
|
8471 @end deftypefn
|
|
8472
|
|
8473 @deftypefn {Lstream Method} int rewinder (Lstream *@var{stream})
|
|
8474 Rewind the stream. If this is @code{NULL}, the stream is not seekable.
|
|
8475 @end deftypefn
|
|
8476
|
|
8477 @deftypefn {Lstream Method} int seekable_p (Lstream *@var{stream})
|
440
|
8478 Indicate whether this stream is seekable---i.e. it can be rewound.
|
428
|
8479 This method is ignored if the stream does not have a rewind method. If
|
|
8480 this method is not present, the result is determined by whether a rewind
|
|
8481 method is present.
|
|
8482 @end deftypefn
|
|
8483
|
|
8484 @deftypefn {Lstream Method} int flusher (Lstream *@var{stream})
|
|
8485 Perform any additional operations necessary to flush the data in this
|
|
8486 stream.
|
|
8487 @end deftypefn
|
|
8488
|
|
8489 @deftypefn {Lstream Method} int pseudo_closer (Lstream *@var{stream})
|
|
8490 @end deftypefn
|
|
8491
|
|
8492 @deftypefn {Lstream Method} int closer (Lstream *@var{stream})
|
|
8493 Perform any additional operations necessary to close this stream down.
|
|
8494 May be @code{NULL}. This function is called when @code{Lstream_close()}
|
|
8495 is called or when the stream is garbage-collected. When this function
|
|
8496 is called, all pending data in the stream will already have been written
|
|
8497 out.
|
|
8498 @end deftypefn
|
|
8499
|
|
8500 @deftypefn {Lstream Method} Lisp_Object marker (Lisp_Object @var{lstream}, void (*@var{markfun}) (Lisp_Object))
|
|
8501 Mark this object for garbage collection. Same semantics as a standard
|
|
8502 @code{Lisp_Object} marker. This function can be @code{NULL}.
|
|
8503 @end deftypefn
|
|
8504
|
|
8505 @node Consoles; Devices; Frames; Windows, The Redisplay Mechanism, Lstreams, Top
|
|
8506 @chapter Consoles; Devices; Frames; Windows
|
462
|
8507 @cindex consoles; devices; frames; windows
|
|
8508 @cindex devices; frames; windows, consoles;
|
|
8509 @cindex frames; windows, consoles; devices;
|
|
8510 @cindex windows, consoles; devices; frames;
|
428
|
8511
|
|
8512 @menu
|
|
8513 * Introduction to Consoles; Devices; Frames; Windows::
|
|
8514 * Point::
|
|
8515 * Window Hierarchy::
|
|
8516 * The Window Object::
|
|
8517 @end menu
|
|
8518
|
462
|
8519 @node Introduction to Consoles; Devices; Frames; Windows
|
428
|
8520 @section Introduction to Consoles; Devices; Frames; Windows
|
462
|
8521 @cindex consoles; devices; frames; windows, introduction to
|
|
8522 @cindex devices; frames; windows, introduction to consoles;
|
|
8523 @cindex frames; windows, introduction to consoles; devices;
|
|
8524 @cindex windows, introduction to consoles; devices; frames;
|
428
|
8525
|
|
8526 A window-system window that you see on the screen is called a
|
|
8527 @dfn{frame} in Emacs terminology. Each frame is subdivided into one or
|
|
8528 more non-overlapping panes, called (confusingly) @dfn{windows}. Each
|
|
8529 window displays the text of a buffer in it. (See above on Buffers.) Note
|
|
8530 that buffers and windows are independent entities: Two or more windows
|
|
8531 can be displaying the same buffer (potentially in different locations),
|
|
8532 and a buffer can be displayed in no windows.
|
|
8533
|
|
8534 A single display screen that contains one or more frames is called
|
|
8535 a @dfn{display}. Under most circumstances, there is only one display.
|
|
8536 However, more than one display can exist, for example if you have
|
|
8537 a @dfn{multi-headed} console, i.e. one with a single keyboard but
|
|
8538 multiple displays. (Typically in such a situation, the various
|
|
8539 displays act like one large display, in that the mouse is only
|
|
8540 in one of them at a time, and moving the mouse off of one moves
|
|
8541 it into another.) In some cases, the different displays will
|
|
8542 have different characteristics, e.g. one color and one mono.
|
|
8543
|
|
8544 XEmacs can display frames on multiple displays. It can even deal
|
|
8545 simultaneously with frames on multiple keyboards (called @dfn{consoles} in
|
|
8546 XEmacs terminology). Here is one case where this might be useful: You
|
|
8547 are using XEmacs on your workstation at work, and leave it running.
|
|
8548 Then you go home and dial in on a TTY line, and you can use the
|
|
8549 already-running XEmacs process to display another frame on your local
|
|
8550 TTY.
|
|
8551
|
|
8552 Thus, there is a hierarchy console -> display -> frame -> window.
|
|
8553 There is a separate Lisp object type for each of these four concepts.
|
|
8554 Furthermore, there is logically a @dfn{selected console},
|
|
8555 @dfn{selected display}, @dfn{selected frame}, and @dfn{selected window}.
|
|
8556 Each of these objects is distinguished in various ways, such as being the
|
|
8557 default object for various functions that act on objects of that type.
|
442
|
8558 Note that every containing object remembers the ``selected'' object
|
428
|
8559 among the objects that it contains: e.g. not only is there a selected
|
|
8560 window, but every frame remembers the last window in it that was
|
|
8561 selected, and changing the selected frame causes the remembered window
|
|
8562 within it to become the selected window. Similar relationships apply
|
|
8563 for consoles to devices and devices to frames.
|
|
8564
|
462
|
8565 @node Point
|
428
|
8566 @section Point
|
462
|
8567 @cindex point
|
428
|
8568
|
|
8569 Recall that every buffer has a current insertion position, called
|
|
8570 @dfn{point}. Now, two or more windows may be displaying the same buffer,
|
|
8571 and the text cursor in the two windows (i.e. @code{point}) can be in
|
|
8572 two different places. You may ask, how can that be, since each
|
|
8573 buffer has only one value of @code{point}? The answer is that each window
|
|
8574 also has a value of @code{point} that is squirreled away in it. There
|
|
8575 is only one selected window, and the value of ``point'' in that buffer
|
|
8576 corresponds to that window. When the selected window is changed
|
|
8577 from one window to another displaying the same buffer, the old
|
|
8578 value of @code{point} is stored into the old window's ``point'' and the
|
|
8579 value of @code{point} from the new window is retrieved and made the
|
|
8580 value of @code{point} in the buffer. This means that @code{window-point}
|
|
8581 for the selected window is potentially inaccurate, and if you
|
|
8582 want to retrieve the correct value of @code{point} for a window,
|
|
8583 you must special-case on the selected window and retrieve the
|
|
8584 buffer's point instead. This is related to why @code{save-window-excursion}
|
|
8585 does not save the selected window's value of @code{point}.
|
|
8586
|
462
|
8587 @node Window Hierarchy
|
428
|
8588 @section Window Hierarchy
|
|
8589 @cindex window hierarchy
|
|
8590 @cindex hierarchy of windows
|
|
8591
|
|
8592 If a frame contains multiple windows (panes), they are always created
|
|
8593 by splitting an existing window along the horizontal or vertical axis.
|
|
8594 Terminology is a bit confusing here: to @dfn{split a window
|
|
8595 horizontally} means to create two side-by-side windows, i.e. to make a
|
|
8596 @emph{vertical} cut in a window. Likewise, to @dfn{split a window
|
|
8597 vertically} means to create two windows, one above the other, by making
|
|
8598 a @emph{horizontal} cut.
|
|
8599
|
|
8600 If you split a window and then split again along the same axis, you
|
|
8601 will end up with a number of panes all arranged along the same axis.
|
|
8602 The precise way in which the splits were made should not be important,
|
|
8603 and this is reflected internally. Internally, all windows are arranged
|
|
8604 in a tree, consisting of two types of windows, @dfn{combination} windows
|
|
8605 (which have children, and are covered completely by those children) and
|
|
8606 @dfn{leaf} windows, which have no children and are visible. Every
|
|
8607 combination window has two or more children, all arranged along the same
|
|
8608 axis. There are (logically) two subtypes of windows, depending on
|
|
8609 whether their children are horizontally or vertically arrayed. There is
|
|
8610 always one root window, which is either a leaf window (if the frame
|
|
8611 contains only one window) or a combination window (if the frame contains
|
|
8612 more than one window). In the latter case, the root window will have
|
|
8613 two or more children, either horizontally or vertically arrayed, and
|
|
8614 each of those children will be either a leaf window or another
|
|
8615 combination window.
|
|
8616
|
|
8617 Here are some rules:
|
|
8618
|
|
8619 @enumerate
|
|
8620 @item
|
|
8621 Horizontal combination windows can never have children that are
|
|
8622 horizontal combination windows; same for vertical.
|
|
8623
|
|
8624 @item
|
|
8625 Only leaf windows can be split (obviously) and this splitting does one
|
|
8626 of two things: (a) turns the leaf window into a combination window and
|
|
8627 creates two new leaf children, or (b) turns the leaf window into one of
|
|
8628 the two new leaves and creates the other leaf. Rule (1) dictates which
|
|
8629 of these two outcomes happens.
|
|
8630
|
|
8631 @item
|
|
8632 Every combination window must have at least two children.
|
|
8633
|
|
8634 @item
|
|
8635 Leaf windows can never become combination windows. They can be deleted,
|
|
8636 however. If this results in a violation of (3), the parent combination
|
|
8637 window also gets deleted.
|
|
8638
|
|
8639 @item
|
|
8640 All functions that accept windows must be prepared to accept combination
|
|
8641 windows, and do something sane (e.g. signal an error if so).
|
|
8642 Combination windows @emph{do} escape to the Lisp level.
|
|
8643
|
|
8644 @item
|
|
8645 All windows have three fields governing their contents:
|
|
8646 these are @dfn{hchild} (a list of horizontally-arrayed children),
|
|
8647 @dfn{vchild} (a list of vertically-arrayed children), and @dfn{buffer}
|
|
8648 (the buffer contained in a leaf window). Exactly one of
|
444
|
8649 these will be non-@code{nil}. Remember that @dfn{horizontally-arrayed}
|
428
|
8650 means ``side-by-side'' and @dfn{vertically-arrayed} means
|
|
8651 @dfn{one above the other}.
|
|
8652
|
|
8653 @item
|
|
8654 Leaf windows also have markers in their @code{start} (the
|
|
8655 first buffer position displayed in the window) and @code{pointm}
|
440
|
8656 (the window's stashed value of @code{point}---see above) fields,
|
444
|
8657 while combination windows have @code{nil} in these fields.
|
428
|
8658
|
|
8659 @item
|
|
8660 The list of children for a window is threaded through the
|
|
8661 @code{next} and @code{prev} fields of each child window.
|
|
8662
|
|
8663 @item
|
|
8664 @strong{Deleted windows can be undeleted}. This happens as a result of
|
|
8665 restoring a window configuration, and is unlike frames, displays, and
|
|
8666 consoles, which, once deleted, can never be restored. Deleting a window
|
|
8667 does nothing except set a special @code{dead} bit to 1 and clear out the
|
|
8668 @code{next}, @code{prev}, @code{hchild}, and @code{vchild} fields, for
|
|
8669 GC purposes.
|
|
8670
|
|
8671 @item
|
440
|
8672 Most frames actually have two top-level windows---one for the
|
428
|
8673 minibuffer and one (the @dfn{root}) for everything else. The modeline
|
|
8674 (if present) separates these two. The @code{next} field of the root
|
|
8675 points to the minibuffer, and the @code{prev} field of the minibuffer
|
|
8676 points to the root. The other @code{next} and @code{prev} fields are
|
|
8677 @code{nil}, and the frame points to both of these windows.
|
|
8678 Minibuffer-less frames have no minibuffer window, and the @code{next}
|
|
8679 and @code{prev} of the root window are @code{nil}. Minibuffer-only
|
|
8680 frames have no root window, and the @code{next} of the minibuffer window
|
|
8681 is @code{nil} but the @code{prev} points to itself. (#### This is an
|
|
8682 artifact that should be fixed.)
|
|
8683 @end enumerate
|
|
8684
|
462
|
8685 @node The Window Object
|
428
|
8686 @section The Window Object
|
462
|
8687 @cindex window object, the
|
|
8688 @cindex object, the window
|
428
|
8689
|
|
8690 Windows have the following accessible fields:
|
|
8691
|
|
8692 @table @code
|
|
8693 @item frame
|
|
8694 The frame that this window is on.
|
|
8695
|
|
8696 @item mini_p
|
|
8697 Non-@code{nil} if this window is a minibuffer window.
|
|
8698
|
|
8699 @item buffer
|
|
8700 The buffer that the window is displaying. This may change often during
|
|
8701 the life of the window.
|
|
8702
|
|
8703 @item dedicated
|
|
8704 Non-@code{nil} if this window is dedicated to its buffer.
|
|
8705
|
|
8706 @item pointm
|
|
8707 @cindex window point internals
|
|
8708 This is the value of point in the current buffer when this window is
|
|
8709 selected; when it is not selected, it retains its previous value.
|
|
8710
|
|
8711 @item start
|
|
8712 The position in the buffer that is the first character to be displayed
|
|
8713 in the window.
|
|
8714
|
|
8715 @item force_start
|
|
8716 If this flag is non-@code{nil}, it says that the window has been
|
|
8717 scrolled explicitly by the Lisp program. This affects what the next
|
|
8718 redisplay does if point is off the screen: instead of scrolling the
|
|
8719 window to show the text around point, it moves point to a location that
|
|
8720 is on the screen.
|
|
8721
|
|
8722 @item last_modified
|
|
8723 The @code{modified} field of the window's buffer, as of the last time
|
|
8724 a redisplay completed in this window.
|
|
8725
|
|
8726 @item last_point
|
|
8727 The buffer's value of point, as of the last time
|
|
8728 a redisplay completed in this window.
|
|
8729
|
|
8730 @item left
|
|
8731 This is the left-hand edge of the window, measured in columns. (The
|
|
8732 leftmost column on the screen is @w{column 0}.)
|
|
8733
|
|
8734 @item top
|
|
8735 This is the top edge of the window, measured in lines. (The top line on
|
|
8736 the screen is @w{line 0}.)
|
|
8737
|
|
8738 @item height
|
|
8739 The height of the window, measured in lines.
|
|
8740
|
|
8741 @item width
|
|
8742 The width of the window, measured in columns.
|
|
8743
|
|
8744 @item next
|
|
8745 This is the window that is the next in the chain of siblings. It is
|
|
8746 @code{nil} in a window that is the rightmost or bottommost of a group of
|
|
8747 siblings.
|
|
8748
|
|
8749 @item prev
|
|
8750 This is the window that is the previous in the chain of siblings. It is
|
|
8751 @code{nil} in a window that is the leftmost or topmost of a group of
|
|
8752 siblings.
|
|
8753
|
|
8754 @item parent
|
|
8755 Internally, XEmacs arranges windows in a tree; each group of siblings has
|
|
8756 a parent window whose area includes all the siblings. This field points
|
|
8757 to a window's parent.
|
|
8758
|
|
8759 Parent windows do not display buffers, and play little role in display
|
|
8760 except to shape their child windows. Emacs Lisp programs usually have
|
|
8761 no access to the parent windows; they operate on the windows at the
|
|
8762 leaves of the tree, which actually display buffers.
|
|
8763
|
|
8764 @item hscroll
|
|
8765 This is the number of columns that the display in the window is scrolled
|
|
8766 horizontally to the left. Normally, this is 0.
|
|
8767
|
|
8768 @item use_time
|
|
8769 This is the last time that the window was selected. The function
|
|
8770 @code{get-lru-window} uses this field.
|
|
8771
|
|
8772 @item display_table
|
|
8773 The window's display table, or @code{nil} if none is specified for it.
|
|
8774
|
|
8775 @item update_mode_line
|
|
8776 Non-@code{nil} means this window's mode line needs to be updated.
|
|
8777
|
|
8778 @item base_line_number
|
|
8779 The line number of a certain position in the buffer, or @code{nil}.
|
|
8780 This is used for displaying the line number of point in the mode line.
|
|
8781
|
|
8782 @item base_line_pos
|
|
8783 The position in the buffer for which the line number is known, or
|
|
8784 @code{nil} meaning none is known.
|
|
8785
|
|
8786 @item region_showing
|
|
8787 If the region (or part of it) is highlighted in this window, this field
|
|
8788 holds the mark position that made one end of that region. Otherwise,
|
|
8789 this field is @code{nil}.
|
|
8790 @end table
|
|
8791
|
|
8792 @node The Redisplay Mechanism, Extents, Consoles; Devices; Frames; Windows, Top
|
|
8793 @chapter The Redisplay Mechanism
|
462
|
8794 @cindex redisplay mechanism, the
|
428
|
8795
|
|
8796 The redisplay mechanism is one of the most complicated sections of
|
|
8797 XEmacs, especially from a conceptual standpoint. This is doubly so
|
|
8798 because, unlike for the basic aspects of the Lisp interpreter, the
|
|
8799 computer science theories of how to efficiently handle redisplay are not
|
|
8800 well-developed.
|
|
8801
|
|
8802 When working with the redisplay mechanism, remember the Golden Rules
|
|
8803 of Redisplay:
|
|
8804
|
|
8805 @enumerate
|
|
8806 @item
|
|
8807 It Is Better To Be Correct Than Fast.
|
|
8808 @item
|
|
8809 Thou Shalt Not Run Elisp From Within Redisplay.
|
|
8810 @item
|
|
8811 It Is Better To Be Fast Than Not To Be.
|
|
8812 @end enumerate
|
|
8813
|
|
8814 @menu
|
|
8815 * Critical Redisplay Sections::
|
|
8816 * Line Start Cache::
|
|
8817 * Redisplay Piece by Piece::
|
|
8818 @end menu
|
|
8819
|
462
|
8820 @node Critical Redisplay Sections
|
428
|
8821 @section Critical Redisplay Sections
|
462
|
8822 @cindex redisplay sections, critical
|
428
|
8823 @cindex critical redisplay sections
|
|
8824
|
|
8825 Within this section, we are defenseless and assume that the
|
|
8826 following cannot happen:
|
|
8827
|
|
8828 @enumerate
|
|
8829 @item
|
|
8830 garbage collection
|
|
8831 @item
|
|
8832 Lisp code evaluation
|
|
8833 @item
|
|
8834 frame size changes
|
|
8835 @end enumerate
|
|
8836
|
|
8837 We ensure (3) by calling @code{hold_frame_size_changes()}, which
|
|
8838 will cause any pending frame size changes to get put on hold
|
|
8839 till after the end of the critical section. (1) follows
|
|
8840 automatically if (2) is met. #### Unfortunately, there are
|
|
8841 some places where Lisp code can be called within this section.
|
|
8842 We need to remove them.
|
|
8843
|
|
8844 If @code{Fsignal()} is called during this critical section, we
|
|
8845 will @code{abort()}.
|
|
8846
|
|
8847 If garbage collection is called during this critical section,
|
|
8848 we simply return. #### We should abort instead.
|
|
8849
|
|
8850 #### If a frame-size change does occur we should probably
|
|
8851 actually be preempting redisplay.
|
|
8852
|
462
|
8853 @node Line Start Cache
|
428
|
8854 @section Line Start Cache
|
|
8855 @cindex line start cache
|
|
8856
|
|
8857 The traditional scrolling code in Emacs breaks in a variable height
|
|
8858 world. It depends on the key assumption that the number of lines that
|
|
8859 can be displayed at any given time is fixed. This led to a complete
|
|
8860 separation of the scrolling code from the redisplay code. In order to
|
|
8861 fully support variable height lines, the scrolling code must actually be
|
|
8862 tightly integrated with redisplay. Only redisplay can determine how
|
|
8863 many lines will be displayed on a screen for any given starting point.
|
|
8864
|
|
8865 What is ideally wanted is a complete list of the starting buffer
|
|
8866 position for every possible display line of a buffer along with the
|
|
8867 height of that display line. Maintaining such a full list would be very
|
|
8868 expensive. We settle for having it include information for all areas
|
|
8869 which we happen to generate anyhow (i.e. the region currently being
|
|
8870 displayed) and for those areas we need to work with.
|
|
8871
|
|
8872 In order to ensure that the cache accurately represents what redisplay
|
|
8873 would actually show, it is necessary to invalidate it in many
|
|
8874 situations. If the buffer changes, the starting positions may no longer
|
|
8875 be correct. If a face or an extent has changed then the line heights
|
|
8876 may have altered. These events happen frequently enough that the cache
|
|
8877 can end up being constantly disabled. With this potentially constant
|
|
8878 invalidation when is the cache ever useful?
|
|
8879
|
|
8880 Even if the cache is invalidated before every single usage, it is
|
|
8881 necessary. Scrolling often requires knowledge about display lines which
|
|
8882 are actually above or below the visible region. The cache provides a
|
|
8883 convenient light-weight method of storing this information for multiple
|
|
8884 display regions. This knowledge is necessary for the scrolling code to
|
|
8885 always obey the First Golden Rule of Redisplay.
|
|
8886
|
|
8887 If the cache already contains all of the information that the scrolling
|
|
8888 routines happen to need so that it doesn't have to go generate it, then
|
|
8889 we are able to obey the Third Golden Rule of Redisplay. The first thing
|
|
8890 we do to help out the cache is to always add the displayed region. This
|
|
8891 region had to be generated anyway, so the cache ends up getting the
|
|
8892 information basically for free. In those cases where a user is simply
|
|
8893 scrolling around viewing a buffer there is a high probability that this
|
|
8894 is sufficient to always provide the needed information. The second
|
|
8895 thing we can do is be smart about invalidating the cache.
|
|
8896
|
440
|
8897 TODO---Be smart about invalidating the cache. Potential places:
|
428
|
8898
|
|
8899 @itemize @bullet
|
|
8900 @item
|
|
8901 Insertions at end-of-line which don't cause line-wraps do not alter the
|
|
8902 starting positions of any display lines. These types of buffer
|
|
8903 modifications should not invalidate the cache. This is actually a large
|
|
8904 optimization for redisplay speed as well.
|
|
8905 @item
|
|
8906 Buffer modifications frequently only affect the display of lines at and
|
|
8907 below where they occur. In these situations we should only invalidate
|
|
8908 the part of the cache starting at where the modification occurs.
|
|
8909 @end itemize
|
|
8910
|
|
8911 In case you're wondering, the Second Golden Rule of Redisplay is not
|
|
8912 applicable.
|
|
8913
|
462
|
8914 @node Redisplay Piece by Piece
|
428
|
8915 @section Redisplay Piece by Piece
|
462
|
8916 @cindex redisplay piece by piece
|
428
|
8917
|
|
8918 As you can begin to see redisplay is complex and also not well
|
|
8919 documented. Chuck no longer works on XEmacs so this section is my take
|
|
8920 on the workings of redisplay.
|
|
8921
|
|
8922 Redisplay happens in three phases:
|
|
8923
|
|
8924 @enumerate
|
|
8925 @item
|
|
8926 Determine desired display in area that needs redisplay.
|
|
8927 Implemented by @code{redisplay.c}
|
|
8928 @item
|
|
8929 Compare desired display with current display
|
|
8930 Implemented by @code{redisplay-output.c}
|
|
8931 @item
|
|
8932 Output changes Implemented by @code{redisplay-output.c},
|
|
8933 @code{redisplay-x.c}, @code{redisplay-msw.c} and @code{redisplay-tty.c}
|
|
8934 @end enumerate
|
|
8935
|
442
|
8936 Steps 1 and 2 are device-independent and relatively complex. Step 3 is
|
428
|
8937 mostly device-dependent.
|
|
8938
|
|
8939 Determining the desired display
|
|
8940
|
|
8941 Display attributes are stored in @code{display_line} structures. Each
|
|
8942 @code{display_line} consists of a set of @code{display_block}'s and each
|
|
8943 @code{display_block} contains a number of @code{rune}'s. Generally
|
|
8944 dynarr's of @code{display_line}'s are held by each window representing
|
|
8945 the current display and the desired display.
|
|
8946
|
442
|
8947 The @code{display_line} structures are tightly tied to buffers which
|
428
|
8948 presents a problem for redisplay as this connection is bogus for the
|
|
8949 modeline. Hence the @code{display_line} generation routines are
|
|
8950 duplicated for generating the modeline. This means that the modeline
|
|
8951 display code has many bugs that the standard redisplay code does not.
|
|
8952
|
|
8953 The guts of @code{display_line} generation are in
|
|
8954 @code{create_text_block}, which creates a single display line for the
|
|
8955 desired locale. This incrementally parses the characters on the current
|
442
|
8956 line and generates redisplay structures for each.
|
428
|
8957
|
|
8958 Gutter redisplay is different. Because the data to display is stored in
|
|
8959 a string we cannot use @code{create_text_block}. Instead we use
|
|
8960 @code{create_text_string_block} which performs the same function as
|
|
8961 @code{create_text_block} but for strings. Many of the complexities of
|
|
8962 @code{create_text_block} to do with cursor handling and selective
|
|
8963 display have been removed.
|
|
8964
|
|
8965 @node Extents, Faces, The Redisplay Mechanism, Top
|
|
8966 @chapter Extents
|
462
|
8967 @cindex extents
|
428
|
8968
|
|
8969 @menu
|
|
8970 * Introduction to Extents:: Extents are ranges over text, with properties.
|
|
8971 * Extent Ordering:: How extents are ordered internally.
|
|
8972 * Format of the Extent Info:: The extent information in a buffer or string.
|
|
8973 * Zero-Length Extents:: A weird special case.
|
442
|
8974 * Mathematics of Extent Ordering:: A rigorous foundation.
|
428
|
8975 * Extent Fragments:: Cached information useful for redisplay.
|
|
8976 @end menu
|
|
8977
|
462
|
8978 @node Introduction to Extents
|
428
|
8979 @section Introduction to Extents
|
462
|
8980 @cindex extents, introduction to
|
428
|
8981
|
|
8982 Extents are regions over a buffer, with a start and an end position
|
|
8983 denoting the region of the buffer included in the extent. In
|
|
8984 addition, either end can be closed or open, meaning that the endpoint
|
|
8985 is or is not logically included in the extent. Insertion of a character
|
|
8986 at a closed endpoint causes the character to go inside the extent;
|
|
8987 insertion at an open endpoint causes the character to go outside.
|
|
8988
|
|
8989 Extent endpoints are stored using memory indices (see @file{insdel.c}),
|
|
8990 to minimize the amount of adjusting that needs to be done when
|
|
8991 characters are inserted or deleted.
|
|
8992
|
|
8993 (Formerly, extent endpoints at the gap could be either before or
|
|
8994 after the gap, depending on the open/closedness of the endpoint.
|
|
8995 The intent of this was to make it so that insertions would
|
|
8996 automatically go inside or out of extents as necessary with no
|
|
8997 further work needing to be done. It didn't work out that way,
|
|
8998 however, and just ended up complexifying and buggifying all the
|
|
8999 rest of the code.)
|
|
9000
|
462
|
9001 @node Extent Ordering
|
428
|
9002 @section Extent Ordering
|
462
|
9003 @cindex extent ordering
|
428
|
9004
|
|
9005 Extents are compared using memory indices. There are two orderings
|
|
9006 for extents and both orders are kept current at all times. The normal
|
|
9007 or @dfn{display} order is as follows:
|
|
9008
|
|
9009 @example
|
|
9010 Extent A is ``less than'' extent B,
|
|
9011 that is, earlier in the display order,
|
|
9012 if: A-start < B-start,
|
|
9013 or if: A-start = B-start, and A-end > B-end
|
|
9014 @end example
|
|
9015
|
|
9016 So if two extents begin at the same position, the larger of them is the
|
|
9017 earlier one in the display order (@code{EXTENT_LESS} is true).
|
|
9018
|
|
9019 For the e-order, the same thing holds:
|
|
9020
|
|
9021 @example
|
|
9022 Extent A is ``less than'' extent B in e-order,
|
|
9023 that is, later in the buffer,
|
|
9024 if: A-end < B-end,
|
|
9025 or if: A-end = B-end, and A-start > B-start
|
|
9026 @end example
|
|
9027
|
|
9028 So if two extents end at the same position, the smaller of them is the
|
|
9029 earlier one in the e-order (@code{EXTENT_E_LESS} is true).
|
|
9030
|
|
9031 The display order and the e-order are complementary orders: any
|
|
9032 theorem about the display order also applies to the e-order if you swap
|
|
9033 all occurrences of ``display order'' and ``e-order'', ``less than'' and
|
|
9034 ``greater than'', and ``extent start'' and ``extent end''.
|
|
9035
|
462
|
9036 @node Format of the Extent Info
|
428
|
9037 @section Format of the Extent Info
|
462
|
9038 @cindex extent info, format of the
|
428
|
9039
|
|
9040 An extent-info structure consists of a list of the buffer or string's
|
|
9041 extents and a @dfn{stack of extents} that lists all of the extents over
|
|
9042 a particular position. The stack-of-extents info is used for
|
440
|
9043 optimization purposes---it basically caches some info that might
|
428
|
9044 be expensive to compute. Certain otherwise hard computations are easy
|
|
9045 given the stack of extents over a particular position, and if the
|
|
9046 stack of extents over a nearby position is known (because it was
|
|
9047 calculated at some prior point in time), it's easy to move the stack
|
|
9048 of extents to the proper position.
|
|
9049
|
|
9050 Given that the stack of extents is an optimization, and given that
|
|
9051 it requires memory, a string's stack of extents is wiped out each
|
|
9052 time a garbage collection occurs. Therefore, any time you retrieve
|
|
9053 the stack of extents, it might not be there. If you need it to
|
|
9054 be there, use the @code{_force} version.
|
|
9055
|
|
9056 Similarly, a string may or may not have an extent_info structure.
|
|
9057 (Generally it won't if there haven't been any extents added to the
|
|
9058 string.) So use the @code{_force} version if you need the extent_info
|
|
9059 structure to be there.
|
|
9060
|
|
9061 A list of extents is maintained as a double gap array: one gap array
|
|
9062 is ordered by start index (the @dfn{display order}) and the other is
|
|
9063 ordered by end index (the @dfn{e-order}). Note that positions in an
|
|
9064 extent list should logically be conceived of as referring @emph{to} a
|
|
9065 particular extent (as is the norm in programs) rather than sitting
|
|
9066 between two extents. Note also that callers of these functions should
|
|
9067 not be aware of the fact that the extent list is implemented as an
|
|
9068 array, except for the fact that positions are integers (this should be
|
|
9069 generalized to handle integers and linked list equally well).
|
|
9070
|
462
|
9071 @node Zero-Length Extents
|
428
|
9072 @section Zero-Length Extents
|
462
|
9073 @cindex zero-length extents
|
|
9074 @cindex extents, zero-length
|
428
|
9075
|
|
9076 Extents can be zero-length, and will end up that way if their endpoints
|
444
|
9077 are explicitly set that way or if their detachable property is @code{nil}
|
428
|
9078 and all the text in the extent is deleted. (The exception is open-open
|
|
9079 zero-length extents, which are barred from existing because there is
|
|
9080 no sensible way to define their properties. Deletion of the text in
|
|
9081 an open-open extent causes it to be converted into a closed-open
|
|
9082 extent.) Zero-length extents are primarily used to represent
|
|
9083 annotations, and behave as follows:
|
|
9084
|
|
9085 @enumerate
|
|
9086 @item
|
|
9087 Insertion at the position of a zero-length extent expands the extent
|
|
9088 if both endpoints are closed; goes after the extent if it is closed-open;
|
|
9089 and goes before the extent if it is open-closed.
|
|
9090
|
|
9091 @item
|
|
9092 Deletion of a character on a side of a zero-length extent whose
|
|
9093 corresponding endpoint is closed causes the extent to be detached if
|
|
9094 it is detachable; if the extent is not detachable or the corresponding
|
|
9095 endpoint is open, the extent remains in the buffer, moving as necessary.
|
|
9096 @end enumerate
|
|
9097
|
|
9098 Note that closed-open, non-detachable zero-length extents behave
|
|
9099 exactly like markers and that open-closed, non-detachable zero-length
|
|
9100 extents behave like the ``point-type'' marker in Mule.
|
|
9101
|
462
|
9102 @node Mathematics of Extent Ordering
|
428
|
9103 @section Mathematics of Extent Ordering
|
462
|
9104 @cindex mathematics of extent ordering
|
428
|
9105 @cindex extent mathematics
|
|
9106 @cindex extent ordering
|
|
9107
|
|
9108 @cindex display order of extents
|
|
9109 @cindex extents, display order
|
|
9110 The extents in a buffer are ordered by ``display order'' because that
|
|
9111 is that order that the redisplay mechanism needs to process them in.
|
|
9112 The e-order is an auxiliary ordering used to facilitate operations
|
|
9113 over extents. The operations that can be performed on the ordered
|
|
9114 list of extents in a buffer are
|
|
9115
|
|
9116 @enumerate
|
|
9117 @item
|
|
9118 Locate where an extent would go if inserted into the list.
|
|
9119 @item
|
|
9120 Insert an extent into the list.
|
|
9121 @item
|
|
9122 Remove an extent from the list.
|
|
9123 @item
|
|
9124 Map over all the extents that overlap a range.
|
|
9125 @end enumerate
|
|
9126
|
|
9127 (4) requires being able to determine the first and last extents
|
|
9128 that overlap a range.
|
|
9129
|
|
9130 NOTE: @dfn{overlap} is used as follows:
|
|
9131
|
|
9132 @itemize @bullet
|
|
9133 @item
|
|
9134 two ranges overlap if they have at least one point in common.
|
|
9135 Whether the endpoints are open or closed makes a difference here.
|
|
9136 @item
|
|
9137 a point overlaps a range if the point is contained within the
|
|
9138 range; this is equivalent to treating a point @math{P} as the range
|
|
9139 @math{[P, P]}.
|
|
9140 @item
|
|
9141 In the case of an @emph{extent} overlapping a point or range, the extent
|
|
9142 is normally treated as having closed endpoints. This applies
|
|
9143 consistently in the discussion of stacks of extents and such below.
|
|
9144 Note that this definition of overlap is not necessarily consistent with
|
|
9145 the extents that @code{map-extents} maps over, since @code{map-extents}
|
|
9146 sometimes pays attention to whether the endpoints of an extents are open
|
|
9147 or closed. But for our purposes, it greatly simplifies things to treat
|
|
9148 all extents as having closed endpoints.
|
|
9149 @end itemize
|
|
9150
|
|
9151 First, define @math{>}, @math{<}, @math{<=}, etc. as applied to extents
|
|
9152 to mean comparison according to the display order. Comparison between
|
|
9153 an extent @math{E} and an index @math{I} means comparison between
|
|
9154 @math{E} and the range @math{[I, I]}.
|
|
9155
|
|
9156 Also define @math{e>}, @math{e<}, @math{e<=}, etc. to mean comparison
|
|
9157 according to the e-order.
|
|
9158
|
|
9159 For any range @math{R}, define @math{R(0)} to be the starting index of
|
|
9160 the range and @math{R(1)} to be the ending index of the range.
|
|
9161
|
|
9162 For any extent @math{E}, define @math{E(next)} to be the extent directly
|
|
9163 following @math{E}, and @math{E(prev)} to be the extent directly
|
|
9164 preceding @math{E}. Assume @math{E(next)} and @math{E(prev)} can be
|
|
9165 determined from @math{E} in constant time. (This is because we store
|
|
9166 the extent list as a doubly linked list.)
|
|
9167
|
|
9168 Similarly, define @math{E(e-next)} and @math{E(e-prev)} to be the
|
|
9169 extents directly following and preceding @math{E} in the e-order.
|
|
9170
|
|
9171 Now:
|
|
9172
|
|
9173 Let @math{R} be a range.
|
|
9174 Let @math{F} be the first extent overlapping @math{R}.
|
|
9175 Let @math{L} be the last extent overlapping @math{R}.
|
|
9176
|
|
9177 Theorem 1: @math{R(1)} lies between @math{L} and @math{L(next)},
|
|
9178 i.e. @math{L <= R(1) < L(next)}.
|
|
9179
|
|
9180 This follows easily from the definition of display order. The
|
|
9181 basic reason that this theorem applies is that the display order
|
|
9182 sorts by increasing starting index.
|
|
9183
|
|
9184 Therefore, we can determine @math{L} just by looking at where we would
|
|
9185 insert @math{R(1)} into the list, and if we know @math{F} and are moving
|
|
9186 forward over extents, we can easily determine when we've hit @math{L} by
|
|
9187 comparing the extent we're at to @math{R(1)}.
|
|
9188
|
|
9189 @example
|
|
9190 Theorem 2: @math{F(e-prev) e< [1, R(0)] e<= F}.
|
|
9191 @end example
|
|
9192
|
|
9193 This is the analog of Theorem 1, and applies because the e-order
|
|
9194 sorts by increasing ending index.
|
|
9195
|
|
9196 Therefore, @math{F} can be found in the same amount of time as
|
|
9197 operation (1), i.e. the time that it takes to locate where an extent
|
|
9198 would go if inserted into the e-order list.
|
|
9199
|
|
9200 If the lists were stored as balanced binary trees, then operation (1)
|
|
9201 would take logarithmic time, which is usually quite fast. However,
|
|
9202 currently they're stored as simple doubly-linked lists, and instead we
|
|
9203 do some caching to try to speed things up.
|
|
9204
|
|
9205 Define a @dfn{stack of extents} (or @dfn{SOE}) as the set of extents
|
|
9206 (ordered in the display order) that overlap an index @math{I}, together
|
|
9207 with the SOE's @dfn{previous} extent, which is an extent that precedes
|
|
9208 @math{I} in the e-order. (Hopefully there will not be very many extents
|
|
9209 between @math{I} and the previous extent.)
|
|
9210
|
|
9211 Now:
|
|
9212
|
|
9213 Let @math{I} be an index, let @math{S} be the stack of extents on
|
|
9214 @math{I}, let @math{F} be the first extent in @math{S}, and let @math{P}
|
|
9215 be @math{S}'s previous extent.
|
|
9216
|
|
9217 Theorem 3: The first extent in @math{S} is the first extent that overlaps
|
|
9218 any range @math{[I, J]}.
|
|
9219
|
|
9220 Proof: Any extent that overlaps @math{[I, J]} but does not include
|
|
9221 @math{I} must have a start index @math{> I}, and thus be greater than
|
|
9222 any extent in @math{S}.
|
|
9223
|
|
9224 Therefore, finding the first extent that overlaps a range @math{R} is
|
|
9225 the same as finding the first extent that overlaps @math{R(0)}.
|
|
9226
|
|
9227 Theorem 4: Let @math{I2} be an index such that @math{I2 > I}, and let
|
|
9228 @math{F2} be the first extent that overlaps @math{I2}. Then, either
|
|
9229 @math{F2} is in @math{S} or @math{F2} is greater than any extent in
|
|
9230 @math{S}.
|
|
9231
|
|
9232 Proof: If @math{F2} does not include @math{I} then its start index is
|
|
9233 greater than @math{I} and thus it is greater than any extent in
|
|
9234 @math{S}, including @math{F}. Otherwise, @math{F2} includes @math{I}
|
|
9235 and thus is in @math{S}, and thus @math{F2 >= F}.
|
|
9236
|
462
|
9237 @node Extent Fragments
|
428
|
9238 @section Extent Fragments
|
462
|
9239 @cindex extent fragments
|
|
9240 @cindex fragments, extent
|
428
|
9241
|
|
9242 Imagine that the buffer is divided up into contiguous, non-overlapping
|
|
9243 @dfn{runs} of text such that no extent starts or ends within a run
|
|
9244 (extents that abut the run don't count).
|
|
9245
|
|
9246 An extent fragment is a structure that holds data about the run that
|
|
9247 contains a particular buffer position (if the buffer position is at the
|
440
|
9248 junction of two runs, the run after the position is used)---the
|
428
|
9249 beginning and end of the run, a list of all of the extents in that run,
|
|
9250 the @dfn{merged face} that results from merging all of the faces
|
|
9251 corresponding to those extents, the begin and end glyphs at the
|
|
9252 beginning of the run, etc. This is the information that redisplay needs
|
|
9253 in order to display this run.
|
|
9254
|
|
9255 Extent fragments have to be very quick to update to a new buffer
|
|
9256 position when moving linearly through the buffer. They rely on the
|
|
9257 stack-of-extents code, which does the heavy-duty algorithmic work of
|
|
9258 determining which extents overly a particular position.
|
|
9259
|
|
9260 @node Faces, Glyphs, Extents, Top
|
|
9261 @chapter Faces
|
462
|
9262 @cindex faces
|
428
|
9263
|
|
9264 Not yet documented.
|
|
9265
|
|
9266 @node Glyphs, Specifiers, Faces, Top
|
|
9267 @chapter Glyphs
|
462
|
9268 @cindex glyphs
|
428
|
9269
|
|
9270 Glyphs are graphical elements that can be displayed in XEmacs buffers or
|
|
9271 gutters. We use the term graphical element here in the broadest possible
|
446
|
9272 sense since glyphs can be as mundane as text or as arcane as a native
|
428
|
9273 tab widget.
|
|
9274
|
|
9275 In XEmacs, glyphs represent the uninstantiated state of graphical
|
|
9276 elements, i.e. they hold all the information necessary to produce an
|
446
|
9277 image on-screen but the image need not exist at this stage, and multiple
|
|
9278 screen images can be instantiated from a single glyph.
|
428
|
9279
|
|
9280 Glyphs are lazily instantiated by calling one of the glyph
|
|
9281 functions. This usually occurs within redisplay when
|
|
9282 @code{Fglyph_height} is called. Instantiation causes an image-instance
|
454
|
9283 to be created and cached. This cache is on a per-device basis for all glyphs
|
|
9284 except widget-glyphs, and on a per-window basis for widgets-glyphs. The
|
428
|
9285 caching is done by @code{image_instantiate} and is necessary because it
|
|
9286 is generally possible to display an image-instance in multiple
|
|
9287 domains. For instance if we create a Pixmap, we can actually display
|
|
9288 this on multiple windows - even though we only need a single Pixmap
|
|
9289 instance to do this. If caching wasn't done then it would be necessary
|
442
|
9290 to create image-instances for every displayable occurrence of a glyph -
|
428
|
9291 and every usage - and this would be extremely memory and cpu intensive.
|
|
9292
|
|
9293 Widget-glyphs (a.k.a native widgets) are not cached in this way. This is
|
|
9294 because widget-glyph image-instances on screen are toolkit windows, and
|
|
9295 thus cannot be reused in multiple XEmacs domains. Thus widget-glyphs are
|
446
|
9296 cached on an XEmacs window basis.
|
428
|
9297
|
|
9298 Any action on a glyph first consults the cache before actually
|
|
9299 instantiating a widget.
|
|
9300
|
454
|
9301 @section Glyph Instantiation
|
462
|
9302 @cindex glyph instantiation
|
|
9303 @cindex instantiation, glyph
|
454
|
9304
|
|
9305 Glyph instantiation is a hairy topic and requires some explanation. The
|
|
9306 guts of glyph instantiation is contained within
|
|
9307 @code{image_instantiate}. A glyph contains an image which is a
|
|
9308 specifier. When a glyph function - for instance @code{Fglyph_height} -
|
|
9309 asks for a property of the glyph that can only be determined from its
|
|
9310 instantiated state, then the glyph image is instantiated and an image
|
|
9311 instance created. The instantiation process is governed by the specifier
|
|
9312 code and goes through a series of steps:
|
|
9313
|
|
9314 @itemize @bullet
|
|
9315 @item
|
|
9316 Validation. Instantiation of image instances happens dynamically - often
|
|
9317 within the guts of redisplay. Thus it is often not feasible to catch
|
|
9318 instantiator errors at instantiation time. Instead the instantiator is
|
|
9319 validated at the time it is added to the image specifier. This function
|
|
9320 is defined by @code{image_validate} and at a simple level validates
|
|
9321 keyword value pairs.
|
|
9322 @item
|
|
9323 Duplication. The specifier code by default takes a copy of the
|
|
9324 instantiator. This is reasonable for most specifiers but in the case of
|
|
9325 widget-glyphs can be problematic, since some of the properties in the
|
|
9326 instantiator - for instance callbacks - could cause infinite recursion
|
|
9327 in the copying process. Thus the image code defines a function -
|
|
9328 @code{image_copy_instantiator} - which will selectively copy values.
|
|
9329 This is controlled by the way that a keyword is defined either using
|
|
9330 @code{IIFORMAT_VALID_KEYWORD} or
|
|
9331 @code{IIFORMAT_VALID_NONCOPY_KEYWORD}. Note that the image caching and
|
|
9332 redisplay code relies on instantiator copying to ensure that current and
|
|
9333 new instantiators are actually different rather than referring to the
|
|
9334 same thing.
|
|
9335 @item
|
|
9336 Normalization. Once the instantiator has been copied it must be
|
|
9337 converted into a form that is viable at instantiation time. This can
|
|
9338 involve no changes at all, but typically involves things like converting
|
|
9339 file names to the actual data. This function is defined by
|
|
9340 @code{image_going_to_add} and @code{normalize_image_instantiator}.
|
|
9341 @item
|
|
9342 Instantiation. When an image instance is actually required for display
|
|
9343 it is instantiated using @code{image_instantiate}. This involves calling
|
|
9344 instantiate methods that are specific to the type of image being
|
|
9345 instantiated.
|
|
9346 @end itemize
|
|
9347
|
|
9348 The final instantiation phase also involves a number of steps. In order
|
|
9349 to understand these we need to describe a number of concepts.
|
|
9350
|
|
9351 An image is instantiated in a @dfn{domain}, where a domain can be any
|
|
9352 one of a device, frame, window or image-instance. The domain gives the
|
|
9353 image-instance context and identity and properties that affect the
|
|
9354 appearance of the image-instance may be different for the same glyph
|
|
9355 instantiated in different domains. An example is the face used to
|
|
9356 display the image-instance.
|
|
9357
|
|
9358 Although an image is instantiated in a particular domain the
|
|
9359 instantiation domain is not necessarily the domain in which the
|
|
9360 image-instance is cached. For example a pixmap can be instantiated in a
|
|
9361 window be actually be cached on a per-device basis. The domain in which
|
|
9362 the image-instance is actually cached is called the
|
|
9363 @dfn{governing-domain}. A governing-domain is currently either a device
|
|
9364 or a window. Widget-glyphs and text-glyphs have a window as a
|
|
9365 governing-domain, all other image-instances have a device as the
|
|
9366 governing-domain. The governing domain for an image-instance is
|
|
9367 determined using the governing_domain image-instance method.
|
|
9368
|
|
9369 @section Widget-Glyphs
|
462
|
9370 @cindex widget-glyphs
|
454
|
9371
|
440
|
9372 @section Widget-Glyphs in the MS-Windows Environment
|
462
|
9373 @cindex widget-glyphs in the MS-Windows environment
|
|
9374 @cindex MS-Windows environment, widget-glyphs in the
|
428
|
9375
|
|
9376 To Do
|
|
9377
|
|
9378 @section Widget-Glyphs in the X Environment
|
462
|
9379 @cindex widget-glyphs in the X environment
|
|
9380 @cindex X environment, widget-glyphs in the
|
428
|
9381
|
446
|
9382 Widget-glyphs under X make heavy use of lwlib (@pxref{Lucid Widget
|
|
9383 Library}) for manipulating the native toolkit objects. This is primarily
|
|
9384 so that different toolkits can be supported for widget-glyphs, just as
|
|
9385 they are supported for features such as menubars etc.
|
428
|
9386
|
454
|
9387 Lwlib is extremely poorly documented and quite hairy so here is my
|
|
9388 understanding of what goes on.
|
|
9389
|
|
9390 Lwlib maintains a set of widget_instances which mirror the hierarchical
|
|
9391 state of Xt widgets. I think this is so that widgets can be updated and
|
|
9392 manipulated generically by the lwlib library. For instance
|
|
9393 update_one_widget_instance can cope with multiple types of widget and
|
|
9394 multiple types of toolkit. Each element in the widget hierarchy is updated
|
|
9395 from its corresponding widget_instance by walking the widget_instance
|
|
9396 tree recursively.
|
|
9397
|
|
9398 This has desirable properties such as lw_modify_all_widgets which is
|
|
9399 called from @file{glyphs-x.c} and updates all the properties of a widget
|
|
9400 without having to know what the widget is or what toolkit it is from.
|
|
9401 Unfortunately this also has hairy properties such as making the lwlib
|
|
9402 code quite complex. And of course lwlib has to know at some level what
|
|
9403 the widget is and how to set its properties.
|
|
9404
|
428
|
9405 @node Specifiers, Menus, Glyphs, Top
|
|
9406 @chapter Specifiers
|
462
|
9407 @cindex specifiers
|
428
|
9408
|
|
9409 Not yet documented.
|
|
9410
|
|
9411 @node Menus, Subprocesses, Specifiers, Top
|
|
9412 @chapter Menus
|
462
|
9413 @cindex menus
|
428
|
9414
|
|
9415 A menu is set by setting the value of the variable
|
|
9416 @code{current-menubar} (which may be buffer-local) and then calling
|
|
9417 @code{set-menubar-dirty-flag} to signal a change. This will cause the
|
|
9418 menu to be redrawn at the next redisplay. The format of the data in
|
|
9419 @code{current-menubar} is described in @file{menubar.c}.
|
|
9420
|
|
9421 Internally the data in current-menubar is parsed into a tree of
|
|
9422 @code{widget_value's} (defined in @file{lwlib.h}); this is accomplished
|
|
9423 by the recursive function @code{menu_item_descriptor_to_widget_value()},
|
|
9424 called by @code{compute_menubar_data()}. Such a tree is deallocated
|
|
9425 using @code{free_widget_value()}.
|
|
9426
|
|
9427 @code{update_screen_menubars()} is one of the external entry points.
|
|
9428 This checks to see, for each screen, if that screen's menubar needs to
|
|
9429 be updated. This is the case if
|
|
9430
|
|
9431 @enumerate
|
|
9432 @item
|
|
9433 @code{set-menubar-dirty-flag} was called since the last redisplay. (This
|
|
9434 function sets the C variable menubar_has_changed.)
|
|
9435 @item
|
|
9436 The buffer displayed in the screen has changed.
|
|
9437 @item
|
|
9438 The screen has no menubar currently displayed.
|
|
9439 @end enumerate
|
|
9440
|
|
9441 @code{set_screen_menubar()} is called for each such screen. This
|
|
9442 function calls @code{compute_menubar_data()} to create the tree of
|
|
9443 widget_value's, then calls @code{lw_create_widget()},
|
|
9444 @code{lw_modify_all_widgets()}, and/or @code{lw_destroy_all_widgets()}
|
|
9445 to create the X-Toolkit widget associated with the menu.
|
|
9446
|
|
9447 @code{update_psheets()}, the other external entry point, actually
|
|
9448 changes the menus being displayed. It uses the widgets fixed by
|
|
9449 @code{update_screen_menubars()} and calls various X functions to ensure
|
|
9450 that the menus are displayed properly.
|
|
9451
|
|
9452 The menubar widget is set up so that @code{pre_activate_callback()} is
|
|
9453 called when the menu is first selected (i.e. mouse button goes down),
|
|
9454 and @code{menubar_selection_callback()} is called when an item is
|
|
9455 selected. @code{pre_activate_callback()} calls the function in
|
|
9456 activate-menubar-hook, which can change the menubar (this is described
|
|
9457 in @file{menubar.c}). If the menubar is changed,
|
|
9458 @code{set_screen_menubars()} is called.
|
|
9459 @code{menubar_selection_callback()} enqueues a menu event, putting in it
|
|
9460 a function to call (either @code{eval} or @code{call-interactively}) and
|
|
9461 its argument, which is the callback function or form given in the menu's
|
|
9462 description.
|
|
9463
|
446
|
9464 @node Subprocesses, Interface to the X Window System, Menus, Top
|
428
|
9465 @chapter Subprocesses
|
462
|
9466 @cindex subprocesses
|
428
|
9467
|
|
9468 The fields of a process are:
|
|
9469
|
|
9470 @table @code
|
|
9471 @item name
|
|
9472 A string, the name of the process.
|
|
9473
|
|
9474 @item command
|
|
9475 A list containing the command arguments that were used to start this
|
|
9476 process.
|
|
9477
|
|
9478 @item filter
|
|
9479 A function used to accept output from the process instead of a buffer,
|
|
9480 or @code{nil}.
|
|
9481
|
|
9482 @item sentinel
|
|
9483 A function called whenever the process receives a signal, or @code{nil}.
|
|
9484
|
|
9485 @item buffer
|
|
9486 The associated buffer of the process.
|
|
9487
|
|
9488 @item pid
|
|
9489 An integer, the Unix process @sc{id}.
|
|
9490
|
|
9491 @item childp
|
|
9492 A flag, non-@code{nil} if this is really a child process.
|
|
9493 It is @code{nil} for a network connection.
|
|
9494
|
|
9495 @item mark
|
|
9496 A marker indicating the position of the end of the last output from this
|
|
9497 process inserted into the buffer. This is often but not always the end
|
|
9498 of the buffer.
|
|
9499
|
|
9500 @item kill_without_query
|
|
9501 If this is non-@code{nil}, killing XEmacs while this process is still
|
|
9502 running does not ask for confirmation about killing the process.
|
|
9503
|
|
9504 @item raw_status_low
|
|
9505 @itemx raw_status_high
|
|
9506 These two fields record 16 bits each of the process status returned by
|
|
9507 the @code{wait} system call.
|
|
9508
|
|
9509 @item status
|
|
9510 The process status, as @code{process-status} should return it.
|
|
9511
|
|
9512 @item tick
|
|
9513 @itemx update_tick
|
|
9514 If these two fields are not equal, a change in the status of the process
|
|
9515 needs to be reported, either by running the sentinel or by inserting a
|
|
9516 message in the process buffer.
|
|
9517
|
|
9518 @item pty_flag
|
|
9519 Non-@code{nil} if communication with the subprocess uses a @sc{pty};
|
|
9520 @code{nil} if it uses a pipe.
|
|
9521
|
|
9522 @item infd
|
|
9523 The file descriptor for input from the process.
|
|
9524
|
|
9525 @item outfd
|
|
9526 The file descriptor for output to the process.
|
|
9527
|
|
9528 @item subtty
|
|
9529 The file descriptor for the terminal that the subprocess is using. (On
|
|
9530 some systems, there is no need to record this, so the value is
|
|
9531 @code{-1}.)
|
|
9532
|
|
9533 @item tty_name
|
|
9534 The name of the terminal that the subprocess is using,
|
|
9535 or @code{nil} if it is using pipes.
|
|
9536 @end table
|
|
9537
|
446
|
9538 @node Interface to the X Window System, Index, Subprocesses, Top
|
|
9539 @chapter Interface to the X Window System
|
462
|
9540 @cindex X Window System, interface to the
|
446
|
9541
|
|
9542 Mostly undocumented.
|
|
9543
|
|
9544 @menu
|
|
9545 * Lucid Widget Library:: An interface to various widget sets.
|
|
9546 @end menu
|
|
9547
|
462
|
9548 @node Lucid Widget Library
|
446
|
9549 @section Lucid Widget Library
|
462
|
9550 @cindex Lucid Widget Library
|
|
9551 @cindex widget library, Lucid
|
|
9552 @cindex library, Lucid Widget
|
446
|
9553
|
|
9554 Lwlib is extremely poorly documented and quite hairy. The author(s)
|
|
9555 blame that on X, Xt, and Motif, with some justice, but also sufficient
|
|
9556 hypocrisy to avoid drawing the obvious conclusion about their own work.
|
|
9557
|
|
9558 The Lucid Widget Library is composed of two more or less independent
|
|
9559 pieces. The first, as the name suggests, is a set of widgets. These
|
|
9560 widgets are intended to resemble and improve on widgets provided in the
|
|
9561 Motif toolkit but not in the Athena widgets, including menubars and
|
|
9562 scrollbars. Recent additions by Andy Piper integrate some ``modern''
|
|
9563 widgets by Edward Falk, including checkboxes, radio buttons, progress
|
|
9564 gauges, and index tab controls (aka notebooks).
|
|
9565
|
|
9566 The second piece of the Lucid widget library is a generic interface to
|
|
9567 several toolkits for X (including Xt, the Athena widget set, and Motif,
|
|
9568 as well as the Lucid widgets themselves) so that core XEmacs code need
|
|
9569 not know which widget set has been used to build the graphical user
|
|
9570 interface.
|
|
9571
|
|
9572 @menu
|
|
9573 * Generic Widget Interface:: The lwlib generic widget interface.
|
|
9574 * Scrollbars::
|
|
9575 * Menubars::
|
|
9576 * Checkboxes and Radio Buttons::
|
|
9577 * Progress Bars::
|
|
9578 * Tab Controls::
|
|
9579 @end menu
|
|
9580
|
462
|
9581 @node Generic Widget Interface
|
446
|
9582 @subsection Generic Widget Interface
|
462
|
9583 @cindex widget interface, generic
|
446
|
9584
|
|
9585 In general in any toolkit a widget may be a composite object. In Xt,
|
|
9586 all widgets have an X window that they manage, but typically a complex
|
|
9587 widget will have widget children, each of which manages a subwindow of
|
|
9588 the parent widget's X window. These children may themselves be
|
|
9589 composite widgets. Thus a widget is actually a tree or hierarchy of
|
|
9590 widgets.
|
|
9591
|
|
9592 For each toolkit widget, lwlib maintains a tree of @code{widget_values}
|
|
9593 which mirror the hierarchical state of Xt widgets (including Motif,
|
|
9594 Athena, 3D Athena, and Falk's widget sets). Each @code{widget_value}
|
|
9595 has @code{contents} member, which points to the head of a linked list of
|
|
9596 its children. The linked list of siblings is chained through the
|
|
9597 @code{next} member of @code{widget_value}.
|
|
9598
|
|
9599 @example
|
|
9600 +-----------+
|
|
9601 | composite |
|
|
9602 +-----------+
|
|
9603 |
|
|
9604 | contents
|
|
9605 V
|
|
9606 +-------+ next +-------+ next +-------+
|
|
9607 | child |----->| child |----->| child |
|
|
9608 +-------+ +-------+ +-------+
|
|
9609 |
|
|
9610 | contents
|
|
9611 V
|
|
9612 +-------------+ next +-------------+
|
|
9613 | grand child |----->| grand child |
|
|
9614 +-------------+ +-------------+
|
|
9615
|
|
9616 The @code{widget_value} hierarchy of a composite widget with two simple
|
|
9617 children and one composite child.
|
|
9618 @end example
|
|
9619
|
|
9620 The @code{widget_instance} structure maintains the inverse view of the
|
|
9621 tree. As for the @code{widget_value}, siblings are chained through the
|
|
9622 @code{next} member. However, rather than naming children, the
|
|
9623 @code{widget_instance} tree links to parents.
|
|
9624
|
|
9625 @example
|
|
9626 +-----------+
|
|
9627 | composite |
|
|
9628 +-----------+
|
|
9629 A
|
|
9630 | parent
|
|
9631 |
|
|
9632 +-------+ next +-------+ next +-------+
|
|
9633 | child |----->| child |----->| child |
|
|
9634 +-------+ +-------+ +-------+
|
|
9635 A
|
|
9636 | parent
|
|
9637 |
|
|
9638 +-------------+ next +-------------+
|
|
9639 | grand child |----->| grand child |
|
|
9640 +-------------+ +-------------+
|
|
9641
|
|
9642 The @code{widget_value} hierarchy of a composite widget with two simple
|
|
9643 children and one composite child.
|
|
9644 @end example
|
|
9645
|
|
9646 This permits widgets derived from different toolkits to be updated and
|
|
9647 manipulated generically by the lwlib library. For instance
|
|
9648 @code{update_one_widget_instance} can cope with multiple types of widget
|
|
9649 and multiple types of toolkit. Each element in the widget hierarchy is
|
|
9650 updated from its corresponding @code{widget_value} by walking the
|
|
9651 @code{widget_value} tree. This has desirable properties. For example,
|
|
9652 @code{lw_modify_all_widgets} is called from @file{glyphs-x.c} and
|
|
9653 updates all the properties of a widget without having to know what the
|
|
9654 widget is or what toolkit it is from. Unfortunately this also has its
|
|
9655 hairy properties; the lwlib code quite complex. And of course lwlib has
|
|
9656 to know at some level what the widget is and how to set its properties.
|
|
9657
|
|
9658 The @code{widget_instance} structure also contains a pointer to the root
|
|
9659 of its tree. Widget instances are further confi
|
|
9660
|
|
9661
|
462
|
9662 @node Scrollbars
|
446
|
9663 @subsection Scrollbars
|
462
|
9664 @cindex scrollbars
|
|
9665
|
|
9666 @node Menubars
|
446
|
9667 @subsection Menubars
|
462
|
9668 @cindex menubars
|
|
9669
|
|
9670 @node Checkboxes and Radio Buttons
|
446
|
9671 @subsection Checkboxes and Radio Buttons
|
462
|
9672 @cindex checkboxes and radio buttons
|
|
9673 @cindex radio buttons, checkboxes and
|
|
9674 @cindex buttons, checkboxes and radio
|
|
9675
|
|
9676 @node Progress Bars
|
446
|
9677 @subsection Progress Bars
|
462
|
9678 @cindex progress bars
|
|
9679 @cindex bars, progress
|
|
9680
|
|
9681 @node Tab Controls
|
446
|
9682 @subsection Tab Controls
|
462
|
9683 @cindex tab controls
|
428
|
9684
|
|
9685 @include index.texi
|
|
9686
|
|
9687 @c Print the tables of contents
|
|
9688 @summarycontents
|
|
9689 @contents
|
|
9690 @c That's all
|
|
9691
|
|
9692 @bye
|