0
|
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
|
|
9 Copyright @copyright{} 1992 - 1996 Ben Wing.
|
116
|
10 Copyright @copyright{} 1996, 1997 Sun Microsystems.
|
0
|
11 Copyright @copyright{} 1994, 1995 Free Software Foundation.
|
|
12 Copyright @copyright{} 1994, 1995 Board of Trustees, University of Illinois.
|
|
13
|
|
14
|
|
15 Permission is granted to make and distribute verbatim copies of this
|
|
16 manual provided the copyright notice and this permission notice are
|
|
17 preserved on all copies.
|
|
18
|
|
19 @ignore
|
|
20 Permission is granted to process this file through TeX and print the
|
|
21 results, provided the printed document carries copying permission notice
|
|
22 identical to this one except for the removal of this paragraph (this
|
|
23 paragraph not being relevant to the printed manual).
|
|
24
|
|
25 @end ignore
|
|
26 Permission is granted to copy and distribute modified versions of this
|
|
27 manual under the conditions for verbatim copying, provided that the
|
|
28 entire resulting derived work is distributed under the terms of a
|
|
29 permission notice identical to this one.
|
|
30
|
|
31 Permission is granted to copy and distribute translations of this manual
|
|
32 into another language, under the above conditions for modified versions,
|
|
33 except that this permission notice may be stated in a translation
|
|
34 approved by the Foundation.
|
|
35
|
|
36 Permission is granted to copy and distribute modified versions of this
|
|
37 manual under the conditions for verbatim copying, provided also that the
|
|
38 section entitled ``GNU General Public License'' is included exactly as
|
|
39 in the original, and provided that the entire resulting derived work is
|
|
40 distributed under the terms of a permission notice identical to this
|
|
41 one.
|
|
42
|
|
43 Permission is granted to copy and distribute translations of this manual
|
|
44 into another language, under the above conditions for modified versions,
|
|
45 except that the section entitled ``GNU General Public License'' may be
|
|
46 included in a translation approved by the Free Software Foundation
|
|
47 instead of in the original English.
|
|
48 @end ifinfo
|
|
49
|
|
50 @c Combine indices.
|
|
51 @synindex cp fn
|
|
52 @syncodeindex vr fn
|
|
53 @syncodeindex ky fn
|
|
54 @syncodeindex pg fn
|
|
55 @syncodeindex tp fn
|
|
56
|
|
57 @setchapternewpage odd
|
|
58 @finalout
|
|
59
|
|
60 @titlepage
|
|
61 @title XEmacs Internals Manual
|
116
|
62 @subtitle Version 1.1, March 1997
|
0
|
63
|
|
64 @author Ben Wing
|
116
|
65 @author Martin Buchholz
|
0
|
66 @page
|
|
67 @vskip 0pt plus 1fill
|
|
68
|
|
69 @noindent
|
|
70 Copyright @copyright{} 1992 - 1996 Ben Wing. @*
|
|
71 Copyright @copyright{} 1996 Sun Microsystems, Inc. @*
|
|
72 Copyright @copyright{} 1994 Free Software Foundation. @*
|
|
73 Copyright @copyright{} 1994, 1995 Board of Trustees, University of Illinois.
|
|
74
|
|
75 @sp 2
|
116
|
76 Version 1.1 @*
|
|
77 March, 1997.@*
|
0
|
78
|
|
79 Permission is granted to make and distribute verbatim copies of this
|
|
80 manual provided the copyright notice and this permission notice are
|
|
81 preserved on all copies.
|
|
82
|
|
83 Permission is granted to copy and distribute modified versions of this
|
|
84 manual under the conditions for verbatim copying, provided also that the
|
|
85 section entitled ``GNU General Public License'' is included
|
|
86 exactly as in the original, and provided that the entire resulting
|
|
87 derived work is distributed under the terms of a permission notice
|
|
88 identical to this one.
|
|
89
|
|
90 Permission is granted to copy and distribute translations of this manual
|
|
91 into another language, under the above conditions for modified versions,
|
|
92 except that the section entitled ``GNU General Public License'' may be
|
|
93 included in a translation approved by the Free Software Foundation
|
|
94 instead of in the original English.
|
|
95 @end titlepage
|
|
96 @page
|
|
97
|
|
98 @node Top, A History of Emacs, (dir), (dir)
|
|
99
|
|
100 @ifinfo
|
|
101 This Info file contains v1.0 of the XEmacs Internals Manual.
|
|
102 @end ifinfo
|
|
103
|
|
104 @menu
|
|
105 * A History of Emacs:: Times, dates, important events.
|
|
106 * XEmacs From the Outside:: A broad conceptual overview.
|
|
107 * The Lisp Language:: An overview.
|
|
108 * XEmacs From the Perspective of Building::
|
|
109 * XEmacs From the Inside::
|
|
110 * The XEmacs Object System (Abstractly Speaking)::
|
|
111 * How Lisp Objects Are Represented in C::
|
|
112 * Rules When Writing New C Code::
|
|
113 * A Summary of the Various XEmacs Modules::
|
|
114 * Allocation of Objects in XEmacs Lisp::
|
|
115 * Events and the Event Loop::
|
|
116 * Evaluation; Stack Frames; Bindings::
|
|
117 * Symbols and Variables::
|
|
118 * Buffers and Textual Representation::
|
|
119 * MULE Character Sets and Encodings::
|
|
120 * The Lisp Reader and Compiler::
|
|
121 * Lstreams::
|
|
122 * Consoles; Devices; Frames; Windows::
|
|
123 * The Redisplay Mechanism::
|
|
124 * Extents::
|
|
125 * Faces and Glyphs::
|
|
126 * Specifiers::
|
|
127 * Menus::
|
|
128 * Subprocesses::
|
|
129 * Interface to X Windows::
|
|
130 * Index:: Index including concepts, functions, variables,
|
|
131 and other terms.
|
|
132
|
|
133 --- The Detailed Node Listing ---
|
|
134
|
|
135 Here are other nodes that are inferiors of those already listed,
|
|
136 mentioned here so you can get to them in one step:
|
|
137
|
|
138 A History of Emacs
|
|
139
|
|
140 * Through Version 18:: Unification prevails.
|
|
141 * Lucid Emacs:: One version 19 Emacs.
|
|
142 * GNU Emacs 19:: The other version 19 Emacs.
|
|
143 * XEmacs:: The continuation of Lucid Emacs.
|
|
144
|
|
145 Rules When Writing New C Code
|
|
146
|
|
147 * General Coding Rules::
|
|
148 * Writing Lisp Primitives::
|
|
149 * Adding Global Lisp Variables::
|
2
|
150 * Techniques for XEmacs Developers::
|
0
|
151
|
|
152 A Summary of the Various XEmacs Modules
|
|
153
|
|
154 * Low-Level Modules::
|
|
155 * Basic Lisp Modules::
|
|
156 * Modules for Standard Editing Operations::
|
|
157 * Editor-Level Control Flow Modules::
|
|
158 * Modules for the Basic Displayable Lisp Objects::
|
|
159 * Modules for other Display-Related Lisp Objects::
|
|
160 * Modules for the Redisplay Mechanism::
|
|
161 * Modules for Interfacing with the File System::
|
|
162 * Modules for Other Aspects of the Lisp Interpreter and Object System::
|
|
163 * Modules for Interfacing with the Operating System::
|
|
164 * Modules for Interfacing with X Windows::
|
|
165 * Modules for Internationalization::
|
|
166
|
|
167 Allocation of Objects in XEmacs Lisp
|
|
168
|
|
169 * Introduction to Allocation::
|
|
170 * Garbage Collection::
|
|
171 * GCPROing::
|
|
172 * Integers and Characters::
|
|
173 * Allocation from Frob Blocks::
|
|
174 * lrecords::
|
|
175 * Low-level allocation::
|
|
176 * Pure Space::
|
|
177 * Cons::
|
|
178 * Vector::
|
|
179 * Bit Vector::
|
|
180 * Symbol::
|
|
181 * Marker::
|
|
182 * String::
|
|
183 * Bytecode::
|
|
184
|
|
185 Events and the Event Loop
|
|
186
|
|
187 * Introduction to Events::
|
|
188 * Main Loop::
|
|
189 * Specifics of the Event Gathering Mechanism::
|
|
190 * Specifics About the Emacs Event::
|
|
191 * The Event Stream Callback Routines::
|
|
192 * Other Event Loop Functions::
|
|
193 * Converting Events::
|
|
194 * Dispatching Events; The Command Builder::
|
|
195
|
|
196 Evaluation; Stack Frames; Bindings
|
|
197
|
|
198 * Evaluation::
|
|
199 * Dynamic Binding; The specbinding Stack; Unwind-Protects::
|
|
200 * Simple Special Forms::
|
|
201 * Catch and Throw::
|
|
202
|
|
203 Symbols and Variables
|
|
204
|
|
205 * Introduction to Symbols::
|
|
206 * Obarrays::
|
|
207 * Symbol Values::
|
|
208
|
|
209 Buffers and Textual Representation
|
|
210
|
|
211 * Introduction to Buffers:: A buffer holds a block of text such as a file.
|
70
|
212 * A Buffer@'s Text:: Representation of the text in a buffer.
|
0
|
213 * Buffer Lists:: Keeping track of all buffers.
|
|
214 * Markers and Extents:: Tagging locations within a buffer.
|
|
215 * Bufbytes and Emchars:: Representation of individual characters.
|
|
216 * The Buffer Object:: The Lisp object corresponding to a buffer.
|
|
217
|
|
218 MULE Character Sets and Encodings
|
|
219
|
|
220 * Character Sets::
|
|
221 * Encodings::
|
|
222 * Internal Mule Encodings::
|
|
223
|
|
224 Encodings
|
|
225
|
|
226 * Japanese EUC (Extended Unix Code)::
|
|
227 * JIS7::
|
|
228
|
|
229 Internal Mule Encodings
|
|
230
|
|
231 * Internal String Encoding::
|
|
232 * Internal Character Encoding::
|
|
233
|
|
234 The Lisp Reader and Compiler
|
|
235
|
|
236 Lstreams
|
|
237
|
|
238 Consoles; Devices; Frames; Windows
|
|
239
|
|
240 * Introduction to Consoles; Devices; Frames; Windows::
|
|
241 * Point::
|
|
242 * Window Hierarchy::
|
|
243
|
|
244 The Redisplay Mechanism
|
|
245
|
|
246 * Critical Redisplay Sections::
|
|
247 * Line Start Cache::
|
|
248
|
|
249 Extents
|
|
250
|
|
251 * Introduction to Extents:: Extents are ranges over text, with properties.
|
|
252 * Extent Ordering:: How extents are ordered internally.
|
|
253 * Format of the Extent Info:: The extent information in a buffer or string.
|
|
254 * Zero-Length Extents:: A weird special case.
|
|
255 * Mathematics of Extent Ordering:: A rigorous foundation.
|
|
256 * Extent Fragments:: Cached information useful for redisplay.
|
|
257
|
|
258 Faces and Glyphs
|
|
259
|
|
260 Specifiers
|
|
261
|
|
262 Menus
|
|
263
|
|
264 Subprocesses
|
|
265
|
|
266 Interface to X Windows
|
|
267
|
|
268 @end menu
|
|
269
|
|
270 @node A History of Emacs, XEmacs From the Outside, Top, Top
|
|
271 @chapter A History of Emacs
|
|
272 @cindex history of Emacs
|
|
273 @cindex Hackers (Steven Levy)
|
|
274 @cindex Levy, Steven
|
|
275 @cindex ITS (Incompatible Timesharing System)
|
|
276 @cindex Stallman, Richard
|
|
277 @cindex RMS
|
|
278 @cindex MIT
|
|
279 @cindex TECO
|
|
280 @cindex FSF
|
|
281 @cindex Free Software Foundation
|
|
282
|
|
283 XEmacs is a powerful, customizable text editor and development
|
|
284 environment. It began as Lucid Emacs, which was in turn derived from
|
|
285 GNU Emacs, a program written by Richard Stallman of the Free Software
|
|
286 Foundation. GNU Emacs dates back to the 1970's, and was modelled
|
|
287 after a package called ``Emacs'', written in 1976, that was a set of
|
|
288 macros on top of TECO, an old, old text editor written at MIT on the
|
|
289 DEC PDP 10 under one of the earliest time-sharing operating systems,
|
|
290 ITS (Incompatible Timesharing System). (ITS dates back well before
|
|
291 Unix.) ITS, TECO, and Emacs were products of a group of people at MIT
|
|
292 who called themselves ``hackers'', who shared an idealistic belief
|
|
293 system about the free exchange of information and were fanatical in
|
|
294 their devotion to and time spent with computers. (The hacker
|
|
295 subculture dates back to the late 1950's at MIT and is described in
|
|
296 detail in Steven Levy's book @cite{Hackers}. This book also includes
|
|
297 a lot of information about Stallman himself and the development of
|
|
298 Lisp, a programming language developed at MIT that underlies Emacs.)
|
|
299
|
|
300 @menu
|
|
301 * Through Version 18:: Unification prevails.
|
|
302 * Lucid Emacs:: One version 19 Emacs.
|
|
303 * GNU Emacs 19:: The other version 19 Emacs.
|
|
304 * XEmacs:: The continuation of Lucid Emacs.
|
|
305 @end menu
|
|
306
|
|
307 @node Through Version 18
|
|
308 @section Through Version 18
|
|
309 @cindex Gosling, James
|
|
310 @cindex Great Usenet Renaming
|
|
311
|
|
312 Although the history of the early versions of GNU Emacs is unclear,
|
|
313 the history is well-known from the middle of 1985. A time line is:
|
|
314
|
|
315 @itemize @bullet
|
|
316 @item
|
|
317 GNU Emacs version 15 (15.34) was released sometime in 1984 or 1985 and
|
|
318 shared some code with a version of Emacs written by James Gosling (the
|
|
319 same James Gosling who later created the Java language).
|
|
320 @item
|
|
321 GNU Emacs version 16 (first released version was 16.56) was released on
|
|
322 July 15, 1985. All Gosling code was removed due to potential copyright
|
|
323 problems with the code.
|
|
324 @item
|
|
325 version 16.57: released on September 16, 1985.
|
|
326 @item
|
|
327 versions 16.58, 16.59: released on September 17, 1985.
|
|
328 @item
|
|
329 version 16.60: released on September 19, 1985. These later version 16's
|
|
330 incorporated patches from the net, esp. for getting Emacs to work under
|
|
331 System V.
|
|
332 @item
|
|
333 version 17.36 (first official v17 release) released on December 20,
|
|
334 1985. Included a TeX-able user manual. First official unpatched
|
|
335 version that worked on vanilla System V machines.
|
|
336 @item
|
|
337 version 17.43 (second official v17 release) released on January 25,
|
|
338 1986.
|
|
339 @item
|
|
340 version 17.45 released on January 30, 1986.
|
|
341 @item
|
|
342 version 17.46 released on February 4, 1986.
|
|
343 @item
|
|
344 version 17.48 released on February 10, 1986.
|
|
345 @item
|
|
346 version 17.49 released on February 12, 1986.
|
|
347 @item
|
|
348 version 17.55 released on March 18, 1986.
|
|
349 @item
|
|
350 version 17.57 released on March 27, 1986.
|
|
351 @item
|
|
352 version 17.58 released on April 4, 1986.
|
|
353 @item
|
|
354 version 17.61 released on April 12, 1986.
|
|
355 @item
|
|
356 version 17.63 released on May 7, 1986.
|
|
357 @item
|
|
358 version 17.64 released on May 12, 1986.
|
|
359 @item
|
|
360 version 18.24 (a beta version) released on October 2, 1986.
|
|
361 @item
|
|
362 version 18.30 (a beta version) released on November 15, 1986.
|
|
363 @item
|
|
364 version 18.31 (a beta version) released on November 23, 1986.
|
|
365 @item
|
|
366 version 18.32 (a beta version) released on December 7, 1986.
|
|
367 @item
|
|
368 version 18.33 (a beta version) released on December 12, 1986.
|
|
369 @item
|
|
370 version 18.35 (a beta version) released on January 5, 1987.
|
|
371 @item
|
|
372 version 18.36 (a beta version) released on January 21, 1987.
|
|
373 @item
|
2
|
374 January 27, 1987: The Great Usenet Renaming. net.emacs is now
|
|
375 comp.emacs.
|
|
376 @item
|
0
|
377 version 18.37 (a beta version) released on February 12, 1987.
|
|
378 @item
|
|
379 version 18.38 (a beta version) released on March 3, 1987.
|
|
380 @item
|
|
381 version 18.39 (a beta version) released on March 14, 1987.
|
|
382 @item
|
|
383 version 18.40 (a beta version) released on March 18, 1987.
|
|
384 @item
|
|
385 version 18.41 (the first ``official'' release) released on March 22,
|
|
386 1987.
|
|
387 @item
|
|
388 version 18.45 released on June 2, 1987.
|
|
389 @item
|
|
390 version 18.46 released on June 9, 1987.
|
|
391 @item
|
|
392 version 18.47 released on June 18, 1987.
|
|
393 @item
|
|
394 version 18.48 released on September 3, 1987.
|
|
395 @item
|
|
396 version 18.49 released on September 18, 1987.
|
|
397 @item
|
|
398 version 18.50 released on February 13, 1988.
|
|
399 @item
|
|
400 version 18.51 released on May 7, 1988.
|
|
401 @item
|
|
402 version 18.52 released on September 1, 1988.
|
|
403 @item
|
|
404 version 18.53 released on February 24, 1989.
|
|
405 @item
|
|
406 version 18.54 released on April 26, 1989.
|
|
407 @item
|
|
408 version 18.55 released on August 23, 1989. This is the earliest version
|
|
409 that is still available by FTP.
|
|
410 @item
|
|
411 version 18.56 released on January 17, 1991.
|
|
412 @item
|
|
413 version 18.57 released late January, 1991.
|
|
414 @item
|
|
415 version 18.58 released ?????.
|
|
416 @item
|
|
417 version 18.59 released October 31, 1992.
|
|
418 @end itemize
|
|
419
|
|
420 @node Lucid Emacs
|
|
421 @section Lucid Emacs
|
|
422 @cindex Lucid Emacs
|
|
423 @cindex Lucid Inc.
|
|
424 @cindex Energize
|
|
425 @cindex Epoch
|
|
426
|
|
427 Lucid Emacs was developed by the (now-defunct) Lucid Inc., a maker of
|
|
428 C++ and Lisp development environments. It began when Lucid decided they
|
|
429 wanted to use Emacs as the editor and cornerstone of their C++
|
|
430 development environment (called ``Energize''). They needed many features
|
|
431 that were not available in the existing version of GNU Emacs (version
|
|
432 18.5something), in particular good and integrated support for GUI
|
|
433 elements such as mouse support, multiple fonts, multiple window-system
|
|
434 windows, etc. A branch of GNU Emacs called Epoch, written at the
|
|
435 University of Illinois, existed that supplied many of these features;
|
|
436 however, Lucid needed more than what existed in Epoch. At the time, the
|
|
437 Free Software Foundation was working on version 19 of Emacs (this was
|
|
438 sometime around 1991), which was planned to have similar features, and
|
|
439 so Lucid decided to work with the Free Software Foundation. Their plan
|
|
440 was to add features that they needed, and coordinate with the FSF so
|
|
441 that the features would get included back into Emacs version 19.
|
|
442
|
|
443 Delays in the release of version 19 occurred, however (resulting in it
|
|
444 finally being released more than a year after what was initially
|
|
445 planned), and Lucid encountered unexpected technical resistance in
|
|
446 getting their changes merged back into version 19, so they decided to
|
|
447 release their own version of Emacs, which became Lucid Emacs 19.0.
|
|
448
|
|
449 @cindex Zawinski, Jamie
|
|
450 @cindex Sexton, Harlan
|
|
451 @cindex Benson, Eric
|
|
452 @cindex Devin, Matthieu
|
|
453 The initial authors of Lucid Emacs were Matthieu Devin, Harlan Sexton,
|
|
454 and Eric Benson, and the work was later taken over by Jamie Zawinski,
|
|
455 who became ``Mr. Lucid Emacs'' for many releases.
|
|
456
|
|
457 A time line for Lucid Emacs/XEmacs is
|
|
458
|
|
459 @itemize @bullet
|
|
460 @item
|
|
461 version 19.0 shipped with Energize 1.0, April 1992.
|
|
462 @item
|
|
463 version 19.1 released June 4, 1992.
|
|
464 @item
|
|
465 version 19.2 released June 19, 1992.
|
|
466 @item
|
|
467 version 19.3 released September 9, 1992.
|
|
468 @item
|
|
469 version 19.4 released January 21, 1993.
|
|
470 @item
|
|
471 version 19.5 was a repackaging of 19.4 with a few bug fixes and
|
|
472 shipped with Energize 2.0. Never released to the net.
|
|
473 @item
|
|
474 version 19.6 released April 9, 1993.
|
|
475 @item
|
|
476 version 19.7 was a repackaging of 19.6 with a few bug fixes and
|
|
477 shipped with Energize 2.1. Never released to the net.
|
|
478 @item
|
|
479 version 19.8 released September 6, 1993.
|
|
480 @item
|
|
481 version 19.9 released January 12, 1994.
|
|
482 @item
|
|
483 version 19.10 released May 27, 1994.
|
|
484 @item
|
|
485 version 19.11 (first XEmacs) released September 13, 1994.
|
|
486 @item
|
|
487 version 19.12 released June 23, 1995.
|
|
488 @item
|
|
489 version 19.13 released September 1, 1995.
|
112
|
490 @item
|
|
491 version 19.14 released June 23, 1996.
|
|
492 @item
|
|
493 version 20.0 released February 9, 1997.
|
120
|
494 @item
|
|
495 version 19.15 released March 28, 1997.
|
149
|
496 @item
|
|
497 version 20.1 (not released to the net) April 15, 1997.
|
|
498 @item
|
|
499 version 20.2 released May 16, 1997.
|
0
|
500 @end itemize
|
|
501
|
|
502 @node GNU Emacs 19
|
|
503 @section GNU Emacs 19
|
|
504 @cindex GNU Emacs 19
|
|
505 @cindex FSF Emacs
|
|
506
|
|
507 About a year after the initial release of Lucid Emacs, the FSF
|
|
508 released a beta of their version of Emacs 19 (referred to here as ``GNU
|
|
509 Emacs''). By this time, the current version of Lucid Emacs was
|
|
510 19.6. (Strangely, the first released beta from the FSF was GNU Emacs
|
|
511 19.7.) A time line for GNU Emacs version 19 is
|
|
512
|
|
513 @itemize @bullet
|
|
514 @item
|
|
515 version 19.8 (beta) released May 27, 1993.
|
|
516 @item
|
|
517 version 19.9 (beta) released May 27, 1993.
|
|
518 @item
|
|
519 version 19.10 (beta) released May 30, 1993.
|
|
520 @item
|
|
521 version 19.11 (beta) released June 1, 1993.
|
|
522 @item
|
|
523 version 19.12 (beta) released June 2, 1993.
|
|
524 @item
|
|
525 version 19.13 (beta) released June 8, 1993.
|
|
526 @item
|
|
527 version 19.14 (beta) released June 17, 1993.
|
|
528 @item
|
|
529 version 19.15 (beta) released June 19, 1993.
|
|
530 @item
|
|
531 version 19.16 (beta) released July 6, 1993.
|
|
532 @item
|
|
533 version 19.17 (beta) released late July, 1993.
|
|
534 @item
|
|
535 version 19.18 (beta) released August 9, 1993.
|
|
536 @item
|
|
537 version 19.19 (beta) released August 15, 1993.
|
|
538 @item
|
|
539 version 19.20 (beta) released November 17, 1993.
|
|
540 @item
|
|
541 version 19.21 (beta) released November 17, 1993.
|
|
542 @item
|
|
543 version 19.22 (beta) released November 28, 1993.
|
|
544 @item
|
|
545 version 19.23 (beta) released May 17, 1994.
|
|
546 @item
|
|
547 version 19.24 (beta) released May 16, 1994.
|
|
548 @item
|
|
549 version 19.25 (beta) released June 3, 1994.
|
|
550 @item
|
|
551 version 19.26 (beta) released September 11, 1994.
|
|
552 @item
|
|
553 version 19.27 (beta) released September 14, 1994.
|
|
554 @item
|
|
555 version 19.28 (first ``official'' release) released November 1, 1994.
|
|
556 @item
|
|
557 version 19.29 released June 21, 1995.
|
112
|
558 @item
|
|
559 version 19.30 released November 24, 1995.
|
|
560 @item
|
|
561 version 19.31 released May 25, 1996.
|
|
562 @item
|
|
563 version 19.32 released July 31, 1996.
|
|
564 @item
|
|
565 version 19.33 released August 11, 1996.
|
|
566 @item
|
|
567 version 19.34 released August 21, 1996.
|
|
568 @item
|
|
569 version 19.34b released September 6, 1996.
|
0
|
570 @end itemize
|
|
571
|
|
572 @cindex Mlynarik, Richard
|
|
573 In some ways, GNU Emacs 19 was better than Lucid Emacs; in some ways,
|
|
574 worse. Lucid soon began incorporating features from GNU Emacs 19 into
|
|
575 Lucid Emacs; the work was mostly done by Richard Mlynarik, who had been
|
|
576 working on and using GNU Emacs for a long time (back as far as version
|
|
577 16 or 17).
|
|
578
|
|
579 @node XEmacs
|
|
580 @section XEmacs
|
|
581 @cindex XEmacs
|
|
582
|
|
583 @cindex Sun Microsystems
|
|
584 @cindex University of Illinois
|
|
585 @cindex Illinois, University of
|
|
586 @cindex SPARCWorks
|
|
587 @cindex Andreessen, Marc
|
120
|
588 @cindex Baur, Steve
|
|
589 @cindex Buchholz, Martin
|
0
|
590 @cindex Kaplan, Simon
|
|
591 @cindex Wing, Ben
|
|
592 @cindex Thompson, Chuck
|
|
593 @cindex Win-Emacs
|
|
594 @cindex Epoch
|
|
595 @cindex Amdahl Corporation
|
|
596 Around the time that Lucid was developing Energize, Sun Microsystems
|
|
597 was developing their own development environment (called ``SPARCWorks'')
|
|
598 and also decided to use Emacs. They joined forces with the Epoch team
|
|
599 at the University of Illinois and later with Lucid. The maintainer of
|
|
600 the last-released version of Epoch was Marc Andreessen, but he dropped
|
|
601 out and the Epoch project, headed by Simon Kaplan, lured Chuck Thompson
|
|
602 away from a system administration job to become the primary Lucid Emacs
|
|
603 author for Epoch and Sun. Chuck's area of specialty became the
|
|
604 redisplay engine (he replaced the old Lucid Emacs redisplay engine with
|
|
605 a ported version from Epoch and then later rewrote it from scratch).
|
|
606 Sun also hired Ben Wing (the author of Win-Emacs, a port of Lucid Emacs
|
|
607 to Microsoft Windows 3.1) in 1993, for what was initially a one-month
|
|
608 contract to fix some event problems but later became a many-year
|
|
609 involvement, punctuated by a six-month contract with Amdahl Corporation.
|
|
610
|
|
611 @cindex rename to XEmacs
|
|
612 In 1994, Sun and Lucid agreed to rename Lucid Emacs to XEmacs (a name
|
|
613 not favorable to either company); the first release called XEmacs was
|
|
614 version 19.11. In June 1994, Lucid folded and Jamie quit to work for
|
|
615 the newly formed Mosaic Communications Corp., later Netscape
|
|
616 Communications Corp. (co-founded by the same Marc Andreessen, who had
|
|
617 quit his Epoch job to work on a graphical browser for the World Wide
|
|
618 Web). Chuck then become the primary maintainer of XEmacs, and put out
|
120
|
619 versions 19.11 through 19.14 in conjunction with Ben. For 19.12 and
|
0
|
620 19.13, Chuck added the new redisplay and many other display improvements
|
|
621 and Ben added MULE support (support for Asian and other languages) and
|
|
622 redesigned most of the internal Lisp subsystems to better support the
|
120
|
623 MULE work and the various other features being added to XEmacs. After
|
|
624 19.14 Chuck retired as primary maintainer and Steve Baur stepped in.
|
|
625
|
|
626 @cindex MULE merged XEmacs appears
|
|
627 Soon after 19.13 was released, work began in earnest on the MULE
|
|
628 internationalization code and the source tree was divided into two
|
|
629 development paths. The MULE version was initially called 19.20, but was
|
|
630 soon renamed to 20.0. In 1996 Martin Buchholz of Sun Microsystems took
|
|
631 over the care and feeding of it and worked on it in parallel with the
|
|
632 19.14 development that was occurring at the same time. After much work
|
|
633 by Martin, it was decided to release 20.0 ahead of 19.15 in February
|
|
634 1997. The source tree remained divided until 20.1 when the version 19
|
|
635 source was finally retired.
|
0
|
636
|
|
637 @cindex merging attempts
|
|
638 Many attempts have been made to merge XEmacs and GNU Emacs, but they
|
|
639 have consistently run into the same technical disagreements and other
|
|
640 problems that Lucid ran into when originally attempting to merge Lucid
|
|
641 Emacs into GNU Emacs.
|
|
642
|
|
643 A more detailed history is contained in the XEmacs About page.
|
|
644
|
|
645 @node XEmacs From the Outside, The Lisp Language, A History of Emacs, Top
|
|
646 @chapter XEmacs From the Outside
|
|
647 @cindex read-eval-print
|
|
648
|
|
649 XEmacs appears to the outside world as an editor, but it is really a
|
|
650 Lisp environment. At its heart is a Lisp interpreter; it also
|
|
651 ``happens'' to contain many specialized object types (e.g. buffers,
|
|
652 windows, frames, events) that are useful for implementing an editor.
|
|
653 Some of these objects (in particular windows and frames) have
|
|
654 displayable representations, and XEmacs provides a function
|
|
655 @code{redisplay()} that ensures that the display of all such objects
|
|
656 matches their internal state. Most of the time, a standard Lisp
|
|
657 environment is in a @dfn{read-eval-print} loop -- i.e. ``read some Lisp
|
|
658 code, execute it, and print the results''. XEmacs has a similar loop:
|
|
659
|
|
660 @itemize @bullet
|
|
661 @item
|
|
662 read an event
|
|
663 @item
|
|
664 dispatch the event (i.e. ``do it'')
|
|
665 @item
|
|
666 redisplay
|
|
667 @end itemize
|
|
668
|
|
669 Reading an event is done using the Lisp function @code{next-event},
|
|
670 which waits for something to happen (typically, the user presses a key
|
|
671 or moves the mouse) and returns an event object describing this.
|
|
672 Dispatching an event is done using the Lisp function
|
|
673 @code{dispatch-event}, which looks up the event in a keymap object (a
|
|
674 particular kind of object that associates an event with a Lisp function)
|
|
675 and calls that function. The function ``does'' what the user has
|
|
676 requested by changing the state of particular frame objects, buffer
|
|
677 objects, etc. Finally, @code{redisplay()} is called, which updates the
|
|
678 display to reflect those changes just made. Thus is an ``editor'' born.
|
|
679
|
|
680 @cindex bridge, playing
|
|
681 @cindex taxes, doing
|
|
682 @cindex pi, calculating
|
|
683 Note that you do not have to use XEmacs as an editor; you could just
|
|
684 as well make it do your taxes, compute pi, play bridge, etc. You'd just
|
|
685 have to write functions to do those operations in Lisp.
|
|
686
|
|
687 @node The Lisp Language, XEmacs From the Perspective of Building, XEmacs From the Outside, Top
|
|
688 @chapter The Lisp Language
|
|
689 @cindex Lisp vs. C
|
|
690 @cindex C vs. Lisp
|
|
691 @cindex Lisp vs. Java
|
|
692 @cindex Java vs. Lisp
|
|
693 @cindex dynamic scoping
|
|
694 @cindex scoping, dynamic
|
|
695 @cindex dynamic types
|
|
696 @cindex types, dynamic
|
|
697 @cindex Java
|
|
698 @cindex Common Lisp
|
|
699 @cindex Gosling, James
|
|
700
|
|
701 Lisp is a general-purpose language that is higher-level than C and in
|
|
702 many ways more powerful than C. Powerful dialects of Lisp such as
|
|
703 Common Lisp are probably much better languages for writing very large
|
|
704 applications than is C. (Unfortunately, for many non-technical
|
|
705 reasons C and its successor C++ have become the dominant languages for
|
|
706 application development. These languages are both inadequate for
|
|
707 extremely large applications, which is evidenced by the fact that newer,
|
|
708 larger programs are becoming ever harder to write and are requiring ever
|
|
709 more programmers despite great increases in C development environments;
|
|
710 and by the fact that, although hardware speeds and reliability have been
|
|
711 growing at an exponential rate, most software is still generally
|
|
712 considered to be slow and buggy.)
|
|
713
|
|
714 The new Java language holds promise as a better general-purpose
|
|
715 development language than C. Java has many features in common with
|
|
716 Lisp that are not shared by C (this is not a coincidence, since
|
|
717 Java was designed by James Gosling, a former Lisp hacker). This
|
|
718 will be discussed more later.
|
|
719
|
|
720 For those used to C, here is a summary of the basic differences between
|
|
721 C and Lisp:
|
|
722
|
|
723 @enumerate
|
|
724 @item
|
|
725 Lisp has an extremely regular syntax. Every function, expression,
|
|
726 and control statement is written in the form
|
|
727
|
|
728 @example
|
|
729 (@var{func} @var{arg1} @var{arg2} ...)
|
|
730 @end example
|
|
731
|
|
732 This is as opposed to C, which writes functions as
|
|
733
|
|
734 @example
|
|
735 func(@var{arg1}, @var{arg2}, ...)
|
|
736 @end example
|
|
737
|
|
738 but writes expressions involving operators as (e.g.)
|
|
739
|
|
740 @example
|
|
741 @var{arg1} + @var{arg2}
|
|
742 @end example
|
|
743
|
|
744 and writes control statements as (e.g.)
|
|
745
|
|
746 @example
|
|
747 while (@var{expr}) @{ @var{statement1}; @var{statement2}; ... @}
|
|
748 @end example
|
|
749
|
|
750 Lisp equivalents of the latter two would be
|
|
751
|
|
752 @example
|
|
753 (+ @var{arg1} @var{arg2} ...)
|
|
754 @end example
|
|
755
|
|
756 and
|
|
757
|
|
758 @example
|
|
759 (while @var{expr} @var{statement1} @var{statement2} ...)
|
|
760 @end example
|
|
761
|
|
762 @item
|
|
763 Lisp is a safe language. Assuming there are no bugs in the Lisp
|
|
764 interpreter/compiler, it is impossible to write a program that ``core
|
|
765 dumps'' or otherwise causes the machine to execute an illegal
|
|
766 instruction. This is very different from C, where perhaps the most
|
|
767 common outcome of a bug is exactly such a crash. A corollary of this is that
|
|
768 the C operation of casting a pointer is impossible (and unnecessary) in
|
|
769 Lisp, and that it is impossible to access memory outside the bounds of
|
|
770 an array.
|
|
771
|
|
772 @item
|
|
773 Programs and data are written in the same form. The
|
|
774 parenthesis-enclosing form described above for statements is the same
|
|
775 form used for the most common data type in Lisp, the list. Thus, it is
|
|
776 possible to represent any Lisp program using Lisp data types, and for
|
|
777 one program to construct Lisp statements and then dynamically
|
|
778 @dfn{evaluate} them, or cause them to execute.
|
|
779
|
|
780 @item
|
|
781 All objects are @dfn{dynamically typed}. This means that part of every
|
|
782 object is an indication of what type it is. A Lisp program can
|
|
783 manipulate an object without knowing what type it is, and can query an
|
|
784 object to determine its type. This means that, correspondingly,
|
|
785 variables and function parameters can hold objects of any type and are
|
|
786 not normally declared as being of any particular type. This is opposed
|
|
787 to the @dfn{static typing} of C, where variables can hold exactly one
|
|
788 type of object and must be declared as such, and objects do not contain
|
|
789 an indication of their type because it's implicit in the variables they
|
|
790 are stored in. It is possible in C to have a variable hold different
|
|
791 types of objects (e.g. through the use of @code{void *} pointers or
|
|
792 variable-argument functions), but the type information must then be
|
|
793 passed explicitly in some other fashion, leading to additional program
|
|
794 complexity.
|
|
795
|
|
796 @item
|
|
797 Allocated memory is automatically reclaimed when it is no longer in use.
|
|
798 This operation is called @dfn{garbage collection} and involves looking
|
|
799 through all variables to see what memory is being pointed to, and
|
|
800 reclaiming any memory that is not pointed to and is thus
|
|
801 ``inaccessible'' and out of use. This is as opposed to C, in which
|
|
802 allocated memory must be explicitly reclaimed using @code{free()}. If
|
|
803 you simply drop all pointers to memory without freeing it, it becomes
|
|
804 ``leaked'' memory that still takes up space. Over a long period of
|
|
805 time, this can cause your program to grow and grow until it runs out of
|
|
806 memory.
|
|
807
|
|
808 @item
|
|
809 Lisp has built-in facilities for handling errors and exceptions. In C,
|
|
810 when an error occurs, usually either the program exits entirely or the
|
|
811 routine in which the error occurs returns a value indicating this. If
|
|
812 an error occurs in a deeply-nested routine, then every routine currently
|
|
813 called must unwind itself normally and return an error value back up to
|
|
814 the next routine. This means that every routine must explicitly check
|
|
815 for an error in all the routines it calls; if it does not do so,
|
|
816 unexpected and often random behavior results. This is an extremely
|
|
817 common source of bugs in C programs. An alternative would be to do a
|
|
818 non-local exit using @code{longjmp()}, but that is often very dangerous
|
|
819 because the routines that were exited past had no opportunity to clean
|
|
820 up after themselves and may leave things in an inconsistent state,
|
|
821 causing a crash shortly afterwards.
|
|
822
|
|
823 Lisp provides mechanisms to make such non-local exits safe. When an
|
|
824 error occurs, a routine simply signals that an error of a particular
|
|
825 class has occurred, and a non-local exit takes place. Any routine can
|
|
826 trap errors occurring in routines it calls by registering an error
|
|
827 handler for some or all classes of errors. (If no handler is registered,
|
|
828 a default handler, generally installed by the top-level event loop, is
|
|
829 executed; this prints out the error and continues.) Routines can also
|
|
830 specify cleanup code (called an @dfn{unwind-protect}) that will be
|
|
831 called when control exits from a block of code, no matter how that exit
|
|
832 occurs -- i.e. even if a function deeply nested below it causes a
|
|
833 non-local exit back to the top level.
|
|
834
|
|
835 Note that this facility has appeared in some recent vintages of C, in
|
|
836 particular Visual C++ and other PC compilers written for the Microsoft
|
|
837 Win32 API.
|
|
838
|
|
839 @item
|
|
840 In Emacs Lisp, local variables are @dfn{dynamically scoped}. This means
|
|
841 that if you declare a local variable in a particular function, and then
|
|
842 call another function, that subfunction can ``see'' the local variable
|
|
843 you declared. This is actually considered a bug in Emacs Lisp and in
|
|
844 all other early dialects of Lisp, and was corrected in Common Lisp. (In
|
|
845 Common Lisp, you can still declare dynamically scoped variables if you
|
|
846 want to -- they are sometimes useful -- but variables by default are
|
|
847 @dfn{lexically scoped} as in C.)
|
|
848 @end enumerate
|
|
849
|
|
850 For those familiar with Lisp, Emacs Lisp is modelled after MacLisp, an
|
|
851 early dialect of Lisp developed at MIT (no relation to the Macintosh
|
|
852 computer). There is a Common Lisp compatibility package available for
|
|
853 Emacs that provides many of the features of Common Lisp.
|
|
854
|
|
855 The Java language is derived in many ways from C, and shares a similar
|
|
856 syntax, but has the following features in common with Lisp (and different
|
|
857 from C):
|
|
858
|
|
859 @enumerate
|
|
860 @item
|
|
861 Java is a safe language, like Lisp.
|
|
862 @item
|
|
863 Java provides garbage collection, like Lisp.
|
|
864 @item
|
|
865 Java has built-in facilities for handling errors and exceptions, like
|
|
866 Lisp.
|
|
867 @item
|
|
868 Java has a type system that combines the best advantages of both static
|
|
869 and dynamic typing. Objects (except very simple types) are explicitly
|
|
870 marked with their type, as in dynamic typing; but there is a hierarchy
|
|
871 of types and functions are declared to accept only certain types, thus
|
|
872 providing the increased compile-time error-checking of static typing.
|
|
873 @end enumerate
|
|
874
|
|
875 @node XEmacs From the Perspective of Building, XEmacs From the Inside, The Lisp Language, Top
|
|
876 @chapter XEmacs From the Perspective of Building
|
|
877
|
|
878 The heart of XEmacs is the Lisp environment, which is written in C.
|
|
879 This is contained in the @file{src/} subdirectory. Underneath
|
|
880 @file{src/} are two subdirectories of header files: @file{s/} (header
|
|
881 files for particular operating systems) and @file{m/} (header files for
|
|
882 particular machine types). In practice the distinction between the two
|
|
883 types of header files is blurred. These header files define or undefine
|
|
884 certain preprocessor constants and macros to indicate particular
|
|
885 characteristics of the associated machine or operating system. As part
|
|
886 of the configure process, one @file{s/} file and one @file{m/} file is
|
|
887 identified for the particular environment in which XEmacs is being
|
|
888 built.
|
|
889
|
|
890 XEmacs also contains a great deal of Lisp code. This implements the
|
|
891 operations that make XEmacs useful as an editor as well as just a
|
|
892 Lisp environment, and also contains many add-on packages that allow
|
|
893 XEmacs to browse directories, act as a mail and Usenet news reader,
|
116
|
894 compile Lisp code, etc. There is actually more Lisp code than
|
0
|
895 C code associated with XEmacs, but much of the Lisp code is
|
|
896 peripheral to the actual operation of the editor. The Lisp code
|
|
897 all lies in subdirectories underneath the @file{lisp/} directory.
|
|
898
|
|
899 The @file{lwlib/} directory contains C code that implements a
|
|
900 generalized interface onto different X widget toolkits and also
|
|
901 implements some widgets of its own that behave like Motif widgets but
|
|
902 are faster, free, and in some cases more powerful. The code in this
|
|
903 directory compiles into a library and is mostly independent from XEmacs.
|
|
904
|
|
905 The @file{etc/} directory contains various data files associated with
|
|
906 XEmacs. Some of them are actually read by XEmacs at startup; others
|
|
907 merely contain useful information of various sorts.
|
|
908
|
|
909 The @file{lib-src/} directory contains C code for various auxiliary
|
|
910 programs that are used in connection with XEmacs. Some of them are used
|
|
911 during the build process; others are used to perform certain functions
|
|
912 that cannot conveniently be placed in the XEmacs executable (e.g. the
|
116
|
913 @file{movemail} program for fetching mail out of @file{/var/spool/mail},
|
|
914 which must be setgid to @file{mail} on many systems; and the
|
|
915 @file{gnuclient} program, which allows an external script to communicate
|
|
916 with a running XEmacs process).
|
0
|
917
|
|
918 The @file{man/} directory contains the sources for the XEmacs
|
|
919 documentation. It is mostly in a form called Texinfo, which can be
|
116
|
920 converted into either a printed document (by passing it through @TeX{})
|
|
921 or into on-line documentation called @dfn{info files}.
|
0
|
922
|
|
923 The @file{info/} directory contains the results of formatting the
|
|
924 XEmacs documentation as @dfn{info files}, for on-line use. These files
|
|
925 are used when you enter the Info system using @kbd{C-h i} or through the
|
|
926 Help menu.
|
|
927
|
|
928 The @file{dynodump/} directory contains auxiliary code used to build
|
|
929 XEmacs on Solaris platforms.
|
|
930
|
|
931 The other directories contain various miscellaneous code and
|
|
932 information that is not normally used or needed.
|
|
933
|
|
934 The first step of building involves running the @file{configure}
|
|
935 program and passing it various parameters to specify any optional
|
|
936 features you want and compiler arguments and such, as described in the
|
|
937 @file{INSTALL} file. This determines what the build environment is,
|
|
938 chooses the appropriate @file{s/} and @file{m/} file, and runs a series
|
|
939 of tests to determine many details about your environment, such as which
|
|
940 library functions are available and exactly how they work. (The
|
|
941 @file{s/} and @file{m/} files only contain information that cannot be
|
|
942 conveniently detected in this fashion.) The reason for running these
|
|
943 tests is that it allows XEmacs to be compiled on a much wider variety of
|
|
944 platforms than those that the XEmacs developers happen to be familiar
|
|
945 with, including various sorts of hybrid platforms. This is especially
|
|
946 important now that many operating systems give you a great deal of
|
|
947 control over exactly what features you want installed, and allow for
|
|
948 easy upgrading of parts of a system without upgrading the rest. It
|
|
949 would be impossible to pre-determine and pre-specify the information for
|
|
950 all possible configurations.
|
|
951
|
|
952 When configure is done running, it generates @file{Makefile}s and the
|
|
953 file @file{config.h} (which describes the features of your system) from
|
|
954 template files. You then run @file{make}, which compiles the auxiliary
|
|
955 code and programs in @file{lib-src/} and @file{lwlib/} and the main
|
|
956 XEmacs executable in @file{src/}. The result of this is an executable
|
|
957 called @file{temacs}, which is @emph{not} the XEmacs executable.
|
|
958 @file{temacs} by itself cannot function as an editor or even display any
|
|
959 windows on the screen, and if you simply run it, it will exit
|
|
960 immediately. The Makefile runs @file{temacs} with certain options that
|
|
961 cause it to initialize itself, read in a number of basic Lisp files, and
|
|
962 then dump itself out into a new executable called @file{xemacs}. This
|
|
963 new executable has been pre-initialized and contains pre-digested Lisp
|
116
|
964 code that is necessary for the editor to function (this includes most
|
|
965 basic Lisp functions, e.g. @code{not}, that can be defined in terms of
|
|
966 other Lisp primitives; some initialization code that is called when
|
|
967 certain objects, such as frames, are created; and all of the standard
|
|
968 keybindings and code for the actions they result in). This executable,
|
|
969 @file{xemacs}, is the executable that you run to use the XEmacs editor.
|
0
|
970
|
|
971 @node XEmacs From the Inside, The XEmacs Object System (Abstractly Speaking), XEmacs From the Perspective of Building, Top
|
|
972 @chapter XEmacs From the Inside
|
|
973
|
|
974 Internally, XEmacs is quite complex, and can be very confusing. To
|
|
975 simplify things, it can be useful to think of XEmacs as containing an
|
|
976 event loop that ``drives'' everything, and a number of other subsystems,
|
116
|
977 such as a Lisp engine and a redisplay mechanism. Each of these other
|
0
|
978 subsystems exists simultaneously in XEmacs, and each has a certain
|
|
979 state. The flow of control continually passes in and out of these
|
|
980 different subsystems in the course of normal operation of the editor.
|
|
981
|
|
982 It is important to keep in mind that, most of the time, the editor is
|
|
983 ``driven'' by the event loop. Except during initialization and batch
|
|
984 mode, all subsystems are entered directly or indirectly through the
|
|
985 event loop, and ultimately, control exits out of all subsystems back up
|
|
986 to the event loop. This cycle of entering a subsystem, exiting back out
|
|
987 to the event loop, and starting another iteration of the event loop
|
|
988 occurs once each keystroke, mouse motion, etc.
|
|
989
|
|
990 If you're trying to understand a particular subsystem (other than the
|
|
991 event loop), think of it as a ``daemon'' process or ``servant'' that is
|
|
992 responsible for one particular aspect of a larger system, and
|
|
993 periodically receives commands or environment changes that cause it to
|
|
994 do something. Ultimately, these commands and environment changes are
|
|
995 always triggered by the event loop. For example:
|
|
996
|
|
997 @itemize @bullet
|
|
998 @item
|
|
999 The window and frame mechanism is responsible for keeping track of what
|
|
1000 windows and frames exist, what buffers are in them, etc. It is
|
|
1001 periodically given commands (usually from the user) to make a change to
|
|
1002 the current window/frame state: i.e. create a new frame, delete a
|
|
1003 window, etc.
|
|
1004
|
|
1005 @item
|
|
1006 The buffer mechanism is responsible for keeping track of what buffers
|
|
1007 exist and what text is in them. It is periodically given commands
|
|
1008 (usually from the user) to insert or delete text, create a buffer, etc.
|
116
|
1009 When it receives a text-change command, it notifies the redisplay
|
|
1010 mechanism.
|
0
|
1011
|
|
1012 @item
|
|
1013 The redisplay mechanism is responsible for making sure that windows and
|
|
1014 frames are displayed correctly. It is periodically told (by the event
|
|
1015 loop) to actually ``do its job'', i.e. snoop around and see what the
|
|
1016 current state of the environment (mostly of the currently-existing
|
|
1017 windows, frames, and buffers) is, and make sure that that state matches
|
|
1018 what's actually displayed. It keeps lots and lots of information around
|
|
1019 (such as what is actually being displayed currently, and what the
|
|
1020 environment was last time it checked) so that it can minimize the work
|
|
1021 it has to do. It is also helped along in that whenever a relevant
|
|
1022 change to the environment occurs, the redisplay mechanism is told about
|
|
1023 this, so it has a pretty good idea of where it has to look to find
|
|
1024 possible changes and doesn't have to look everywhere.
|
|
1025
|
|
1026 @item
|
|
1027 The Lisp engine is responsible for executing the Lisp code in which most
|
|
1028 user commands are written. It is entered through a call to @code{eval}
|
|
1029 or @code{funcall}, which occurs as a result of dispatching an event from
|
|
1030 the event loop. The functions it calls issue commands to the buffer
|
|
1031 mechanism, the window/frame subsystem, etc.
|
|
1032
|
|
1033 @item
|
|
1034 The Lisp allocation subsystem is responsible for keeping track of Lisp
|
|
1035 objects. It is given commands from the Lisp engine to allocate objects,
|
|
1036 garbage collect, etc.
|
|
1037 @end itemize
|
|
1038
|
|
1039 etc.
|
|
1040
|
|
1041 The important idea here is that there are a number of independent
|
2
|
1042 subsystems each with its own responsibility and persistent state, just
|
0
|
1043 like different employees in a company, and each subsystem is
|
|
1044 periodically given commands from other subsystems. Commands can flow
|
|
1045 from any one subsystem to any other, but there is usually some sort of
|
|
1046 hierarchy, with all commands originating from the event subsystem.
|
|
1047
|
|
1048 XEmacs is entered in @code{main()}, which is in @file{emacs.c}. When
|
|
1049 this is called the first time (in a properly-invoked @file{temacs}), it
|
|
1050 does the following:
|
|
1051
|
|
1052 @enumerate
|
|
1053 @item
|
|
1054 It does some very basic environment initializations, such as determining
|
|
1055 where it and its directories (e.g. @file{lisp/} and @file{etc/}) reside
|
|
1056 and setting up signal handlers.
|
|
1057 @item
|
|
1058 It initializes the entire Lisp interpreter.
|
|
1059 @item
|
|
1060 It sets the initial values of many built-in variables (including many
|
|
1061 variables that are visible to Lisp programs), such as the global keymap
|
|
1062 object and the built-in faces (a face is an object that describes the
|
|
1063 display characteristics of text). This involves creating Lisp objects
|
|
1064 and thus is dependent on step (2).
|
|
1065 @item
|
|
1066 It performs various other initializations that are relevant to the
|
|
1067 particular environment it is running in, such as retrieving environment
|
|
1068 variables, determining the current date and the user who is running the
|
|
1069 program, examining its standard input, creating any necessary file
|
|
1070 descriptors, etc.
|
|
1071 @item
|
|
1072 At this point, the C initialization is complete. A Lisp program that
|
|
1073 was specified on the command line (usually @file{loadup.el}) is called
|
|
1074 (temacs is normally invoked as @code{temacs -batch -l loadup.el dump}).
|
|
1075 @file{loadup.el} loads all of the other Lisp files that are needed for
|
|
1076 the operation of the editor, calls the @code{dump-emacs} function to
|
|
1077 write out @file{xemacs}, and then kills the temacs process.
|
|
1078 @end enumerate
|
|
1079
|
|
1080 When @file{xemacs} is then run, it only redoes steps (1) and (4)
|
|
1081 above; all variables already contain the values they were set to when
|
|
1082 the executable was dumped, and all memory that was allocated with
|
|
1083 @code{malloc()} is still around. (XEmacs knows whether it is being run
|
|
1084 as @file{xemacs} or @file{temacs} because it sets the global variable
|
|
1085 @code{initialized} to 1 after step (4) above.) At this point,
|
|
1086 @file{xemacs} calls a Lisp function to do any further initialization,
|
|
1087 which includes parsing the command-line (the C code can only do limited
|
|
1088 command-line parsing, which includes looking for the @samp{-batch} and
|
|
1089 @samp{-l} flags and a few other flags that it needs to know about before
|
|
1090 initialization is complete), creating the first frame (or @dfn{window}
|
|
1091 in standard window-system parlance), running the user's init file
|
|
1092 (usually the file @file{.emacs} in the user's home directory), etc. The
|
|
1093 function to do this is usually called @code{normal-top-level};
|
|
1094 @file{loadup.el} tells the C code about this function by setting its
|
|
1095 name as the value of the Lisp variable @code{top-level}.
|
|
1096
|
|
1097 When the Lisp initialization code is done, the C code enters the event
|
|
1098 loop, and stays there for the duration of the XEmacs process. The code
|
|
1099 for the event loop is contained in @file{keyboard.c}, and is called
|
|
1100 @code{Fcommand_loop_1()}. Note that this event loop could very well be
|
|
1101 written in Lisp, and in fact a Lisp version exists; but apparently,
|
|
1102 doing this makes XEmacs run noticeably slower.
|
|
1103
|
|
1104 Notice how much of the initialization is done in Lisp, not in C.
|
|
1105 In general, XEmacs tries to move as much code as is possible
|
|
1106 into Lisp. Code that remains in C is code that implements the
|
|
1107 Lisp interpreter itself, or code that needs to be very fast, or
|
|
1108 code that needs to do system calls or other such stuff that
|
|
1109 needs to be done in C, or code that needs to have access to
|
|
1110 ``forbidden'' structures. (One conscious aspect of the design of
|
|
1111 Lisp under XEmacs is a clean separation between the external
|
|
1112 interface to a Lisp object's functionality and its internal
|
|
1113 implementation. Part of this design is that Lisp programs
|
|
1114 are forbidden from accessing the contents of the object other
|
|
1115 than through using a standard API. In this respect, XEmacs Lisp
|
|
1116 is similar to modern Lisp dialects but differs from GNU Emacs,
|
|
1117 which tends to expose the implementation and allow Lisp
|
|
1118 programs to look at it directly. The major advantage of
|
|
1119 hiding the implementation is that it allows the implementation
|
|
1120 to be redesigned without affecting any Lisp programs, including
|
|
1121 those that might want to be ``clever'' by looking directly at
|
|
1122 the object's contents and possibly manipulating them.)
|
|
1123
|
|
1124 Moving code into Lisp makes the code easier to debug and maintain and
|
|
1125 makes it much easier for people who are not XEmacs developers to
|
|
1126 customize XEmacs, because they can make a change with much less chance
|
|
1127 of obscure and unwanted interactions occurring than if they were to
|
|
1128 change the C code.
|
|
1129
|
|
1130 @node The XEmacs Object System (Abstractly Speaking), How Lisp Objects Are Represented in C, XEmacs From the Inside, Top
|
|
1131 @chapter The XEmacs Object System (Abstractly Speaking)
|
|
1132
|
|
1133 At the heart of the Lisp interpreter is its management of objects.
|
|
1134 XEmacs Lisp contains many built-in objects, some of which are
|
|
1135 simple and others of which can be very complex; and some of which
|
|
1136 are very common, and others of which are rarely used or are only
|
|
1137 used internally. (Since the Lisp allocation system, with its
|
|
1138 automatic reclamation of unused storage, is so much more convenient
|
|
1139 than @code{malloc()} and @code{free()}, the C code makes extensive use of it
|
|
1140 in its internal operations.)
|
|
1141
|
|
1142 The basic Lisp objects are
|
|
1143
|
|
1144 @table @code
|
|
1145 @item integer
|
|
1146 28 bits of precision, or 60 bits on 64-bit machines; the reason for this
|
|
1147 is described below when the internal Lisp object representation is
|
|
1148 described.
|
|
1149 @item float
|
|
1150 Same precision as a double in C.
|
|
1151 @item cons
|
|
1152 A simple container for two Lisp objects, used to implement lists and
|
|
1153 most other data structures in Lisp.
|
|
1154 @item char
|
|
1155 An object representing a single character of text; chars behave like
|
|
1156 integers in many ways but are logically considered text rather than
|
|
1157 numbers and have a different read syntax. (the read syntax for a char
|
|
1158 contains the char itself or some textual encoding of it -- for example,
|
|
1159 a Japanese Kanji character might be encoded as @samp{^[$(B#&^[(B} using the
|
|
1160 ISO-2022 encoding standard -- rather than the numerical representation
|
|
1161 of the char; this way, if the mapping between chars and integers
|
|
1162 changes, which is quite possible for Kanji characters and other extended
|
|
1163 characters, the same character will still be created. Note that some
|
|
1164 primitives confuse chars and integers. The worst culprit is @code{eq},
|
|
1165 which makes a special exception and considers a char to be @code{eq} to
|
|
1166 its integer equivalent, even though in no other case are objects of two
|
|
1167 different types @code{eq}. The reason for this monstrosity is
|
|
1168 compatibility with existing code; the separation of char from integer
|
|
1169 came fairly recently.)
|
|
1170 @item symbol
|
|
1171 An object that contains Lisp objects and is referred to by name;
|
|
1172 symbols are used to implement variables and named functions
|
|
1173 and to provide the equivalent of preprocessor constants in C.
|
|
1174 @item vector
|
|
1175 A one-dimensional array of Lisp objects providing constant-time access
|
|
1176 to any of the objects; access to an arbitrary object in a vector is
|
|
1177 faster than for lists, but the operations that can be done on a vector
|
|
1178 are more limited.
|
|
1179 @item string
|
|
1180 Self-explanatory; behaves much like a vector of chars
|
|
1181 but has a different read syntax and is stored and manipulated
|
|
1182 more compactly and efficiently.
|
|
1183 @item bit-vector
|
|
1184 A vector of bits; similar to a string in spirit.
|
|
1185 @item compiled-function
|
|
1186 An object describing compiled Lisp code, known as @dfn{byte code}.
|
|
1187 @item subr
|
|
1188 An object describing a Lisp primitive.
|
|
1189 @end table
|
|
1190
|
|
1191 @cindex closure
|
|
1192 Note that there is no basic ``function'' type, as in more powerful
|
|
1193 versions of Lisp (where it's called a @dfn{closure}). XEmacs Lisp does
|
|
1194 not provide the closure semantics implemented by Common Lisp and Scheme.
|
|
1195 The guts of a function in XEmacs Lisp are represented in one of four
|
|
1196 ways: a symbol specifying another function (when one function is an
|
|
1197 alias for another), a list containing the function's source code, a
|
|
1198 bytecode object, or a subr object. (In other words, given a symbol
|
|
1199 specifying the name of a function, calling @code{symbol-function} to
|
|
1200 retrieve the contents of the symbol's function cell will return one of
|
|
1201 these types of objects.)
|
|
1202
|
|
1203 XEmacs Lisp also contains numerous specialized objects used to
|
|
1204 implement the editor:
|
|
1205
|
116
|
1206 @table @code
|
0
|
1207 @item buffer
|
|
1208 Stores text like a string, but is optimized for insertion and deletion
|
|
1209 and has certain other properties that can be set.
|
|
1210 @item frame
|
|
1211 An object with various properties whose displayable representation is a
|
|
1212 @dfn{window} in window-system parlance.
|
|
1213 @item window
|
|
1214 A section of a frame that displays the contents of a buffer;
|
|
1215 often called a @dfn{pane} in window-system parlance.
|
|
1216 @item window-configuration
|
|
1217 An object that represents a saved configuration of windows in a frame.
|
|
1218 @item device
|
|
1219 An object representing a screen on which frames can be displayed;
|
|
1220 equivalent to a @dfn{display} in the X Window System and a @dfn{TTY} in
|
|
1221 character mode.
|
|
1222 @item face
|
|
1223 An object specifying the appearance of text or graphics; it contains
|
|
1224 characteristics such as font, foreground color, and background color.
|
|
1225 @item marker
|
|
1226 An object that refers to a particular position in a buffer and moves
|
|
1227 around as text is inserted and deleted to stay in the same relative
|
|
1228 position to the text around it.
|
|
1229 @item extent
|
|
1230 Similar to a marker but covers a range of text in a buffer; can also
|
|
1231 specify properties of the text, such as a face in which the text is to
|
|
1232 be displayed, whether the text is invisible or unmodifiable, etc.
|
|
1233 @item event
|
|
1234 Generated by calling @code{next-event} and contains information
|
|
1235 describing a particular event happening in the system, such as the user
|
|
1236 pressing a key or a process terminating.
|
|
1237 @item keymap
|
|
1238 An object that maps from events (described using lists, vectors, and
|
|
1239 symbols rather than with an event object because the mapping is for
|
|
1240 classes of events, rather than individual events) to functions to
|
|
1241 execute or other events to recursively look up; the functions are
|
|
1242 described by name, using a symbol, or using lists to specify the
|
|
1243 function's code.
|
|
1244 @item glyph
|
|
1245 An object that describes the appearance of an image (e.g. pixmap) on
|
|
1246 the screen; glyphs can be attached to the beginning or end of extents
|
|
1247 and in some future version of XEmacs will be able to be inserted
|
|
1248 directly into a buffer.
|
|
1249 @item process
|
|
1250 An object that describes a connection to an externally-running process.
|
|
1251 @end table
|
|
1252
|
|
1253 There are some other, less-commonly-encountered general objects:
|
|
1254
|
116
|
1255 @table @code
|
0
|
1256 @item hashtable
|
|
1257 An object that maps from an arbitrary Lisp object to another arbitrary
|
|
1258 Lisp object, using hashing for fast lookup.
|
|
1259 @item obarray
|
|
1260 A limited form of hashtable that maps from strings to symbols; obarrays
|
|
1261 are used to look up a symbol given its name and are not actually their
|
|
1262 own object type but are kludgily represented using vectors with hidden
|
|
1263 fields (this representation derives from GNU Emacs).
|
|
1264 @item specifier
|
|
1265 A complex object used to specify the value of a display property; a
|
|
1266 default value is given and different values can be specified for
|
|
1267 particular frames, buffers, windows, devices, or classes of device.
|
|
1268 @item char-table
|
|
1269 An object that maps from chars or classes of chars to arbitrary Lisp
|
|
1270 objects; internally char tables use a complex nested-vector
|
|
1271 representation that is optimized to the way characters are represented
|
|
1272 as integers.
|
|
1273 @item range-table
|
|
1274 An object that maps from ranges of integers to arbitrary Lisp objects.
|
|
1275 @end table
|
|
1276
|
|
1277 And some strange special-purpose objects:
|
|
1278
|
116
|
1279 @table @code
|
0
|
1280 @item charset
|
|
1281 @itemx coding-system
|
|
1282 Objects used when MULE, or multi-lingual/Asian-language, support is
|
|
1283 enabled.
|
|
1284 @item color-instance
|
|
1285 @itemx font-instance
|
|
1286 @itemx image-instance
|
|
1287 An object that encapsulates a window-system resource; instances are
|
|
1288 mostly used internally but are exposed on the Lisp level for cleanness
|
|
1289 of the specifier model and because it's occasionally useful for Lisp
|
|
1290 program to create or query the properties of instances.
|
|
1291 @item subwindow
|
|
1292 An object that encapsulate a @dfn{subwindow} resource, i.e. a
|
|
1293 window-system child window that is drawn into by an external process;
|
|
1294 this object should be integrated into the glyph system but isn't yet,
|
|
1295 and may change form when this is done.
|
|
1296 @item tooltalk-message
|
|
1297 @itemx tooltalk-pattern
|
|
1298 Objects that represent resources used in the ToolTalk interprocess
|
|
1299 communication protocol.
|
|
1300 @item toolbar-button
|
|
1301 An object used in conjunction with the toolbar.
|
|
1302 @item x-resource
|
|
1303 An object that encapsulates certain miscellaneous resources in the X
|
|
1304 window system, used only when Epoch support is enabled.
|
|
1305 @end table
|
|
1306
|
|
1307 And objects that are only used internally:
|
|
1308
|
|
1309 @table @asis
|
|
1310 @item opaque
|
|
1311 A generic object for encapsulating arbitrary memory; this allows you the
|
|
1312 generality of @code{malloc()} and the convenience of the Lisp object
|
|
1313 system.
|
|
1314 @item lstream
|
|
1315 A buffering I/O stream, used to provide a unified interface to anything
|
|
1316 that can accept output or provide input, such as a file descriptor, a
|
|
1317 stdio stream, a chunk of memory, a Lisp buffer, a Lisp string, etc.;
|
|
1318 it's a Lisp object to make its memory management more convenient.
|
|
1319 @item char-table-entry
|
|
1320 Subsidiary objects in the internal char-table representation.
|
|
1321 @item extent-auxiliary
|
|
1322 @itemx menubar-data
|
|
1323 @itemx toolbar-data
|
|
1324 Various special-purpose objects that are basically just used to
|
|
1325 encapsulate memory for particular subsystems, similar to the more
|
|
1326 general ``opaque'' object.
|
|
1327 @item symbol-value-forward
|
|
1328 @itemx symbol-value-buffer-local
|
|
1329 @itemx symbol-value-varalias
|
|
1330 @itemx symbol-value-lisp-magic
|
|
1331 Special internal-only objects that are placed in the value cell of a
|
|
1332 symbol to indicate that there is something special with this variable --
|
|
1333 e.g. it has no value, it mirrors another variable, or it mirrors some C
|
|
1334 variable; there is really only one kind of object, called a
|
|
1335 @dfn{symbol-value-magic}, but it is sort-of halfway kludged into
|
|
1336 semi-different object types.
|
|
1337 @end table
|
|
1338
|
|
1339 @cindex permanent objects
|
|
1340 @cindex temporary objects
|
|
1341 Some types of objects are @dfn{permanent}, meaning that once created,
|
|
1342 they do not disappear until explicitly destroyed, using a function such
|
|
1343 as @code{delete-buffer}, @code{delete-window}, @code{delete-frame}, etc.
|
|
1344 Others will disappear once they are not longer used, through the garbage
|
|
1345 collection mechanism. Buffers, frames, windows, devices, and processes
|
|
1346 are among the objects that are permanent. Note that some objects can go
|
|
1347 both ways: Faces can be created either way; extents are normally
|
|
1348 permanent, but detached extents (extents not referring to any text, as
|
|
1349 happens to some extents when the text they are referring to is deleted)
|
|
1350 are temporary. Note that some permanent objects, such as faces and
|
|
1351 coding systems, cannot be deleted. Note also that windows are unique in
|
|
1352 that they can be @emph{undeleted} after having previously been
|
|
1353 deleted. (This happens as a result of restoring a window configuration.)
|
|
1354
|
|
1355 @cindex read syntax
|
|
1356 Note that many types of objects have a @dfn{read syntax}, i.e. a way of
|
|
1357 specifying an object of that type in Lisp code. When you load a Lisp
|
|
1358 file, or type in code to be evaluated, what really happens is that the
|
|
1359 function @code{read} is called, which reads some text and creates an object
|
|
1360 based on the syntax of that text; then @code{eval} is called, which
|
|
1361 possibly does something special; then this loop repeats until there's
|
|
1362 no more text to read. (@code{eval} only actually does something special
|
|
1363 with symbols, which causes the symbol's value to be returned,
|
|
1364 similar to referencing a variable; and with conses [i.e. lists],
|
|
1365 which cause a function invocation. All other values are returned
|
|
1366 unchanged.)
|
|
1367
|
|
1368 The read syntax
|
|
1369
|
|
1370 @example
|
|
1371 17297
|
|
1372 @end example
|
|
1373
|
|
1374 converts to an integer whose value is 17297.
|
|
1375
|
|
1376 @example
|
|
1377 1.983e-4
|
|
1378 @end example
|
|
1379
|
|
1380 converts to a float whose value is 1983.23e-4, or .0001983.
|
|
1381
|
|
1382 @example
|
|
1383 ?b
|
|
1384 @end example
|
|
1385
|
|
1386 converts to a char that represents the lowercase letter b.
|
|
1387
|
|
1388 @example
|
|
1389 ?^[$(B#&^[(B
|
|
1390 @end example
|
|
1391
|
|
1392 (where @samp{^[} actually is an @samp{ESC} character) converts to a
|
116
|
1393 particular Kanji character when using an ISO2022-based coding system for
|
|
1394 input. (To decode this gook: @samp{ESC} begins an escape sequence;
|
|
1395 @samp{ESC $ (} is a class of escape sequences meaning ``switch to a
|
|
1396 94x94 character set''; @samp{ESC $ ( B} means ``switch to Japanese
|
|
1397 Kanji''; @samp{#} and @samp{&} collectively index into a 94-by-94 array
|
|
1398 of characters [subtract 33 from the ASCII value of each character to get
|
|
1399 the corresponding index]; @samp{ESC (} is a class of escape sequences
|
|
1400 meaning ``switch to a 94 character set''; @samp{ESC (B} means ``switch
|
|
1401 to US ASCII''. It is a coincidence that the letter @samp{B} is used to
|
|
1402 denote both Japanese Kanji and US ASCII. If the first @samp{B} were
|
|
1403 replaced with an @samp{A}, you'd be requesting a Chinese Hanzi character
|
|
1404 from the GB2312 character set.)
|
0
|
1405
|
|
1406 @example
|
|
1407 "foobar"
|
|
1408 @end example
|
|
1409
|
|
1410 converts to a string.
|
|
1411
|
|
1412 @example
|
|
1413 foobar
|
|
1414 @end example
|
|
1415
|
|
1416 converts to a symbol whose name is @code{"foobar"}. This is done by
|
|
1417 looking up the string equivalent in the global variable
|
|
1418 @code{obarray}, whose contents should be an obarray. If no symbol
|
|
1419 is found, a new symbol with the name @code{"foobar"} is automatically
|
|
1420 created and adding it to @code{obarray}; this process is called
|
|
1421 @dfn{interning} the symbol.
|
|
1422 @cindex interning
|
|
1423
|
|
1424 @example
|
|
1425 (foo . bar)
|
|
1426 @end example
|
|
1427
|
|
1428 converts to a cons cell containing the symbols @code{foo} and @code{bar}.
|
|
1429
|
|
1430 @example
|
|
1431 (1 a 2.5)
|
|
1432 @end example
|
|
1433
|
|
1434 converts to a three-element list containing the specified objects
|
|
1435 (note that a list is actually a set of nested conses; see the
|
|
1436 XEmacs Lisp Reference).
|
|
1437
|
|
1438 @example
|
|
1439 [1 a 2.5]
|
|
1440 @end example
|
|
1441
|
|
1442 converts to a three-element vector containing the specified objects.
|
|
1443
|
|
1444 @example
|
|
1445 #[... ... ... ...]
|
|
1446 @end example
|
|
1447
|
|
1448 converts to a compiled-function object (the actual contents are not
|
|
1449 shown since they are not relevant here; look at a file that ends with
|
|
1450 @file{.elc} for examples).
|
|
1451
|
|
1452 @example
|
|
1453 #*01110110
|
|
1454 @end example
|
|
1455
|
|
1456 converts to a bit-vector.
|
|
1457
|
|
1458 @example
|
|
1459 #s(range-table ... ...)
|
|
1460 @end example
|
|
1461
|
|
1462 converts to a range table (the actual contents are not shown).
|
|
1463
|
|
1464 @example
|
|
1465 #s(char-table ... ...)
|
|
1466 @end example
|
|
1467
|
|
1468 converts to a char table (the actual contents are not shown).
|
|
1469 (Note that the #s syntax is the general syntax for structures,
|
|
1470 which are not really implemented in XEmacs Lisp but should be.)
|
|
1471
|
|
1472 When an object is printed out (using @code{print} or a related
|
|
1473 function), the read syntax is used, so that the same object can be read
|
|
1474 in again.
|
|
1475
|
|
1476 The other objects do not have read syntaxes, usually because it does
|
|
1477 not really make sense to create them in this fashion (i.e. processes,
|
|
1478 where it doesn't make sense to have a subprocess created as a side
|
|
1479 effect of reading some Lisp code), or because they can't be created at
|
|
1480 all (e.g. subrs). Permanent objects, as a rule, do not have a read
|
|
1481 syntax; nor do most complex objects, which contain too much state to be
|
|
1482 easily initialized through a read syntax.
|
|
1483
|
|
1484 @node How Lisp Objects Are Represented in C, Rules When Writing New C Code, The XEmacs Object System (Abstractly Speaking), Top
|
|
1485 @chapter How Lisp Objects Are Represented in C
|
|
1486
|
|
1487 Lisp objects are represented in C using a 32- or 64-bit machine word
|
|
1488 (depending on the processor; i.e. DEC Alphas use 64-bit Lisp objects and
|
|
1489 most other processors use 32-bit Lisp objects). The representation
|
|
1490 stuffs a pointer together with a tag, as follows:
|
|
1491
|
|
1492 @example
|
|
1493 [ 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 ]
|
|
1494 [ 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 ]
|
|
1495
|
|
1496 ^ <---> <------------------------------------------------------>
|
|
1497 | tag a pointer to a structure, or an integer
|
|
1498 |
|
|
1499 `---> mark bit
|
|
1500 @end example
|
|
1501
|
|
1502 The tag describes the type of the Lisp object. For integers and
|
|
1503 chars, the lower 28 bits contain the value of the integer or char; for
|
|
1504 all others, the lower 28 bits contain a pointer. The mark bit is used
|
|
1505 during garbage-collection, and is always 0 when garbage collection is
|
|
1506 not happening. Many macros that extract out parts of a Lisp object
|
|
1507 expect that the mark bit is 0, and will produce incorrect results if
|
|
1508 it's not. (The way that garbage collection works, basically, is that it
|
|
1509 loops over all places where Lisp objects could exist -- this includes
|
|
1510 all global variables in C that contain Lisp objects [including
|
|
1511 @code{Vobarray}, the C equivalent of @code{obarray}; through this, all
|
|
1512 Lisp variables will get marked], plus various other places -- and
|
|
1513 recursively scans through the Lisp objects, marking each object it finds
|
|
1514 by setting the mark bit. Then it goes through the lists of all objects
|
|
1515 allocated, freeing the ones that are not marked and turning off the
|
|
1516 mark bit of the ones that are marked.)
|
|
1517
|
|
1518 Lisp objects use the typedef @code{Lisp_Object}, but the actual C type
|
|
1519 used for the Lisp object can vary. It can be either a simple type
|
|
1520 (@code{long} on the DEC Alpha, @code{int} on other machines) or a
|
|
1521 structure whose fields are bit fields that line up properly (actually,
|
|
1522 it's a union of structures that's used). Generally the simple integral
|
|
1523 type is preferable because it ensures that the compiler will actually
|
|
1524 use a machine word to represent the object (some compilers will use more
|
|
1525 general and less efficient code for unions and structs even if they can
|
|
1526 fit in a machine word). The union type, however, has the advantage of
|
|
1527 stricter type checking (if you accidentally pass an integer where a Lisp
|
|
1528 object is desired, you get a compile error), and it makes it easier to
|
|
1529 decode Lisp objects when debugging. The choice of which type to use is
|
|
1530 determined by the presence or absence of the preprocessor constant
|
|
1531 @code{NO_UNION_TYPE}. (Shouldn't it be @code{USE_UNION_TYPE}, with
|
|
1532 opposite semantics? ``Hysterical reasons'', of course.)
|
|
1533
|
|
1534 @cindex record type
|
|
1535 Note that there are only eight types that the tag can represent,
|
|
1536 but many more actual types than this. This is handled by having
|
116
|
1537 one of the tag types specify a meta-type called a @dfn{record};
|
0
|
1538 for all such objects, the first four bytes of the pointed-to
|
|
1539 structure indicate what the actual type is.
|
|
1540
|
|
1541 Note also that having 28 bits for pointers and integers restricts a
|
|
1542 lot of things to 256 megabytes of memory. (Basically, enough pointers
|
|
1543 and indices and whatnot get stuffed into Lisp objects that the total
|
|
1544 amount of memory used by XEmacs can't grow above 256 megabytes. In
|
|
1545 older versions of XEmacs and GNU Emacs, the tag was 5 bits wide,
|
|
1546 allowing for 32 types, which was more than the actual number of types
|
|
1547 that existed at the time, and no ``record'' type was necessary.
|
|
1548 However, this limited the editor to 64 megabytes total, which some users
|
|
1549 who edited large files might conceivably exceed.)
|
|
1550
|
|
1551 Also, note that there is an implicit assumption here that all pointers
|
|
1552 are low enough that the top bits are all zero and can just be chopped
|
|
1553 off. On standard machines that allocate memory from the bottom up (and
|
|
1554 give each process its own address space), this works fine. Some
|
|
1555 machines, however, put the data space somewhere else in memory
|
|
1556 (e.g. beginning at 0x80000000). Those machines cope by defining
|
|
1557 @code{DATA_SEG_BITS} in the corresponding @file{m/} or @file{s/} file to
|
|
1558 the proper mask. Then, pointers retrieved from Lisp objects are
|
|
1559 automatically OR'ed with this value prior to being used.
|
|
1560
|
116
|
1561 A corollary of the previous paragraph is that @strong{(pointers to)
|
|
1562 stack-allocated structures cannot be put into Lisp objects}. The stack
|
|
1563 is generally located near the top of memory; if you put such a pointer
|
|
1564 into a Lisp object, it will get its top bits chopped off, and you will
|
|
1565 lose.
|
0
|
1566
|
|
1567 Various macros are used to construct Lisp objects and extract the
|
|
1568 components. Macros of the form @code{XINT()}, @code{XCHAR()},
|
|
1569 @code{XSTRING()}, @code{XSYMBOL()}, etc. mask out the pointer/integer
|
|
1570 field and cast it to the appropriate type. All of the macros that
|
|
1571 construct pointers will @code{OR} with @code{DATA_SEG_BITS} if
|
|
1572 necessary. @code{XINT()} needs to be a bit tricky so that negative
|
|
1573 numbers are properly sign-extended: Usually it does this by shifting the
|
|
1574 number four bits to the left and then four bits to the right. This
|
|
1575 assumes that the right-shift operator does an arithmetic shift (i.e. it
|
|
1576 leaves the most-significant bit as-is rather than shifting in a zero, so
|
|
1577 that it mimics a divide-by-two even for negative numbers). Not all
|
|
1578 machines/compilers do this, and on the ones that don't, a more
|
|
1579 complicated definition is selected by defining
|
|
1580 @code{EXPLICIT_SIGN_EXTEND}.
|
|
1581
|
|
1582 Note that when @code{ERROR_CHECK_TYPECHECK} is defined, the extractor
|
|
1583 macros become more complicated -- they check the tag bits and/or the
|
|
1584 type field in the first four bytes of a record type to ensure that the
|
|
1585 object is really of the correct type. This is great for catching places
|
|
1586 where an incorrect type is being dereferenced -- this typically results
|
|
1587 in a pointer being dereferenced as the wrong type of structure, with
|
|
1588 unpredictable (and sometimes not easily traceable) results.
|
|
1589
|
116
|
1590 There are similar @code{XSET@var{TYPE}()} macros that construct a Lisp object.
|
|
1591 These macros are of the form @code{XSET@var{TYPE} (@var{lvalue}, @var{result})},
|
0
|
1592 i.e. they have to be a statement rather than just used in an expression.
|
|
1593 The reason for this is that standard C doesn't let you ``construct'' a
|
|
1594 structure (but GCC does). Granted, this sometimes isn't too convenient;
|
|
1595 for the case of integers, at least, you can use the function
|
|
1596 @code{make_number()}, which constructs and @emph{returns} an integer
|
116
|
1597 Lisp object. Note that the @code{XSET@var{TYPE}()} macros are also
|
|
1598 affected by @code{ERROR_CHECK_TYPECHECK} and make sure that the
|
|
1599 structure is of the right type in the case of record types, where the
|
|
1600 type is contained in the structure.
|
0
|
1601
|
|
1602 @node Rules When Writing New C Code, A Summary of the Various XEmacs Modules, How Lisp Objects Are Represented in C, Top
|
|
1603 @chapter Rules When Writing New C Code
|
|
1604
|
|
1605 The XEmacs C Code is extremely complex and intricate, and there are
|
|
1606 many rules that are more or less consistently followed throughout the code.
|
|
1607 Many of these rules are not obvious, so they are explained here. It is
|
|
1608 of the utmost importance that you follow them. If you don't, you may get
|
|
1609 something that appears to work, but which will crash in odd situations,
|
|
1610 often in code far away from where the actual breakage is.
|
|
1611
|
|
1612 @menu
|
|
1613 * General Coding Rules::
|
|
1614 * Writing Lisp Primitives::
|
|
1615 * Adding Global Lisp Variables::
|
2
|
1616 * Techniques for XEmacs Developers::
|
0
|
1617 @end menu
|
|
1618
|
|
1619 @node General Coding Rules
|
|
1620 @section General Coding Rules
|
|
1621
|
|
1622 Almost every module contains a @code{syms_of_*()} function and a
|
|
1623 @code{vars_of_*()} function. The former declares any Lisp primitives
|
|
1624 you have defined and defines any symbols you will be using. The latter
|
|
1625 declares any global Lisp variables you have added and initializes global
|
|
1626 C variables in the module. For each such function, declare it in
|
|
1627 @file{symsinit.h} and make sure it's called in the appropriate place in
|
116
|
1628 @file{emacs.c}. @strong{Important}: There are stringent requirements on
|
0
|
1629 exactly what can go into these functions. See the comment in
|
116
|
1630 @file{emacs.c}. The reason for this is to avoid obscure unwanted
|
0
|
1631 interactions during initialization. If you don't follow these rules,
|
|
1632 you'll be sorry! If you want to do anything that isn't allowed, create
|
|
1633 a @code{complex_vars_of_*()} function for it. Doing this is tricky,
|
|
1634 though: You have to make sure your function is called at the right time
|
|
1635 so that all the initialization dependencies work out.
|
|
1636
|
|
1637 Every module includes @file{<config.h>} (angle brackets so that
|
116
|
1638 @samp{--srcdir} works correctly; @file{config.h} may or may not be in
|
|
1639 the same directory as the C sources) and @file{lisp.h}. @file{config.h}
|
0
|
1640 should always be included before any other header files (including
|
|
1641 system header files) to ensure that certain tricks played by various
|
|
1642 @file{s/} and @file{m/} files work out correctly.
|
|
1643
|
|
1644 @strong{All global and static variables that are to be modifiable must
|
|
1645 be declared uninitialized.} This means that you may not use the ``declare
|
|
1646 with initializer'' form for these variables, such as @code{int
|
|
1647 some_variable = 0;}. The reason for this has to do with some kludges
|
|
1648 done during the dumping process: If possible, the initialized data
|
|
1649 segment is re-mapped so that it becomes part of the (unmodifiable) code
|
|
1650 segment in the dumped executable. This allows this memory to be shared
|
|
1651 among multiple running XEmacs processes. XEmacs is careful to place as
|
|
1652 much constant data as possible into initialized variables (in
|
|
1653 particular, into what's called the @dfn{pure space} -- see below) during
|
|
1654 the @file{temacs} phase.
|
|
1655
|
|
1656 @cindex copy-on-write
|
|
1657 @strong{Note:} This kludge only works on a few systems nowadays, and is
|
|
1658 rapidly becoming irrelevant because most modern operating systems provide
|
|
1659 @dfn{copy-on-write} semantics. All data is initially shared between
|
|
1660 processes, and a private copy is automatically made (on a page-by-page
|
|
1661 basis) when a process first attempts to write to a page of memory.
|
|
1662
|
|
1663 Formerly, there was a requirement that static variables not be
|
|
1664 declared inside of functions. This had to do with another hack along
|
|
1665 the same vein as what was just described: old USG systems put
|
|
1666 statically-declared variables in the initialized data space, so those
|
|
1667 header files had a @code{#define static} declaration. (That way, the
|
|
1668 data-segment remapping described above could still work.) This fails
|
|
1669 badly on static variables inside of functions, which suddenly become
|
|
1670 automatic variables; therefore, you weren't supposed to have any of
|
|
1671 them. This awful kludge has been removed in XEmacs because
|
|
1672
|
|
1673 @enumerate
|
|
1674 @item
|
|
1675 almost all of the systems that used this kludge ended up having
|
|
1676 to disable the data-segment remapping anyway;
|
|
1677 @item
|
|
1678 the only systems that didn't were extremely outdated ones;
|
|
1679 @item
|
|
1680 this hack completely messed up inline functions.
|
|
1681 @end enumerate
|
|
1682
|
|
1683 @node Writing Lisp Primitives
|
|
1684 @section Writing Lisp Primitives
|
|
1685
|
|
1686 Lisp primitives are Lisp functions implemented in C. The details of
|
|
1687 interfacing the C function so that Lisp can call it are handled by a few
|
|
1688 C macros. The only way to really understand how to write new C code is
|
|
1689 to read the source, but we can explain some things here.
|
|
1690
|
|
1691 An example of a special form is the definition of @code{or}, from
|
|
1692 @file{eval.c}. (An ordinary function would have the same general
|
|
1693 appearance.)
|
|
1694
|
|
1695 @cindex garbage collection protection
|
|
1696 @smallexample
|
|
1697 @group
|
44
|
1698 DEFUN ("or", For, 0, UNEVALLED, 0, /*
|
0
|
1699 Eval args until one of them yields non-nil, then return that value.
|
|
1700 The remaining args are not evalled at all.
|
|
1701 If all args return nil, return nil.
|
44
|
1702 */
|
|
1703 (args))
|
0
|
1704 @{
|
|
1705 /* This function can GC */
|
|
1706 REGISTER Lisp_Object val;
|
|
1707 Lisp_Object args_left;
|
|
1708 struct gcpro gcpro1;
|
44
|
1709
|
0
|
1710 if (NILP (args))
|
|
1711 return Qnil;
|
|
1712
|
|
1713 args_left = args;
|
|
1714 GCPRO1 (args_left);
|
44
|
1715
|
0
|
1716 do
|
|
1717 @{
|
|
1718 val = Feval (Fcar (args_left));
|
|
1719 if (!NILP (val))
|
44
|
1720 break;
|
0
|
1721 args_left = Fcdr (args_left);
|
|
1722 @}
|
|
1723 while (!NILP (args_left));
|
44
|
1724
|
0
|
1725 UNGCPRO;
|
|
1726 return val;
|
|
1727 @}
|
|
1728 @end group
|
|
1729 @end smallexample
|
|
1730
|
|
1731 Let's start with a precise explanation of the arguments to the
|
|
1732 @code{DEFUN} macro. Here is a template for them:
|
|
1733
|
|
1734 @example
|
116
|
1735 DEFUN (@var{lname}, @var{fname}, @var{min}, @var{max}, @var{interactive}, /*
|
44
|
1736 @var{docstring}
|
|
1737 */
|
|
1738 (@var{arglist}) )
|
0
|
1739 @end example
|
|
1740
|
|
1741 @table @var
|
|
1742 @item lname
|
116
|
1743 This string is the name of the Lisp symbol to define as the function
|
|
1744 name; in the example above, it is @code{"or"}.
|
0
|
1745
|
|
1746 @item fname
|
44
|
1747 This is the C function name for this function. This is the name that is
|
|
1748 used in C code for calling the function. The name is, by convention,
|
|
1749 @samp{F} prepended to the Lisp name, with all dashes (@samp{-}) in the
|
|
1750 Lisp name changed to underscores. Thus, to call this function from C
|
|
1751 code, call @code{For}. Remember that the arguments are of type
|
|
1752 @code{Lisp_Object}; various macros and functions for creating values of
|
|
1753 type @code{Lisp_Object} are declared in the file @file{lisp.h}.
|
0
|
1754
|
|
1755 Primitives whose names are special characters (e.g. @code{+} or
|
|
1756 @code{<}) are named by spelling out, in some fashion, the special
|
|
1757 character: e.g. @code{Fplus()} or @code{Flss()}. Primitives whose names
|
|
1758 begin with normal alphanumeric characters but also contain special
|
|
1759 characters are spelled out in some creative way, e.g. @code{let*}
|
|
1760 becomes @code{FletX()}.
|
|
1761
|
44
|
1762 Each function also has an associated structure that holds the data for
|
0
|
1763 the subr object that represents the function in Lisp. This structure
|
|
1764 conveys the Lisp symbol name to the initialization routine that will
|
44
|
1765 create the symbol and store the subr object as its definition. The C
|
|
1766 variable name of this structure is always @samp{S} prepended to the
|
|
1767 @var{fname}. You hardly ever need to be aware of the existence of this
|
|
1768 structure.
|
0
|
1769
|
|
1770 @item min
|
|
1771 This is the minimum number of arguments that the function requires. The
|
|
1772 function @code{or} allows a minimum of zero arguments.
|
|
1773
|
|
1774 @item max
|
|
1775 This is the maximum number of arguments that the function accepts, if
|
|
1776 there is a fixed maximum. Alternatively, it can be @code{UNEVALLED},
|
|
1777 indicating a special form that receives unevaluated arguments, or
|
|
1778 @code{MANY}, indicating an unlimited number of evaluated arguments (the
|
|
1779 equivalent of @code{&rest}). Both @code{UNEVALLED} and @code{MANY} are
|
|
1780 macros. If @var{max} is a number, it may not be less than @var{min} and
|
44
|
1781 it may not be greater than 8. (If you need to add a function with
|
|
1782 more than 8 arguments, either use the @code{MANY} form or edit the
|
0
|
1783 definition of @code{DEFUN} in @file{lisp.h}. If you do the latter,
|
|
1784 make sure to also add another clause to the switch statement in
|
|
1785 @code{primitive_funcall().})
|
|
1786
|
|
1787 @item interactive
|
|
1788 This is an interactive specification, a string such as might be used as
|
|
1789 the argument of @code{interactive} in a Lisp function. In the case of
|
|
1790 @code{or}, it is 0 (a null pointer), indicating that @code{or} cannot be
|
|
1791 called interactively. A value of @code{""} indicates a function that
|
|
1792 should receive no arguments when called interactively.
|
|
1793
|
44
|
1794 @item docstring
|
0
|
1795 This is the documentation string. It is written just like a
|
44
|
1796 documentation string for a function defined in Lisp; in particular, the
|
|
1797 first line should be a single sentence. Note how the documentation
|
|
1798 string is enclosed in a comment, none of the documentation is placed on
|
|
1799 the same lines as the comment-start and comment-end characters, and the
|
|
1800 comment-start characters are on the same line as the interactive
|
0
|
1801 specification. @file{make-docfile}, which scans the C files for
|
44
|
1802 documentation strings, is very particular about what it looks for, and
|
116
|
1803 will not properly extract the doc string if it's not in this exact format.
|
44
|
1804
|
|
1805 You are free to put the various arguments to @code{DEFUN} on separate
|
0
|
1806 lines to avoid overly long lines. However, make sure to put the
|
|
1807 comment-start characters for the doc string on the same line as the
|
44
|
1808 interactive specification, and put a newline directly after them (and
|
|
1809 before the comment-end characters).
|
|
1810
|
|
1811 @item arglist
|
|
1812 This is the comma-separated list of arguments to the C function. For a
|
|
1813 function with a fixed maximum number of arguments, provide a C argument
|
|
1814 for each Lisp argument. In this case, unlike regular C functions, the
|
|
1815 types of the arguments are not declared; they are simply always of type
|
|
1816 @code{Lisp_Object}.
|
|
1817
|
|
1818 The names of the C arguments will be used as the names of the arguments
|
|
1819 to the Lisp primitive as displayed in its documentation, modulo the same
|
|
1820 concerns described above for @code{F...} names (in particular,
|
0
|
1821 underscores in the C arguments become dashes in the Lisp arguments).
|
70
|
1822 There is one additional kludge: A C argument called @code{defalt}
|
|
1823 becomes the Lisp argument @code{default}. This deliberate misspelling
|
|
1824 is done because @code{default} is a reserved word in the C language.
|
0
|
1825
|
44
|
1826 A Lisp function with @w{@var{max} = @code{UNEVALLED}} is a
|
|
1827 @w{@dfn{special form}}; its arguments are not evaluated. Instead it
|
|
1828 receives one argument of type @code{Lisp_Object}, a (Lisp) list of the
|
|
1829 unevaluated arguments, conventionally named @code{(args)}.
|
|
1830
|
|
1831 When a Lisp function has no upper limit on the number of arguments,
|
|
1832 specify @w{@var{max} = @code{MANY}}. In this case its implementation in
|
|
1833 C actually receives exactly two arguments: the number of Lisp arguments
|
|
1834 (an @code{int}) and the address of a block containing their values (a
|
|
1835 @w{@code{Lisp_Object *}}). In this case only are the C types specified
|
|
1836 in the @var{arglist}: @w{@code{(int nargs, Lisp_Object *args)}}.
|
|
1837
|
|
1838 @end table
|
0
|
1839
|
|
1840 Within the function @code{For} itself, note the use of the macros
|
|
1841 @code{GCPRO1} and @code{UNGCPRO}. @code{GCPRO1} is used to ``protect''
|
|
1842 a variable from garbage collection---to inform the garbage collector
|
|
1843 that it must look in that variable and regard its contents as an
|
|
1844 accessible object. This is necessary whenever you call @code{Feval} or
|
|
1845 anything that can directly or indirectly call @code{Feval} (this
|
|
1846 includes the @code{QUIT} macro!). At such a time, any Lisp object that
|
|
1847 you intend to refer to again must be protected somehow. @code{UNGCPRO}
|
|
1848 cancels the protection of the variables that are protected in the
|
|
1849 current function. It is necessary to do this explicitly.
|
|
1850
|
|
1851 The macro @code{GCPRO1} protects just one local variable. If you want
|
|
1852 to protect two, use @code{GCPRO2} instead; repeating @code{GCPRO1} will
|
|
1853 not work. Macros @code{GCPRO3} and @code{GCPRO4} also exist.
|
|
1854
|
|
1855 These macros implicitly use local variables such as @code{gcpro1}; you
|
|
1856 must declare these explicitly, with type @code{struct gcpro}. Thus, if
|
|
1857 you use @code{GCPRO2}, you must declare @code{gcpro1} and @code{gcpro2}.
|
|
1858
|
|
1859 @cindex caller-protects (@code{GCPRO} rule)
|
|
1860 Note also that the general rule is @dfn{caller-protects}; i.e. you
|
|
1861 are only responsible for protecting those Lisp objects that you create.
|
|
1862 Any objects passed to you as parameters should have been protected
|
|
1863 by whoever created them, so you don't in general have to protect them.
|
|
1864 @code{For} is an exception; it protects its parameters to provide
|
|
1865 extra assurance against Lisp primitives elsewhere that are incorrectly
|
|
1866 written, and against malicious self-modifying code. There are a few
|
|
1867 other standard functions that also do this.
|
|
1868
|
|
1869 @code{GCPRO}ing is perhaps the trickiest and most error-prone part
|
|
1870 of XEmacs coding. It is @strong{extremely} important that you get this
|
|
1871 right and use a great deal of discipline when writing this code.
|
|
1872 @xref{GCPROing, ,@code{GCPRO}ing}, for full details on how to do this.
|
|
1873
|
|
1874 What @code{DEFUN} actually does is declare a global structure of
|
116
|
1875 type @code{Lisp_Subr} whose name begins with capital @samp{SF} and
|
0
|
1876 which contains information about the primitive (e.g. a pointer to the
|
|
1877 function, its minimum and maximum allowed arguments, a string describing
|
|
1878 its Lisp name); @code{DEFUN} then begins a normal C function
|
|
1879 declaration using the @code{F...} name. The Lisp subr object that is
|
|
1880 the function definition of a primitive (i.e. the object in the function
|
|
1881 slot of the symbol that names the primitive) actually points to this
|
116
|
1882 @samp{SF} structure; when @code{Feval} encounters a subr, it looks in the
|
0
|
1883 structure to find out how to call the C function.
|
|
1884
|
|
1885 Defining the C function is not enough to make a Lisp primitive
|
|
1886 available; you must also create the Lisp symbol for the primitive (the
|
|
1887 symbol is @dfn{interned}; @pxref{Obarrays}) and store a suitable subr
|
|
1888 object in its function cell. (If you don't do this, the primitive won't
|
|
1889 be seen by Lisp code.) The code looks like this:
|
|
1890
|
|
1891 @example
|
116
|
1892 DEFSUBR (@var{fname});
|
0
|
1893 @end example
|
|
1894
|
116
|
1895 @noindent
|
|
1896 Here @var{fname} is the name you used as the second argument to
|
|
1897 @code{DEFUN}.
|
|
1898
|
|
1899 This call to @code{DEFSUBR} should go in the @code{syms_of_*()}
|
0
|
1900 function at the end of the module. If no such function exists, create
|
|
1901 it and make sure to also declare it in @file{symsinit.h} and call it
|
|
1902 from the appropriate spot in @code{main()}. @xref{General Coding
|
|
1903 Rules}.
|
|
1904
|
|
1905 Note that C code cannot call functions by name unless they are defined
|
116
|
1906 in C. The way to call a function written in Lisp from C is to use
|
0
|
1907 @code{Ffuncall}, which embodies the Lisp function @code{funcall}. Since
|
|
1908 the Lisp function @code{funcall} accepts an unlimited number of
|
|
1909 arguments, in C it takes two: the number of Lisp-level arguments, and a
|
|
1910 one-dimensional array containing their values. The first Lisp-level
|
|
1911 argument is the Lisp function to call, and the rest are the arguments to
|
|
1912 pass to it. Since @code{Ffuncall} can call the evaluator, you must
|
|
1913 protect pointers from garbage collection around the call to
|
|
1914 @code{Ffuncall}. (However, @code{Ffuncall} explicitly protects all of
|
|
1915 its parameters, so you don't have to protect any pointers passed
|
|
1916 as parameters to it.)
|
|
1917
|
|
1918 The C functions @code{call0}, @code{call1}, @code{call2}, and so on,
|
|
1919 provide handy ways to call a Lisp function conveniently with a fixed
|
|
1920 number of arguments. They work by calling @code{Ffuncall}.
|
|
1921
|
|
1922 @file{eval.c} is a very good file to look through for examples;
|
|
1923 @file{lisp.h} contains the definitions for some important macros and
|
|
1924 functions.
|
|
1925
|
|
1926 @node Adding Global Lisp Variables
|
|
1927 @section Adding Global Lisp Variables
|
|
1928
|
|
1929 Global variables whose names begin with @samp{Q} are constants whose
|
|
1930 value is a symbol of a particular name. The name of the variable should
|
|
1931 be derived from the name of the symbol using the same rules as for Lisp
|
|
1932 primitives. These variables are initialized using a call to
|
|
1933 @code{defsymbol()} in the @code{syms_of_*()} function. (This call
|
|
1934 interns a symbol, sets the C variable to the resulting Lisp object, and
|
|
1935 calls @code{staticpro()} on the C variable to tell the
|
|
1936 garbage-collection mechanism about this variable. What
|
|
1937 @code{staticpro()} does is add a pointer to the variable to a large
|
|
1938 global array; when garbage-collection happens, all pointers listed in
|
|
1939 the array are used as starting points for marking Lisp objects. This is
|
|
1940 important because it's quite possible that the only current reference to
|
|
1941 the object is the C variable. In the case of symbols, the
|
|
1942 @code{staticpro()} doesn't matter all that much because the symbol is
|
|
1943 contained in @code{obarray}, which is itself @code{staticpro()}ed.
|
|
1944 However, it's possible that a naughty user could do something like
|
|
1945 uninterning the symbol out of @code{obarray} or even setting
|
|
1946 @code{obarray} to a different value [although this is likely to make
|
|
1947 XEmacs crash!].)
|
|
1948
|
|
1949 @strong{Note:} It is potentially deadly if you declare a @samp{Q...}
|
|
1950 variable in two different modules. The two calls to @code{defsymbol()}
|
|
1951 are no problem, but some linkers will complain about multiply-defined
|
|
1952 symbols. The most insidious aspect of this is that often the link will
|
|
1953 succeed anyway, but then the resulting executable will sometimes crash
|
|
1954 in obscure ways during certain operations! To avoid this problem,
|
|
1955 declare any symbols with common names (such as @code{text}) that are not
|
|
1956 obviously associated with this particular module in the module
|
|
1957 @file{general.c}.
|
|
1958
|
|
1959 Global variables whose names begin with @samp{V} are variables that
|
|
1960 contain Lisp objects. The convention here is that all global variables
|
|
1961 of type @code{Lisp_Object} begin with @samp{V}, and all others don't
|
|
1962 (including integer and boolean variables that have Lisp
|
|
1963 equivalents). Most of the time, these variables have equivalents in
|
|
1964 Lisp, but some don't. Those that do are declared this way by a call to
|
|
1965 @code{DEFVAR_LISP()} in the @code{vars_of_*()} initializer for the
|
|
1966 module. What this does is create a special @dfn{symbol-value-forward}
|
|
1967 Lisp object that contains a pointer to the C variable, intern a symbol
|
|
1968 whose name is as specified in the call to @code{DEFVAR_LISP()}, and set
|
|
1969 its value to the symbol-value-forward Lisp object; it also calls
|
|
1970 @code{staticpro()} on the C variable to tell the garbage-collection
|
|
1971 mechanism about the variable. When @code{eval} (or actually
|
|
1972 @code{symbol-value}) encounters this special object in the process of
|
|
1973 retrieving a variable's value, it follows the indirection to the C
|
|
1974 variable and gets its value. @code{setq} does similar things so that
|
|
1975 the C variable gets changed.
|
|
1976
|
|
1977 Whether or not you @code{DEFVAR_LISP()} a variable, you need to
|
|
1978 initialize it in the @code{vars_of_*()} function; otherwise it will end
|
|
1979 up as all zeroes, which is the integer 0 (@emph{not} @code{nil}), and
|
|
1980 this is probably not what you want. Also, if the variable is not
|
|
1981 @code{DEFVAR_LISP()}ed, @strong{you must call} @code{staticpro()} on the
|
|
1982 C variable in the @code{vars_of_*()} function. Otherwise, the
|
|
1983 garbage-collection mechanism won't know that the object in this variable
|
|
1984 is in use, and will happily collect it and reuse its storage for another
|
|
1985 Lisp object, and you will be the one who's unhappy when you can't figure
|
|
1986 out how your variable got overwritten.
|
|
1987
|
2
|
1988 @node Techniques for XEmacs Developers
|
|
1989 @section Techniques for XEmacs Developers
|
|
1990
|
|
1991 To make a quantified XEmacs, do: @code{make quantmacs}.
|
|
1992
|
|
1993 You simply can't dump Quantified and Purified images. Run the image
|
|
1994 like so: @code{quantmacs -batch -l loadup.el run-temacs -q}.
|
|
1995
|
|
1996 Before you go through the trouble, are you compiling with all
|
|
1997 debugging and error-checking off? If not try that first. Be warned
|
|
1998 that while Quantify is directly responsible for quite a few
|
|
1999 optimizations which have been made to XEmacs, doing a run which
|
|
2000 generates results which can be acted upon is not necessarily a trivial
|
|
2001 task.
|
|
2002
|
|
2003 Also, if you're still willing to do some runs make sure you configure
|
|
2004 with the @samp{--quantify} flag. That will keep Quantify from starting
|
|
2005 to record data until after the loadup is completed and will shut off
|
|
2006 recording right before it shuts down (which generates enough bogus data
|
|
2007 to throw most results off). It also enables three additional elisp
|
|
2008 commands: @code{quantify-start-recording-data},
|
|
2009 @code{quantify-stop-recording-data} and @code{quantify-clear-data}.
|
|
2010
|
|
2011 To get started debugging XEmacs, take a look at the @file{gdbinit} and
|
|
2012 @file{dbxrc} files in the @file{src} directory.
|
|
2013
|
|
2014
|
0
|
2015 @node A Summary of the Various XEmacs Modules, Allocation of Objects in XEmacs Lisp, Rules When Writing New C Code, Top
|
|
2016 @chapter A Summary of the Various XEmacs Modules
|
|
2017
|
|
2018 This is accurate as of XEmacs 20.0.
|
|
2019
|
|
2020 @menu
|
|
2021 * Low-Level Modules::
|
|
2022 * Basic Lisp Modules::
|
|
2023 * Modules for Standard Editing Operations::
|
|
2024 * Editor-Level Control Flow Modules::
|
|
2025 * Modules for the Basic Displayable Lisp Objects::
|
|
2026 * Modules for other Display-Related Lisp Objects::
|
|
2027 * Modules for the Redisplay Mechanism::
|
|
2028 * Modules for Interfacing with the File System::
|
|
2029 * Modules for Other Aspects of the Lisp Interpreter and Object System::
|
|
2030 * Modules for Interfacing with the Operating System::
|
|
2031 * Modules for Interfacing with X Windows::
|
|
2032 * Modules for Internationalization::
|
|
2033 @end menu
|
|
2034
|
|
2035 @node Low-Level Modules
|
|
2036 @section Low-Level Modules
|
|
2037
|
|
2038 @example
|
|
2039 size name
|
|
2040 ------- ---------------------
|
|
2041 18150 config.h
|
|
2042 @end example
|
|
2043
|
|
2044 This is automatically generated from @file{config.h.in} based on the
|
|
2045 results of configure tests and user-selected optional features and
|
|
2046 contains preprocessor definitions specifying the nature of the
|
|
2047 environment in which XEmacs is being compiled.
|
|
2048
|
|
2049
|
|
2050
|
|
2051 @example
|
|
2052 2347 paths.h
|
|
2053 @end example
|
|
2054
|
|
2055 This is automatically generated from @file{paths.h.in} based on supplied
|
|
2056 configure values, and allows for non-standard installed configurations
|
|
2057 of the XEmacs directories. It's currently broken, though.
|
|
2058
|
|
2059
|
|
2060
|
|
2061 @example
|
|
2062 47878 emacs.c
|
|
2063 20239 signal.c
|
|
2064 @end example
|
|
2065
|
|
2066 @file{emacs.c} contains @code{main()} and other code that performs the most
|
|
2067 basic environment initializations and handles shutting down the XEmacs
|
|
2068 process (this includes @code{kill-emacs}, the normal way that XEmacs is
|
|
2069 exited; @code{dump-emacs}, which is used during the build process to
|
|
2070 write out the XEmacs executable; @code{run-emacs-from-temacs}, which can
|
|
2071 be used to start XEmacs directly when temacs has finished loading all
|
|
2072 the Lisp code; and emergency code to handle crashes [XEmacs tries to
|
|
2073 auto-save all files before it crashes]).
|
|
2074
|
|
2075 Low-level code that directly interacts with the Unix signal mechanism,
|
|
2076 however, is in @file{signal.c}. Note that this code does not handle system
|
|
2077 dependencies in interfacing to signals; that is handled using the
|
|
2078 @file{syssignal.h} header file, described in section J below.
|
|
2079
|
|
2080
|
|
2081
|
|
2082 @example
|
|
2083 23458 unexaix.c
|
|
2084 9893 unexalpha.c
|
|
2085 11302 unexapollo.c
|
|
2086 16544 unexconvex.c
|
|
2087 31967 unexec.c
|
|
2088 30959 unexelf.c
|
|
2089 35791 unexelfsgi.c
|
|
2090 3207 unexencap.c
|
|
2091 7276 unexenix.c
|
|
2092 20539 unexfreebsd.c
|
|
2093 1153 unexfx2800.c
|
|
2094 13432 unexhp9k3.c
|
|
2095 11049 unexhp9k800.c
|
|
2096 9165 unexmips.c
|
|
2097 8981 unexnext.c
|
|
2098 1673 unexsol2.c
|
|
2099 19261 unexsunos4.c
|
|
2100 @end example
|
|
2101
|
|
2102 These modules contain code dumping out the XEmacs executable on various
|
|
2103 different systems. (This process is highly machine-specific and
|
|
2104 requires intimate knowledge of the executable format and the memory map
|
|
2105 of the process.) Only one of these modules is actually used; this is
|
|
2106 chosen by @file{configure}.
|
|
2107
|
|
2108
|
|
2109
|
|
2110 @example
|
|
2111 15715 crt0.c
|
|
2112 1484 lastfile.c
|
|
2113 1115 pre-crt0.c
|
|
2114 @end example
|
|
2115
|
|
2116 These modules are used in conjunction with the dump mechanism. On some
|
|
2117 systems, an alternative version of the C startup code (the actual code
|
|
2118 that receives control from the operating system when the process is
|
|
2119 started, and which calls @code{main()}) is required so that the dumping
|
|
2120 process works properly; @file{crt0.c} provides this.
|
|
2121
|
|
2122 @file{pre-crt0.c} and @file{lastfile.c} should be the very first and
|
|
2123 very last file linked, respectively. (Actually, this is not really true.
|
|
2124 @file{lastfile.c} should be after all Emacs modules whose initialized
|
|
2125 data should be made constant, and before all other Emacs files and all
|
|
2126 libraries. In particular, the allocation modules @file{gmalloc.c},
|
|
2127 @file{alloca.c}, etc. are normally placed past @file{lastfile.c}, and
|
|
2128 all of the files that implement Xt widget classes @emph{must} be placed
|
|
2129 after @file{lastfile.c} because they contain various structures that
|
|
2130 must be statically initialized and into which Xt writes at various
|
|
2131 times.) @file{pre-crt0.c} and @file{lastfile.c} contain exported symbols
|
116
|
2132 that are used to determine the start and end of XEmacs' initialized
|
0
|
2133 data space when dumping.
|
|
2134
|
|
2135
|
|
2136
|
|
2137 @example
|
|
2138 14786 alloca.c
|
|
2139 16678 free-hook.c
|
|
2140 1692 getpagesize.h
|
|
2141 41936 gmalloc.c
|
|
2142 25141 malloc.c
|
|
2143 3802 mem-limits.h
|
|
2144 39011 ralloc.c
|
|
2145 3436 vm-limit.c
|
|
2146 @end example
|
|
2147
|
|
2148 These handle basic C allocation of memory. @file{alloca.c} is an emulation of
|
|
2149 the stack allocation function @code{alloca()} on machines that lack
|
|
2150 this. (XEmacs makes extensive use of @code{alloca()} in its code.)
|
|
2151
|
|
2152 @file{gmalloc.c} and @file{malloc.c} are two implementations of the standard C
|
|
2153 functions @code{malloc()}, @code{realloc()} and @code{free()}. They are
|
|
2154 often used in place of the standard system-provided @code{malloc()}
|
|
2155 because they usually provide a much faster implementation, at the
|
|
2156 expense of additional memory use. @file{gmalloc.c} is a newer implementation
|
|
2157 that is much more memory-efficient for large allocations than @file{malloc.c},
|
|
2158 and should always be preferred if it works. (At one point, @file{gmalloc.c}
|
|
2159 didn't work on some systems where @file{malloc.c} worked; but this should be
|
|
2160 fixed now.)
|
|
2161
|
|
2162 @cindex relocating allocator
|
|
2163 @file{ralloc.c} is the @dfn{relocating allocator}. It provides functions
|
|
2164 similar to @code{malloc()}, @code{realloc()} and @code{free()} that allocate
|
|
2165 memory that can be dynamically relocated in memory. The advantage of
|
|
2166 this is that allocated memory can be shuffled around to place all the
|
|
2167 free memory at the end of the heap, and the heap can then be shrunk,
|
|
2168 releasing the memory back to the operating system. The use of this can
|
|
2169 be controlled with the configure option @code{--rel-alloc}; if enabled, memory allocated for
|
|
2170 buffers will be relocatable, so that if a very large file is visited and
|
|
2171 the buffer is later killed, the memory can be released to the operating
|
|
2172 system. (The disadvantage of this mechanism is that it can be very
|
|
2173 slow. On systems with the @code{mmap()} system call, the XEmacs version
|
|
2174 of @file{ralloc.c} uses this to move memory around without actually having to
|
|
2175 block-copy it, which can speed things up; but it can still cause
|
|
2176 noticeable performance degradation.)
|
|
2177
|
|
2178 @file{free-hook.c} contains some debugging functions for checking for invalid
|
|
2179 arguments to @code{free()}.
|
|
2180
|
|
2181 @file{vm-limit.c} contains some functions that warn the user when memory is
|
|
2182 getting low. These are callback functions that are called by @file{gmalloc.c}
|
|
2183 and @file{malloc.c} at appropriate times.
|
|
2184
|
|
2185 @file{getpagesize.h} provides a uniform interface for retrieving the size of a
|
|
2186 page in virtual memory. @file{mem-limits.h} provides a uniform interface for
|
|
2187 retrieving the total amount of available virtual memory. Both are
|
|
2188 similar in spirit to the @file{sys*.h} files described in section J, below.
|
|
2189
|
|
2190
|
|
2191
|
|
2192 @example
|
|
2193 2659 blocktype.c
|
|
2194 1410 blocktype.h
|
|
2195 7194 dynarr.c
|
|
2196 2671 dynarr.h
|
|
2197 @end example
|
|
2198
|
|
2199 These implement a couple of basic C data types to facilitate memory
|
|
2200 allocation. The @code{Blocktype} type efficiently manages the
|
|
2201 allocation of fixed-size blocks by minimizing the number of times that
|
|
2202 @code{malloc()} and @code{free()} are called. It allocates memory in
|
|
2203 large chunks, subdivides the chunks into blocks of the proper size, and
|
|
2204 returns the blocks as requested. When blocks are freed, they are placed
|
|
2205 onto a linked list, so they can be efficiently reused. This data type
|
|
2206 is not much used in XEmacs currently, because it's a fairly new
|
|
2207 addition.
|
|
2208
|
|
2209 @cindex dynamic array
|
|
2210 The @code{Dynarr} type implements a @dfn{dynamic array}, which is
|
|
2211 similar to a standard C array but has no fixed limit on the number of
|
|
2212 elements it can contain. Dynamic arrays can hold elements of any type,
|
|
2213 and when you add a new element, the array automatically resizes itself
|
|
2214 if it isn't big enough. Dynarrs are extensively used in the redisplay
|
|
2215 mechanism.
|
|
2216
|
|
2217
|
|
2218
|
|
2219 @example
|
|
2220 2058 inline.c
|
|
2221 @end example
|
|
2222
|
|
2223 This module is used in connection with inline functions (available in
|
|
2224 some compilers). Often, inline functions need to have a corresponding
|
|
2225 non-inline function that does the same thing. This module is where they
|
|
2226 reside. It contains no actual code, but defines some special flags that
|
|
2227 cause inline functions defined in header files to be rendered as actual
|
|
2228 functions. It then includes all header files that contain any inline
|
|
2229 function definitions, so that each one gets a real function equivalent.
|
|
2230
|
|
2231
|
|
2232
|
|
2233 @example
|
|
2234 6489 debug.c
|
|
2235 2267 debug.h
|
|
2236 @end example
|
|
2237
|
|
2238 These functions provide a system for doing internal consistency checks
|
|
2239 during code development. This system is not currently used; instead the
|
|
2240 simpler @code{assert()} macro is used along with the various checks
|
|
2241 provided by the @samp{--error-check-*} configuration options.
|
|
2242
|
|
2243
|
|
2244
|
|
2245 @example
|
|
2246 1643 prefix-args.c
|
|
2247 @end example
|
|
2248
|
|
2249 This is actually the source for a small, self-contained program
|
|
2250 used during building.
|
|
2251
|
|
2252
|
|
2253 @example
|
|
2254 904 universe.h
|
|
2255 @end example
|
|
2256
|
|
2257 This is not currently used.
|
|
2258
|
|
2259
|
|
2260
|
|
2261 @node Basic Lisp Modules
|
|
2262 @section Basic Lisp Modules
|
|
2263
|
|
2264 @example
|
|
2265 size name
|
|
2266 ------- ---------------------
|
|
2267 70167 emacsfns.h
|
|
2268 6305 lisp-disunion.h
|
|
2269 7086 lisp-union.h
|
|
2270 54929 lisp.h
|
|
2271 14235 lrecord.h
|
|
2272 10728 symsinit.h
|
|
2273 @end example
|
|
2274
|
|
2275 These are the basic header files for all XEmacs modules. Each module
|
|
2276 includes @file{lisp.h}, which brings the other header files in.
|
|
2277 @file{lisp.h} contains the definitions of the structures and extractor
|
|
2278 and constructor macros for the basic Lisp objects and various other
|
|
2279 basic definitions for the Lisp environment, as well as some
|
|
2280 general-purpose definitions (e.g. @code{min()} and @code{max()}).
|
|
2281 @file{lisp.h} includes either @file{lisp-disunion.h} or
|
|
2282 @file{lisp-union.h}, depending on whether @code{NO_UNION_TYPE} is
|
|
2283 defined. These files define the typedef of the Lisp object itself (as
|
|
2284 described above) and the low-level macros that hide the actual
|
|
2285 implementation of the Lisp object. All extractor and constructor macros
|
|
2286 for particular types of Lisp objects are defined in terms of these
|
|
2287 low-level macros.
|
|
2288
|
|
2289 As a general rule, all typedefs should go into the typedefs section of
|
|
2290 @file{lisp.h} rather than into a module-specific header file even if the
|
|
2291 structure is defined elsewhere. This allows function prototypes that
|
|
2292 use the typedef to be placed into @file{emacsfns.h}. Forward structure
|
|
2293 declarations (i.e. a simple declaration like @code{struct foo;} where
|
|
2294 the structure itself is defined elsewhere) should be placed into the
|
|
2295 typedefs section as necessary.
|
|
2296
|
|
2297 @file{lrecord.h} contains the basic structures and macros that implement
|
|
2298 all record-type Lisp objects -- i.e. all objects whose type is a field
|
|
2299 in their C structure, which includes all objects except the few most
|
|
2300 basic ones.
|
|
2301
|
|
2302 @file{emacsfns.h} contains prototypes for most of the exported functions
|
|
2303 in the various modules. (In particular, prototypes for Lisp primitives
|
2
|
2304 should always go into this header file. Prototypes for other functions
|
0
|
2305 can either go here or in a module-specific header file, depending on how
|
|
2306 general-purpose the function is and whether it has special-purpose
|
|
2307 argument types requiring definitions not in @file{lisp.h}.) All
|
|
2308 initialization functions are prototyped in @file{symsinit.h}.
|
|
2309
|
|
2310
|
|
2311
|
|
2312 @example
|
|
2313 120478 alloc.c
|
|
2314 1029 pure.c
|
|
2315 2506 puresize.h
|
|
2316 @end example
|
|
2317
|
|
2318 The large module @file{alloc.c} implements all of the basic allocation and
|
|
2319 garbage collection for Lisp objects. The most commonly used Lisp
|
|
2320 objects are allocated in chunks, similar to the Blocktype data type
|
|
2321 described above; others are allocated in individually @code{malloc()}ed
|
|
2322 blocks. This module provides the foundation on which all other aspects
|
|
2323 of the Lisp environment sit, and is the first module initialized at
|
|
2324 startup.
|
|
2325
|
|
2326 Note that @file{alloc.c} provides a series of generic functions that are
|
|
2327 not dependent on any particular object type, and interfaces to
|
|
2328 particular types of objects using a standardized interface of
|
|
2329 type-specific methods. This scheme is a fundamental principle of
|
|
2330 object-oriented programming and is heavily used throughout XEmacs. The
|
|
2331 great advantage of this is that it allows for a clean separation of
|
|
2332 functionality into different modules -- new classes of Lisp objects, new
|
|
2333 event interfaces, new device types, new stream interfaces, etc. can be
|
|
2334 added transparently without affecting code anywhere else in XEmacs.
|
|
2335 Because the different subsystems are divided into general and specific
|
|
2336 code, adding a new subtype within a subsystem will in general not
|
|
2337 require changes to the generic subsystem code or affect any of the other
|
|
2338 subtypes in the subsystem; this provides a great deal of robustness to
|
|
2339 the XEmacs code.
|
|
2340
|
|
2341 @cindex pure space
|
|
2342 @file{pure.c} contains the declaration of the @dfn{purespace} array.
|
|
2343 Pure space is a hack used to place some constant Lisp data into the code
|
|
2344 segment of the XEmacs executable, even though the data needs to be
|
|
2345 initialized through function calls. (See above in section VIII for more
|
|
2346 info about this.) During startup, certain sorts of data is
|
|
2347 automatically copied into pure space, and other data is copied manually
|
|
2348 in some of the basic Lisp files by calling the function @code{purecopy},
|
|
2349 which copies the object if possible (this only works in temacs, of
|
|
2350 course) and returns the new object. In particular, while temacs is
|
|
2351 executing, the Lisp reader automatically copies all compiled-function
|
|
2352 objects that it reads into pure space. Since compiled-function objects
|
|
2353 are large, are never modified, and typically comprise the majority of
|
|
2354 the contents of a compiled-Lisp file, this works well. While XEmacs is
|
|
2355 running, any attempt to modify an object that resides in pure space
|
|
2356 causes an error. Objects in pure space are never garbage collected --
|
|
2357 almost all of the time, they're intended to be permanent, and in any
|
|
2358 case you can't write into pure space to set the mark bits.
|
|
2359
|
|
2360 @file{puresize.h} contains the declaration of the size of the pure space
|
|
2361 array. This depends on the optional features that are compiled in, any
|
|
2362 extra purespace requested by the user at compile time, and certain other
|
|
2363 factors (e.g. 64-bit machines need more pure space because their Lisp
|
|
2364 objects are larger). The smallest size that suffices should be used, so
|
|
2365 that there's no wasted space. If there's not enough pure space, you
|
|
2366 will get an error during the build process, specifying how much more
|
|
2367 pure space is needed.
|
|
2368
|
|
2369
|
|
2370
|
|
2371 @example
|
|
2372 122243 eval.c
|
|
2373 2305 backtrace.h
|
|
2374 @end example
|
|
2375
|
|
2376 This module contains all of the functions to handle the flow of control.
|
|
2377 This includes the mechanisms of defining functions, calling functions,
|
|
2378 traversing stack frames, and binding variables; the control primitives
|
|
2379 and other special forms such as @code{while}, @code{if}, @code{eval},
|
|
2380 @code{let}, @code{and}, @code{or}, @code{progn}, etc.; handling of
|
|
2381 non-local exits, unwind-protects, and exception handlers; entering the
|
|
2382 debugger; methods for the subr Lisp object type; etc. It does
|
|
2383 @emph{not} include the @code{read} function, the @code{print} function,
|
|
2384 or the handling of symbols and obarrays.
|
|
2385
|
|
2386 @file{backtrace.h} contains some structures related to stack frames and the
|
|
2387 flow of control.
|
|
2388
|
|
2389
|
|
2390
|
|
2391 @example
|
|
2392 64949 lread.c
|
|
2393 @end example
|
|
2394
|
|
2395 This module implements the Lisp reader and the @code{read} function,
|
|
2396 which converts text into Lisp objects, according to the read syntax of
|
|
2397 the objects, as described above. This is similar to the parser that is
|
|
2398 a part of all compilers.
|
|
2399
|
|
2400
|
|
2401
|
|
2402 @example
|
|
2403 40900 print.c
|
|
2404 @end example
|
|
2405
|
|
2406 This module implements the Lisp print mechanism and the @code{print}
|
|
2407 function and related functions. This is the inverse of the Lisp reader
|
|
2408 -- it converts Lisp objects to a printed, textual representation.
|
|
2409 (Hopefully something that can be read back in using @code{read} to get
|
|
2410 an equivalent object.)
|
|
2411
|
|
2412
|
|
2413
|
|
2414 @example
|
|
2415 4518 general.c
|
|
2416 60220 symbols.c
|
|
2417 9966 symeval.h
|
|
2418 @end example
|
|
2419
|
|
2420 @file{symbols.c} implements the handling of symbols, obarrays, and
|
|
2421 retrieving the values of symbols. Much of the code is devoted to
|
|
2422 handling the special @dfn{symbol-value-magic} objects that define
|
|
2423 special types of variables -- this includes buffer-local variables,
|
|
2424 variable aliases, variables that forward into C variables, etc. This
|
|
2425 module is initialized extremely early (right after @file{alloc.c}),
|
|
2426 because it is here that the basic symbols @code{t} and @code{nil} are
|
|
2427 created, and those symbols are used everywhere throughout XEmacs.
|
|
2428
|
|
2429 @file{symeval.h} contains the definitions of symbol structures and the
|
|
2430 @code{DEFVAR_LISP()} and related macros for declaring variables.
|
|
2431
|
|
2432
|
|
2433
|
|
2434 @example
|
|
2435 48973 data.c
|
|
2436 25694 floatfns.c
|
|
2437 71049 fns.c
|
|
2438 @end example
|
|
2439
|
|
2440 These modules implement the methods and standard Lisp primitives for all
|
|
2441 the basic Lisp object types other than symbols (which are described
|
|
2442 above). @file{data.c} contains all the predicates (primitives that return
|
|
2443 whether an object is of a particular type); the integer arithmetic
|
|
2444 functions; and the basic accessor and mutator primitives for the various
|
|
2445 object types. @file{fns.c} contains all the standard predicates for working
|
|
2446 with sequences (where, abstractly speaking, a sequence is an ordered set
|
|
2447 of objects, and can be represented by a list, string, vector, or
|
|
2448 bit-vector); it also contains @code{equal}, perhaps on the grounds that
|
|
2449 bulk of the operation of @code{equal} is comparing sequences.
|
|
2450 @file{floatfns.c} contains methods and primitives for floats and floating-point
|
|
2451 arithmetic.
|
|
2452
|
|
2453
|
|
2454
|
|
2455 @example
|
|
2456 23555 bytecode.c
|
|
2457 3358 bytecode.h
|
|
2458 @end example
|
|
2459
|
|
2460 @file{bytecode.c} implements the byte-code interpreter, and @file{bytecode.h} contains
|
|
2461 associated structures. Note that the byte-code @emph{compiler} is
|
|
2462 written in Lisp.
|
|
2463
|
|
2464
|
|
2465
|
|
2466
|
|
2467 @node Modules for Standard Editing Operations
|
|
2468 @section Modules for Standard Editing Operations
|
|
2469
|
|
2470 @example
|
|
2471 size name
|
|
2472 ------- ---------------------
|
|
2473 82900 buffer.c
|
|
2474 60964 buffer.h
|
|
2475 6059 bufslots.h
|
|
2476 @end example
|
|
2477
|
2
|
2478 @file{buffer.c} implements the @dfn{buffer} Lisp object type. This
|
|
2479 includes functions that create and destroy buffers; retrieve buffers by
|
|
2480 name or by other properties; manipulate lists of buffers (remember that
|
|
2481 buffers are permanent objects and stored in various ordered lists);
|
|
2482 retrieve or change buffer properties; etc. It also contains the
|
|
2483 definitions of all the built-in buffer-local variables (which can be
|
|
2484 viewed as buffer properties). It does @emph{not} contain code to
|
|
2485 manipulate buffer-local variables (that's in @file{symbols.c}, described
|
|
2486 above); or code to manipulate the text in a buffer.
|
0
|
2487
|
|
2488 @file{buffer.h} defines the structures associated with a buffer and the various
|
|
2489 macros for retrieving text from a buffer and special buffer positions
|
|
2490 (e.g. @code{point}, the default location for text insertion). It also
|
|
2491 contains macros for working with buffer positions and converting between
|
|
2492 their representations as character offsets and as byte offsets (under
|
|
2493 MULE, they are different, because characters can be multi-byte). It is
|
|
2494 one of the largest header files.
|
|
2495
|
|
2496 @file{bufslots.h} defines the fields in the buffer structure that correspond to
|
|
2497 the built-in buffer-local variables. It is its own header file because
|
|
2498 it is included many times in @file{buffer.c}, as a way of iterating over all
|
|
2499 the built-in buffer-local variables.
|
|
2500
|
|
2501
|
|
2502
|
|
2503 @example
|
|
2504 79888 insdel.c
|
|
2505 6103 insdel.h
|
|
2506 @end example
|
|
2507
|
|
2508 @file{insdel.c} contains low-level functions for inserting and deleting text in
|
|
2509 a buffer, keeping track of changed regions for use by redisplay, and
|
|
2510 calling any before-change and after-change functions that may have been
|
|
2511 registered for the buffer. It also contains the actual functions that
|
|
2512 convert between byte offsets and character offsets.
|
|
2513
|
|
2514 @file{insdel.h} contains associated headers.
|
|
2515
|
|
2516
|
|
2517
|
|
2518 @example
|
|
2519 10975 marker.c
|
|
2520 @end example
|
|
2521
|
2
|
2522 This module implements the @dfn{marker} Lisp object type, which
|
|
2523 conceptually is a pointer to a text position in a buffer that moves
|
|
2524 around as text is inserted and deleted, so as to remain in the same
|
|
2525 relative position. This module doesn't actually move the markers around
|
|
2526 -- that's handled in @file{insdel.c}. This module just creates them and
|
|
2527 implements the primitives for working with them. As markers are simple
|
|
2528 objects, this does not entail much.
|
0
|
2529
|
|
2530 Note that the standard arithmetic primitives (e.g. @code{+}) accept
|
|
2531 markers in place of integers and automatically substitute the value of
|
|
2532 @code{marker-position} for the marker, i.e. an integer describing the
|
|
2533 current buffer position of the marker.
|
|
2534
|
|
2535
|
|
2536
|
|
2537 @example
|
|
2538 193714 extents.c
|
|
2539 15686 extents.h
|
|
2540 @end example
|
|
2541
|
2
|
2542 This module implements the @dfn{extent} Lisp object type, which is like
|
|
2543 a marker that works over a range of text rather than a single position.
|
0
|
2544 Extents are also much more complex and powerful than markers and have a
|
|
2545 more efficient (and more algorithmically complex) implementation. The
|
|
2546 implementation is described in detail in comments in @file{extents.c}.
|
|
2547
|
|
2548 The code in @file{extents.c} works closely with @file{insdel.c} so that
|
|
2549 extents are properly moved around as text is inserted and deleted.
|
|
2550 There is also code in @file{extents.c} that provides information needed
|
|
2551 by the redisplay mechanism for efficient operation. (Remember that
|
|
2552 extents can have display properties that affect [sometimes drastically,
|
|
2553 as in the @code{invisible} property] the display of the text they
|
|
2554 cover.)
|
|
2555
|
|
2556
|
|
2557
|
|
2558 @example
|
|
2559 60155 editfns.c
|
|
2560 @end example
|
|
2561
|
|
2562 @file{editfns.c} contains the standard Lisp primitives for working with
|
|
2563 a buffer's text, and calls the low-level functions in @file{insdel.c}.
|
|
2564 It also contains primitives for working with @code{point} (the default
|
|
2565 buffer insertion location).
|
|
2566
|
|
2567 @file{editfns.c} also contains functions for retrieving various
|
|
2568 characteristics from the external environment: the current time, the
|
|
2569 process ID of the running XEmacs process, the name of the user who ran
|
|
2570 this XEmacs process, etc. It's not clear why this code is in
|
|
2571 @file{editfns.c}.
|
|
2572
|
|
2573
|
|
2574
|
|
2575 @example
|
|
2576 26081 callint.c
|
|
2577 12577 cmds.c
|
|
2578 2749 commands.h
|
|
2579 @end example
|
|
2580
|
|
2581 @cindex interactive
|
|
2582 These modules implement the basic @dfn{interactive} commands,
|
|
2583 i.e. user-callable functions. Commands, as opposed to other functions,
|
|
2584 have special ways of getting their parameters interactively (by querying
|
|
2585 the user), as opposed to having them passed in a normal function
|
|
2586 invocation. Many commands are not really meant to be called from other
|
|
2587 Lisp functions, because they modify global state in a way that's often
|
|
2588 undesired as part of other Lisp functions.
|
|
2589
|
|
2590 @file{callint.c} implements the mechanism for querying the user for
|
|
2591 parameters and calling interactive commands. The bulk of this module is
|
|
2592 code that parses the interactive spec that is supplied with an
|
|
2593 interactive command.
|
|
2594
|
|
2595 @file{cmds.c} implements the basic, most commonly used editing commands:
|
|
2596 commands to move around the current buffer and insert and delete
|
|
2597 characters. These commands are implemented using the Lisp primitives
|
|
2598 defined in @file{editfns.c}.
|
|
2599
|
|
2600 @file{commands.h} contains associated structure definitions and prototypes.
|
|
2601
|
|
2602
|
|
2603
|
|
2604 @example
|
|
2605 194863 regex.c
|
|
2606 18968 regex.h
|
|
2607 79800 search.c
|
|
2608 @end example
|
|
2609
|
|
2610 @file{search.c} implements the Lisp primitives for searching for text in
|
|
2611 a buffer, and some of the low-level algorithms for doing this. In
|
|
2612 particular, the fast fixed-string Boyer-Moore search algorithm is
|
|
2613 implemented in @file{search.c}. The low-level algorithms for doing
|
|
2614 regular-expression searching, however, are implemented in @file{regex.c}
|
|
2615 and @file{regex.h}. These two modules are largely independent of
|
|
2616 XEmacs, and are similar to (and based upon) the regular-expression
|
|
2617 routines used in @file{grep} and other GNU utilities.
|
|
2618
|
|
2619
|
|
2620
|
|
2621 @example
|
|
2622 20476 doprnt.c
|
|
2623 @end example
|
|
2624
|
|
2625 @file{doprnt.c} implements formatted-string processing, similar to
|
|
2626 @code{printf()} command in C.
|
|
2627
|
|
2628
|
|
2629
|
|
2630 @example
|
|
2631 15372 undo.c
|
|
2632 @end example
|
|
2633
|
|
2634 This module implements the undo mechanism for tracking buffer changes.
|
|
2635 Most of this could be implemented in Lisp.
|
|
2636
|
|
2637
|
|
2638
|
|
2639 @node Editor-Level Control Flow Modules
|
|
2640 @section Editor-Level Control Flow Modules
|
|
2641
|
|
2642 @example
|
|
2643 size name
|
|
2644 ------- ---------------------
|
|
2645 84546 event-Xt.c
|
|
2646 121483 event-stream.c
|
|
2647 6658 event-tty.c
|
|
2648 49271 events.c
|
|
2649 14459 events.h
|
|
2650 @end example
|
|
2651
|
|
2652 These implement the handling of events (user input and other system
|
|
2653 notifications).
|
|
2654
|
2
|
2655 @file{events.c} and @file{events.h} define the @dfn{event} Lisp object
|
|
2656 type and primitives for manipulating it.
|
0
|
2657
|
|
2658 @file{event-stream.c} implements the basic functions for working with
|
|
2659 event queues, dispatching an event by looking it up in relevant keymaps
|
|
2660 and such, and handling timeouts; this includes the primitives
|
|
2661 @code{next-event} and @code{dispatch-event}, as well as related
|
|
2662 primitives such as @code{sit-for}, @code{sleep-for}, and
|
|
2663 @code{accept-process-output}. (@file{event-stream.c} is one of the
|
|
2664 hairiest and trickiest modules in XEmacs. Beware! You can easily mess
|
|
2665 things up here.)
|
|
2666
|
|
2667 @file{event-Xt.c} and @file{event-tty.c} implement the low-level
|
|
2668 interfaces onto retrieving events from Xt (the X toolkit) and from TTY's
|
|
2669 (using @code{read()} and @code{select()}), respectively. The event
|
|
2670 interface enforces a clean separation between the specific code for
|
|
2671 interfacing with the operating system and the generic code for working
|
|
2672 with events, by defining an API of basic, low-level event methods;
|
|
2673 @file{event-Xt.c} and @file{event-tty.c} are two different
|
|
2674 implementations of this API. To add support for a new operating system
|
|
2675 (e.g. NeXTstep), one merely needs to provide another implementation of
|
|
2676 those API functions.
|
|
2677
|
|
2678 Note that the choice of whether to use @file{event-Xt.c} or
|
|
2679 @file{event-tty.c} is made at compile time! Or at the very latest, it
|
|
2680 is made at startup time. @file{event-Xt.c} handles events for
|
|
2681 @emph{both} X and TTY frames; @file{event-tty.c} is only used when X
|
|
2682 support is not compiled into XEmacs. The reason for this is that there
|
|
2683 is only one event loop in XEmacs: thus, it needs to be able to receive
|
|
2684 events from all different kinds of frames.
|
|
2685
|
|
2686
|
|
2687
|
|
2688 @example
|
|
2689 129583 keymap.c
|
|
2690 2621 keymap.h
|
|
2691 @end example
|
|
2692
|
2
|
2693 @file{keymap.c} and @file{keymap.h} define the @dfn{keymap} Lisp object
|
|
2694 type and associated methods and primitives. (Remember that keymaps are
|
0
|
2695 objects that associate event descriptions with functions to be called to
|
|
2696 ``execute'' those events; @code{dispatch-event} looks up events in the
|
|
2697 relevant keymaps.)
|
|
2698
|
|
2699
|
|
2700
|
|
2701 @example
|
|
2702 25212 keyboard.c
|
|
2703 @end example
|
|
2704
|
|
2705 @file{keyboard.c} contains functions that implement the actual editor
|
|
2706 command loop -- i.e. the event loop that cyclically retrieves and
|
|
2707 dispatches events. This code is also rather tricky, just like
|
|
2708 @file{event-stream.c}.
|
|
2709
|
|
2710
|
|
2711
|
|
2712 @example
|
|
2713 9973 macros.c
|
|
2714 1397 macros.h
|
|
2715 @end example
|
|
2716
|
|
2717 These two modules contain the basic code for defining keyboard macros.
|
|
2718 These functions don't actually do much; most of the code that handles keyboard
|
|
2719 macros is mixed in with the event-handling code in @file{event-stream.c}.
|
|
2720
|
|
2721
|
|
2722
|
|
2723 @example
|
|
2724 23234 minibuf.c
|
|
2725 @end example
|
|
2726
|
|
2727 This contains some miscellaneous code related to the minibuffer (most of
|
|
2728 the minibuffer code was moved into Lisp by Richard Mlynarik). This
|
|
2729 includes the primitives for completion (although filename completion is
|
|
2730 in @file{dired.c}), the lowest-level interface to the minibuffer (if the
|
|
2731 command loop were cleaned up, this too could be in Lisp), and code for
|
|
2732 dealing with the echo area (this, too, was mostly moved into Lisp, and
|
|
2733 the only code remaining is code to call out to Lisp or provide simple
|
|
2734 bootstrapping implementations early in temacs, before the echo-area Lisp
|
|
2735 code is loaded).
|
|
2736
|
|
2737
|
|
2738
|
|
2739 @node Modules for the Basic Displayable Lisp Objects
|
|
2740 @section Modules for the Basic Displayable Lisp Objects
|
|
2741
|
|
2742 @example
|
|
2743 size name
|
|
2744 ------- ---------------------
|
|
2745 985 device-ns.h
|
|
2746 6454 device-stream.c
|
|
2747 1196 device-stream.h
|
|
2748 9526 device-tty.c
|
|
2749 8660 device-tty.h
|
|
2750 43798 device-x.c
|
|
2751 11667 device-x.h
|
|
2752 26056 device.c
|
|
2753 22993 device.h
|
|
2754 @end example
|
|
2755
|
2
|
2756 These modules implement the @dfn{device} Lisp object type. This
|
|
2757 abstracts a particular screen or connection on which frames are
|
|
2758 displayed. As with Lisp objects, event interfaces, and other
|
|
2759 subsystems, the device code is separated into a generic component that
|
|
2760 contains a standardized interface (in the form of a set of methods) onto
|
|
2761 particular device types.
|
0
|
2762
|
|
2763 The device subsystem defines all the methods and provides method
|
|
2764 services for not only device operations but also for the frame, window,
|
|
2765 menubar, scrollbar, toolbar, and other displayable-object subsystems.
|
|
2766 The reason for this is that all of these subsystems have the same
|
|
2767 subtypes (X, TTY, NeXTstep, Microsoft Windows, etc.) as devices do.
|
|
2768
|
|
2769
|
|
2770
|
|
2771 @example
|
|
2772 934 frame-ns.h
|
|
2773 2303 frame-tty.c
|
|
2774 69205 frame-x.c
|
|
2775 5976 frame-x.h
|
|
2776 68175 frame.c
|
|
2777 15080 frame.h
|
|
2778 @end example
|
|
2779
|
|
2780 Each device contains one or more frames in which objects (e.g. text) are
|
|
2781 displayed. A frame corresponds to a window in the window system;
|
|
2782 usually this is a top-level window but it could potentially be one of a
|
|
2783 number of overlapping child windows within a top-level window, using the
|
|
2784 MDI (Multiple Document Interface) protocol in Microsoft Windows or a
|
|
2785 similar scheme.
|
|
2786
|
2
|
2787 The @file{frame-*} files implement the @dfn{frame} Lisp object type and
|
|
2788 provide the generic and device-type-specific operations on frames
|
|
2789 (e.g. raising, lowering, resizing, moving, etc.).
|
0
|
2790
|
|
2791
|
|
2792
|
|
2793 @example
|
|
2794 160783 window.c
|
|
2795 15974 window.h
|
|
2796 @end example
|
|
2797
|
|
2798 @cindex window (in Emacs)
|
|
2799 @cindex pane
|
|
2800 Each frame consists of one or more non-overlapping @dfn{windows} (better
|
|
2801 known as @dfn{panes} in standard window-system terminology) in which a
|
|
2802 buffer's text can be displayed. Windows can also have scrollbars
|
|
2803 displayed around their edges.
|
|
2804
|
2
|
2805 @file{window.c} and @file{window.h} implement the @dfn{window} Lisp
|
|
2806 object type and provide code to manage windows. Since windows have no
|
0
|
2807 associated resources in the window system (the window system knows only
|
|
2808 about the frame; no child windows or anything are used for XEmacs
|
|
2809 windows), there is no device-type-specific code here; all of that code
|
|
2810 is part of the redisplay mechanism or the code for particular object
|
|
2811 types such as scrollbars.
|
|
2812
|
|
2813
|
|
2814
|
|
2815 @node Modules for other Display-Related Lisp Objects
|
|
2816 @section Modules for other Display-Related Lisp Objects
|
|
2817
|
|
2818 @example
|
|
2819 size name
|
|
2820 ------- ---------------------
|
|
2821 54397 faces.c
|
|
2822 15173 faces.h
|
|
2823 @end example
|
|
2824
|
|
2825
|
|
2826
|
|
2827 @example
|
|
2828 4961 bitmaps.h
|
|
2829 954 glyphs-ns.h
|
|
2830 105345 glyphs-x.c
|
|
2831 4288 glyphs-x.h
|
|
2832 72102 glyphs.c
|
|
2833 16356 glyphs.h
|
|
2834 @end example
|
|
2835
|
|
2836
|
|
2837
|
|
2838 @example
|
|
2839 952 objects-ns.h
|
|
2840 9971 objects-tty.c
|
|
2841 1465 objects-tty.h
|
|
2842 32326 objects-x.c
|
|
2843 2806 objects-x.h
|
|
2844 31944 objects.c
|
|
2845 6809 objects.h
|
|
2846 @end example
|
|
2847
|
|
2848
|
|
2849
|
|
2850 @example
|
|
2851 57511 menubar-x.c
|
|
2852 11243 menubar.c
|
|
2853 @end example
|
|
2854
|
|
2855
|
|
2856
|
|
2857 @example
|
|
2858 25012 scrollbar-x.c
|
|
2859 2554 scrollbar-x.h
|
|
2860 26954 scrollbar.c
|
|
2861 2778 scrollbar.h
|
|
2862 @end example
|
|
2863
|
|
2864
|
|
2865
|
|
2866 @example
|
|
2867 23117 toolbar-x.c
|
|
2868 43456 toolbar.c
|
|
2869 4280 toolbar.h
|
|
2870 @end example
|
|
2871
|
|
2872
|
|
2873
|
|
2874 @example
|
|
2875 25070 font-lock.c
|
|
2876 @end example
|
|
2877
|
|
2878 This file provides C support for syntax highlighting -- i.e.
|
|
2879 highlighting different syntactic constructs of a source file in
|
|
2880 different colors, for easy reading. The C support is provided so that
|
|
2881 this is fast.
|
|
2882
|
|
2883
|
|
2884
|
|
2885 @example
|
|
2886 32180 dgif_lib.c
|
|
2887 3999 gif_err.c
|
|
2888 10697 gif_lib.h
|
|
2889 9371 gifalloc.c
|
|
2890 @end example
|
|
2891
|
|
2892 These modules decode GIF-format image files, for use with glyphs.
|
|
2893
|
|
2894
|
|
2895
|
|
2896 @node Modules for the Redisplay Mechanism
|
|
2897 @section Modules for the Redisplay Mechanism
|
|
2898
|
|
2899 @example
|
|
2900 size name
|
|
2901 ------- ---------------------
|
|
2902 38692 redisplay-output.c
|
|
2903 40835 redisplay-tty.c
|
|
2904 65069 redisplay-x.c
|
|
2905 234142 redisplay.c
|
|
2906 17026 redisplay.h
|
|
2907 @end example
|
|
2908
|
|
2909 These files provide the redisplay mechanism. As with many other
|
|
2910 subsystems in XEmacs, there is a clean separation between the general
|
|
2911 and device-specific support.
|
|
2912
|
|
2913 @file{redisplay.c} contains the bulk of the redisplay engine. These
|
|
2914 functions update the redisplay structures (which describe how the screen
|
|
2915 is to appear) to reflect any changes made to the state of any
|
|
2916 displayable objects (buffer, frame, window, etc.) since the last time
|
|
2917 that redisplay was called. These functions are highly optimized to
|
|
2918 avoid doing more work than necessary (since redisplay is called
|
|
2919 extremely often and is potentially a huge time sink), and depend heavily
|
|
2920 on notifications from the objects themselves that changes have occurred,
|
|
2921 so that redisplay doesn't explicitly have to check each possible object.
|
|
2922 The redisplay mechanism also contains a great deal of caching to further
|
|
2923 speed things up; some of this caching is contained within the various
|
|
2924 displayable objects.
|
|
2925
|
|
2926 @file{redisplay-output.c} goes through the redisplay structures and converts
|
|
2927 them into calls to device-specific methods to actually output the screen
|
|
2928 changes.
|
|
2929
|
|
2930 @file{redisplay-x.c} and @file{redisplay-tty.c} are two implementations
|
|
2931 of these redisplay output methods, for X frames and TTY frames,
|
|
2932 respectively.
|
|
2933
|
|
2934
|
|
2935
|
|
2936 @example
|
|
2937 14129 indent.c
|
|
2938 @end example
|
|
2939
|
|
2940 This module contains various functions and Lisp primitives for
|
|
2941 converting between buffer positions and screen positions. These
|
|
2942 functions call the redisplay mechanism to do most of the work, and then
|
|
2943 examine the redisplay structures to get the necessary information. This
|
|
2944 module needs work.
|
|
2945
|
|
2946
|
|
2947
|
|
2948 @example
|
|
2949 14754 termcap.c
|
|
2950 2141 terminfo.c
|
|
2951 7253 tparam.c
|
|
2952 @end example
|
|
2953
|
|
2954 These files contain functions for working with the termcap (BSD-style)
|
|
2955 and terminfo (System V style) databases of terminal capabilities and
|
|
2956 escape sequences, used when XEmacs is displaying in a TTY.
|
|
2957
|
|
2958
|
|
2959
|
|
2960 @example
|
|
2961 10869 cm.c
|
|
2962 5876 cm.h
|
|
2963 @end example
|
|
2964
|
|
2965 These files provide some miscellaneous TTY-output functions and should
|
|
2966 probably be merged into @file{redisplay-tty.c}.
|
|
2967
|
|
2968
|
|
2969
|
|
2970 @node Modules for Interfacing with the File System
|
|
2971 @section Modules for Interfacing with the File System
|
|
2972
|
|
2973 @example
|
|
2974 size name
|
|
2975 ------- ---------------------
|
|
2976 43362 lstream.c
|
|
2977 14240 lstream.h
|
|
2978 @end example
|
|
2979
|
2
|
2980 These modules implement the @dfn{stream} Lisp object type. This is an
|
0
|
2981 internal-only Lisp object that implements a generic buffering stream.
|
|
2982 The idea is to provide a uniform interface onto all sources and sinks of
|
|
2983 data, including file descriptors, stdio streams, chunks of memory, Lisp
|
|
2984 buffers, Lisp strings, etc. That way, I/O functions can be written to
|
|
2985 the stream interface and can transparently handle all possible sources
|
|
2986 and sinks. (For example, the @code{read} function can read data from a
|
|
2987 file, a string, a buffer, or even a function that is called repeatedly
|
|
2988 to return data, without worrying about where the data is coming from or
|
|
2989 what-size chunks it is returned in.)
|
|
2990
|
|
2991 @cindex lstream
|
|
2992 Note that in the C code, streams are called @dfn{lstreams} (for ``Lisp
|
|
2993 streams'') to distinguish them from other kinds of streams, e.g. stdio
|
|
2994 streams and C++ I/O streams.
|
|
2995
|
|
2996 Similar to other subsystems in XEmacs, lstreams are separated into
|
|
2997 generic functions and a set of methods for the different types of
|
|
2998 lstreams. @file{lstream.c} provides implementations of many different
|
|
2999 types of streams; others are provided, e.g., in @file{mule-coding.c}.
|
|
3000
|
|
3001
|
|
3002
|
|
3003 @example
|
|
3004 126926 fileio.c
|
|
3005 @end example
|
|
3006
|
|
3007 This implements the basic primitives for interfacing with the file
|
|
3008 system. This includes primitives for reading files into buffers,
|
|
3009 writing buffers into files, checking for the presence or accessibility
|
|
3010 of files, canonicalizing file names, etc. Note that these primitives
|
|
3011 are usually not invoked directly by the user: There is a great deal of
|
|
3012 higher-level Lisp code that implements the user commands such as
|
|
3013 @code{find-file} and @code{save-buffer}. This is similar to the
|
|
3014 distinction between the lower-level primitives in @file{editfns.c} and
|
|
3015 the higher-level user commands in @file{commands.c} and
|
|
3016 @file{simple.el}.
|
|
3017
|
|
3018
|
|
3019
|
|
3020 @example
|
|
3021 10960 filelock.c
|
|
3022 @end example
|
|
3023
|
|
3024 This file provides functions for detecting clashes between different
|
|
3025 processes (e.g. XEmacs and some external process, or two different
|
|
3026 XEmacs processes) modifying the same file. (XEmacs can optionally use
|
|
3027 the @file{lock/} subdirectory to provide a form of ``locking'' between
|
|
3028 different XEmacs processes.) This module is also used by the low-level
|
|
3029 functions in @file{insdel.c} to ensure that, if the first modification
|
|
3030 is being made to a buffer whose corresponding file has been externally
|
|
3031 modified, the user is made aware of this so that the buffer can be
|
|
3032 synched up with the external changes if necessary.
|
|
3033
|
|
3034
|
|
3035 @example
|
|
3036 4527 filemode.c
|
|
3037 @end example
|
|
3038
|
|
3039 This file provides some miscellaneous functions that construct a
|
|
3040 @samp{rwxr-xr-x}-type permissions string (as might appear in an
|
|
3041 @file{ls}-style directory listing) given the information returned by the
|
|
3042 @code{stat()} system call.
|
|
3043
|
|
3044
|
|
3045
|
|
3046 @example
|
|
3047 22855 dired.c
|
|
3048 2094 ndir.h
|
|
3049 @end example
|
|
3050
|
|
3051 These files implement the XEmacs interface to directory searching. This
|
|
3052 includes a number of primitives for determining the files in a directory
|
|
3053 and for doing filename completion. (Remember that generic completion is
|
|
3054 handled by a different mechanism, in @file{minibuf.c}.)
|
|
3055
|
|
3056 @file{ndir.h} is a header file used for the directory-searching
|
|
3057 emulation functions provided in @file{sysdep.c} (see section J below),
|
|
3058 for systems that don't provide any directory-searching functions. (On
|
|
3059 those systems, directories can be read directly as files, and parsed.)
|
|
3060
|
|
3061
|
|
3062
|
|
3063 @example
|
|
3064 4311 realpath.c
|
|
3065 @end example
|
|
3066
|
|
3067 This file provides an implementation of the @code{realpath()} function
|
|
3068 for expanding symbolic links, on systems that don't implement it or have
|
|
3069 a broken implementation.
|
|
3070
|
|
3071
|
|
3072
|
|
3073 @node Modules for Other Aspects of the Lisp Interpreter and Object System
|
|
3074 @section Modules for Other Aspects of the Lisp Interpreter and Object System
|
|
3075
|
|
3076 @example
|
|
3077 size name
|
|
3078 ------- ---------------------
|
|
3079 22290 elhash.c
|
|
3080 2454 elhash.h
|
|
3081 12169 hash.c
|
|
3082 3369 hash.h
|
|
3083 @end example
|
|
3084
|
2
|
3085 These files implement the @dfn{hashtable} Lisp object type.
|
|
3086 @file{hash.c} and @file{hash.h} provide a generic C implementation of
|
|
3087 hash tables (which can stand independently of XEmacs), and
|
|
3088 @file{elhash.c} and @file{elhash.h} provide a Lisp interface onto the C
|
|
3089 hash tables using the hashtable Lisp object type.
|
0
|
3090
|
|
3091
|
|
3092
|
|
3093 @example
|
|
3094 95691 specifier.c
|
|
3095 11167 specifier.h
|
|
3096 @end example
|
|
3097
|
2
|
3098 This module implements the @dfn{specifier} Lisp object type. This is
|
0
|
3099 primarily used for displayable properties, and allows for values that
|
|
3100 are specific to a particular buffer, window, frame, device, or device
|
|
3101 class, as well as a default value existing. This is used, for example,
|
|
3102 to control the height of the horizontal scrollbar or the appearance of
|
|
3103 the @code{default}, @code{bold}, or other faces. The specifier object
|
|
3104 consists of a number of specifications, each of which maps from a
|
|
3105 buffer, window, etc. to a value. The function @code{specifier-instance}
|
|
3106 looks up a value given a window (from which a buffer, frame, and device
|
|
3107 can be derived).
|
|
3108
|
|
3109
|
|
3110 @example
|
|
3111 43058 chartab.c
|
|
3112 6503 chartab.h
|
|
3113 9918 casetab.c
|
|
3114 @end example
|
|
3115
|
116
|
3116 @file{chartab.c} and @file{chartab.h} implement the @dfn{char table}
|
|
3117 Lisp object type, which maps from characters or certain sorts of
|
|
3118 character ranges to Lisp objects. The implementation of this object
|
|
3119 type is optimized for the internal representation of characters. Char
|
|
3120 tables come in different types, which affect the allowed object types to
|
|
3121 which a character can be mapped and also dictate certain other
|
|
3122 properties of the char table.
|
0
|
3123
|
|
3124 @cindex case table
|
|
3125 @file{casetab.c} implements one sort of char table, the @dfn{case
|
|
3126 table}, which maps characters to other characters of possibly different
|
|
3127 case. These are used by XEmacs to implement case-changing primitives
|
|
3128 and to do case-insensitive searching.
|
|
3129
|
|
3130
|
|
3131
|
|
3132 @example
|
|
3133 49593 syntax.c
|
|
3134 10200 syntax.h
|
|
3135 @end example
|
|
3136
|
|
3137 @cindex scanner
|
116
|
3138 This module implements @dfn{syntax tables}, another sort of char table
|
|
3139 that maps characters into syntax classes that define the syntax of these
|
|
3140 characters (e.g. a parenthesis belongs to a class of @samp{open}
|
|
3141 characters that have corresponding @samp{close} characters and can be
|
|
3142 nested). This module also implements the Lisp @dfn{scanner}, a set of
|
|
3143 primitives for scanning over text based on syntax tables. This is used,
|
|
3144 for example, to find the matching parenthesis in a command such as
|
0
|
3145 @code{forward-sexp}, and by @file{font-lock.c} to locate quoted strings,
|
|
3146 comments, etc.
|
|
3147
|
|
3148
|
|
3149
|
|
3150 @example
|
|
3151 10438 casefiddle.c
|
|
3152 @end example
|
|
3153
|
|
3154 This module implements various Lisp primitives for upcasing, downcasing
|
|
3155 and capitalizing strings or regions of buffers.
|
|
3156
|
|
3157
|
|
3158
|
|
3159 @example
|
|
3160 20234 rangetab.c
|
|
3161 @end example
|
|
3162
|
2
|
3163 This module implements the @dfn{range table} Lisp object type, which
|
|
3164 provides for a mapping from ranges of integers to arbitrary Lisp
|
|
3165 objects.
|
0
|
3166
|
|
3167
|
|
3168
|
|
3169 @example
|
|
3170 3201 opaque.c
|
|
3171 2206 opaque.h
|
|
3172 @end example
|
|
3173
|
2
|
3174 This module implements the @dfn{opaque} Lisp object type, an
|
|
3175 internal-only Lisp object that encapsulates an arbitrary block of memory
|
|
3176 so that it can be managed by the Lisp allocation system. To create an
|
|
3177 opaque object, you call @code{make_opaque()}, passing a pointer to a
|
|
3178 block of memory. An object is created that is big enough to hold the
|
|
3179 memory, which is copied into the object's storage. The object will then
|
|
3180 stick around as long as you keep pointers to it, after which it will be
|
0
|
3181 automatically reclaimed.
|
|
3182
|
|
3183 @cindex mark method
|
|
3184 Opaque objects can also have an arbitrary @dfn{mark method} associated
|
|
3185 with them, in case the block of memory contains other Lisp objects that
|
|
3186 need to be marked for garbage-collection purposes. (If you need other
|
|
3187 object methods, such as a finalize method, you should just go ahead and
|
|
3188 create a new Lisp object type -- it's not hard.)
|
|
3189
|
|
3190
|
|
3191
|
|
3192 @example
|
|
3193 8783 abbrev.c
|
|
3194 @end example
|
|
3195
|
|
3196 This function provides a few primitives for doing dynamic abbreviation
|
|
3197 expansion. In XEmacs, most of the code for this has been moved into
|
|
3198 Lisp. Some C code remains for speed and because the primitive
|
|
3199 @code{self-insert-command} (which is executed for all self-inserting
|
|
3200 characters) hooks into the abbrev mechanism. (@code{self-insert-command}
|
|
3201 is itself in C only for speed.)
|
|
3202
|
|
3203
|
|
3204
|
|
3205 @example
|
|
3206 21934 doc.c
|
|
3207 @end example
|
|
3208
|
|
3209 This function provides primitives for retrieving the documentation
|
|
3210 strings of functions and variables. These documentation strings contain
|
|
3211 certain special markers that get dynamically expanded (e.g. a
|
|
3212 reverse-lookup is performed on some named functions to retrieve their
|
|
3213 current key bindings). Some documentation strings (in particular, for
|
|
3214 the built-in primitives and pre-loaded Lisp functions) are stored
|
|
3215 externally in a file @file{DOC} in the @file{lib-src/} directory and
|
|
3216 need to be fetched from that file. (Part of the build stage involves
|
|
3217 building this file, and another part involves constructing an index for
|
|
3218 this file and embedding it into the executable, so that the functions in
|
|
3219 @file{doc.c} do not have to search the entire @file{DOC} file to find
|
|
3220 the appropriate documentation string.)
|
|
3221
|
|
3222
|
|
3223
|
|
3224 @example
|
|
3225 13197 md5.c
|
|
3226 @end example
|
|
3227
|
|
3228 This function provides a Lisp primitive that implements the MD5 secure
|
|
3229 hashing scheme, used to create a large hash value of a string of data such that
|
|
3230 the data cannot be derived from the hash value. This is used for
|
|
3231 various security applications on the Internet.
|
|
3232
|
|
3233
|
|
3234
|
|
3235 @example
|
|
3236 7000 mocklisp.c
|
|
3237 @end example
|
|
3238
|
|
3239 This function provides some emulation of MockLisp, a version of Lisp
|
|
3240 provided in Gosling Emacs (aka Unipress Emacs), from which some old
|
|
3241 versions of GNU Emacs were derived. You have to explicitly enable this
|
|
3242 code with a configure option and shouldn't normally, because it changes
|
|
3243 the semantics of XEmacs Lisp in ways that are not desirable for normal
|
|
3244 Lisp programs.
|
|
3245
|
|
3246
|
|
3247
|
|
3248 @node Modules for Interfacing with the Operating System
|
|
3249 @section Modules for Interfacing with the Operating System
|
|
3250
|
|
3251 @example
|
|
3252 size name
|
|
3253 ------- ---------------------
|
|
3254 33533 callproc.c
|
|
3255 89697 process.c
|
|
3256 4663 process.h
|
|
3257 @end example
|
|
3258
|
|
3259 These modules allow XEmacs to spawn and communicate with subprocesses
|
|
3260 and network connections.
|
|
3261
|
|
3262 @cindex synchronous subprocesses
|
|
3263 @cindex subprocesses, synchronous
|
|
3264 @file{callproc.c} implements (through the @code{call-process}
|
|
3265 primitive) what are called @dfn{synchronous subprocesses}. This means
|
|
3266 that XEmacs runs a program, waits till it's done, and retrieves its
|
|
3267 output. A typical example might be calling the @file{ls} program to get
|
|
3268 a directory listing.
|
|
3269
|
|
3270 @cindex asynchronous subprocesses
|
|
3271 @cindex subprocesses, asynchronous
|
|
3272 @file{process.c} and @file{process.h} implement @dfn{asynchronous
|
|
3273 subprocesses}. This means that XEmacs starts a program and then
|
|
3274 continues normally, not waiting for the process to finish. Data can be
|
|
3275 sent to the process or retrieved from it as it's running. This is used
|
|
3276 for the @code{shell} command (which provides a front end onto a shell
|
|
3277 program such as @file{csh}), the mail and news readers implemented in
|
|
3278 XEmacs, etc. The result of calling @code{start-process} to start a
|
|
3279 subprocess is a process object, a particular kind of object used to
|
|
3280 communicate with the subprocess. You can send data to the process by
|
|
3281 passing the process object and the data to @code{send-process}, and you
|
|
3282 can specify what happens to data retrieved from the process by setting
|
|
3283 properties of the process object. (When the process sends data, XEmacs
|
|
3284 receives a process event, which says that there is data ready. When
|
|
3285 @code{dispatch-event} is called on this event, it reads the data from
|
|
3286 the process and does something with it, as specified by the process
|
|
3287 object's properties. Typically, this means inserting the data into a
|
|
3288 buffer or calling a function.) Another property of the process object is
|
|
3289 called the @dfn{sentinel}, which is a function that is called when the
|
|
3290 process terminates.
|
|
3291
|
|
3292 @cindex network connections
|
|
3293 Process objects are also used for network connections (connections to a
|
|
3294 process running on another machine). Network connections are started
|
|
3295 with @code{open-network-stream} but otherwise work just like
|
|
3296 subprocesses.
|
|
3297
|
|
3298
|
|
3299
|
|
3300 @example
|
|
3301 136029 sysdep.c
|
|
3302 5986 sysdep.h
|
|
3303 @end example
|
|
3304
|
|
3305 These modules implement most of the low-level, messy operating-system
|
|
3306 interface code. This includes various device control (ioctl) operations
|
|
3307 for file descriptors, TTY's, pseudo-terminals, etc. (usually this stuff
|
|
3308 is fairly system-dependent; thus the name of this module), and emulation
|
|
3309 of standard library functions and system calls on systems that don't
|
|
3310 provide them or have broken versions.
|
|
3311
|
|
3312
|
|
3313
|
|
3314 @example
|
|
3315 3605 sysdir.h
|
|
3316 6708 sysfile.h
|
|
3317 2027 sysfloat.h
|
|
3318 2918 sysproc.h
|
|
3319 745 syspwd.h
|
|
3320 7643 syssignal.h
|
|
3321 6892 systime.h
|
|
3322 12477 systty.h
|
|
3323 3487 syswait.h
|
|
3324 @end example
|
|
3325
|
|
3326 These header files provide consistent interfaces onto system-dependent
|
|
3327 header files and system calls. The idea is that, instead of including a
|
|
3328 standard header file like @file{<sys/param.h>} (which may or may not
|
|
3329 exist on various systems) or having to worry about whether all system
|
|
3330 provide a particular preprocessor constant, or having to deal with the
|
|
3331 four different paradigms for manipulating signals, you just include the
|
|
3332 appropriate @file{sys*.h} header file, which includes all the right
|
|
3333 system header files, defines and missing preprocessor constants,
|
|
3334 provides a uniform interface onto system calls, etc.
|
|
3335
|
|
3336 @file{sysdir.h} provides a uniform interface onto directory-querying
|
|
3337 functions. (In some cases, this is in conjunction with emulation
|
|
3338 functions in @file{sysdep.c}.)
|
|
3339
|
|
3340 @file{sysfile.h} includes all the necessary header files for standard
|
|
3341 system calls (e.g. @code{read()}), ensures that all necessary
|
|
3342 @code{open()} and @code{stat()} preprocessor constants are defined, and
|
|
3343 possibly (usually) substitutes sugared versions of @code{read()},
|
|
3344 @code{write()}, etc. that automatically restart interrupted I/O
|
|
3345 operations.
|
|
3346
|
|
3347 @file{sysfloat.h} includes the necessary header files for floating-point
|
|
3348 operations.
|
|
3349
|
|
3350 @file{sysproc.h} includes the necessary header files for calling
|
|
3351 @code{select()}, @code{fork()}, @code{execve()}, socket operations, and
|
|
3352 the like, and ensures that the @code{FD_*()} macros for descriptor-set
|
|
3353 manipulations are available.
|
|
3354
|
|
3355 @file{syspwd.h} includes the necessary header files for obtaining
|
|
3356 information from @file{/etc/passwd} (the functions are emulated under
|
|
3357 VMS).
|
|
3358
|
|
3359 @file{syssignal.h} includes the necessary header files for
|
|
3360 signal-handling and provides a uniform interface onto the different
|
|
3361 signal-handling and signal-blocking paradigms.
|
|
3362
|
|
3363 @file{systime.h} includes the necessary header files and provides
|
|
3364 uniform interfaces for retrieving the time of day, setting file
|
|
3365 access/modification times, getting the amount of time used by the XEmacs
|
|
3366 process, etc.
|
|
3367
|
|
3368 @file{systty.h} buffers against the infinitude of different ways of
|
|
3369 controlling TTY's.
|
|
3370
|
|
3371 @file{syswait.h} provides a uniform way of retrieving the exit status
|
|
3372 from a @code{wait()}ed-on process (some systems use a union, others use
|
|
3373 an int).
|
|
3374
|
|
3375
|
|
3376
|
|
3377 @example
|
|
3378 7940 hpplay.c
|
|
3379 10920 libsst.c
|
|
3380 1480 libsst.h
|
|
3381 3260 libst.h
|
|
3382 15355 linuxplay.c
|
|
3383 15849 nas.c
|
|
3384 19133 sgiplay.c
|
|
3385 15411 sound.c
|
|
3386 7358 sunplay.c
|
|
3387 @end example
|
|
3388
|
|
3389 These files implement the ability to play various sounds on some types
|
|
3390 of computers. You have to configure your XEmacs with sound support in
|
|
3391 order to get this capability.
|
|
3392
|
|
3393 @file{sound.c} provides the generic interface. It implements various
|
|
3394 Lisp primitives and variables that let you specify which sounds should
|
|
3395 be played in certain conditions. (The conditions are identified by
|
|
3396 symbols, which are passed to @code{ding} to make a sound. Various
|
|
3397 standard functions call this function at certain times; if sound support
|
|
3398 does not exist, a simple beep results.
|
|
3399
|
|
3400 @cindex native sound
|
|
3401 @cindex sound, native
|
|
3402 @file{sgiplay.c}, @file{sunplay.c}, @file{hpplay.c}, and
|
|
3403 @file{linuxplay.c} interface to the machine's speaker for various
|
|
3404 different kind of machines. This is called @dfn{native} sound.
|
|
3405
|
|
3406 @cindex sound, network
|
|
3407 @cindex network sound
|
|
3408 @cindex NAS
|
|
3409 @file{nas.c} interfaces to a computer somewhere else on the network
|
|
3410 using the NAS (Network Audio Server) protocol, playing sounds on that
|
|
3411 machine. This allows you to run XEmacs on a remote machine, with its
|
|
3412 display set to your local machine, and have the sounds be made on your
|
|
3413 local machine, provided that you have a NAS server running on your local
|
|
3414 machine.
|
|
3415
|
|
3416 @file{libsst.c}, @file{libsst.h}, and @file{libst.h} provide some
|
|
3417 additional functions for playing sound on a Sun SPARC but are not
|
|
3418 currently in use.
|
|
3419
|
|
3420
|
|
3421
|
|
3422 @example
|
|
3423 44368 tooltalk.c
|
|
3424 2137 tooltalk.h
|
|
3425 @end example
|
|
3426
|
|
3427 These two modules implement an interface to the ToolTalk protocol, which
|
|
3428 is an interprocess communication protocol implemented on some versions
|
|
3429 of Unix. ToolTalk is a high-level protocol that allows processes to
|
|
3430 register themselves as providers of particular services; other processes
|
|
3431 can then request a service without knowing or caring exactly who is
|
|
3432 providing the service. It is similar in spirit to the DDE protocol
|
|
3433 provided under Microsoft Windows. ToolTalk is a part of the new CDE
|
|
3434 (Common Desktop Environment) specification and is used to connect the
|
|
3435 parts of the SPARCWorks development environment.
|
|
3436
|
|
3437
|
|
3438
|
|
3439 @example
|
|
3440 22695 getloadavg.c
|
|
3441 @end example
|
|
3442
|
|
3443 This module provides the ability to retrieve the system's current load
|
|
3444 average. (The way to do this is highly system-specific, unfortunately,
|
|
3445 and requires a lot of special-case code.)
|
|
3446
|
|
3447
|
|
3448
|
|
3449 @example
|
|
3450 148520 energize.c
|
|
3451 6896 energize.h
|
|
3452 @end example
|
|
3453
|
|
3454 This module provides code to interface to an Energize server (when
|
|
3455 XEmacs is used as part of Lucid's Energize development environment) and
|
|
3456 provides some other Energize-specific functions. Much of the code in
|
|
3457 this module should be made more general-purpose and moved elsewhere, but
|
|
3458 is no longer very relevant now that Lucid is defunct. It also hasn't
|
|
3459 worked since version 19.12, since nobody has been maintaining it.
|
|
3460
|
|
3461
|
|
3462
|
|
3463 @example
|
|
3464 2861 sunpro.c
|
|
3465 @end example
|
|
3466
|
|
3467 This module provides a small amount of code used internally at Sun to
|
|
3468 keep statistics on the usage of XEmacs.
|
|
3469
|
|
3470
|
|
3471
|
|
3472 @example
|
|
3473 5548 broken-sun.h
|
|
3474 3468 strcmp.c
|
|
3475 2179 strcpy.c
|
|
3476 1650 sunOS-fix.c
|
|
3477 @end example
|
|
3478
|
|
3479 These files provide replacement functions and prototypes to fix numerous
|
|
3480 bugs in early releases of SunOS 4.1.
|
|
3481
|
|
3482
|
|
3483
|
|
3484 @example
|
|
3485 11669 hftctl.c
|
|
3486 @end example
|
|
3487
|
|
3488 This module provides some terminal-control code necessary on versions of
|
|
3489 AIX prior to 4.1.
|
|
3490
|
|
3491
|
|
3492
|
|
3493 @example
|
|
3494 1776 acldef.h
|
|
3495 1602 chpdef.h
|
|
3496 9032 uaf.h
|
|
3497 105 vlimit.h
|
|
3498 7145 vms-pp.c
|
|
3499 1158 vms-pwd.h
|
|
3500 26532 vmsfns.c
|
|
3501 6038 vmsmap.c
|
|
3502 695 vmspaths.h
|
|
3503 17482 vmsproc.c
|
|
3504 469 vmsproc.h
|
|
3505 @end example
|
|
3506
|
|
3507 All of these files are used for VMS support, which has never worked in
|
|
3508 XEmacs.
|
|
3509
|
|
3510
|
|
3511
|
|
3512 @example
|
|
3513 28316 msdos.c
|
|
3514 1472 msdos.h
|
|
3515 @end example
|
|
3516
|
|
3517 These modules are used for MS-DOS support, which does not work in
|
|
3518 XEmacs.
|
|
3519
|
|
3520
|
|
3521
|
|
3522 @node Modules for Interfacing with X Windows
|
|
3523 @section Modules for Interfacing with X Windows
|
|
3524
|
|
3525 @example
|
|
3526 size name
|
|
3527 ------- ---------------------
|
|
3528 3196 Emacs.ad.h
|
|
3529 @end example
|
|
3530
|
|
3531 A file generated from @file{Emacs.ad}, which contains XEmacs-supplied
|
|
3532 fallback resources (so that XEmacs has pretty defaults).
|
|
3533
|
|
3534
|
|
3535
|
|
3536 @example
|
|
3537 24242 EmacsFrame.c
|
|
3538 6979 EmacsFrame.h
|
|
3539 3351 EmacsFrameP.h
|
|
3540 @end example
|
|
3541
|
|
3542 These modules implement an Xt widget class that encapsulates a frame.
|
|
3543 This is for ease in integrating with Xt. The EmacsFrame widget covers
|
|
3544 the entire X window except for the menubar; the scrollbars are
|
|
3545 positioned on top of the EmacsFrame widget.
|
|
3546
|
|
3547 @strong{Warning:} Abandon hope, all ye who enter here. This code took
|
|
3548 an ungodly amount of time to get right, and is likely to fall apart
|
|
3549 mercilessly at the slightest change. Such is life under Xt.
|
|
3550
|
|
3551
|
|
3552
|
|
3553 @example
|
|
3554 8178 EmacsManager.c
|
|
3555 1967 EmacsManager.h
|
|
3556 1895 EmacsManagerP.h
|
|
3557 @end example
|
|
3558
|
|
3559 These modules implement a simple Xt manager (i.e. composite) widget
|
|
3560 class that simply lets its children set whatever geometry they want.
|
|
3561 It's amazing that Xt doesn't provide this standardly, but on second
|
|
3562 thought, it makes sense, considering how amazingly broken Xt is.
|
|
3563
|
|
3564
|
|
3565 @example
|
|
3566 13188 EmacsShell-sub.c
|
|
3567 4588 EmacsShell.c
|
|
3568 2180 EmacsShell.h
|
|
3569 3133 EmacsShellP.h
|
|
3570 @end example
|
|
3571
|
|
3572 These modules implement two Xt widget classes that are subclasses of
|
|
3573 the TopLevelShell and TransientShell classes. This is necessary to deal
|
|
3574 with more brokenness that Xt has sadistically thrust onto the backs of
|
|
3575 developers.
|
|
3576
|
|
3577
|
|
3578
|
|
3579 @example
|
|
3580 9673 xgccache.c
|
|
3581 1111 xgccache.h
|
|
3582 @end example
|
|
3583
|
|
3584 These modules provide functions for maintenance and caching of GC's
|
|
3585 (graphics contexts) under the X Window System. This code is junky and
|
|
3586 needs to be rewritten.
|
|
3587
|
|
3588
|
|
3589
|
|
3590 @example
|
|
3591 69181 xselect.c
|
|
3592 @end example
|
|
3593
|
|
3594 @cindex selections
|
|
3595 This module provides an interface to the X Window System's concept of
|
|
3596 @dfn{selections}, the standard way for X applications to communicate
|
|
3597 with each other.
|
|
3598
|
|
3599
|
|
3600
|
|
3601 @example
|
|
3602 929 xintrinsic.h
|
|
3603 1038 xintrinsicp.h
|
|
3604 1579 xmmanagerp.h
|
|
3605 1585 xmprimitivep.h
|
|
3606 @end example
|
|
3607
|
|
3608 These header files are similar in spirit to the @file{sys*.h} files and buffer
|
|
3609 against different implementations of Xt and Motif.
|
|
3610
|
|
3611 @itemize @bullet
|
|
3612 @item
|
|
3613 @file{xintrinsic.h} should be included in place of @file{<Intrinsic.h>}.
|
|
3614 @item
|
|
3615 @file{xintrinsicp.h} should be included in place of @file{<IntrinsicP.h>}.
|
|
3616 @item
|
|
3617 @file{xmmanagerp.h} should be included in place of @file{<XmManagerP.h>}.
|
|
3618 @item
|
|
3619 @file{xmprimitivep.h} should be included in place of @file{<XmPrimitiveP.h>}.
|
|
3620 @end itemize
|
|
3621
|
|
3622
|
|
3623
|
|
3624 @example
|
|
3625 16930 xmu.c
|
|
3626 936 xmu.h
|
|
3627 @end example
|
|
3628
|
|
3629 These files provide an emulation of the Xmu library for those systems
|
|
3630 (i.e. HPUX) that don't provide it as a standard part of X.
|
|
3631
|
|
3632
|
|
3633
|
|
3634 @example
|
|
3635 4201 ExternalClient-Xlib.c
|
|
3636 18083 ExternalClient.c
|
|
3637 2035 ExternalClient.h
|
|
3638 2104 ExternalClientP.h
|
|
3639 22684 ExternalShell.c
|
|
3640 1709 ExternalShell.h
|
|
3641 1971 ExternalShellP.h
|
|
3642 2478 extw-Xlib.c
|
|
3643 1481 extw-Xlib.h
|
|
3644 6565 extw-Xt.c
|
|
3645 1430 extw-Xt.h
|
|
3646 @end example
|
|
3647
|
|
3648 @cindex external widget
|
|
3649 These files provide the @dfn{external widget} interface, which allows an
|
|
3650 XEmacs frame to appear as a widget in another application. To do this,
|
|
3651 you have to configure with @samp{--external-widget}.
|
|
3652
|
|
3653 @file{ExternalShell*} provides the server (XEmacs) side of the
|
|
3654 connection.
|
|
3655
|
|
3656 @file{ExternalClient*} provides the client (other application) side of
|
|
3657 the connection. These files are not compiled into XEmacs but are
|
|
3658 compiled into libraries that are then linked into your application.
|
|
3659
|
|
3660 @file{extw-*} is common code that is used for both the client and server.
|
|
3661
|
|
3662 Don't touch this code; something is liable to break if you do.
|
|
3663
|
|
3664
|
|
3665
|
|
3666 @example
|
|
3667 31014 epoch.c
|
|
3668 @end example
|
|
3669
|
|
3670 This file provides some additional, Epoch-compatible, functionality for
|
|
3671 interfacing to the X Window System.
|
|
3672
|
|
3673
|
|
3674
|
|
3675 @node Modules for Internationalization
|
|
3676 @section Modules for Internationalization
|
|
3677
|
|
3678 @example
|
|
3679 size name
|
|
3680 ------- ---------------------
|
|
3681 42836 mule-canna.c
|
|
3682 16737 mule-ccl.c
|
|
3683 41080 mule-charset.c
|
|
3684 30176 mule-charset.h
|
|
3685 146844 mule-coding.c
|
|
3686 16588 mule-coding.h
|
|
3687 6996 mule-mcpath.c
|
|
3688 2899 mule-mcpath.h
|
|
3689 57158 mule-wnnfns.c
|
|
3690 3351 mule.c
|
|
3691 @end example
|
|
3692
|
|
3693 These files implement the MULE (Asian-language) support. Note that MULE
|
|
3694 actually provides a general interface for all sorts of languages, not
|
|
3695 just Asian languages (although they are generally the most complicated
|
|
3696 to support). This code is still in beta.
|
|
3697
|
|
3698 @file{mule-charset.*} and @file{mule-coding.*} provide the heart of the
|
2
|
3699 XEmacs MULE support. @file{mule-charset.*} implements the @dfn{charset}
|
|
3700 Lisp object type, which encapsulates a character set (an ordered one- or
|
|
3701 two-dimensional set of characters, such as US ASCII or JISX0208 Japanese
|
|
3702 Kanji).
|
|
3703
|
|
3704 @file{mule-coding.*} implements the @dfn{coding-system} Lisp object
|
|
3705 type, which encapsulates a method of converting between different
|
116
|
3706 encodings. An encoding is a representation of a stream of characters,
|
|
3707 possibly from multiple character sets, using a stream of bytes or words,
|
|
3708 and defines (e.g.) which escape sequences are used to specify particular
|
2
|
3709 character sets, how the indices for a character are converted into bytes
|
|
3710 (sometimes this involves setting the high bit; sometimes complicated
|
|
3711 rearranging of the values takes place, as in the Shift-JIS encoding),
|
|
3712 etc.
|
0
|
3713
|
|
3714 @file{mule-ccl.c} provides the CCL (Code Conversion Language)
|
|
3715 interpreter. CCL is similar in spirit to Lisp byte code and is used to
|
|
3716 implement converters for custom encodings.
|
|
3717
|
|
3718 @file{mule-canna.c} and @file{mule-wnnfns.c} implement interfaces to
|
|
3719 external programs used to implement the Canna and WNN input methods,
|
116
|
3720 respectively. This is currently in beta.
|
44
|
3721
|
|
3722 @file{mule-mcpath.c} provides some functions to allow for pathnames
|
|
3723 containing extended characters. This code is fragmentary, obsolete, and
|
|
3724 completely non-working. Instead, @var{pathname-coding-system} is used
|
|
3725 to specify conversions of names of files and directories. The standard
|
|
3726 C I/O functions like @samp{open()} are wrapped so that conversion occurs
|
|
3727 automatically.
|
0
|
3728
|
|
3729 @file{mule.c} provides a few miscellaneous things that should probably
|
|
3730 be elsewhere.
|
|
3731
|
|
3732
|
|
3733
|
|
3734 @example
|
|
3735 9400 intl.c
|
|
3736 @end example
|
|
3737
|
|
3738 This provides some miscellaneous internationalization code for
|
|
3739 implementing message translation and interfacing to the Ximp input
|
|
3740 method. None of this code is currently working.
|
|
3741
|
|
3742
|
|
3743
|
|
3744 @example
|
|
3745 1764 iso-wide.h
|
|
3746 @end example
|
|
3747
|
|
3748 This contains leftover code from an earlier implementation of
|
|
3749 Asian-language support, and is not currently used.
|
|
3750
|
|
3751
|
|
3752
|
|
3753
|
|
3754 @node Allocation of Objects in XEmacs Lisp, Events and the Event Loop, A Summary of the Various XEmacs Modules, Top
|
|
3755 @chapter Allocation of Objects in XEmacs Lisp
|
|
3756
|
|
3757 @menu
|
|
3758 * Introduction to Allocation::
|
|
3759 * Garbage Collection::
|
|
3760 * GCPROing::
|
|
3761 * Integers and Characters::
|
|
3762 * Allocation from Frob Blocks::
|
|
3763 * lrecords::
|
|
3764 * Low-level allocation::
|
|
3765 * Pure Space::
|
|
3766 * Cons::
|
|
3767 * Vector::
|
|
3768 * Bit Vector::
|
|
3769 * Symbol::
|
|
3770 * Marker::
|
|
3771 * String::
|
|
3772 * Bytecode::
|
|
3773 @end menu
|
|
3774
|
|
3775 @node Introduction to Allocation
|
|
3776 @section Introduction to Allocation
|
|
3777
|
|
3778 Emacs Lisp, like all Lisps, has garbage collection. This means that
|
|
3779 the programmer never has to explicitly free (destroy) an object; it
|
|
3780 happens automatically when the object becomes inaccessible. Most
|
|
3781 experts agree that garbage collection is a necessity in a modern,
|
|
3782 high-level language. Its omission from C stems from the fact that C was
|
|
3783 originally designed to be a nice abstract layer on top of assembly
|
|
3784 language, for writing kernels and basic system utilities rather than
|
|
3785 large applications.
|
|
3786
|
|
3787 Lisp objects can be created by any of a number of Lisp primitives.
|
|
3788 Most object types have one or a small number of basic primitives
|
|
3789 for creating objects. For conses, the basic primitive is @code{cons};
|
|
3790 for vectors, the primitives are @code{make-vector} and @code{vector}; for
|
|
3791 symbols, the primitives are @code{make-symbol} and @code{intern}; etc.
|
|
3792 Some Lisp objects, especially those that are primarily used internally,
|
|
3793 have no corresponding Lisp primitives. Every Lisp object, though,
|
|
3794 has at least one C primitive for creating it.
|
|
3795
|
|
3796 Recall from section (VII) that a Lisp object, as stored in a 32-bit
|
|
3797 or 64-bit word, has a mark bit, a few tag bits, and a ``value'' that
|
|
3798 occupies the remainder of the bits. We can separate the different
|
|
3799 Lisp object types into four broad categories:
|
|
3800
|
|
3801 @itemize @bullet
|
|
3802 @item
|
|
3803 (a) Those for whom the value directly represents the contents of the
|
|
3804 Lisp object. Only two types are in this category: integers and
|
|
3805 characters. No special allocation or garbage collection is necessary
|
116
|
3806 for such objects. Lisp objects of these types do not need to be
|
|
3807 @code{GCPRO}ed.
|
0
|
3808 @end itemize
|
|
3809
|
|
3810 In the remaining three categories, the value is a pointer to a
|
|
3811 structure.
|
|
3812
|
|
3813 @itemize @bullet
|
|
3814 @item
|
|
3815 @cindex frob block
|
|
3816 (b) Those for whom the tag directly specifies the type. Recall that
|
|
3817 there are only three tag bits; this means that at most five types can be
|
|
3818 specified this way. The most commonly-used types are stored in this
|
|
3819 format; this includes conses, strings, vectors, and sometimes symbols.
|
|
3820 With the exception of vectors, objects in this category are allocated in
|
|
3821 @dfn{frob blocks}, i.e. large blocks of memory that are subdivided into
|
|
3822 individual objects. This saves a lot on malloc overhead, since there
|
|
3823 are typically quite a lot of these objects around, and the objects are
|
|
3824 small. (A cons, for example, occupies 8 bytes on 32-bit machines -- 4
|
|
3825 bytes for each of the two objects it contains.) Vectors are individually
|
|
3826 @code{malloc()}ed since they are of variable size. (It would be
|
|
3827 possible, and desirable, to allocate vectors of certain small sizes out
|
|
3828 of frob blocks, but it isn't currently done.) Strings are handled
|
|
3829 specially: Each string is allocated in two parts, a fixed size structure
|
|
3830 containing a length and a data pointer, and the actual data of the
|
|
3831 string. The former structure is allocated in frob blocks as usual, and
|
|
3832 the latter data is stored in @dfn{string chars blocks} and is relocated
|
|
3833 during garbage collection to eliminate holes.
|
|
3834 @end itemize
|
|
3835
|
|
3836 In the remaining two categories, the type is stored in the object
|
|
3837 itself. The tag for all such objects is the generic @dfn{lrecord}
|
|
3838 (Lisp_Record) tag. The first four bytes (or eight, for 64-bit machines)
|
|
3839 of the object's structure are a pointer to a structure that describes
|
|
3840 the object's type, which includes method pointers and a pointer to a
|
|
3841 string naming the type. Note that it's possible to save some space by
|
|
3842 using a one- or two-byte tag, rather than a four- or eight-byte pointer
|
|
3843 to store the type, but it's not clear it's worth making the change.
|
|
3844
|
|
3845 @itemize @bullet
|
|
3846 @item
|
|
3847 (c) Those lrecords that are allocated in frob blocks (see above). This
|
|
3848 includes the objects that are most common and relatively small, and
|
|
3849 includes floats, bytecodes, symbols (when not in category (b)), extents,
|
|
3850 events, and markers. With the cleanup of frob blocks done in 19.12,
|
|
3851 it's not terribly hard to add more objects to this category, but it's a
|
|
3852 bit trickier than adding an object type to type (d) (esp. if the object
|
|
3853 needs a finalization method), and is not likely to save much space
|
|
3854 unless the object is small and there are many of them. (In fact, if
|
|
3855 there are very few of them, it might actually waste space.)
|
|
3856 @item
|
|
3857 (d) Those lrecords that are individually @code{malloc()}ed. These are
|
|
3858 called @dfn{lcrecords}. All other types are in this category. Adding a
|
|
3859 new type to this category is comparatively easy, and all types added
|
|
3860 since 19.8 (when the current allocation scheme was devised, by Richard
|
|
3861 Mlynarik), with the exception of the character type, have been in this
|
|
3862 category.
|
|
3863 @end itemize
|
|
3864
|
|
3865 Note that bit vectors are a bit of a special case. They are
|
|
3866 simple lrecords as in category (c), but are individually @code{malloc()}ed
|
|
3867 like vectors. You can basically view them as exactly like vectors
|
|
3868 except that their type is stored in lrecord fashion rather than
|
|
3869 in directly-tagged fashion.
|
|
3870
|
|
3871 Note that FSF Emacs redesigned their object system in 19.29 to follow
|
|
3872 a similar scheme. However, given RMS's expressed dislike for data
|
|
3873 abstraction, the FSF scheme is not nearly as clean or as easy to
|
|
3874 extend. (FSF calls items of type (c) @code{Lisp_Misc} and items of type
|
|
3875 (d) @code{Lisp_Vectorlike}, with separate tags for each, although
|
|
3876 @code{Lisp_Vectorlike} is also used for vectors.)
|
|
3877
|
|
3878 @node Garbage Collection
|
|
3879 @section Garbage Collection
|
|
3880 @cindex garbage collection
|
|
3881
|
|
3882 @cindex mark and sweep
|
|
3883 Garbage collection is simple in theory but tricky to implement.
|
|
3884 Emacs Lisp uses the oldest garbage collection method, called
|
|
3885 @dfn{mark and sweep}. Garbage collection begins by starting with
|
|
3886 all accessible locations (i.e. all variables and other slots where
|
|
3887 Lisp objects might occur) and recursively traversing all objects
|
|
3888 accessible from those slots, marking each one that is found.
|
|
3889 We then go through all of memory and free each object that is
|
|
3890 not marked, and unmarking each object that is marked. Note
|
|
3891 that ``all of memory'' means all currently allocated objects.
|
|
3892 Traversing all these objects means traversing all frob blocks,
|
|
3893 all vectors (which are chained in one big list), and all
|
|
3894 lcrecords (which are likewise chained).
|
|
3895
|
|
3896 Note that, when an object is marked, the mark has to occur
|
|
3897 inside of the object's structure, rather than in the 32-bit
|
|
3898 @code{Lisp_Object} holding the object's pointer; i.e. you can't just
|
|
3899 set the pointer's mark bit. This is because there may be many
|
|
3900 pointers to the same object. This means that the method of
|
|
3901 marking an object can differ depending on the type. The
|
|
3902 different marking methods are approximately as follows:
|
|
3903
|
|
3904 @enumerate
|
|
3905 @item
|
|
3906 For conses, the mark bit of the car is set.
|
|
3907 @item
|
|
3908 For strings, the mark bit of the string's plist is set.
|
|
3909 @item
|
|
3910 For symbols when not lrecords, the mark bit of the
|
|
3911 symbol's plist is set.
|
|
3912 @item
|
|
3913 For vectors, the length is negated after adding 1.
|
|
3914 @item
|
|
3915 For lrecords, the pointer to the structure describing
|
|
3916 the type is changed (see below).
|
|
3917 @item
|
|
3918 Integers and characters do not need to be marked, since
|
|
3919 no allocation occurs for them.
|
|
3920 @end enumerate
|
|
3921
|
|
3922 The details of this are in the @code{mark_object()} function.
|
|
3923
|
|
3924 Note that any code that operates during garbage collection has
|
|
3925 to be especially careful because of the fact that some objects
|
|
3926 may be marked and as such may not look like they normally do.
|
|
3927 In particular:
|
|
3928
|
|
3929 @itemize @bullet
|
|
3930 Some object pointers may have their mark bit set. This will make
|
|
3931 @code{FOOBARP()} predicates fail. Use @code{GC_FOOBARP()} to deal with
|
|
3932 this.
|
|
3933 @item
|
|
3934 Even if you clear the mark bit, @code{FOOBARP()} will still fail
|
|
3935 for lrecords because the implementation pointer has been
|
|
3936 changed (see below). @code{GC_FOOBARP()} will correctly deal with
|
|
3937 this.
|
|
3938 @item
|
|
3939 Vectors have their size field munged, so anything that
|
|
3940 looks at this field will fail.
|
|
3941 @item
|
|
3942 Note that @code{XFOOBAR()} macros @emph{will} work correctly on object
|
|
3943 pointers with their mark bit set, because the logical shift operations
|
|
3944 that remove the tag also remove the mark bit.
|
|
3945 @end itemize
|
|
3946
|
|
3947 Finally, note that garbage collection can be invoked explicitly
|
|
3948 by calling @code{garbage-collect} but is also called automatically
|
|
3949 by @code{eval}, once a certain amount of memory has been allocated
|
|
3950 since the last garbage collection (according to @code{gc-cons-threshold}).
|
|
3951
|
|
3952 @node GCPROing
|
|
3953 @section @code{GCPRO}ing
|
|
3954
|
|
3955 @code{GCPRO}ing is one of the ugliest and trickiest parts of Emacs
|
|
3956 internals. The basic idea is that whenever garbage collection
|
|
3957 occurs, all in-use objects must be reachable somehow or
|
|
3958 other from one of the roots of accessibility. The roots
|
|
3959 of accessibility are:
|
|
3960
|
|
3961 @enumerate
|
|
3962 @item
|
|
3963 All objects that have been @code{staticpro()}d. This is used for
|
|
3964 any global C variables that hold Lisp objects. A call to
|
|
3965 @code{staticpro()} happens implicitly as a result of any symbols
|
|
3966 declared with @code{defsymbol()} and any variables declared with
|
|
3967 @code{DEFVAR_FOO()}. You need to explicitly call @code{staticpro()}
|
|
3968 (in the @code{vars_of_foo()} method of a module) for other global
|
|
3969 C variables holding Lisp objects. (This typically includes
|
|
3970 internal lists and such things.)
|
|
3971
|
|
3972 Note that @code{obarray} is one of the @code{staticpro()}d things.
|
|
3973 Therefore, all functions and variables get marked through this.
|
|
3974 @item
|
|
3975 Any shadowed bindings that are sitting on the specpdl stack.
|
|
3976 @item
|
116
|
3977 Any objects sitting in currently active (Lisp) stack frames,
|
0
|
3978 catches, and condition cases.
|
|
3979 @item
|
|
3980 A couple of special-case places where active objects are
|
|
3981 located.
|
|
3982 @item
|
|
3983 Anything currently marked with @code{GCPRO}.
|
|
3984 @end enumerate
|
|
3985
|
|
3986 Marking with @code{GCPRO} is necessary because some C functions (quite
|
|
3987 a lot, in fact), allocate objects during their operation. Quite
|
|
3988 frequently, there will be no other pointer to the object while the
|
|
3989 function is running, and if a garbage collection occurs and the object
|
|
3990 needs to be referenced again, bad things will happen. The solution is
|
|
3991 to mark those objects with @code{GCPRO}. Unfortunately this is easy to
|
|
3992 forget, and there is basically no way around this problem. Here are
|
|
3993 some rules, though:
|
|
3994
|
|
3995 @enumerate
|
|
3996 @item
|
|
3997 For every @code{GCPRO@var{n}}, there have to be declarations of
|
|
3998 @code{struct gcpro gcpro1, gcpro2}, etc.
|
|
3999
|
|
4000 @item
|
|
4001 You @emph{must} @code{UNGCPRO} anything that's @code{GCPRO}ed, and you
|
|
4002 @emph{must not} @code{UNGCPRO} if you haven't @code{GCPRO}ed. Getting
|
|
4003 either of these wrong will lead to crashes, often in completely random
|
|
4004 places unrelated to where the problem lies.
|
|
4005
|
|
4006 @item
|
|
4007 The way this actually works is that all currently active @code{GCPRO}s
|
|
4008 are chained through the @code{struct gcpro} local variables, with the
|
|
4009 variable @samp{gcprolist} pointing to the head of the list and the nth
|
|
4010 local @code{gcpro} variable pointing to the first @code{gcpro} variable
|
|
4011 in the next enclosing stack frame. Each @code{GCPRO}ed thing is an
|
|
4012 lvalue, and the @code{struct gcpro} local variable contains a pointer to
|
|
4013 this lvalue. This is why things will mess up badly if you don't pair up
|
|
4014 the @code{GCPRO}s and @code{UNGCPRO}s -- you will end up with
|
|
4015 @code{gcprolist}s containing pointers to @code{struct gcpro}s or local
|
|
4016 @code{Lisp_Object} variables in no-longer-active stack frames.
|
|
4017
|
|
4018 @item
|
|
4019 It is actually possible for a single @code{struct gcpro} to
|
|
4020 protect a contiguous array of any number of values, rather than
|
|
4021 just a single lvalue. To effect this, call @code{GCPRO@var{n}} as usual on
|
|
4022 the first object in the array and then set @code{gcpron.nvars}.
|
|
4023
|
|
4024 @item
|
|
4025 @strong{Strings are relocated.} What this means in practice is that the
|
116
|
4026 pointer obtained using @code{XSTRING_DATA()} is liable to change at any
|
0
|
4027 time, and you should never keep it around past any function call, or
|
|
4028 pass it as an argument to any function that might cause a garbage
|
|
4029 collection. This is why a number of functions accept either a
|
|
4030 ``non-relocatable'' @code{char *} pointer or a relocatable Lisp string,
|
|
4031 and only access the Lisp string's data at the very last minute. In some
|
|
4032 cases, you may end up having to @code{alloca()} some space and copy the
|
|
4033 string's data into it.
|
|
4034
|
|
4035 @item
|
|
4036 By convention, if you have to nest @code{GCPRO}'s, use @code{NGCPRO@var{n}}
|
|
4037 (along with @code{struct gcpro ngcpro1, ngcpro2}, etc.), @code{NNGCPRO@var{n}},
|
|
4038 etc. This avoids compiler warnings about shadowed locals.
|
|
4039
|
|
4040 @item
|
|
4041 It is @emph{always} better to err on the side of extra @code{GCPRO}s
|
|
4042 rather than too few. The extra cycles spent on this are
|
|
4043 almost never going to make a whit of difference in the
|
|
4044 speed of anything.
|
|
4045
|
|
4046 @item
|
|
4047 The general rule to follow is that caller, not callee, @code{GCPRO}s.
|
|
4048 That is, you should not have to explicitly @code{GCPRO} any Lisp objects
|
|
4049 that are passed in as parameters, but if you create any Lisp objects
|
|
4050 (remember, this happens in all sorts of circumstances, e.g. with
|
|
4051 @code{Fcons()}, etc.), you are responsible for @code{GCPRO}ing the
|
|
4052 objects unless you are @emph{absolutely sure} that there's no
|
|
4053 possibility that a garbage-collection can occur while you need to use
|
|
4054 the object. Even then, consider @code{GCPRO}ing.
|
|
4055
|
|
4056 @item
|
|
4057 A garbage collection can occur whenever anything calls @code{Feval}, or
|
|
4058 whenever a QUIT can occur where execution can continue past
|
|
4059 this. (Remember, this is almost anywhere.)
|
|
4060
|
|
4061 @item
|
|
4062 If you have the @emph{least smidgeon of doubt} about whether
|
|
4063 you need to @code{GCPRO}, you should @code{GCPRO}.
|
|
4064
|
|
4065 @item
|
|
4066 Beware of @code{GCPRO}ing something that is uninitialized. If you have
|
116
|
4067 any shade of doubt about this, initialize all your variables to @code{Qnil}.
|
0
|
4068
|
|
4069 @item
|
|
4070 Be careful of traps, like calling @code{Fcons()} in the argument to
|
|
4071 another function. By the ``caller protects'' law, you should be
|
|
4072 @code{GCPRO}ing the newly-created cons, but you aren't. A certain
|
|
4073 number of functions that are commonly called on freshly created stuff
|
|
4074 (e.g. @code{nconc2()}, @code{Fsignal()}), break the ``caller protects''
|
|
4075 law and go ahead and @code{GCPRO} their arguments so as to simplify
|
|
4076 things, but make sure and check if it's OK whenever doing something like
|
|
4077 this.
|
|
4078
|
|
4079 @item
|
|
4080 Once again, remember to @code{GCPRO}! Bugs resulting from insufficient
|
|
4081 @code{GCPRO}ing are intermittent and extremely difficult to track down,
|
|
4082 often showing up in crashes inside of @code{garbage-collect} or in
|
|
4083 weirdly corrupted objects or even in incorrect values in a totally
|
|
4084 different section of code.
|
|
4085 @end enumerate
|
|
4086
|
|
4087 @cindex garbage collection, conservative
|
|
4088 @cindex conservative garbage collection
|
|
4089 Given the extremely error-prone nature of the @code{GCPRO} scheme, and
|
|
4090 the difficulties in tracking down, it should be considered a deficiency
|
|
4091 in the XEmacs code. A solution to this problem would involve
|
|
4092 implementing so-called @dfn{conservative} garbage collection for the C
|
|
4093 stack. That involves looking through all of stack memory and treating
|
|
4094 anything that looks like a reference to an object as a reference. This
|
|
4095 will result in a few objects not getting collected when they should, but
|
|
4096 it obviates the need for @code{GCPRO}ing, and allows garbage collection
|
|
4097 to happen at any point at all, such as during object allocation.
|
|
4098
|
|
4099 @node Integers and Characters
|
|
4100 @section Integers and Characters
|
|
4101
|
|
4102 Integer and character Lisp objects are created from integers using the
|
|
4103 macros @code{XSETINT()} and @code{XSETCHAR()} or the equivalent
|
|
4104 functions @code{make_int()} and @code{make_char()}. (These are actually
|
|
4105 macros on most systems.) These functions basically just do some moving
|
|
4106 of bits around, since the integral value of the object is stored
|
|
4107 directly in the @code{Lisp_Object}.
|
|
4108
|
|
4109 @code{XSETINT()} and the like will truncate values given to them that
|
|
4110 are too big; i.e. you won't get the value you expected but the tag bits
|
|
4111 will at least be correct.
|
|
4112
|
|
4113 @node Allocation from Frob Blocks
|
|
4114 @section Allocation from Frob Blocks
|
|
4115
|
|
4116 The uninitialized memory required by a @code{Lisp_Object} of a particular type
|
|
4117 is allocated using
|
|
4118 @code{ALLOCATE_FIXED_TYPE()}. This only occurs inside of the
|
|
4119 lowest-level object-creating functions in @file{alloc.c}:
|
|
4120 @code{Fcons()}, @code{make_float()}, @code{Fmake_byte_code()},
|
|
4121 @code{Fmake_symbol()}, @code{allocate_extent()},
|
|
4122 @code{allocate_event()}, @code{Fmake_marker()}, and
|
|
4123 @code{make_uninit_string()}. The idea is that, for each type, there are
|
|
4124 a number of frob blocks (each 2K in size); each frob block is divided up
|
|
4125 into object-sized chunks. Each frob block will have some of these
|
|
4126 chunks that are currently assigned to objects, and perhaps some that are
|
|
4127 free. (If a frob block has nothing but free chunks, it is freed at the
|
|
4128 end of the garbage collection cycle.) The free chunks are stored in a
|
|
4129 free list, which is chained by storing a pointer in the first four bytes
|
|
4130 of the chunk. (Except for the free chunks at the end of the last frob
|
|
4131 block, which are handled using an index which points past the end of the
|
|
4132 last-allocated chunk in the last frob block.)
|
|
4133 @code{ALLOCATE_FIXED_TYPE()} first tries to retrieve a chunk from the
|
|
4134 free list; if that fails, it calls
|
|
4135 @code{ALLOCATE_FIXED_TYPE_FROM_BLOCK()}, which looks at the end of the
|
|
4136 last frob block for space, and creates a new frob block if there is
|
|
4137 none. (There are actually two versions of these macros, one of which is
|
|
4138 more defensive but less efficient and is used for error-checking.)
|
|
4139
|
|
4140 @node lrecords
|
|
4141 @section lrecords
|
|
4142
|
|
4143 [see @file{lrecord.h}]
|
|
4144
|
|
4145 All lrecords have at the beginning of their structure a @code{struct
|
|
4146 lrecord_header}. This just contains a pointer to a @code{struct
|
|
4147 lrecord_implementation}, which is a structure containing method pointers
|
|
4148 and such. There is one of these for each type, and it is a global,
|
|
4149 constant, statically-declared structure that is declared in the
|
|
4150 @code{DEFINE_LRECORD_IMPLEMENTATION()} macro. (This macro actually
|
|
4151 declares an array of two @code{struct lrecord_implementation}
|
|
4152 structures. The first one contains all the standard method pointers,
|
|
4153 and is used in all normal circumstances. During garbage collection,
|
|
4154 however, the lrecord is @dfn{marked} by bumping its implementation
|
|
4155 pointer by one, so that it points to the second structure in the array.
|
|
4156 This structure contains a special indication in it that it's a
|
|
4157 @dfn{marked-object} structure: the finalize method is the special
|
|
4158 function @code{this_marks_a_marked_record()}, and all other methods are
|
|
4159 null pointers. At the end of garbage collection, all lrecords will
|
|
4160 either be reclaimed or unmarked by decrementing their implementation
|
|
4161 pointers, so this second structure pointer will never remain past
|
|
4162 garbage collection.
|
|
4163
|
|
4164 Simple lrecords (of type (c) above) just have a @code{struct
|
|
4165 lrecord_header} at their beginning. lcrecords, however, actually have a
|
|
4166 @code{struct lcrecord_header}. This, in turn, has a @code{struct
|
|
4167 lrecord_header} at its beginning, so sanity is preserved; but it also
|
2
|
4168 has a pointer used to chain all lcrecords together, and a special ID
|
0
|
4169 field used to distinguish one lcrecord from another. (This field is used
|
|
4170 only for debugging and could be removed, but the space gain is not
|
|
4171 significant.)
|
|
4172
|
|
4173 Simple lrecords are created using @code{ALLOCATE_FIXED_TYPE()}, just
|
|
4174 like for other frob blocks. The only change is that the implementation
|
|
4175 pointer must be initialized correctly. (The implementation structure for
|
|
4176 an lrecord, or rather the pointer to it, is named @code{lrecord_float},
|
|
4177 @code{lrecord_extent}, @code{lrecord_buffer}, etc.)
|
|
4178
|
|
4179 lcrecords are created using @code{alloc_lcrecord()}. This takes a
|
|
4180 size to allocate and an implementation pointer. (The size needs to be
|
|
4181 passed because some lcrecords, such as window configurations, are of
|
|
4182 variable size.) This basically just @code{malloc()}s the storage,
|
|
4183 initializes the @code{struct lcrecord_header}, and chains the lcrecord
|
|
4184 onto the head of the list of all lcrecords, which is stored in the
|
|
4185 variable @code{all_lcrecords}. The calls to @code{alloc_lcrecord()}
|
|
4186 generally occur in the lowest-level allocation function for each lrecord
|
|
4187 type.
|
|
4188
|
|
4189 Whenever you create an lrecord, you need to call either
|
|
4190 @code{DEFINE_LRECORD_IMPLEMENTATION()} or
|
|
4191 @code{DEFINE_LRECORD_SEQUENCE_IMPLEMENTATION()}. This needs to be
|
|
4192 specified in a C file, at the top level. What this actually does is
|
|
4193 define and initialize the implementation structure for the lrecord. (And
|
|
4194 possibly declares a function @code{error_check_foo()} that implements
|
|
4195 the @code{XFOO()} macro when error-checking is enabled.) The arguments
|
|
4196 to the macros are the actual type name (this is used to construct the C
|
|
4197 variable name of the lrecord implementation structure and related
|
|
4198 structures using the @samp{##} macro concatenation operator), a string
|
|
4199 that names the type on the Lisp level (this may not be the same as the C
|
|
4200 type name; typically, the C type name has underscores, while the Lisp
|
|
4201 string has dashes), various method pointers, and the name of the C
|
|
4202 structure that contains the object. The methods are used to encapsulate
|
|
4203 type-specific information about the object, such as how to print it or
|
|
4204 mark it for garbage collection, so that it's easy to add new object
|
|
4205 types without having to add a specific case for each new type in a bunch
|
|
4206 of different places.
|
|
4207
|
|
4208 The difference between @code{DEFINE_LRECORD_IMPLEMENTATION()} and
|
|
4209 @code{DEFINE_LRECORD_SEQUENCE_IMPLEMENTATION()} is that the former is
|
|
4210 used for fixed-size object types and the latter is for variable-size
|
|
4211 object types. Most object types are fixed-size; some complex
|
|
4212 types, however (e.g. window configurations), are variable-size.
|
|
4213 Variable-size object types have an extra method, which is called
|
|
4214 to determine the actual size of a particular object of that type.
|
|
4215 (Currently this is only used for keeping allocation statistics.)
|
|
4216
|
|
4217 For the purpose of keeping allocation statistics, the allocation
|
|
4218 engine keeps a list of all the different types that exist. Note that,
|
|
4219 since @code{DEFINE_LRECORD_IMPLEMENTATION()} is a macro that is
|
|
4220 specified at top-level, there is no way for it to add to the list of all
|
|
4221 existing types. What happens instead is that each implementation
|
|
4222 structure contains in it a dynamically assigned number that is
|
|
4223 particular to that type. (Or rather, it contains a pointer to another
|
|
4224 structure that contains this number. This evasiveness is done so that
|
|
4225 the implementation structure can be declared const.) In the sweep stage
|
|
4226 of garbage collection, each lrecord is examined to see if its
|
|
4227 implementation structure has its dynamically-assigned number set. If
|
|
4228 not, it must be a new type, and it is added to the list of known types
|
|
4229 and a new number assigned. The number is used to index into an array
|
|
4230 holding the number of objects of each type and the total memory
|
|
4231 allocated for objects of that type. The statistics in this array are
|
|
4232 also computed during the sweep stage. These statistics are returned by
|
|
4233 the call to @code{garbage-collect} and are printed out at the end of the
|
|
4234 loadup phase.
|
|
4235
|
|
4236 Note that for every type defined with a @code{DEFINE_LRECORD_*()}
|
|
4237 macro, there needs to be a @code{DECLARE_LRECORD_IMPLEMENTATION()}
|
|
4238 somewhere in a @file{.h} file, and this @file{.h} file needs to be
|
|
4239 included by @file{inline.c}.
|
|
4240
|
|
4241 Furthermore, there should generally be a set of @code{XFOOBAR()},
|
|
4242 @code{FOOBARP()}, etc. macros in a @file{.h} (or occasionally @file{.c})
|
|
4243 file. To create one of these, copy an existing model and modify as
|
|
4244 necessary.
|
|
4245
|
|
4246 The various methods in the lrecord implementation structure are:
|
|
4247
|
|
4248 @enumerate
|
|
4249 @item
|
|
4250 @cindex mark method
|
|
4251 A @dfn{mark} method. This is called during the marking stage and passed
|
|
4252 a function pointer (usually the @code{mark_object()} function), which is
|
|
4253 used to mark an object. All Lisp objects that are contained within the
|
|
4254 object need to be marked by applying this function to them. The mark
|
|
4255 method should also return a Lisp object, which should be either nil or
|
|
4256 an object to mark. (This can be used in lieu of calling
|
|
4257 @code{mark_object()} on the object, to reduce the recursion depth, and
|
|
4258 consequently should be the most heavily nested sub-object, such as a
|
|
4259 long list.)
|
|
4260
|
|
4261 @strong{Note}: When the mark method is called, garbage collection
|
|
4262 is in progress, and special precautions need to be taken
|
|
4263 when accessing objects; see section (B) above.
|
|
4264
|
|
4265 If your mark method does not need to do anything, it can be
|
|
4266 @code{NULL}.
|
|
4267
|
|
4268 @item
|
|
4269 A @dfn{print} method. This is called to create a printed representation
|
|
4270 of the object, whenever @code{princ}, @code{prin1}, or the like is
|
|
4271 called. It is passed the object, a stream to which the output is to be
|
|
4272 directed, and an @code{escapeflag} which indicates whether the object's
|
|
4273 printed representation should be @dfn{escaped} so that it is
|
|
4274 readable. (This corresponds to the difference between @code{princ} and
|
|
4275 @code{prin1}.) Basically, @dfn{escaped} means that strings will have
|
|
4276 quotes around them and confusing characters in the strings such as
|
|
4277 quotes, backslashes, and newlines will be backslashed; and that special
|
|
4278 care will be taken to make symbols print in a readable fashion
|
|
4279 (e.g. symbols that look like numbers will be backslashed). Other
|
|
4280 readable objects should perhaps pass @code{escapeflag} on when
|
|
4281 sub-objects are printed, so that readability is preserved when necessary
|
|
4282 (or if not, always pass in a 1 for @code{escapeflag}). Non-readable
|
|
4283 objects should in general ignore @code{escapeflag}, except that some use
|
|
4284 it as an indication that more verbose output should be given.
|
|
4285
|
|
4286 Sub-objects are printed using @code{print_internal()}, which takes
|
|
4287 exactly the same arguments as are passed to the print method.
|
|
4288
|
|
4289 Literal C strings should be printed using @code{write_c_string()},
|
|
4290 or @code{write_string_1()} for non-null-terminated strings.
|
|
4291
|
|
4292 Functions that do not have a readable representation should check the
|
|
4293 @code{print_readably} flag and signal an error if it is set.
|
|
4294
|
|
4295 If you specify NULL for the print method, the
|
|
4296 @code{default_object_printer()} will be used.
|
|
4297
|
|
4298 @item
|
|
4299 A @dfn{finalize} method. This is called at the beginning of the sweep
|
|
4300 stage on lcrecords that are about to be freed, and should be used to
|
|
4301 perform any extra object cleanup. This typically involves freeing any
|
|
4302 extra @code{malloc()}ed memory associated with the object, releasing any
|
|
4303 operating-system and window-system resources associated with the object
|
|
4304 (e.g. pixmaps, fonts), etc.
|
|
4305
|
|
4306 The finalize method can be NULL if nothing needs to be done.
|
|
4307
|
|
4308 WARNING #1: The finalize method is also called at the end of the dump
|
|
4309 phase; this time with the for_disksave parameter set to non-zero. The
|
|
4310 object is @emph{not} about to disappear, so you have to make sure to
|
|
4311 @emph{not} free any extra @code{malloc()}ed memory if you're going to
|
|
4312 need it later. (Also, signal an error if there are any operating-system
|
|
4313 and window-system resources here, because they can't be dumped.)
|
|
4314
|
|
4315 Finalize methods should, as a rule, set to zero any pointers after
|
|
4316 they've been freed, and check to make sure pointers are not zero before
|
|
4317 freeing. Although I'm pretty sure that finalize methods are not called
|
|
4318 twice on the same object (except for the @code{for_disksave} proviso),
|
|
4319 we've gotten nastily burned in some cases by not doing this.
|
|
4320
|
|
4321 WARNING #2: The finalize method is @emph{only} called for
|
|
4322 lcrecords, @emph{not} for simply lrecords. If you need a
|
|
4323 finalize method for simple lrecords, you have to stick
|
|
4324 it in the @code{ADDITIONAL_FREE_foo()} macro in @file{alloc.c}.
|
|
4325
|
|
4326 WARNING #3: Things are in an @emph{extremely} bizarre state
|
|
4327 when @code{ADDITIONAL_FREE_foo()} is called, so you have to
|
|
4328 be incredibly careful when writing one of these functions.
|
|
4329 See the comment in @code{gc_sweep()}. If you ever have to add
|
|
4330 one of these, consider using an lcrecord or dealing with
|
|
4331 the problem in a different fashion.
|
|
4332
|
|
4333 @item
|
|
4334 An @dfn{equal} method. This compares the two objects for similarity,
|
|
4335 when @code{equal} is called. It should compare the contents of the
|
|
4336 objects in some reasonable fashion. It is passed the two objects and a
|
|
4337 @dfn{depth} value, which is used to catch circular objects. To compare
|
|
4338 sub-Lisp-objects, call @code{internal_equal()} and bump the depth value
|
|
4339 by one. If this value gets too high, a @code{circular-object} error
|
|
4340 will be signaled.
|
|
4341
|
|
4342 If this is NULL, objects are @code{equal} only when they are @code{eq},
|
|
4343 i.e. identical.
|
|
4344
|
|
4345 @item
|
|
4346 A @dfn{hash} method. This is used to hash objects when they are to be
|
|
4347 compared with @code{equal}. The rule here is that if two objects are
|
|
4348 @code{equal}, they @emph{must} hash to the same value; i.e. your hash
|
|
4349 function should use some subset of the sub-fields of the object that are
|
|
4350 compared in the ``equal'' method. If you specify this method as
|
|
4351 @code{NULL}, the object's pointer will be used as the hash, which will
|
|
4352 @emph{fail} if the object has an @code{equal} method, so don't do this.
|
|
4353
|
|
4354 To hash a sub-Lisp-object, call @code{internal_hash()}. Bump the
|
|
4355 depth by one, just like in the ``equal'' method.
|
|
4356
|
|
4357 To convert a Lisp object directly into a hash value (using
|
|
4358 its pointer), use @code{LISP_HASH()}. This is what happens when
|
|
4359 the hash method is NULL.
|
|
4360
|
|
4361 To hash two or more values together into a single value, use
|
|
4362 @code{HASH2()}, @code{HASH3()}, @code{HASH4()}, etc.
|
|
4363
|
|
4364 @item
|
|
4365 @dfn{getprop}, @dfn{putprop}, @dfn{remprop}, and @dfn{plist} methods.
|
|
4366 These are used for object types that have properties. I don't feel like
|
|
4367 documenting them here. If you create one of these objects, you have to
|
|
4368 use different macros to define them,
|
|
4369 i.e. @code{DEFINE_LRECORD_IMPLEMENTATION_WITH_PROPS()} or
|
|
4370 @code{DEFINE_LRECORD_SEQUENCE_IMPLEMENTATION_WITH_PROPS()}.
|
|
4371
|
|
4372 @item
|
|
4373 A @dfn{size_in_bytes} method, when the object is of variable-size.
|
|
4374 (i.e. declared with a @code{_SEQUENCE_IMPLEMENTATION} macro.) This should
|
|
4375 simply return the object's size in bytes, exactly as you might expect.
|
|
4376 For an example, see the methods for window configurations and opaques.
|
|
4377 @end enumerate
|
|
4378
|
|
4379 @node Low-level allocation
|
|
4380 @section Low-level allocation
|
|
4381
|
|
4382 Memory that you want to allocate directly should be allocated using
|
|
4383 @code{xmalloc()} rather than @code{malloc()}. This implements
|
|
4384 error-checking on the return value, and once upon a time did some more
|
|
4385 vital stuff (i.e. @code{BLOCK_INPUT}, which is no longer necessary).
|
|
4386 Free using @code{xfree()}, and realloc using @code{xrealloc()}. Note
|
|
4387 that @code{xmalloc()} will do a non-local exit if the memory can't be
|
|
4388 allocated. (Many functions, however, do not expect this, and thus XEmacs
|
|
4389 will likely crash if this happens. @strong{This is a bug.} If you can,
|
|
4390 you should strive to make your function handle this OK. However, it's
|
|
4391 difficult in the general circumstance, perhaps requiring extra
|
|
4392 unwind-protects and such.)
|
|
4393
|
|
4394 Note that XEmacs provides two separate replacements for the standard
|
|
4395 @code{malloc()} library function. These are called @dfn{old GNU malloc}
|
|
4396 (@file{malloc.c}) and @dfn{new GNU malloc} (@file{gmalloc.c}),
|
|
4397 respectively. New GNU malloc is better in pretty much every way than
|
|
4398 old GNU malloc, and should be used if possible. (It used to be that on
|
|
4399 some systems, the old one worked but the new one didn't. I think this
|
|
4400 was due specifically to a bug in SunOS, which the new one now works
|
|
4401 around; so I don't think the old one ever has to be used any more.) The
|
|
4402 primary difference between both of these mallocs and the standard system
|
|
4403 malloc is that they are much faster, at the expense of increased space.
|
|
4404 The basic idea is that memory is allocated in fixed chunks of powers of
|
|
4405 two. This allows for basically constant malloc time, since the various
|
|
4406 chunks can just be kept on a number of free lists. (The standard system
|
|
4407 malloc typically allocates arbitrary-sized chunks and has to spend some
|
|
4408 time, sometimes a significant amount of time, walking the heap looking
|
|
4409 for a free block to use and cleaning things up.) The new GNU malloc
|
|
4410 improves on things by allocating large objects in chunks of 4096 bytes
|
|
4411 rather than in ever larger powers of two, which results in ever larger
|
|
4412 wastage. There is a slight speed loss here, but it's of doubtful
|
|
4413 significance.
|
|
4414
|
|
4415 NOTE: Apparently there is a third-generation GNU malloc that is
|
|
4416 significantly better than the new GNU malloc, and should probably
|
|
4417 be included in XEmacs.
|
|
4418
|
|
4419 There is also the relocating allocator, @file{ralloc.c}. This actually
|
|
4420 moves blocks of memory around so that the @code{sbrk()} pointer shrunk
|
|
4421 and virtual memory released back to the system. On some systems,
|
|
4422 this is a big win. On all systems, it causes a noticeable (and
|
|
4423 sometimes huge) speed penalty, so I turn it off by default.
|
|
4424 @file{ralloc.c} only works with the new GNU malloc in @file{gmalloc.c}.
|
|
4425 There are also two versions of @file{ralloc.c}, one that uses @code{mmap()}
|
|
4426 rather than block copies to move data around. This purports to
|
|
4427 be faster, although that depends on the amount of data that would
|
|
4428 have had to be block copied and the system-call overhead for
|
|
4429 @code{mmap()}. I don't know exactly how this works, except that the
|
|
4430 relocating-allocation routines are pretty much used only for
|
|
4431 the memory allocated for a buffer, which is the biggest consumer
|
|
4432 of space, esp. of space that may get freed later.
|
|
4433
|
|
4434 Note that the GNU mallocs have some ``memory warning'' facilities.
|
|
4435 XEmacs taps into them and issues a warning through the standard
|
|
4436 warning system, when memory gets to 75%, 85%, and 95% full.
|
|
4437 (On some systems, the memory warnings are not functional.)
|
|
4438
|
|
4439 Allocated memory that is going to be used to make a Lisp object
|
|
4440 is created using @code{allocate_lisp_storage()}. This calls @code{xmalloc()}
|
|
4441 but also verifies that the pointer to the memory can fit into
|
|
4442 a Lisp word (remember that some bits are taken away for a type
|
|
4443 tag and a mark bit). If not, an error is issued through @code{memory_full()}.
|
|
4444 @code{allocate_lisp_storage()} is called by @code{alloc_lcrecord()},
|
|
4445 @code{ALLOCATE_FIXED_TYPE()}, and the vector and bit-vector creation
|
|
4446 routines. These routines also call @code{INCREMENT_CONS_COUNTER()} at the
|
|
4447 appropriate times; this keeps statistics on how much memory is
|
|
4448 allocated, so that garbage-collection can be invoked when the
|
|
4449 threshold is reached.
|
|
4450
|
|
4451 @node Pure Space
|
|
4452 @section Pure Space
|
|
4453
|
|
4454 Not yet documented.
|
|
4455
|
|
4456 @node Cons
|
|
4457 @section Cons
|
|
4458
|
|
4459 Conses are allocated in standard frob blocks. The only thing to
|
|
4460 note is that conses can be explicitly freed using @code{free_cons()}
|
|
4461 and associated functions @code{free_list()} and @code{free_alist()}. This
|
|
4462 immediately puts the conses onto the cons free list, and decrements
|
|
4463 the statistics on memory allocation appropriately. This is used
|
|
4464 to good effect by some extremely commonly-used code, to avoid
|
|
4465 generating extra objects and thereby triggering GC sooner.
|
|
4466 However, you have to be @emph{extremely} careful when doing this.
|
|
4467 If you mess this up, you will get BADLY BURNED, and it has happened
|
|
4468 before.
|
|
4469
|
|
4470 @node Vector
|
|
4471 @section Vector
|
|
4472
|
|
4473 As mentioned above, each vector is @code{malloc()}ed individually, and
|
|
4474 all are threaded through the variable @code{all_vectors}. Vectors are
|
|
4475 marked strangely during garbage collection, by kludging the size field.
|
116
|
4476 Note that the @code{struct Lisp_Vector} is declared with its
|
|
4477 @code{contents} field being a @emph{stretchy} array of one element. It
|
|
4478 is actually @code{malloc()}ed with the right size, however, and access
|
|
4479 to any element through the @code{contents} array works fine.
|
0
|
4480
|
|
4481 @node Bit Vector
|
|
4482 @section Bit Vector
|
|
4483
|
|
4484 Bit vectors work exactly like vectors, except for more complicated
|
|
4485 code to access an individual bit, and except for the fact that bit
|
|
4486 vectors are lrecords while vectors are not. (The only difference here is
|
|
4487 that there's an lrecord implementation pointer at the beginning and the
|
|
4488 tag field in bit vector Lisp words is ``lrecord'' rather than
|
|
4489 ``vector''.)
|
|
4490
|
|
4491 @node Symbol
|
|
4492 @section Symbol
|
|
4493
|
|
4494 Symbols are also allocated in frob blocks. Note that the code
|
|
4495 exists for symbols to be either lrecords (category (c) above)
|
|
4496 or simple types (category (b) above), and are lrecords by
|
|
4497 default (I think), although there is no good reason for this.
|
|
4498
|
|
4499 Note that symbols in the awful horrible obarray structure are
|
|
4500 chained through their @code{next} field.
|
|
4501
|
|
4502 Remember that @code{intern} looks up a symbol in an obarray, creating
|
|
4503 one if necessary.
|
|
4504
|
|
4505 @node Marker
|
|
4506 @section Marker
|
|
4507
|
|
4508 Markers are allocated in frob blocks, as usual. They are kept
|
|
4509 in a buffer unordered, but in a doubly-linked list so that they
|
|
4510 can easily be removed. (Formerly this was a singly-linked list,
|
|
4511 but in some cases garbage collection took an extraordinarily
|
|
4512 long time due to the O(N^2) time required to remove lots of
|
|
4513 markers from a buffer.) Markers are removed from a buffer in
|
|
4514 the finalize stage, in @code{ADDITIONAL_FREE_marker()}.
|
|
4515
|
|
4516 @node String
|
|
4517 @section String
|
|
4518
|
|
4519 As mentioned above, strings are a special case. A string is logically
|
|
4520 two parts, a fixed-size object (containing the length, property list,
|
|
4521 and a pointer to the actual data), and the actual data in the string.
|
|
4522 The fixed-size object is a @code{struct Lisp_String} and is allocated in
|
|
4523 frob blocks, as usual. The actual data is stored in special
|
|
4524 @dfn{string-chars blocks}, which are 8K blocks of memory.
|
|
4525 Currently-allocated strings are simply laid end to end in these
|
|
4526 string-chars blocks, with a pointer back to the @code{struct Lisp_String}
|
|
4527 stored before each string in the string-chars block. When a new string
|
|
4528 needs to be allocated, the remaining space at the end of the last
|
|
4529 string-chars block is used if there's enough, and a new string-chars
|
|
4530 block is created otherwise.
|
|
4531
|
|
4532 There are never any holes in the string-chars blocks due to the string
|
|
4533 compaction and relocation that happens at the end of garbage collection.
|
|
4534 During the sweep stage of garbage collection, when objects are
|
|
4535 reclaimed, the garbage collector goes through all string-chars blocks,
|
|
4536 looking for unused strings. Each chunk of string data is preceded by a
|
|
4537 pointer to the corresponding @code{struct Lisp_String}, which indicates
|
|
4538 both whether the string is used and how big the string is, i.e. how to
|
2
|
4539 get to the next chunk of string data. Holes are compressed by
|
0
|
4540 block-copying the next string into the empty space and relocating the
|
|
4541 pointer stored in the corresponding @code{struct Lisp_String}.
|
|
4542 @strong{This means you have to be careful with strings in your code.}
|
|
4543 See the section above on @code{GCPRO}ing.
|
|
4544
|
|
4545 Note that there is one situation not handled: a string that is too big
|
|
4546 to fit into a string-chars block. Such strings, called @dfn{big
|
|
4547 strings}, are all @code{malloc()}ed as their own block. (#### Although it
|
|
4548 would make more sense for the threshold for big strings to be somewhat
|
|
4549 lower, e.g. 1/2 or 1/4 the size of a string-chars block. It seems that
|
|
4550 this was indeed the case formerly -- indeed, the threshold was set at
|
|
4551 1/8 -- but Mly forgot about this when rewriting things for 19.8.)
|
|
4552
|
|
4553 Note also that the string data in string-chars blocks is padded as
|
|
4554 necessary so that proper alignment constraints on the @code{struct
|
|
4555 Lisp_String} back pointers are maintained.
|
|
4556
|
|
4557 Finally, strings can be resized. This happens in Mule when a
|
|
4558 character is substituted with a different-length character, or during
|
|
4559 modeline frobbing. (You could also export this to Lisp, but it's not
|
|
4560 done so currently.) Resizing a string is a potentially tricky process.
|
|
4561 If the change is small enough that the padding can absorb it, nothing
|
|
4562 other than a simple memory move needs to be done. Keep in mind,
|
|
4563 however, that the string can't shrink too much because the offset to the
|
|
4564 next string in the string-chars block is computed by looking at the
|
|
4565 length and rounding to the nearest multiple of four or eight. If the
|
|
4566 string would shrink or expand beyond the correct padding, new string
|
|
4567 data needs to be allocated at the end of the last string-chars block and
|
|
4568 the data moved appropriately. This leaves some dead string data, which
|
|
4569 is marked by putting a special marker of 0xFFFFFFFF in the @code{struct
|
|
4570 Lisp_String} pointer before the data (there's no real @code{struct
|
|
4571 Lisp_String} to point to and relocate), and storing the size of the dead
|
|
4572 string data (which would normally be obtained from the now-non-existent
|
|
4573 @code{struct Lisp_String}) at the beginning of the dead string data gap.
|
|
4574 The string compactor recognizes this special 0xFFFFFFFF marker and
|
|
4575 handles it correctly.
|
|
4576
|
|
4577 @node Bytecode
|
|
4578 @section Bytecode
|
|
4579
|
|
4580 Not yet documented.
|
|
4581
|
|
4582 @node Events and the Event Loop, Evaluation; Stack Frames; Bindings, Allocation of Objects in XEmacs Lisp, Top
|
|
4583 @chapter Events and the Event Loop
|
|
4584
|
|
4585 @menu
|
|
4586 * Introduction to Events::
|
|
4587 * Main Loop::
|
|
4588 * Specifics of the Event Gathering Mechanism::
|
|
4589 * Specifics About the Emacs Event::
|
|
4590 * The Event Stream Callback Routines::
|
|
4591 * Other Event Loop Functions::
|
|
4592 * Converting Events::
|
|
4593 * Dispatching Events; The Command Builder::
|
|
4594 @end menu
|
|
4595
|
|
4596 @node Introduction to Events
|
|
4597 @section Introduction to Events
|
|
4598
|
|
4599 An event is an object that encapsulates information about an
|
|
4600 interesting occurrence in the operating system. Events are
|
|
4601 generated either by user action, direct (e.g. typing on the
|
|
4602 keyboard or moving the mouse) or indirect (moving another
|
|
4603 window, thereby generating an expose event on an Emacs frame),
|
|
4604 or as a result of some other typically asynchronous action happening,
|
|
4605 such as output from a subprocess being ready or a timer expiring.
|
|
4606 Events come into the system in an asynchronous fashion (typically
|
|
4607 through a callback being called) and are converted into a
|
|
4608 synchronous event queue (first-in, first-out) in a process that
|
|
4609 we will call @dfn{collection}.
|
|
4610
|
2
|
4611 Note that each application has its own event queue. (It is
|
0
|
4612 immaterial whether the collection process directly puts the
|
|
4613 events in the proper application's queue, or puts them into
|
|
4614 a single system queue, which is later split up.)
|
|
4615
|
|
4616 The most basic level of event collection is done by the
|
|
4617 operating system or window system. Typically, XEmacs does
|
|
4618 its own event collection as well. Often there are multiple
|
|
4619 layers of collection in XEmacs, with events from various
|
|
4620 sources being collected into a queue, which is then combined
|
|
4621 with other sources to go into another queue (i.e. a second
|
|
4622 level of collection), with perhaps another level on top of
|
|
4623 this, etc.
|
|
4624
|
|
4625 XEmacs has its own types of events (called @dfn{Emacs events}),
|
|
4626 which provides an abstract layer on top of the system-dependent
|
|
4627 nature of the most basic events that are received. Part of the
|
|
4628 complex nature of the XEmacs event collection process involves
|
|
4629 converting from the operating-system events into the proper
|
|
4630 Emacs events -- there may not be a one-to-one correspondence.
|
|
4631
|
|
4632 Emacs events are documented in @file{events.h}; I'll discuss them
|
|
4633 later.
|
|
4634
|
|
4635 @node Main Loop
|
|
4636 @section Main Loop
|
|
4637
|
|
4638 The @dfn{command loop} is the top-level loop that the editor is always
|
|
4639 running. It loops endlessly, calling @code{next-event} to retrieve an
|
|
4640 event and @code{dispatch-event} to execute it. @code{dispatch-event} does
|
|
4641 the appropriate thing with non-user events (process, timeout,
|
|
4642 magic, eval, mouse motion); this involves calling a Lisp handler
|
|
4643 function, redrawing a newly-exposed part of a frame, reading
|
|
4644 subprocess output, etc. For user events, @code{dispatch-event}
|
|
4645 looks up the event in relevant keymaps or menubars; when a
|
|
4646 full key sequence or menubar selection is reached, the appropriate
|
|
4647 function is executed. @code{dispatch-event} may have to keep state
|
|
4648 across calls; this is done in the ``command-builder'' structure
|
|
4649 associated with each console (remember, there's usually only
|
|
4650 one console), and the engine that looks up keystrokes and
|
|
4651 constructs full key sequences is called the @dfn{command builder}.
|
|
4652 This is documented elsewhere.
|
|
4653
|
|
4654 The guts of the command loop are in @code{command_loop_1()}. This
|
|
4655 function doesn't catch errors, though -- that's the job of
|
|
4656 @code{command_loop_2()}, which is a condition-case (i.e. error-trapping)
|
|
4657 wrapper around @code{command_loop_1()}. @code{command_loop_1()} never
|
|
4658 returns, but may get thrown out of.
|
|
4659
|
|
4660 When an error occurs, @code{cmd_error()} is called, which usually
|
|
4661 invokes the Lisp error handler in @code{command-error}; however, a
|
|
4662 default error handler is provided if @code{command-error} is @code{nil}
|
|
4663 (e.g. during startup). The purpose of the error handler is simply to
|
|
4664 display the error message and do associated cleanup; it does not need to
|
|
4665 throw anywhere. When the error handler finishes, the condition-case in
|
|
4666 @code{command_loop_2()} will finish and @code{command_loop_2()} will
|
|
4667 reinvoke @code{command_loop_1()}.
|
|
4668
|
|
4669 @code{command_loop_2()} is invoked from three places: from
|
|
4670 @code{initial_command_loop()} (called from @code{main()} at the end of
|
|
4671 internal initialization), from the Lisp function @code{recursive-edit},
|
|
4672 and from @code{call_command_loop()}.
|
|
4673
|
|
4674 @code{call_command_loop()} is called when a macro is started and when
|
|
4675 the minibuffer is entered; normal termination of the macro or minibuffer
|
|
4676 causes a throw out of the recursive command loop. (To
|
|
4677 @code{execute-kbd-macro} for macros and @code{exit} for minibuffers.
|
|
4678 Note also that the low-level minibuffer-entering function,
|
|
4679 @code{read-minibuffer-internal}, provides its own error handling and
|
|
4680 does not need @code{command_loop_2()}'s error encapsulation; so it tells
|
|
4681 @code{call_command_loop()} to invoke @code{command_loop_1()} directly.)
|
|
4682
|
|
4683 Note that both read-minibuffer-internal and recursive-edit set up a
|
|
4684 catch for @code{exit}; this is why @code{abort-recursive-edit}, which
|
|
4685 throws to this catch, exits out of either one.
|
|
4686
|
|
4687 @code{initial_command_loop()}, called from @code{main()}, sets up a
|
|
4688 catch for @code{top-level} when invoking @code{command_loop_2()},
|
|
4689 allowing functions to throw all the way to the top level if they really
|
|
4690 need to. Before invoking @code{command_loop_2()},
|
|
4691 @code{initial_command_loop()} calls @code{top_level_1()}, which handles
|
|
4692 all of the startup stuff (creating the initial frame, handling the
|
|
4693 command-line options, loading the user's @file{.emacs} file, etc.). The
|
|
4694 function that actually does this is in Lisp and is pointed to by the
|
|
4695 variable @code{top-level}; normally this function is
|
|
4696 @code{normal-top-level}. @code{top_level_1()} is just an error-handling
|
|
4697 wrapper similar to @code{command_loop_2()}. Note also that
|
|
4698 @code{initial_command_loop()} sets up a catch for @code{top-level} when
|
|
4699 invoking @code{top_level_1()}, just like when it invokes
|
|
4700 @code{command_loop_2()}.
|
|
4701
|
|
4702 @node Specifics of the Event Gathering Mechanism
|
|
4703 @section Specifics of the Event Gathering Mechanism
|
|
4704
|
|
4705 Here is an approximate diagram of the collection processes
|
|
4706 at work in XEmacs, under TTY's (TTY's are simpler than X
|
|
4707 so we'll look at this first):
|
|
4708
|
|
4709 @noindent
|
|
4710 @example
|
|
4711 asynch. asynch. asynch. asynch. [Collectors in
|
|
4712 kbd events kbd events process process the OS]
|
|
4713 | | output output
|
|
4714 | | | |
|
|
4715 | | | | SIGINT, [signal handlers
|
|
4716 | | | | SIGQUIT, in XEmacs]
|
|
4717 V V V V SIGWINCH,
|
|
4718 file file file file SIGALRM
|
|
4719 desc. desc. desc. desc. |
|
|
4720 (TTY) (TTY) (pipe) (pipe) |
|
|
4721 | | | | fake timeouts
|
|
4722 | | | | file |
|
|
4723 | | | | desc. |
|
|
4724 | | | | (pipe) |
|
|
4725 | | | | | |
|
|
4726 | | | | | |
|
|
4727 | | | | | |
|
|
4728 V V V V V V
|
|
4729 ------>-----------<----------------<----------------
|
|
4730 |
|
|
4731 |
|
|
4732 | [collected using select() in emacs_tty_next_event()
|
|
4733 | and converted to the appropriate Emacs event]
|
|
4734 |
|
|
4735 |
|
|
4736 V (above this line is TTY-specific)
|
|
4737 Emacs ------------------------------------------------
|
|
4738 event (below this line is the generic event mechanism)
|
|
4739 |
|
|
4740 |
|
|
4741 was there if not, call
|
|
4742 a SIGINT? emacs_tty_next_event()
|
|
4743 | |
|
|
4744 | |
|
|
4745 | |
|
|
4746 V V
|
|
4747 --->-------<----
|
|
4748 |
|
|
4749 | [collected in event_stream_next_event();
|
|
4750 | SIGINT is converted using maybe_read_quit_event()]
|
|
4751 V
|
|
4752 Emacs
|
|
4753 event
|
|
4754 |
|
|
4755 \---->------>----- maybe_kbd_translate() ---->---\
|
|
4756 |
|
|
4757 |
|
|
4758 |
|
|
4759 command event queue |
|
|
4760 if not from command
|
|
4761 (contains events that were event queue, call
|
|
4762 read earlier but not processed, event_stream_next_event()
|
|
4763 typically when waiting in a |
|
|
4764 sit-for, sleep-for, etc. for |
|
|
4765 a particular event to be received) |
|
|
4766 | |
|
|
4767 | |
|
|
4768 V V
|
|
4769 ---->------------------------------------<----
|
|
4770 |
|
|
4771 | [collected in
|
|
4772 | next_event_internal()]
|
|
4773 |
|
|
4774 unread- unread- event from |
|
|
4775 command- command- keyboard else, call
|
|
4776 events event macro next_event_internal()
|
|
4777 | | | |
|
|
4778 | | | |
|
|
4779 | | | |
|
|
4780 V V V V
|
|
4781 --------->----------------------<------------
|
|
4782 |
|
|
4783 | [collected in `next-event', which may loop
|
|
4784 | more than once if the event it gets is on
|
|
4785 | a dead frame, device, etc.]
|
|
4786 |
|
|
4787 |
|
|
4788 V
|
|
4789 feed into top-level event loop,
|
|
4790 which repeatedly calls `next-event'
|
|
4791 and then dispatches the event
|
|
4792 using `dispatch-event'
|
|
4793 @end example
|
|
4794
|
|
4795 Notice the separation between TTY-specific and generic event mechanism.
|
|
4796 When using the Xt-based event loop, the TTY-specific stuff is replaced
|
|
4797 but the rest stays the same.
|
|
4798
|
|
4799 It's also important to realize that only one different kind of
|
|
4800 system-specific event loop can be operating at a time, and must be able
|
|
4801 to receive all kinds of events simultaneously. For the two existing
|
|
4802 event loops (implemented in @file{event-tty.c} and @file{event-Xt.c},
|
|
4803 respectively), the TTY event loop @emph{only} handles TTY consoles,
|
|
4804 while the Xt event loop handles @emph{both} TTY and X consoles. This
|
|
4805 situation is different from all of the output handlers, where you simply
|
|
4806 have one per console type.
|
|
4807
|
|
4808 Here's the Xt Event Loop Diagram (notice that below a certain point,
|
|
4809 it's the same as the above diagram):
|
|
4810
|
|
4811 @example
|
|
4812 asynch. asynch. asynch. asynch. [Collectors in
|
|
4813 kbd kbd process process the OS]
|
|
4814 events events output output
|
|
4815 | | | |
|
|
4816 | | | | asynch. asynch. [Collectors in the
|
|
4817 | | | | X X OS and X Window System]
|
|
4818 | | | | events events
|
|
4819 | | | | | |
|
|
4820 | | | | | |
|
|
4821 | | | | | | SIGINT, [signal handlers
|
|
4822 | | | | | | SIGQUIT, in XEmacs]
|
|
4823 | | | | | | SIGWINCH,
|
|
4824 | | | | | | SIGALRM
|
|
4825 | | | | | | |
|
|
4826 | | | | | | |
|
|
4827 | | | | | | | timeouts
|
|
4828 | | | | | | | |
|
|
4829 | | | | | | | |
|
|
4830 | | | | | | V |
|
|
4831 V V V V V V fake |
|
|
4832 file file file file file file file |
|
|
4833 desc. desc. desc. desc. desc. desc. desc. |
|
|
4834 (TTY) (TTY) (pipe) (pipe) (socket) (socket) (pipe) |
|
|
4835 | | | | | | | |
|
|
4836 | | | | | | | |
|
|
4837 | | | | | | | |
|
|
4838 V V V V V V V V
|
|
4839 --->----------------------------------------<---------<------
|
|
4840 | | |
|
|
4841 | | | [collected using select() in
|
|
4842 | | | _XtWaitForSomething(), called
|
|
4843 | | | from XtAppProcessEvent(), called
|
|
4844 | | | in emacs_Xt_next_event();
|
|
4845 | | | dispatched to various callbacks]
|
|
4846 | | |
|
|
4847 | | |
|
|
4848 emacs_Xt_ p_s_callback(), | [popup_selection_callback]
|
|
4849 event_handler() x_u_v_s_callback(),| [x_update_vertical_scrollbar_
|
|
4850 | x_u_h_s_callback(),| callback]
|
|
4851 | search_callback() | [x_update_horizontal_scrollbar_
|
|
4852 | | | callback]
|
|
4853 | | |
|
|
4854 | | |
|
|
4855 enqueue_Xt_ signal_special_ |
|
|
4856 dispatch_event() Xt_user_event() |
|
|
4857 [maybe multiple | |
|
|
4858 times, maybe 0 | |
|
|
4859 times] | |
|
|
4860 | enqueue_Xt_ |
|
|
4861 | dispatch_event() |
|
|
4862 | | |
|
|
4863 | | |
|
|
4864 V V |
|
|
4865 -->----------<-- |
|
|
4866 | |
|
|
4867 | |
|
|
4868 dispatch Xt_what_callback()
|
|
4869 event sets flags
|
|
4870 queue |
|
|
4871 | |
|
|
4872 | |
|
|
4873 | |
|
|
4874 | |
|
|
4875 ---->-----------<--------
|
|
4876 |
|
|
4877 |
|
|
4878 | [collected and converted as appropriate in
|
|
4879 | emacs_Xt_next_event()]
|
|
4880 |
|
|
4881 |
|
|
4882 V (above this line is Xt-specific)
|
|
4883 Emacs ------------------------------------------------
|
|
4884 event (below this line is the generic event mechanism)
|
|
4885 |
|
|
4886 |
|
|
4887 was there if not, call
|
|
4888 a SIGINT? emacs_Xt_next_event()
|
|
4889 | |
|
|
4890 | |
|
|
4891 | |
|
|
4892 V V
|
|
4893 --->-------<----
|
|
4894 |
|
|
4895 | [collected in event_stream_next_event();
|
|
4896 | SIGINT is converted using maybe_read_quit_event()]
|
|
4897 V
|
|
4898 Emacs
|
|
4899 event
|
|
4900 |
|
|
4901 \---->------>----- maybe_kbd_translate() -->-----\
|
|
4902 |
|
|
4903 |
|
|
4904 |
|
|
4905 command event queue |
|
|
4906 if not from command
|
|
4907 (contains events that were event queue, call
|
|
4908 read earlier but not processed, event_stream_next_event()
|
|
4909 typically when waiting in a |
|
|
4910 sit-for, sleep-for, etc. for |
|
|
4911 a particular event to be received) |
|
|
4912 | |
|
|
4913 | |
|
|
4914 V V
|
|
4915 ---->----------------------------------<------
|
|
4916 |
|
|
4917 | [collected in
|
|
4918 | next_event_internal()]
|
|
4919 |
|
|
4920 unread- unread- event from |
|
|
4921 command- command- keyboard else, call
|
|
4922 events event macro next_event_internal()
|
|
4923 | | | |
|
|
4924 | | | |
|
|
4925 | | | |
|
|
4926 V V V V
|
|
4927 --------->----------------------<------------
|
|
4928 |
|
|
4929 | [collected in `next-event', which may loop
|
|
4930 | more than once if the event it gets is on
|
|
4931 | a dead frame, device, etc.]
|
|
4932 |
|
|
4933 |
|
|
4934 V
|
|
4935 feed into top-level event loop,
|
|
4936 which repeatedly calls `next-event'
|
|
4937 and then dispatches the event
|
|
4938 using `dispatch-event'
|
|
4939 @end example
|
|
4940
|
|
4941 @node Specifics About the Emacs Event
|
|
4942 @section Specifics About the Emacs Event
|
|
4943
|
|
4944 @node The Event Stream Callback Routines
|
|
4945 @section The Event Stream Callback Routines
|
|
4946
|
|
4947 @node Other Event Loop Functions
|
|
4948 @section Other Event Loop Functions
|
|
4949
|
|
4950 @code{detect_input_pending()} and @code{input-pending-p} look for
|
|
4951 input by calling @code{event_stream->event_pending_p} and looking in
|
|
4952 @code{[V]unread-command-event} and the @code{command_event_queue} (they
|
|
4953 do not check for an executing keyboard macro, though).
|
|
4954
|
|
4955 @code{discard-input} cancels any command events pending (and any
|
|
4956 keyboard macros currently executing), and puts the others onto the
|
|
4957 @code{command_event_queue}. There is a comment about a ``race
|
|
4958 condition'', which is not a good sign.
|
|
4959
|
|
4960 @code{next-command-event} and @code{read-char} are higher-level
|
|
4961 interfaces to @code{next-event}. @code{next-command-event} gets the
|
116
|
4962 next @dfn{command} event (i.e. keypress, mouse event, menu selection,
|
|
4963 or scrollbar action), calling @code{dispatch-event} on any others.
|
|
4964 @code{read-char} calls @code{next-command-event} and uses
|
|
4965 @code{event_to_character()} to return the character equivalent. With
|
|
4966 the right kind of input method support, it is possible for (read-char)
|
|
4967 to return a Kanji character.
|
0
|
4968
|
|
4969 @node Converting Events
|
|
4970 @section Converting Events
|
|
4971
|
|
4972 @code{character_to_event()}, @code{event_to_character()},
|
|
4973 @code{event-to-character}, and @code{character-to-event} convert between
|
116
|
4974 characters and keypress events corresponding to the characters. If the
|
0
|
4975 event was not a keypress, @code{event_to_character()} returns -1 and
|
|
4976 @code{event-to-character} returns @code{nil}. These functions convert
|
116
|
4977 between character representation and the split-up event representation
|
0
|
4978 (keysym plus mod keys).
|
|
4979
|
|
4980 @node Dispatching Events; The Command Builder
|
|
4981 @section Dispatching Events; The Command Builder
|
|
4982
|
|
4983 Not yet documented.
|
|
4984
|
|
4985 @node Evaluation; Stack Frames; Bindings, Symbols and Variables, Events and the Event Loop, Top
|
|
4986 @chapter Evaluation; Stack Frames; Bindings
|
|
4987
|
|
4988 @menu
|
|
4989 * Evaluation::
|
|
4990 * Dynamic Binding; The specbinding Stack; Unwind-Protects::
|
|
4991 * Simple Special Forms::
|
|
4992 * Catch and Throw::
|
|
4993 @end menu
|
|
4994
|
|
4995 @node Evaluation
|
|
4996 @section Evaluation
|
|
4997
|
|
4998 @code{Feval()} evaluates the form (a Lisp object) that is passed to
|
|
4999 it. Note that evaluation is only non-trivial for two types of objects:
|
|
5000 symbols and conses. Under normal circumstances (i.e. not mocklisp) a
|
|
5001 symbol is evaluated simply by calling symbol-value on it and returning
|
|
5002 the value.
|
|
5003
|
|
5004 Evaluating a cons means calling a function. First, @code{eval} checks
|
|
5005 to see if garbage-collection is necessary, and calls
|
|
5006 @code{Fgarbage_collect()} if so. It then increases the evaluation depth
|
|
5007 by 1 (@code{lisp_eval_depth}, which is always less than @code{max_lisp_eval_depth}) and adds an
|
|
5008 element to the linked list of @code{struct backtrace}'s
|
|
5009 (@code{backtrace_list}). Each such structure contains a pointer to the
|
|
5010 function being called plus a list of the function's arguments.
|
|
5011 Originally these values are stored unevalled, and as they are evaluated,
|
|
5012 the backtrace structure is updated. Garbage collection pays attention
|
|
5013 to the objects pointed to in the backtrace structures (garbage
|
|
5014 collection might happen while a function is being called or while an
|
|
5015 argument is being evaluated, and there could easily be no other
|
|
5016 references to the arguments in the argument list; once an argument is
|
|
5017 evaluated, however, the unevalled version is not needed by eval, and so
|
|
5018 the backtrace structure is changed).
|
|
5019
|
|
5020 At this point, the function to be called is determined by looking at
|
|
5021 the car of the cons (if this is a symbol, its function definition is
|
|
5022 retrieved and the process repeated). The function should then consist
|
116
|
5023 of either a @code{Lisp_Subr} (built-in function), a
|
|
5024 @code{Lisp_Compiled_Function} object, or a cons whose car is the symbol
|
|
5025 @code{autoload}, @code{macro}, @code{lambda}, or @code{mocklisp}.
|
|
5026
|
|
5027 If the function is a @code{Lisp_Subr}, the lisp object points to a
|
|
5028 @code{struct Lisp_Subr} (created by @code{DEFUN()}), which contains a
|
|
5029 pointer to the C function, a minimum and maximum number of arguments
|
|
5030 (possibly the special constants @code{MANY} or @code{UNEVALLED}), a
|
|
5031 pointer to the symbol referring to that subr, and a couple of other
|
|
5032 things. If the subr wants its arguments @code{UNEVALLED}, they are
|
|
5033 passed raw as a list. Otherwise, an array of evaluated arguments is
|
|
5034 created and put into the backtrace structure, and either passed whole
|
|
5035 (@code{MANY}) or each argument is passed as a C argument.
|
|
5036
|
|
5037 If the function is a @code{Lisp_Compiled_Function} object or a lambda,
|
0
|
5038 @code{apply_lambda()} is called. If the function is a macro,
|
|
5039 [..... fill in] is done. If the function is an autoload,
|
|
5040 @code{do_autoload()} is called to load the definition and then eval
|
|
5041 starts over [explain this more]. If the function is a mocklisp,
|
|
5042 @code{ml_apply()} is called.
|
|
5043
|
|
5044 When @code{Feval} exits, the evaluation depth is reduced by one, the
|
|
5045 debugger is called if appropriate, and the current backtrace structure
|
|
5046 is removed from the list.
|
|
5047
|
|
5048 @code{apply_lambda()} is passed a function, a list of arguments, and a
|
|
5049 flag indicating whether to evaluate the arguments. It creates an array
|
|
5050 of (possibly) evaluated arguments and fixes up the backtrace structure,
|
|
5051 just like eval does. Then it calls @code{funcall_lambda()}.
|
|
5052
|
|
5053 @code{funcall_lambda()} goes through the formal arguments to the
|
|
5054 function and binds them to the actual arguments, checking for
|
|
5055 @code{&rest} and @code{&optional} symbols in the formal arguments and
|
|
5056 making sure the number of actual arguments is correct. Then either
|
116
|
5057 @code{progn} or @code{byte-code} is called to actually execute the body
|
|
5058 and return a value.
|
0
|
5059
|
|
5060 @code{Ffuncall()} implements Lisp @code{funcall}. @code{(funcall fun
|
|
5061 x1 x2 x3 ...)} is equivalent to @code{(eval (list fun (quote x1) (quote
|
|
5062 x2) (quote x3) ...))}. @code{Ffuncall()} contains its own code to do
|
|
5063 the evaluation, however, and is almost identical to eval.
|
|
5064
|
|
5065 @code{Fapply()} implements Lisp @code{apply}, which is very similar to
|
|
5066 funcall except that if the last argument is a list, the result is the
|
|
5067 same as if each of the arguments in the list had been passed separately.
|
|
5068 @code{Fapply()} does some business to expand the last argument if it's a
|
|
5069 list, then calls @code{Ffuncall()} to do the work.
|
|
5070
|
|
5071 @code{apply1()}, @code{call0()}, @code{call1()}, @code{call2()}, and
|
|
5072 @code{call3()} call a function, passing it the argument(s) given (the
|
|
5073 arguments are given as separate C arguments rather than being passed as
|
|
5074 an array). @code{apply1()} uses @code{apply} while the others use
|
|
5075 @code{funcall}.
|
|
5076
|
|
5077 @node Dynamic Binding; The specbinding Stack; Unwind-Protects
|
|
5078 @section Dynamic Binding; The specbinding Stack; Unwind-Protects
|
|
5079
|
|
5080 @example
|
|
5081 struct specbinding
|
|
5082 @{
|
|
5083 Lisp_Object symbol, old_value;
|
2
|
5084 Lisp_Object (*func) (Lisp_Object); /* for unwind-protect */
|
0
|
5085 @};
|
|
5086 @end example
|
|
5087
|
|
5088 @code{struct specbinding} is used for local-variable bindings and
|
|
5089 unwind-protects. @code{specpdl} holds an array of @code{struct specbinding}'s,
|
|
5090 @code{specpdl_ptr} points to the beginning of the free bindings in the
|
|
5091 array, @code{specpdl_size} specifies the total number of binding slots
|
|
5092 in the array, and @code{max_specpdl_size} specifies the maximum number
|
|
5093 of bindings the array can be expanded to hold. @code{grow_specpdl()}
|
|
5094 increases the size of the specpdl array, multiplying its size by 2 but
|
|
5095 never exceeding max_specpdl_size (except that if this number is less
|
|
5096 than 400, it is first set to 400).
|
|
5097
|
|
5098 @code{specbind()} binds a symbol to a value and is used for local
|
|
5099 variables and @code{let} forms. The symbol and its old value (which
|
|
5100 might be @code{Qunbound}, indicating no prior value) are recorded in the
|
|
5101 specpdl array, and @code{specpdl_size} is increased by 1.
|
|
5102
|
|
5103 @code{record_unwind_protect()} implements an @dfn{unwind-protect},
|
|
5104 which, when placed around a section of code, ensures that some specified
|
|
5105 cleanup routine will be executed even if the code exits abnormally
|
116
|
5106 (e.g. through a @code{throw} or quit). @code{record_unwind_protect()}
|
|
5107 simply adds a new specbinding to the specpdl array and stores the
|
|
5108 appropriate information in it. The cleanup routine can either be a C
|
|
5109 function, which is stored in the @code{func} field, or a @code{progn}
|
|
5110 form, which is stored in the @code{old_value} field.
|
0
|
5111
|
|
5112 @code{unbind_to()} removes specbindings from the specpdl array until
|
116
|
5113 the specified position is reached. Each specbinding can be one of three
|
0
|
5114 types:
|
|
5115
|
|
5116 @enumerate
|
|
5117 @item
|
116
|
5118 an unwind-protect with a C cleanup function (@code{func} is not 0, and
|
0
|
5119 @code{old_value} holds an argument to be passed to the function);
|
|
5120 @item
|
116
|
5121 an unwind-protect with a Lisp form (@code{func} is 0, @code{symbol}
|
|
5122 is @code{nil}, and @code{old_value} holds the form to be executed with
|
0
|
5123 @code{Fprogn()}); or
|
|
5124 @item
|
116
|
5125 a local-variable binding (@code{func} is 0, @code{symbol} is not
|
|
5126 @code{nil}, and @code{old_value} holds the old value, which is stored as
|
0
|
5127 the symbol's value).
|
|
5128 @end enumerate
|
|
5129
|
|
5130 @node Simple Special Forms
|
|
5131 @section Simple Special Forms
|
|
5132
|
|
5133 @code{or}, @code{and}, @code{if}, @code{cond}, @code{progn},
|
|
5134 @code{prog1}, @code{prog2}, @code{setq}, @code{quote}, @code{function},
|
|
5135 @code{let*}, @code{let}, @code{while}
|
|
5136
|
|
5137 All of these are very simple and work as expected, calling
|
|
5138 @code{Feval()} or @code{Fprogn()} as necessary and (in the case of
|
|
5139 @code{let} and @code{let*}) using @code{specbind()} to create bindings
|
|
5140 and @code{unbind_to()} to undo the bindings when finished. Note that
|
|
5141 these functions do a lot of @code{GCPRO}ing to protect their arguments
|
|
5142 from garbage collection because they call @code{Feval()} (@pxref{Garbage
|
|
5143 Collection}).
|
|
5144
|
|
5145 @node Catch and Throw
|
|
5146 @section Catch and Throw
|
|
5147
|
|
5148 @example
|
|
5149 struct catchtag
|
|
5150 @{
|
|
5151 Lisp_Object tag;
|
|
5152 Lisp_Object val;
|
|
5153 struct catchtag *next;
|
|
5154 struct gcpro *gcpro;
|
|
5155 jmp_buf jmp;
|
|
5156 struct backtrace *backlist;
|
|
5157 int lisp_eval_depth;
|
|
5158 int pdlcount;
|
|
5159 @};
|
|
5160 @end example
|
|
5161
|
|
5162 @code{catch} is a Lisp function that places a catch around a body of
|
|
5163 code. A catch is a means of non-local exit from the code. When a catch
|
|
5164 is created, a tag is specified, and executing a @code{throw} to this tag
|
|
5165 will exit from the body of code caught with this tag, and its value will
|
|
5166 be the value given in the call to @code{throw}. If there is no such
|
|
5167 call, the code will be executed normally.
|
|
5168
|
|
5169 Information pertaining to a catch is held in a @code{struct catchtag},
|
|
5170 which is placed at the head of a linked list pointed to by
|
|
5171 @code{catchlist}. @code{internal_catch()} is passed a C function to
|
|
5172 call (@code{Fprogn()} when Lisp @code{catch} is called) and arguments to
|
|
5173 give it, and places a catch around the function. Each @code{struct
|
|
5174 catchtag} is held in the stack frame of the @code{internal_catch()}
|
|
5175 instance that created the catch.
|
|
5176
|
|
5177 @code{internal_catch()} is fairly straightforward. It stores into the
|
|
5178 @code{struct catchtag} the tag name and the current values of
|
|
5179 @code{backtrace_list}, @code{lisp_eval_depth}, @code{gcprolist}, and the
|
|
5180 offset into the specpdl array, sets a jump point with @code{_setjmp()}
|
|
5181 (storing the jump point into the @code{struct catchtag}), and calls the
|
|
5182 function. Control will return to @code{internal_catch()} either when
|
|
5183 the function exits normally or through a @code{_longjmp()} to this jump
|
|
5184 point. In the latter case, @code{throw} will store the value to be
|
|
5185 returned into the @code{struct catchtag} before jumping. When it's
|
|
5186 done, @code{internal_catch()} removes the @code{struct catchtag} from
|
|
5187 the catchlist and returns the proper value.
|
|
5188
|
|
5189 @code{Fthrow()} goes up through the catchlist until it finds one with
|
|
5190 a matching tag. It then calls @code{unbind_catch()} to restore
|
|
5191 everything to what it was when the appropriate catch was set, stores the
|
|
5192 return value in the @code{struct catchtag}, and jumps (with
|
|
5193 @code{_longjmp()}) to its jump point.
|
|
5194
|
|
5195 @code{unbind_catch()} removes all catches from the catchlist until it
|
|
5196 finds the correct one. Some of the catches might have been placed for
|
|
5197 error-trapping, and if so, the appropriate entries on the handlerlist
|
|
5198 must be removed (see ``errors''). @code{unbind_catch()} also restores
|
|
5199 the values of @code{gcprolist}, @code{backtrace_list}, and
|
|
5200 @code{lisp_eval}, and calls @code{unbind_to()} to undo any specbindings
|
|
5201 created since the catch.
|
|
5202
|
|
5203
|
|
5204 @node Symbols and Variables, Buffers and Textual Representation, Evaluation; Stack Frames; Bindings, Top
|
|
5205 @chapter Symbols and Variables
|
|
5206
|
|
5207 @menu
|
|
5208 * Introduction to Symbols::
|
|
5209 * Obarrays::
|
|
5210 * Symbol Values::
|
|
5211 @end menu
|
|
5212
|
|
5213 @node Introduction to Symbols
|
|
5214 @section Introduction to Symbols
|
|
5215
|
|
5216 A symbol is basically just an object with four fields: a name (a
|
|
5217 string), a value (some Lisp object), a function (some Lisp object), and
|
|
5218 a property list (usually a list of alternating keyword/value pairs).
|
|
5219 What makes symbols special is that there is usually only one symbol with
|
|
5220 a given name, and the symbol is referred to by name. This makes a
|
|
5221 symbol a convenient way of calling up data by name, i.e. of implementing
|
|
5222 variables. (The variable's value is stored in the @dfn{value slot}.)
|
|
5223 Similarly, functions are referenced by name, and the definition of the
|
|
5224 function is stored in a symbol's @dfn{function slot}. This means that
|
|
5225 there can be a distinct function and variable with the same name. The
|
|
5226 property list is used as a more general mechanism of associating
|
|
5227 additional values with particular names, and once again the namespace is
|
|
5228 independent of the function and variable namespaces.
|
|
5229
|
|
5230 @node Obarrays
|
|
5231 @section Obarrays
|
|
5232
|
|
5233 The identity of symbols with their names is accomplished through a
|
|
5234 structure called an obarray, which is just a poorly-implemented hash
|
|
5235 table mapping from strings to symbols whose name is that string. (I say
|
|
5236 ``poorly implemented'' because an obarray appears in Lisp as a vector
|
|
5237 with some hidden fields rather than as its own opaque type. This is an
|
|
5238 Emacs Lisp artifact that should be fixed.)
|
|
5239
|
|
5240 Obarrays are implemented as a vector of some fixed size (which should
|
|
5241 be a prime for best results), where each ``bucket'' of the vector
|
|
5242 contains one or more symbols, threaded through a hidden @code{next}
|
|
5243 field in the symbol. Lookup of a symbol in an obarray, and adding a
|
|
5244 symbol to an obarray, is accomplished through standard hash-table
|
|
5245 techniques.
|
|
5246
|
|
5247 The standard Lisp function for working with symbols and obarrays is
|
|
5248 @code{intern}. This looks up a symbol in an obarray given its name; if
|
|
5249 it's not found, a new symbol is automatically created with the specified
|
|
5250 name, added to the obarray, and returned. This is what happens when the
|
|
5251 Lisp reader encounters a symbol (or more precisely, encounters the name
|
|
5252 of a symbol) in some text that it is reading. There is a standard
|
|
5253 obarray called @code{obarray} that is used for this purpose, although
|
|
5254 the Lisp programmer is free to create his own obarrays and @code{intern}
|
|
5255 symbols in them.
|
|
5256
|
|
5257 Note that, once a symbol is in an obarray, it stays there until
|
|
5258 something is done about it, and the standard obarray @code{obarray}
|
|
5259 always stays around, so once you use any particular variable name, a
|
|
5260 corresponding symbol will stay around in @code{obarray} until you exit
|
|
5261 XEmacs.
|
|
5262
|
|
5263 Note that @code{obarray} itself is a variable, and as such there is a
|
|
5264 symbol in @code{obarray} whose name is @code{"obarray"} and which
|
|
5265 contains @code{obarray} as its value.
|
|
5266
|
|
5267 Note also that this call to @code{intern} occurs only when in the Lisp
|
|
5268 reader, not when the code is executed (at which point the symbol is
|
|
5269 already around, stored as such in the definition of the function).
|
|
5270
|
|
5271 You can create your own obarray using @code{make-vector} (this is
|
|
5272 horrible but is an artifact) and intern symbols into that obarray.
|
|
5273 Doing that will result in two or more symbols with the same name.
|
|
5274 However, at most one of these symbols is in the standard @code{obarray}:
|
|
5275 You cannot have two symbols of the same name in any particular obarray.
|
|
5276 Note that you cannot add a symbol to an obarray in any fashion other
|
|
5277 than using @code{intern}: i.e. you can't take an existing symbol and put
|
|
5278 it in an existing obarray. Nor can you change the name of an existing
|
|
5279 symbol. (Since obarrays are vectors, you can violate the consistency of
|
|
5280 things by storing directly into the vector, but let's ignore that
|
|
5281 possibility.)
|
|
5282
|
|
5283 Usually symbols are created by @code{intern}, but if you really want,
|
|
5284 you can explicitly create a symbol using @code{make-symbol}, giving it
|
|
5285 some name. The resulting symbol is not in any obarray (i.e. it is
|
|
5286 @dfn{uninterned}), and you can't add it to any obarray. Therefore its
|
116
|
5287 primary purpose is as a symbol to use in macros to avoid namespace
|
|
5288 pollution. It can also be used as a carrier of information, but cons
|
|
5289 cells could probably be used just as well.
|
0
|
5290
|
|
5291 You can also use @code{intern-soft} to look up a symbol but not create
|
|
5292 a new one, and @code{unintern} to remove a symbol from an obarray. This
|
|
5293 returns the removed symbol. (Remember: You can't put the symbol back
|
|
5294 into any obarray.) Finally, @code{mapatoms} maps over all of the symbols
|
|
5295 in an obarray.
|
|
5296
|
|
5297 @node Symbol Values
|
|
5298 @section Symbol Values
|
|
5299
|
|
5300 The value field of a symbol normally contains a Lisp object. However,
|
|
5301 a symbol can be @dfn{unbound}, meaning that it logically has no value.
|
|
5302 This is internally indicated by storing a special Lisp object, called
|
|
5303 @dfn{the unbound marker} and stored in the global variable
|
|
5304 @code{Qunbound}. The unbound marker is of a special Lisp object type
|
|
5305 called @dfn{symbol-value-magic}. It is impossible for the Lisp
|
|
5306 programmer to directly create or access any object of this type.
|
|
5307
|
|
5308 @strong{You must not let any ``symbol-value-magic'' object escape to
|
|
5309 the Lisp level.} Printing any of these objects will cause the message
|
|
5310 @samp{INTERNAL EMACS BUG} to appear as part of the print representation.
|
|
5311 (You may see this normally when you call @code{debug_print()} from the
|
|
5312 debugger on a Lisp object.) If you let one of these objects escape to
|
|
5313 the Lisp level, you will violate a number of assumptions contained in
|
|
5314 the C code and make the unbound marker not function right.
|
|
5315
|
|
5316 When a symbol is created, its value field (and function field) are set
|
|
5317 to @code{Qunbound}. The Lisp programmer can restore these conditions
|
|
5318 later using @code{makunbound} or @code{fmakunbound}, and can query to
|
|
5319 see whether the value of function fields are @dfn{bound} (i.e. have a
|
|
5320 value other than @code{Qunbound}) using @code{boundp} and
|
|
5321 @code{fboundp}. The fields are set to a normal Lisp object using
|
|
5322 @code{set} (or @code{setq}) and @code{fset}.
|
|
5323
|
|
5324 Other symbol-value-magic objects are used as special markers to
|
|
5325 indicate variables that have non-normal properties. This includes any
|
|
5326 variables that are tied into C variables (setting the variable magically
|
|
5327 sets some global variable in the C code, and likewise for retrieving the
|
|
5328 variable's value), variables that magically tie into slots in the
|
|
5329 current buffer, variables that are buffer-local, etc. The
|
|
5330 symbol-value-magic object is stored in the value cell in place of
|
|
5331 a normal object, and the code to retrieve a symbol's value
|
|
5332 (i.e. @code{symbol-value}) knows how to do special things with them.
|
|
5333 This means that you should not just fetch the value cell directly if you
|
|
5334 want a symbol's value.
|
|
5335
|
|
5336 The exact workings of this are rather complex and involved and are
|
|
5337 well-documented in comments in @file{buffer.c}, @file{symbols.c}, and
|
|
5338 @file{lisp.h}.
|
|
5339
|
|
5340 @node Buffers and Textual Representation, MULE Character Sets and Encodings, Symbols and Variables, Top
|
|
5341 @chapter Buffers and Textual Representation
|
|
5342
|
|
5343 @menu
|
|
5344 * Introduction to Buffers:: A buffer holds a block of text such as a file.
|
70
|
5345 * A Buffer@'s Text:: Representation of the text in a buffer.
|
0
|
5346 * Buffer Lists:: Keeping track of all buffers.
|
|
5347 * Markers and Extents:: Tagging locations within a buffer.
|
|
5348 * Bufbytes and Emchars:: Representation of individual characters.
|
|
5349 * The Buffer Object:: The Lisp object corresponding to a buffer.
|
|
5350 @end menu
|
|
5351
|
|
5352 @node Introduction to Buffers
|
|
5353 @section Introduction to Buffers
|
|
5354
|
|
5355 A buffer is logically just a Lisp object that holds some text.
|
|
5356 In this, it is like a string, but a buffer is optimized for
|
|
5357 frequent insertion and deletion, while a string is not. Furthermore:
|
|
5358
|
|
5359 @enumerate
|
|
5360 @item
|
116
|
5361 Buffers are @dfn{permanent} objects, i.e. once you create them, they
|
0
|
5362 remain around, and need to be explicitly deleted before they go away.
|
|
5363 @item
|
|
5364 Each buffer has a unique name, which is a string. Buffers are
|
|
5365 normally referred to by name. In this respect, they are like
|
|
5366 symbols.
|
|
5367 @item
|
|
5368 Buffers have a default insertion position, called @dfn{point}.
|
|
5369 Inserting text (unless you explicitly give a position) goes at point,
|
|
5370 and moves point forward past the text. This is what is going on when
|
|
5371 you type text into Emacs.
|
|
5372 @item
|
|
5373 Buffers have lots of extra properties associated with them.
|
|
5374 @item
|
|
5375 Buffers can be @dfn{displayed}. What this means is that there
|
|
5376 exist a number of @dfn{windows}, which are objects that correspond
|
|
5377 to some visible section of your display, and each window has
|
|
5378 an associated buffer, and the current contents of the buffer
|
|
5379 are shown in that section of the display. The redisplay mechanism
|
|
5380 (which takes care of doing this) knows how to look at the
|
|
5381 text of a buffer and come up with some reasonable way of displaying
|
|
5382 this. Many of the properties of a buffer control how the
|
|
5383 buffer's text is displayed.
|
|
5384 @item
|
|
5385 One buffer is distinguished and called the @dfn{current buffer}. It is
|
|
5386 stored in the variable @code{current_buffer}. Buffer operations operate
|
|
5387 on this buffer by default. When you are typing text into a buffer, the
|
|
5388 buffer you are typing into is always @code{current_buffer}. Switching
|
|
5389 to a different window changes the current buffer. Note that Lisp code
|
|
5390 can temporarily change the current buffer using @code{set-buffer} (often
|
|
5391 enclosed in a @code{save-excursion} so that the former current buffer
|
|
5392 gets restored when the code is finished). However, calling
|
|
5393 @code{set-buffer} will NOT cause a permanent change in the current
|
|
5394 buffer. The reason for this is that the top-level event loop sets
|
116
|
5395 @code{current_buffer} to the buffer of the selected window, each time
|
|
5396 it finishes executing a user command.
|
0
|
5397 @end enumerate
|
|
5398
|
|
5399 Make sure you understand the distinction between @dfn{current buffer}
|
|
5400 and @dfn{buffer of the selected window}, and the distinction between
|
|
5401 @dfn{point} of the current buffer and @dfn{window-point} of the selected
|
|
5402 window. (This latter distinction is explained in detail in the section
|
|
5403 on windows.)
|
|
5404
|
70
|
5405 @node A Buffer@'s Text
|
|
5406 @section A Buffer's Text
|
0
|
5407
|
|
5408 The text in a buffer consists of a sequence of zero or more
|
|
5409 characters. A @dfn{character} is an integer that logically represents
|
|
5410 a letter, number, space, or other unit of text. Most of the characters
|
|
5411 that you will typically encounter belong to the ASCII set of characters,
|
|
5412 but there are also characters for various sorts of accented letters,
|
|
5413 special symbols, Chinese and Japanese ideograms (i.e. Kanji, Katakana,
|
|
5414 etc.), Cyrillic and Greek letters, etc. The actual number of possible
|
|
5415 characters is quite large.
|
|
5416
|
|
5417 For now, we can view a character as some non-negative integer that
|
|
5418 has some shape that defines how it typically appears (e.g. as an
|
116
|
5419 uppercase A). (The exact way in which a character appears depends on the
|
|
5420 font used to display the character.) The internal type of characters in
|
|
5421 the C code is an @code{Emchar}; this is just an @code{int}, but using a
|
|
5422 symbolic type makes the code clearer.
|
0
|
5423
|
|
5424 Between every character in a buffer is a @dfn{buffer position} or
|
|
5425 @dfn{character position}. We can speak of the character before or after
|
|
5426 a particular buffer position, and when you insert a character at a
|
|
5427 particular position, all characters after that position end up at new
|
|
5428 positions. When we speak of the character @dfn{at} a position, we
|
|
5429 really mean the character after the position. (This schizophrenia
|
|
5430 between a buffer position being ``between'' a character and ``on'' a
|
|
5431 character is rampant in Emacs.)
|
|
5432
|
|
5433 Buffer positions are numbered starting at 1. This means that
|
|
5434 position 1 is before the first character, and position 0 is not
|
|
5435 valid. If there are N characters in a buffer, then buffer
|
|
5436 position N+1 is after the last one, and position N+2 is not valid.
|
|
5437
|
|
5438 The internal makeup of the Emchar integer varies depending on whether
|
|
5439 we have compiled with MULE support. If not, the Emchar integer is an
|
|
5440 8-bit integer with possible values from 0 - 255. 0 - 127 are the
|
|
5441 standard ASCII characters, while 128 - 255 are the characters from the
|
|
5442 ISO-8859-1 character set. If we have compiled with MULE support, an
|
|
5443 Emchar is a 19-bit integer, with the various bits having meanings
|
|
5444 according to a complex scheme that will be detailed later. The
|
|
5445 characters numbered 0 - 255 still have the same meanings as for the
|
|
5446 non-MULE case, though.
|
|
5447
|
|
5448 Internally, the text in a buffer is represented in a fairly simple
|
|
5449 fashion: as a contiguous array of bytes, with a @dfn{gap} of some size
|
|
5450 in the middle. Although the gap is of some substantial size in bytes,
|
|
5451 there is no text contained within it: From the perspective of the text
|
|
5452 in the buffer, it does not exist. The gap logically sits at some buffer
|
|
5453 position, between two characters (or possibly at the beginning or end of
|
|
5454 the buffer). Insertion of text in a buffer at a particular position is
|
|
5455 always accomplished by first moving the gap to that position
|
|
5456 (i.e. through some block moving of text), then writing the text into the
|
|
5457 beginning of the gap, thereby shrinking the gap. If the gap shrinks
|
|
5458 down to nothing, a new gap is created. (What actually happens is that a
|
|
5459 new gap is ``created'' at the end of the buffer's text, which requires
|
|
5460 nothing more than changing a couple of indices; then the gap is
|
|
5461 ``moved'' to the position where the insertion needs to take place by
|
|
5462 moving up in memory all the text after that position.) Similarly,
|
|
5463 deletion occurs by moving the gap to the place where the text is to be
|
|
5464 deleted, and then simply expanding the gap to include the deleted text.
|
|
5465 (@dfn{Expanding} and @dfn{shrinking} the gap as just described means
|
|
5466 just that the internal indices that keep track of where the gap is
|
|
5467 located are changed.)
|
|
5468
|
|
5469 Note that the total amount of memory allocated for a buffer text never
|
|
5470 decreases while the buffer is live. Therefore, if you load up a
|
|
5471 20-megabyte file and then delete all but one character, there will be a
|
|
5472 20-megabyte gap, which won't get any smaller (except by inserting
|
|
5473 characters back again). Once the buffer is killed, the memory allocated
|
|
5474 for the buffer text will be freed, but it will still be sitting on the
|
|
5475 heap, taking up virtual memory, and will not be released back to the
|
|
5476 operating system. (However, if you have compiled XEmacs with rel-alloc,
|
|
5477 the situation is different. In this case, the space @emph{will} be
|
116
|
5478 released back to the operating system. However, this tends to result in a
|
0
|
5479 noticeable speed penalty.)
|
|
5480
|
|
5481 Astute readers may notice that the text in a buffer is represented as
|
|
5482 an array of @emph{bytes}, while (at least in the MULE case) an Emchar is
|
|
5483 a 19-bit integer, which clearly cannot fit in a byte. This means (of
|
|
5484 course) that the text in a buffer uses a different representation from
|
|
5485 an Emchar: specifically, the 19-bit Emchar becomes a series of one to
|
|
5486 four bytes. The conversion between these two representations is complex
|
|
5487 and will be described later.
|
|
5488
|
|
5489 In the non-MULE case, everything is very simple: An Emchar
|
|
5490 is an 8-bit value, which fits neatly into one byte.
|
|
5491
|
|
5492 If we are given a buffer position and want to retrieve the
|
|
5493 character at that position, we need to follow these steps:
|
|
5494
|
|
5495 @enumerate
|
|
5496 @item
|
|
5497 Pretend there's no gap, and convert the buffer position into a @dfn{byte
|
|
5498 index} that indexes to the appropriate byte in the buffer's stream of
|
|
5499 textual bytes. By convention, byte indices begin at 1, just like buffer
|
|
5500 positions. In the non-MULE case, byte indices and buffer positions are
|
|
5501 identical, since one character equals one byte.
|
|
5502 @item
|
|
5503 Convert the byte index into a @dfn{memory index}, which takes the gap
|
|
5504 into account. The memory index is a direct index into the block of
|
|
5505 memory that stores the text of a buffer. This basically just involves
|
|
5506 checking to see if the byte index is past the gap, and if so, adding the
|
|
5507 size of the gap to it. By convention, memory indices begin at 1, just
|
|
5508 like buffer positions and byte indices, and when referring to the
|
|
5509 position that is @dfn{at} the gap, we always use the memory position at
|
|
5510 the @emph{beginning}, not at the end, of the gap.
|
|
5511 @item
|
|
5512 Fetch the appropriate bytes at the determined memory position.
|
|
5513 @item
|
|
5514 Convert these bytes into an Emchar.
|
|
5515 @end enumerate
|
|
5516
|
|
5517 In the non-Mule case, (3) and (4) boil down to a simple one-byte
|
|
5518 memory access.
|
|
5519
|
|
5520 Note that we have defined three types of positions in a buffer:
|
|
5521
|
|
5522 @enumerate
|
|
5523 @item
|
|
5524 @dfn{buffer positions} or @dfn{character positions}, typedef @code{Bufpos}
|
|
5525 @item
|
|
5526 @dfn{byte indices}, typedef @code{Bytind}
|
|
5527 @item
|
|
5528 @dfn{memory indices}, typedef @code{Memind}
|
|
5529 @end enumerate
|
|
5530
|
116
|
5531 All three typedefs are just @code{int}s, but defining them this way makes
|
0
|
5532 things a lot clearer.
|
|
5533
|
|
5534 Most code works with buffer positions. In particular, all Lisp code
|
|
5535 that refers to text in a buffer uses buffer positions. Lisp code does
|
|
5536 not know that byte indices or memory indices exist.
|
|
5537
|
|
5538 Finally, we have a typedef for the bytes in a buffer. This is a
|
|
5539 @code{Bufbyte}, which is an unsigned char. Referring to them as
|
|
5540 Bufbytes underscores the fact that we are working with a string of bytes
|
|
5541 in the internal Emacs buffer representation rather than in one of a
|
116
|
5542 number of possible alternative representations (e.g. EUC-encoded text,
|
0
|
5543 etc.).
|
|
5544
|
|
5545 @node Buffer Lists
|
|
5546 @section Buffer Lists
|
|
5547
|
|
5548 Recall earlier that buffers are @dfn{permanent} objects, i.e. that
|
|
5549 they remain around until explicitly deleted. This entails that there is
|
|
5550 a list of all the buffers in existence. This list is actually an
|
|
5551 assoc-list (mapping from the buffer's name to the buffer) and is stored
|
|
5552 in the global variable @code{Vbuffer_alist}.
|
|
5553
|
|
5554 The order of the buffers in the list is important: the buffers are
|
|
5555 ordered approximately from most-recently-used to least-recently-used.
|
|
5556 Switching to a buffer using @code{switch-to-buffer},
|
|
5557 @code{pop-to-buffer}, etc. and switching windows using
|
|
5558 @code{other-window}, etc. usually brings the new current buffer to the
|
|
5559 front of the list. @code{switch-to-buffer}, @code{other-buffer},
|
|
5560 etc. look at the beginning of the list to find an alternative buffer to
|
|
5561 suggest. You can also explicitly move a buffer to the end of the list
|
|
5562 using @code{bury-buffer}.
|
|
5563
|
|
5564 In addition to the global ordering in @code{Vbuffer_alist}, each frame
|
|
5565 has its own ordering of the list. These lists always contain the same
|
|
5566 elements as in @code{Vbuffer_alist} although possibly in a different
|
|
5567 order. @code{buffer-list} normally returns the list for the selected
|
|
5568 frame. This allows you to work in separate frames without things
|
|
5569 interfering with each other.
|
|
5570
|
|
5571 The standard way to look up a buffer given a name is
|
|
5572 @code{get-buffer}, and the standard way to create a new buffer is
|
|
5573 @code{get-buffer-create}, which looks up a buffer with a given name,
|
|
5574 creating a new one if necessary. These operations correspond exactly
|
|
5575 with the symbol operations @code{intern-soft} and @code{intern},
|
|
5576 respectively. You can also force a new buffer to be created using
|
|
5577 @code{generate-new-buffer}, which takes a name and (if necessary) makes
|
|
5578 a unique name from this by appending a number, and then creates the
|
|
5579 buffer. This is basically like the symbol operation @code{gensym}.
|
|
5580
|
|
5581 @node Markers and Extents
|
|
5582 @section Markers and Extents
|
|
5583
|
|
5584 Among the things associated with a buffer are things that are
|
|
5585 logically attached to certain buffer positions. This can be used to
|
|
5586 keep track of a buffer position when text is inserted and deleted, so
|
|
5587 that it remains at the same spot relative to the text around it; to
|
|
5588 assign properties to particular sections of text; etc. There are two
|
|
5589 such objects that are useful in this regard: they are @dfn{markers} and
|
|
5590 @dfn{extents}.
|
|
5591
|
|
5592 A @dfn{marker} is simply a flag placed at a particular buffer
|
|
5593 position, which is moved around as text is inserted and deleted.
|
|
5594 Markers are used for all sorts of purposes, such as the @code{mark} that
|
|
5595 is the other end of textual regions to be cut, copied, etc.
|
|
5596
|
|
5597 An @dfn{extent} is similar to two markers plus some associated
|
|
5598 properties, and is used to keep track of regions in a buffer as text is
|
|
5599 inserted and deleted, and to add properties (e.g. fonts) to particular
|
|
5600 regions of text. The external interface of extents is explained
|
|
5601 elsewhere.
|
|
5602
|
|
5603 The important thing here is that markers and extents simply contain
|
|
5604 buffer positions in them as integers, and every time text is inserted or
|
|
5605 deleted, these positions must be updated. In order to minimize the
|
|
5606 amount of shuffling that needs to be done, the positions in markers and
|
|
5607 extents (there's one per marker, two per extent) and stored in Meminds.
|
|
5608 This means that they only need to be moved when the text is physically
|
|
5609 moved in memory; since the gap structure tries to minimize this, it also
|
|
5610 minimizes the number of marker and extent indices that need to be
|
|
5611 adjusted. Look in @file{insdel.c} for the details of how this works.
|
|
5612
|
|
5613 One other important distinction is that markers are @dfn{temporary}
|
|
5614 while extents are @dfn{permanent}. This means that markers disappear as
|
|
5615 soon as there are no more pointers to them, and correspondingly, there
|
|
5616 is no way to determine what markers are in a buffer if you are just
|
|
5617 given the buffer. Extents remain in a buffer until they are detached
|
|
5618 (which could happen as a result of text being deleted) or the buffer is
|
|
5619 deleted, and primitives do exist to enumerate the extents in a buffer.
|
|
5620
|
|
5621 @node Bufbytes and Emchars
|
|
5622 @section Bufbytes and Emchars
|
|
5623
|
|
5624 Not yet documented.
|
|
5625
|
|
5626 @node The Buffer Object
|
|
5627 @section The Buffer Object
|
|
5628
|
|
5629 Buffers contain fields not directly accessible by the Lisp programmer.
|
|
5630 We describe them here, naming them by the names used in the C code.
|
|
5631 Many are accessible indirectly in Lisp programs via Lisp primitives.
|
|
5632
|
|
5633 @table @code
|
|
5634 @item name
|
|
5635 The buffer name is a string that names the buffer. It is guaranteed to
|
|
5636 be unique. @xref{Buffer Names,,, lispref, XEmacs Lisp Programmer's
|
|
5637 Manual}.
|
|
5638
|
|
5639 @item save_modified
|
|
5640 This field contains the time when the buffer was last saved, as an
|
|
5641 integer. @xref{Buffer Modification,,, lispref, XEmacs Lisp Programmer's
|
|
5642 Manual}.
|
|
5643
|
|
5644 @item modtime
|
|
5645 This field contains the modification time of the visited file. It is
|
|
5646 set when the file is written or read. Every time the buffer is written
|
|
5647 to the file, this field is compared to the modification time of the
|
|
5648 file. @xref{Buffer Modification,,, lispref, XEmacs Lisp Programmer's
|
|
5649 Manual}.
|
|
5650
|
|
5651 @item auto_save_modified
|
|
5652 This field contains the time when the buffer was last auto-saved.
|
|
5653
|
|
5654 @item last_window_start
|
|
5655 This field contains the @code{window-start} position in the buffer as of
|
|
5656 the last time the buffer was displayed in a window.
|
|
5657
|
|
5658 @item undo_list
|
|
5659 This field points to the buffer's undo list. @xref{Undo,,, lispref,
|
|
5660 XEmacs Lisp Programmer's Manual}.
|
|
5661
|
|
5662 @item syntax_table_v
|
|
5663 This field contains the syntax table for the buffer. @xref{Syntax
|
|
5664 Tables,,, lispref, XEmacs Lisp Programmer's Manual}.
|
|
5665
|
|
5666 @item downcase_table
|
|
5667 This field contains the conversion table for converting text to lower
|
|
5668 case. @xref{Case Tables,,, lispref, XEmacs Lisp Programmer's Manual}.
|
|
5669
|
|
5670 @item upcase_table
|
|
5671 This field contains the conversion table for converting text to upper
|
|
5672 case. @xref{Case Tables,,, lispref, XEmacs Lisp Programmer's Manual}.
|
|
5673
|
|
5674 @item case_canon_table
|
|
5675 This field contains the conversion table for canonicalizing text for
|
|
5676 case-folding search. @xref{Case Tables,,, lispref, XEmacs Lisp
|
|
5677 Programmer's Manual}.
|
|
5678
|
|
5679 @item case_eqv_table
|
|
5680 This field contains the equivalence table for case-folding search.
|
|
5681 @xref{Case Tables,,, lispref, XEmacs Lisp Programmer's Manual}.
|
|
5682
|
|
5683 @item display_table
|
|
5684 This field contains the buffer's display table, or @code{nil} if it
|
|
5685 doesn't have one. @xref{Display Tables,,, lispref, XEmacs Lisp
|
|
5686 Programmer's Manual}.
|
|
5687
|
|
5688 @item markers
|
|
5689 This field contains the chain of all markers that currently point into
|
|
5690 the buffer. Deletion of text in the buffer, and motion of the buffer's
|
|
5691 gap, must check each of these markers and perhaps update it.
|
|
5692 @xref{Markers,,, lispref, XEmacs Lisp Programmer's Manual}.
|
|
5693
|
|
5694 @item backed_up
|
|
5695 This field is a flag that tells whether a backup file has been made for
|
|
5696 the visited file of this buffer.
|
|
5697
|
|
5698 @item mark
|
|
5699 This field contains the mark for the buffer. The mark is a marker,
|
|
5700 hence it is also included on the list @code{markers}. @xref{The Mark,,,
|
|
5701 lispref, XEmacs Lisp Programmer's Manual}.
|
|
5702
|
|
5703 @item mark_active
|
|
5704 This field is non-@code{nil} if the buffer's mark is active.
|
|
5705
|
|
5706 @item local_var_alist
|
|
5707 This field contains the association list describing the variables local
|
|
5708 in this buffer, and their values, with the exception of local variables
|
|
5709 that have special slots in the buffer object. (Those slots are omitted
|
|
5710 from this table.) @xref{Buffer-Local Variables,,, lispref, XEmacs Lisp
|
|
5711 Programmer's Manual}.
|
|
5712
|
|
5713 @item modeline_format
|
|
5714 This field contains a Lisp object which controls how to display the mode
|
|
5715 line for this buffer. @xref{Modeline Format,,, lispref, XEmacs Lisp
|
|
5716 Programmer's Manual}.
|
|
5717
|
|
5718 @item base_buffer
|
|
5719 This field holds the buffer's base buffer (if it is an indirect buffer),
|
|
5720 or @code{nil}.
|
|
5721 @end table
|
|
5722
|
|
5723 @node MULE Character Sets and Encodings, The Lisp Reader and Compiler, Buffers and Textual Representation, Top
|
|
5724 @chapter MULE Character Sets and Encodings
|
|
5725
|
|
5726 Recall that there are two primary ways that text is represented in
|
|
5727 XEmacs. The @dfn{buffer} representation sees the text as a series of
|
|
5728 bytes (Bufbytes), with a variable number of bytes used per character.
|
|
5729 The @dfn{character} representation sees the text as a series of integers
|
|
5730 (Emchars), one per character. The character representation is a cleaner
|
|
5731 representation from a theoretical standpoint, and is thus used in many
|
|
5732 cases when lots of manipulations on a string need to be done. However,
|
|
5733 the buffer representation is the standard representation used in both
|
|
5734 Lisp strings and buffers, and because of this, it is the ``default''
|
|
5735 representation that text comes in. The reason for using this
|
|
5736 representation is that it's compact and is compatible with ASCII.
|
|
5737
|
|
5738 @menu
|
|
5739 * Character Sets::
|
|
5740 * Encodings::
|
|
5741 * Internal Mule Encodings::
|
|
5742 * CCL::
|
|
5743 @end menu
|
|
5744
|
|
5745 @node Character Sets
|
|
5746 @section Character Sets
|
|
5747
|
|
5748 A character set (or @dfn{charset}) is an ordered set of characters. A
|
|
5749 particular character in a charset is indexed using one or more
|
|
5750 @dfn{position codes}, which are non-negative integers. The number of
|
|
5751 position codes needed to identify a particular character in a charset is
|
|
5752 called the @dfn{dimension} of the charset. In XEmacs/Mule, all charsets
|
|
5753 have dimension 1 or 2, and the size of all charsets (except for a few
|
|
5754 special cases) is either 94, 96, 94 by 94, or 96 by 96. The range of
|
|
5755 position codes used to index characters from any of these types of
|
|
5756 character sets is as follows:
|
|
5757
|
|
5758 @example
|
|
5759 Charset type Position code 1 Position code 2
|
|
5760 ------------------------------------------------------------
|
|
5761 94 33 - 126 N/A
|
|
5762 96 32 - 127 N/A
|
|
5763 94x94 33 - 126 33 - 126
|
|
5764 96x96 32 - 127 32 - 127
|
|
5765 @end example
|
|
5766
|
|
5767 Note that in the above cases position codes do not start at an
|
|
5768 expected value such as 0 or 1. The reason for this will become clear
|
|
5769 later.
|
|
5770
|
|
5771 For example, Latin-1 is a 96-character charset, and JISX0208 (the
|
|
5772 Japanese national character set) is a 94x94-character charset.
|
|
5773
|
|
5774 [Note that, although the ranges above define the @emph{valid} position
|
|
5775 codes for a charset, some of the slots in a particular charset may in
|
|
5776 fact be empty. This is the case for JISX0208, for example, where (e.g.)
|
|
5777 all the slots whose first position code is in the range 118 - 127 are
|
|
5778 empty.]
|
|
5779
|
|
5780 There are three charsets that do not follow the above rules. All of
|
|
5781 them have one dimension, and have ranges of position codes as follows:
|
|
5782
|
|
5783 @example
|
|
5784 Charset name Position code 1
|
|
5785 ------------------------------------
|
|
5786 ASCII 0 - 127
|
|
5787 Control-1 0 - 31
|
|
5788 Composite 0 - some large number
|
|
5789 @end example
|
|
5790
|
|
5791 (The upper bound of the position code for composite characters has not
|
|
5792 yet been determined, but it will probably be at least 16,383).
|
|
5793
|
|
5794 ASCII is the union of two subsidiary character sets: Printing-ASCII
|
|
5795 (the printing ASCII character set, consisting of position codes 33 -
|
|
5796 126, like for a standard 94-character charset) and Control-ASCII (the
|
|
5797 non-printing characters that would appear in a binary file with codes 0
|
|
5798 - 32 and 127).
|
|
5799
|
|
5800 Control-1 contains the non-printing characters that would appear in a
|
|
5801 binary file with codes 128 - 159.
|
|
5802
|
|
5803 Composite contains characters that are generated by overstriking one
|
|
5804 or more characters from other charsets.
|
|
5805
|
|
5806 Note that some characters in ASCII, and all characters in Control-1,
|
|
5807 are @dfn{control} (non-printing) characters. These have no printed
|
|
5808 representation but instead control some other function of the printing
|
|
5809 (e.g. TAB or 8 moves the current character position to the next tab
|
|
5810 stop). All other characters in all charsets are @dfn{graphic}
|
|
5811 (printing) characters.
|
|
5812
|
|
5813 When a binary file is read in, the bytes in the file are assigned to
|
|
5814 character sets as follows:
|
|
5815
|
|
5816 @example
|
|
5817 Bytes Character set Range
|
|
5818 --------------------------------------------------
|
|
5819 0 - 127 ASCII 0 - 127
|
|
5820 128 - 159 Control-1 0 - 31
|
|
5821 160 - 255 Latin-1 32 - 127
|
|
5822 @end example
|
|
5823
|
|
5824 This is a bit ad-hoc but gets the job done.
|
|
5825
|
|
5826 @node Encodings
|
|
5827 @section Encodings
|
|
5828
|
|
5829 An @dfn{encoding} is a way of numerically representing characters from
|
|
5830 one or more character sets. If an encoding only encompasses one
|
|
5831 character set, then the position codes for the characters in that
|
|
5832 character set could be used directly. This is not possible, however, if
|
|
5833 more than one character set is to be used in the encoding.
|
|
5834
|
|
5835 For example, the conversion detailed above between bytes in a binary
|
|
5836 file and characters is effectively an encoding that encompasses the
|
|
5837 three character sets ASCII, Control-1, and Latin-1 in a stream of 8-bit
|
|
5838 bytes.
|
|
5839
|
|
5840 Thus, an encoding can be viewed as a way of encoding characters from a
|
|
5841 specified group of character sets using a stream of bytes, each of which
|
|
5842 contains a fixed number of bits (but not necessarily 8, as in the common
|
|
5843 usage of ``byte'').
|
|
5844
|
|
5845 Here are descriptions of a couple of common
|
|
5846 encodings:
|
|
5847
|
|
5848 @menu
|
|
5849 * Japanese EUC (Extended Unix Code)::
|
|
5850 * JIS7::
|
|
5851 @end menu
|
|
5852
|
|
5853 @node Japanese EUC (Extended Unix Code)
|
|
5854 @subsection Japanese EUC (Extended Unix Code)
|
|
5855
|
44
|
5856 This encompasses the character sets Printing-ASCII, Japanese-JISSX0201,
|
|
5857 and Japanese-JISX0208-Kana (half-width katakana, the right half of
|
0
|
5858 JISX0201). It uses 8-bit bytes.
|
|
5859
|
44
|
5860 Note that Printing-ASCII and Japanese-JISX0201-Kana are 94-character
|
|
5861 charsets, while Japanese-JISX0208 is a 94x94-character charset.
|
|
5862
|
|
5863 The encoding is as follows:
|
0
|
5864
|
|
5865 @example
|
44
|
5866 Character set Representation (PC=position-code)
|
|
5867 ------------- --------------
|
|
5868 Printing-ASCII PC1
|
|
5869 Japanese-JISX0201-Kana 0x8E | PC1 + 0x80
|
|
5870 Japanese-JISX0208 PC1 + 0x80 | PC2 + 0x80
|
|
5871 Japanese-JISX0212 PC1 + 0x80 | PC2 + 0x80
|
0
|
5872 @end example
|
|
5873
|
|
5874
|
|
5875 @node JIS7
|
|
5876 @subsection JIS7
|
|
5877
|
44
|
5878 This encompasses the character sets Printing-ASCII,
|
|
5879 Japanese-JISX0201-Roman (the left half of JISX0201; this character set
|
|
5880 is very similar to Printing-ASCII and is a 94-character charset),
|
|
5881 Japanese-JISX0208, and Japanese-JISX0201-Kana. It uses 7-bit bytes.
|
|
5882
|
|
5883 Unlike Japanese EUC, this is a @dfn{modal} encoding, which
|
0
|
5884 means that there are multiple states that the encoding can
|
|
5885 be in, which affect how the bytes are to be interpreted.
|
|
5886 Special sequences of bytes (called @dfn{escape sequences})
|
|
5887 are used to change states.
|
|
5888
|
|
5889 The encoding is as follows:
|
|
5890
|
|
5891 @example
|
44
|
5892 Character set Representation (PC=position-code)
|
|
5893 ------------- --------------
|
|
5894 Printing-ASCII PC1
|
|
5895 Japanese-JISX0201-Roman PC1
|
|
5896 Japanese-JISX0201-Kana PC1
|
|
5897 Japanese-JISX0208 PC1 PC2
|
0
|
5898
|
|
5899
|
|
5900 Escape sequence ASCII equivalent Meaning
|
|
5901 --------------- ---------------- -------
|
44
|
5902 0x1B 0x28 0x4A ESC ( J invoke Japanese-JISX0201-Roman
|
|
5903 0x1B 0x28 0x49 ESC ( I invoke Japanese-JISX0201-Kana
|
|
5904 0x1B 0x24 0x42 ESC $ B invoke Japanese-JISX0208
|
0
|
5905 0x1B 0x28 0x42 ESC ( B invoke Printing-ASCII
|
|
5906 @end example
|
|
5907
|
|
5908 Initially, Printing-ASCII is invoked.
|
|
5909
|
|
5910 @node Internal Mule Encodings
|
|
5911 @section Internal Mule Encodings
|
|
5912
|
44
|
5913 In XEmacs/Mule, each character set is assigned a unique number, called a
|
|
5914 @dfn{leading byte}. This is used in the encodings of a character.
|
|
5915 Leading bytes are in the range 0x80 - 0xFF (except for ASCII, which has
|
|
5916 a leading byte of 0), although some leading bytes are reserved.
|
|
5917
|
|
5918 Charsets whose leading byte is in the range 0x80 - 0x9F are called
|
|
5919 @dfn{official} and are used for built-in charsets. Other charsets are
|
|
5920 called @dfn{private} and have leading bytes in the range 0xA0 - 0xFF;
|
|
5921 these are user-defined charsets.
|
0
|
5922
|
|
5923 More specifically:
|
|
5924
|
|
5925 @example
|
|
5926 Character set Leading byte
|
|
5927 ------------- ------------
|
|
5928 ASCII 0
|
|
5929 Composite 0x80
|
|
5930 Dimension-1 Official 0x81 - 0x8D
|
|
5931 (0x8E is free)
|
|
5932 Control-1 0x8F
|
|
5933 Dimension-2 Official 0x90 - 0x99
|
|
5934 (0x9A - 0x9D are free;
|
|
5935 0x9E and 0x9F are reserved)
|
|
5936 Dimension-1 Private 0xA0 - 0xEF
|
|
5937 Dimension-2 Private 0xF0 - 0xFF
|
|
5938 @end example
|
|
5939
|
44
|
5940 There are two internal encodings for characters in XEmacs/Mule. One is
|
|
5941 called @dfn{string encoding} and is an 8-bit encoding that is used for
|
|
5942 representing characters in a buffer or string. It uses 1 to 4 bytes per
|
|
5943 character. The other is called @dfn{character encoding} and is a 19-bit
|
|
5944 encoding that is used for representing characters individually in a
|
|
5945 variable.
|
|
5946
|
|
5947 (In the following descriptions, we'll ignore composite characters for
|
|
5948 the moment. We also give a general (structural) overview first,
|
|
5949 followed later by the exact details.)
|
0
|
5950
|
|
5951 @menu
|
|
5952 * Internal String Encoding::
|
|
5953 * Internal Character Encoding::
|
|
5954 @end menu
|
|
5955
|
|
5956 @node Internal String Encoding
|
|
5957 @subsection Internal String Encoding
|
|
5958
|
44
|
5959 ASCII characters are encoded using their position code directly. Other
|
|
5960 characters are encoded using their leading byte followed by their
|
|
5961 position code(s) with the high bit set. Characters in private character
|
|
5962 sets have their leading byte prefixed with a @dfn{leading byte prefix},
|
|
5963 which is either 0x9E or 0x9F. (No character sets are ever assigned these
|
|
5964 leading bytes.) Specifically:
|
0
|
5965
|
|
5966 @example
|
|
5967 Character set Encoding (PC=position-code, LB=leading-byte)
|
|
5968 ------------- --------
|
|
5969 ASCII PC-1 |
|
|
5970 Control-1 LB | PC1 + 0xA0 |
|
|
5971 Dimension-1 official LB | PC1 + 0x80 |
|
|
5972 Dimension-1 private 0x9E | LB | PC1 + 0x80 |
|
|
5973 Dimension-2 official LB | PC1 + 0x80 | PC2 + 0x80 |
|
|
5974 Dimension-2 private 0x9F | LB | PC1 + 0x80 | PC2 + 0x80
|
|
5975 @end example
|
|
5976
|
|
5977 The basic characteristic of this encoding is that the first byte
|
|
5978 of all characters is in the range 0x00 - 0x9F, and the second and
|
|
5979 following bytes of all characters is in the range 0xA0 - 0xFF.
|
|
5980 This means that it is impossible to get out of sync, or more
|
|
5981 specifically:
|
|
5982
|
|
5983 @enumerate
|
|
5984 @item
|
|
5985 Given any byte position, the beginning of the character it is
|
|
5986 within can be determined in constant time.
|
|
5987 @item
|
|
5988 Given any byte position at the beginning of a character, the
|
|
5989 beginning of the next character can be determined in constant
|
|
5990 time.
|
|
5991 @item
|
|
5992 Given any byte position at the beginning of a character, the
|
|
5993 beginning of the previous character can be determined in constant
|
|
5994 time.
|
|
5995 @item
|
|
5996 Textual searches can simply treat encoded strings as if they
|
|
5997 were encoded in a one-byte-per-character fashion rather than
|
|
5998 the actual multi-byte encoding.
|
|
5999 @end enumerate
|
|
6000
|
|
6001 None of the standard non-modal encodings meet all of these
|
|
6002 conditions. For example, EUC satisfies only (2) and (3), while
|
|
6003 Shift-JIS and Big5 (not yet described) satisfy only (2). (All
|
|
6004 non-modal encodings must satisfy (2), in order to be unambiguous.)
|
|
6005
|
|
6006 @node Internal Character Encoding
|
|
6007 @subsection Internal Character Encoding
|
|
6008
|
|
6009 One 19-bit word represents a single character. The word is
|
|
6010 separated into three fields:
|
|
6011
|
|
6012 @example
|
|
6013 Bit number: 18 17 16 15 14 13 12 11 10 09 08 07 06 05 04 03 02 01 00
|
|
6014 <------------> <------------------> <------------------>
|
|
6015 Field: 1 2 3
|
|
6016 @end example
|
|
6017
|
|
6018 Note that fields 2 and 3 hold 7 bits each, while field 1 holds 5 bits.
|
|
6019
|
|
6020 @example
|
|
6021 Character set Field 1 Field 2 Field 3
|
|
6022 ------------- ------- ------- -------
|
|
6023 ASCII 0 0 PC1
|
|
6024 range: (00 - 7F)
|
|
6025 Control-1 0 1 PC1
|
|
6026 range: (00 - 1F)
|
|
6027 Dimension-1 official 0 LB - 0x80 PC1
|
|
6028 range: (01 - 0D) (20 - 7F)
|
|
6029 Dimension-1 private 0 LB - 0x80 PC1
|
|
6030 range: (20 - 6F) (20 - 7F)
|
|
6031 Dimension-2 official LB - 0x8F PC1 PC2
|
|
6032 range: (01 - 0A) (20 - 7F) (20 - 7F)
|
|
6033 Dimension-2 private LB - 0xE1 PC1 PC2
|
|
6034 range: (0F - 1E) (20 - 7F) (20 - 7F)
|
|
6035 Composite 0x1F ? ?
|
|
6036 @end example
|
|
6037
|
|
6038 Note that character codes 0 - 255 are the same as the ``binary encoding''
|
|
6039 described above.
|
|
6040
|
|
6041 @node CCL
|
|
6042 @section CCL
|
|
6043
|
|
6044 @example
|
|
6045 CCL PROGRAM SYNTAX:
|
|
6046 CCL_PROGRAM := (CCL_MAIN_BLOCK
|
|
6047 [ CCL_EOF_BLOCK ])
|
|
6048
|
|
6049 CCL_MAIN_BLOCK := CCL_BLOCK
|
|
6050 CCL_EOF_BLOCK := CCL_BLOCK
|
|
6051
|
|
6052 CCL_BLOCK := STATEMENT | (STATEMENT [STATEMENT ...])
|
|
6053 STATEMENT :=
|
|
6054 SET | IF | BRANCH | LOOP | REPEAT | BREAK
|
|
6055 | READ | WRITE
|
|
6056
|
|
6057 SET := (REG = EXPRESSION) | (REG SELF_OP EXPRESSION)
|
|
6058 | INT-OR-CHAR
|
|
6059
|
|
6060 EXPRESSION := ARG | (EXPRESSION OP ARG)
|
|
6061
|
|
6062 IF := (if EXPRESSION CCL_BLOCK CCL_BLOCK)
|
|
6063 BRANCH := (branch EXPRESSION CCL_BLOCK [CCL_BLOCK ...])
|
|
6064 LOOP := (loop STATEMENT [STATEMENT ...])
|
|
6065 BREAK := (break)
|
|
6066 REPEAT := (repeat)
|
|
6067 | (write-repeat [REG | INT-OR-CHAR | string])
|
|
6068 | (write-read-repeat REG [INT-OR-CHAR | string | ARRAY]?)
|
|
6069 READ := (read REG) | (read REG REG)
|
|
6070 | (read-if REG ARITH_OP ARG CCL_BLOCK CCL_BLOCK)
|
|
6071 | (read-branch REG CCL_BLOCK [CCL_BLOCK ...])
|
|
6072 WRITE := (write REG) | (write REG REG)
|
|
6073 | (write INT-OR-CHAR) | (write STRING) | STRING
|
|
6074 | (write REG ARRAY)
|
|
6075 END := (end)
|
|
6076
|
|
6077 REG := r0 | r1 | r2 | r3 | r4 | r5 | r6 | r7
|
|
6078 ARG := REG | INT-OR-CHAR
|
|
6079 OP := + | - | * | / | % | & | '|' | ^ | << | >> | <8 | >8 | //
|
|
6080 | < | > | == | <= | >= | !=
|
|
6081 SELF_OP :=
|
|
6082 += | -= | *= | /= | %= | &= | '|=' | ^= | <<= | >>=
|
|
6083 ARRAY := '[' INT-OR-CHAR ... ']'
|
|
6084 INT-OR-CHAR := INT | CHAR
|
|
6085
|
|
6086 MACHINE CODE:
|
|
6087
|
|
6088 The machine code consists of a vector of 32-bit words.
|
|
6089 The first such word specifies the start of the EOF section of the code;
|
|
6090 this is the code executed to handle any stuff that needs to be done
|
|
6091 (e.g. designating back to ASCII and left-to-right mode) after all
|
|
6092 other encoded/decoded data has been written out. This is not used for
|
|
6093 charset CCL programs.
|
|
6094
|
|
6095 REGISTER: 0..7 -- refered by RRR or rrr
|
|
6096
|
|
6097 OPERATOR BIT FIELD (27-bit): XXXXXXXXXXXXXXX RRR TTTTT
|
|
6098 TTTTT (5-bit): operator type
|
|
6099 RRR (3-bit): register number
|
|
6100 XXXXXXXXXXXXXXXX (15-bit):
|
|
6101 CCCCCCCCCCCCCCC: constant or address
|
|
6102 000000000000rrr: register number
|
|
6103
|
|
6104 AAAA: 00000 +
|
|
6105 00001 -
|
|
6106 00010 *
|
|
6107 00011 /
|
|
6108 00100 %
|
|
6109 00101 &
|
|
6110 00110 |
|
|
6111 00111 ~
|
|
6112
|
|
6113 01000 <<
|
|
6114 01001 >>
|
|
6115 01010 <8
|
|
6116 01011 >8
|
|
6117 01100 //
|
|
6118 01101 not used
|
|
6119 01110 not used
|
|
6120 01111 not used
|
|
6121
|
|
6122 10000 <
|
|
6123 10001 >
|
|
6124 10010 ==
|
|
6125 10011 <=
|
|
6126 10100 >=
|
|
6127 10101 !=
|
|
6128
|
|
6129 OPERATORS: TTTTT RRR XX..
|
|
6130
|
|
6131 SetCS: 00000 RRR C...C RRR = C...C
|
|
6132 SetCL: 00001 RRR ..... RRR = c...c
|
|
6133 c.............c
|
|
6134 SetR: 00010 RRR ..rrr RRR = rrr
|
|
6135 SetA: 00011 RRR ..rrr RRR = array[rrr]
|
|
6136 C.............C size of array = C...C
|
|
6137 c.............c contents = c...c
|
|
6138
|
|
6139 Jump: 00100 000 c...c jump to c...c
|
|
6140 JumpCond: 00101 RRR c...c if (!RRR) jump to c...c
|
|
6141 WriteJump: 00110 RRR c...c Write1 RRR, jump to c...c
|
|
6142 WriteReadJump: 00111 RRR c...c Write1, Read1 RRR, jump to c...c
|
|
6143 WriteCJump: 01000 000 c...c Write1 C...C, jump to c...c
|
|
6144 C...C
|
|
6145 WriteCReadJump: 01001 RRR c...c Write1 C...C, Read1 RRR,
|
|
6146 C.............C and jump to c...c
|
|
6147 WriteSJump: 01010 000 c...c WriteS, jump to c...c
|
|
6148 C.............C
|
|
6149 S.............S
|
|
6150 ...
|
|
6151 WriteSReadJump: 01011 RRR c...c WriteS, Read1 RRR, jump to c...c
|
|
6152 C.............C
|
|
6153 S.............S
|
|
6154 ...
|
|
6155 WriteAReadJump: 01100 RRR c...c WriteA, Read1 RRR, jump to c...c
|
|
6156 C.............C size of array = C...C
|
|
6157 c.............c contents = c...c
|
|
6158 ...
|
|
6159 Branch: 01101 RRR C...C if (RRR >= 0 && RRR < C..)
|
|
6160 c.............c branch to (RRR+1)th address
|
|
6161 Read1: 01110 RRR ... read 1-byte to RRR
|
|
6162 Read2: 01111 RRR ..rrr read 2-byte to RRR and rrr
|
|
6163 ReadBranch: 10000 RRR C...C Read1 and Branch
|
|
6164 c.............c
|
|
6165 ...
|
|
6166 Write1: 10001 RRR ..... write 1-byte RRR
|
|
6167 Write2: 10010 RRR ..rrr write 2-byte RRR and rrr
|
|
6168 WriteC: 10011 000 ..... write 1-char C...CC
|
|
6169 C.............C
|
|
6170 WriteS: 10100 000 ..... write C..-byte of string
|
|
6171 C.............C
|
|
6172 S.............S
|
|
6173 ...
|
|
6174 WriteA: 10101 RRR ..... write array[RRR]
|
|
6175 C.............C size of array = C...C
|
|
6176 c.............c contents = c...c
|
|
6177 ...
|
|
6178 End: 10110 000 ..... terminate the execution
|
|
6179
|
|
6180 SetSelfCS: 10111 RRR C...C RRR AAAAA= C...C
|
|
6181 ..........AAAAA
|
|
6182 SetSelfCL: 11000 RRR ..... RRR AAAAA= c...c
|
|
6183 c.............c
|
|
6184 ..........AAAAA
|
|
6185 SetSelfR: 11001 RRR ..Rrr RRR AAAAA= rrr
|
|
6186 ..........AAAAA
|
|
6187 SetExprCL: 11010 RRR ..Rrr RRR = rrr AAAAA c...c
|
|
6188 c.............c
|
|
6189 ..........AAAAA
|
|
6190 SetExprR: 11011 RRR ..rrr RRR = rrr AAAAA Rrr
|
|
6191 ............Rrr
|
|
6192 ..........AAAAA
|
|
6193 JumpCondC: 11100 RRR c...c if !(RRR AAAAA C..) jump to c...c
|
|
6194 C.............C
|
|
6195 ..........AAAAA
|
|
6196 JumpCondR: 11101 RRR c...c if !(RRR AAAAA rrr) jump to c...c
|
|
6197 ............rrr
|
|
6198 ..........AAAAA
|
|
6199 ReadJumpCondC: 11110 RRR c...c Read1 and JumpCondC
|
|
6200 C.............C
|
|
6201 ..........AAAAA
|
|
6202 ReadJumpCondR: 11111 RRR c...c Read1 and JumpCondR
|
|
6203 ............rrr
|
|
6204 ..........AAAAA
|
|
6205 @end example
|
|
6206
|
|
6207 @node The Lisp Reader and Compiler, Lstreams, MULE Character Sets and Encodings, Top
|
|
6208 @chapter The Lisp Reader and Compiler
|
|
6209
|
|
6210 Not yet documented.
|
|
6211
|
|
6212 @node Lstreams, Consoles; Devices; Frames; Windows, The Lisp Reader and Compiler, Top
|
|
6213 @chapter Lstreams
|
|
6214
|
|
6215 An @dfn{lstream} is an internal Lisp object that provides a generic
|
|
6216 buffering stream implementation. Conceptually, you send data to the
|
|
6217 stream or read data from the stream, not caring what's on the other end
|
|
6218 of the stream. The other end could be another stream, a file
|
|
6219 descriptor, a stdio stream, a fixed block of memory, a reallocating
|
|
6220 block of memory, etc. The main purpose of the stream is to provide a
|
|
6221 standard interface and to do buffering. Macros are defined to read or
|
|
6222 write characters, so the calling functions do not have to worry about
|
|
6223 blocking data together in order to achieve efficiency.
|
|
6224
|
|
6225 @menu
|
|
6226 * Creating an Lstream:: Creating an lstream object.
|
|
6227 * Lstream Types:: Different sorts of things that are streamed.
|
|
6228 * Lstream Functions:: Functions for working with lstreams.
|
|
6229 * Lstream Methods:: Creating new lstream types.
|
|
6230 @end menu
|
|
6231
|
|
6232 @node Creating an Lstream
|
|
6233 @section Creating an Lstream
|
|
6234
|
|
6235 Lstreams come in different types, depending on what is being interfaced
|
|
6236 to. Although the primitive for creating new lstreams is
|
|
6237 @code{Lstream_new()}, generally you do not call this directly. Instead,
|
|
6238 you call some type-specific creation function, which creates the lstream
|
|
6239 and initializes it as appropriate for the particular type.
|
|
6240
|
|
6241 All lstream creation functions take a @var{mode} argument, specifying
|
|
6242 what mode the lstream should be opened as. This controls whether the
|
|
6243 lstream is for input and output, and optionally whether data should be
|
|
6244 blocked up in units of MULE characters. Note that some types of
|
|
6245 lstreams can only be opened for input; others only for output; and
|
|
6246 others can be opened either way. #### Richard Mlynarik thinks that
|
|
6247 there should be a strict separation between input and output streams,
|
|
6248 and he's probably right.
|
|
6249
|
|
6250 @var{mode} is a string, one of
|
|
6251
|
|
6252 @table @code
|
|
6253 @item "r"
|
|
6254 Open for reading.
|
|
6255 @item "w"
|
|
6256 Open for writing.
|
|
6257 @item "rc"
|
|
6258 Open for reading, but ``read'' never returns partial MULE characters.
|
|
6259 @item "wc"
|
|
6260 Open for writing, but never writes partial MULE characters.
|
|
6261 @end table
|
|
6262
|
|
6263 @node Lstream Types
|
|
6264 @section Lstream Types
|
|
6265
|
|
6266 @table @asis
|
|
6267 @item stdio
|
|
6268
|
|
6269 @item filedesc
|
|
6270
|
|
6271 @item lisp-string
|
|
6272
|
|
6273 @item fixed-buffer
|
|
6274
|
|
6275 @item resizing-buffer
|
|
6276
|
|
6277 @item dynarr
|
|
6278
|
|
6279 @item lisp-buffer
|
|
6280
|
|
6281 @item print
|
|
6282
|
|
6283 @item decoding
|
|
6284
|
|
6285 @item encoding
|
|
6286 @end table
|
|
6287
|
|
6288 @node Lstream Functions
|
|
6289 @section Lstream Functions
|
|
6290
|
|
6291 @deftypefun {Lstream *} Lstream_new (Lstream_implementation *@var{imp}, CONST char *@var{mode})
|
|
6292 Allocate and return a new Lstream. This function is not really meant to
|
|
6293 be called directly; rather, each stream type should provide its own
|
|
6294 stream creation function, which creates the stream and does any other
|
|
6295 necessary creation stuff (e.g. opening a file).
|
|
6296 @end deftypefun
|
|
6297
|
|
6298 @deftypefun void Lstream_set_buffering (Lstream *@var{lstr}, Lstream_buffering @var{buffering}, int @var{buffering_size})
|
|
6299 Change the buffering of a stream. See @file{lstream.h}. By default the
|
|
6300 buffering is @code{STREAM_BLOCK_BUFFERED}.
|
|
6301 @end deftypefun
|
|
6302
|
|
6303 @deftypefun int Lstream_flush (Lstream *@var{lstr})
|
|
6304 Flush out any pending unwritten data in the stream. Clear any buffered
|
|
6305 input data. Returns 0 on success, -1 on error.
|
|
6306 @end deftypefun
|
|
6307
|
|
6308 @deftypefn Macro int Lstream_putc (Lstream *@var{stream}, int @var{c})
|
|
6309 Write out one byte to the stream. This is a macro and so it is very
|
|
6310 efficient. The @var{c} argument is only evaluated once but the @var{stream}
|
|
6311 argument is evaluated more than once. Returns 0 on success, -1 on
|
|
6312 error.
|
|
6313 @end deftypefn
|
|
6314
|
|
6315 @deftypefn Macro int Lstream_getc (Lstream *@var{stream})
|
|
6316 Read one byte from the stream. This is a macro and so it is very
|
|
6317 efficient. The @var{stream} argument is evaluated more than once. Return
|
|
6318 value is -1 for EOF or error.
|
|
6319 @end deftypefn
|
|
6320
|
|
6321 @deftypefn Macro void Lstream_ungetc (Lstream *@var{stream}, int @var{c})
|
|
6322 Push one byte back onto the input queue. This will be the next byte
|
|
6323 read from the stream. Any number of bytes can be pushed back and will
|
|
6324 be read in the reverse order they were pushed back -- most recent
|
|
6325 first. (This is necessary for consistency -- if there are a number of
|
|
6326 bytes that have been unread and I read and unread a byte, it needs to be
|
|
6327 the first to be read again.) This is a macro and so it is very
|
|
6328 efficient. The @var{c} argument is only evaluated once but the @var{stream}
|
|
6329 argument is evaluated more than once.
|
|
6330 @end deftypefn
|
|
6331
|
|
6332 @deftypefun int Lstream_fputc (Lstream *@var{stream}, int @var{c})
|
|
6333 @deftypefunx int Lstream_fgetc (Lstream *@var{stream})
|
|
6334 @deftypefunx void Lstream_fungetc (Lstream *@var{stream}, int @var{c})
|
|
6335 Function equivalents of the above macros.
|
|
6336 @end deftypefun
|
|
6337
|
|
6338 @deftypefun int Lstream_read (Lstream *@var{stream}, void *@var{data}, int @var{size})
|
|
6339 Read @var{size} bytes of @var{data} from the stream. Return the number
|
|
6340 of bytes read. 0 means EOF. -1 means an error occurred and no bytes
|
|
6341 were read.
|
|
6342 @end deftypefun
|
|
6343
|
|
6344 @deftypefun int Lstream_write (Lstream *@var{stream}, void *@var{data}, int @var{size})
|
|
6345 Write @var{size} bytes of @var{data} to the stream. Return the number
|
|
6346 of bytes written. -1 means an error occurred and no bytes were written.
|
|
6347 @end deftypefun
|
|
6348
|
|
6349 @deftypefun void Lstream_unread (Lstream *@var{stream}, void *@var{data}, int @var{size})
|
|
6350 Push back @var{size} bytes of @var{data} onto the input queue. The next
|
|
6351 call to @code{Lstream_read()} with the same size will read the same
|
|
6352 bytes back. Note that this will be the case even if there is other
|
|
6353 pending unread data.
|
|
6354 @end deftypefun
|
|
6355
|
|
6356 @deftypefun int Lstream_close (Lstream *@var{stream})
|
|
6357 Close the stream. All data will be flushed out.
|
|
6358 @end deftypefun
|
|
6359
|
|
6360 @deftypefun void Lstream_reopen (Lstream *@var{stream})
|
|
6361 Reopen a closed stream. This enables I/O on it again. This is not
|
|
6362 meant to be called except from a wrapper routine that reinitializes
|
|
6363 variables and such -- the close routine may well have freed some
|
|
6364 necessary storage structures, for example.
|
|
6365 @end deftypefun
|
|
6366
|
|
6367 @deftypefun void Lstream_rewind (Lstream *@var{stream})
|
|
6368 Rewind the stream to the beginning.
|
|
6369 @end deftypefun
|
|
6370
|
|
6371 @node Lstream Methods
|
|
6372 @section Lstream Methods
|
|
6373
|
|
6374 @deftypefn {Lstream Method} int reader (Lstream *@var{stream}, unsigned char *@var{data}, int @var{size})
|
|
6375 Read some data from the stream's end and store it into @var{data}, which
|
|
6376 can hold @var{size} bytes. Return the number of bytes read. A return
|
|
6377 value of 0 means no bytes can be read at this time. This may be because
|
|
6378 of an EOF, or because there is a granularity greater than one byte that
|
|
6379 the stream imposes on the returned data, and @var{size} is less than
|
|
6380 this granularity. (This will happen frequently for streams that need to
|
|
6381 return whole characters, because @code{Lstream_read()} calls the reader
|
|
6382 function repeatedly until it has the number of bytes it wants or until 0
|
|
6383 is returned.) The lstream functions do not treat a 0 return as EOF or
|
|
6384 do anything special; however, the calling function will interpret any 0
|
|
6385 it gets back as EOF. This will normally not happen unless the caller
|
|
6386 calls @code{Lstream_read()} with a very small size.
|
|
6387
|
|
6388 This function can be @code{NULL} if the stream is output-only.
|
|
6389 @end deftypefn
|
|
6390
|
|
6391 @deftypefn {Lstream Method} int writer (Lstream *@var{stream}, CONST unsigned char *@var{data}, int @var{size})
|
|
6392 Send some data to the stream's end. Data to be sent is in @var{data}
|
|
6393 and is @var{size} bytes. Return the number of bytes sent. This
|
|
6394 function can send and return fewer bytes than is passed in; in that
|
|
6395 case, the function will just be called again until there is no data left
|
|
6396 or 0 is returned. A return value of 0 means that no more data can be
|
|
6397 currently stored, but there is no error; the data will be squirreled
|
|
6398 away until the writer can accept data. (This is useful, e.g., if you're
|
|
6399 dealing with a non-blocking file descriptor and are getting
|
|
6400 @code{EWOULDBLOCK} errors.) This function can be @code{NULL} if the
|
|
6401 stream is input-only.
|
|
6402 @end deftypefn
|
|
6403
|
|
6404 @deftypefn {Lstream Method} int rewinder (Lstream *@var{stream})
|
|
6405 Rewind the stream. If this is @code{NULL}, the stream is not seekable.
|
|
6406 @end deftypefn
|
|
6407
|
|
6408 @deftypefn {Lstream Method} int seekable_p (Lstream *@var{stream})
|
|
6409 Indicate whether this stream is seekable -- i.e. it can be rewound.
|
|
6410 This method is ignored if the stream does not have a rewind method. If
|
|
6411 this method is not present, the result is determined by whether a rewind
|
|
6412 method is present.
|
|
6413 @end deftypefn
|
|
6414
|
|
6415 @deftypefn {Lstream Method} int flusher (Lstream *@var{stream})
|
|
6416 Perform any additional operations necessary to flush the data in this
|
|
6417 stream.
|
|
6418 @end deftypefn
|
|
6419
|
|
6420 @deftypefn {Lstream Method} int pseudo_closer (Lstream *@var{stream})
|
|
6421 @end deftypefn
|
|
6422
|
|
6423 @deftypefn {Lstream Method} int closer (Lstream *@var{stream})
|
|
6424 Perform any additional operations necessary to close this stream down.
|
|
6425 May be @code{NULL}. This function is called when @code{Lstream_close()}
|
|
6426 is called or when the stream is garbage-collected. When this function
|
|
6427 is called, all pending data in the stream will already have been written
|
|
6428 out.
|
|
6429 @end deftypefn
|
|
6430
|
|
6431 @deftypefn {Lstream Method} Lisp_Object marker (Lisp_Object @var{lstream}, void (*@var{markfun}) (Lisp_Object))
|
|
6432 Mark this object for garbage collection. Same semantics as a standard
|
|
6433 @code{Lisp_Object} marker. This function can be @code{NULL}.
|
|
6434 @end deftypefn
|
|
6435
|
|
6436 @node Consoles; Devices; Frames; Windows, The Redisplay Mechanism, Lstreams, Top
|
|
6437 @chapter Consoles; Devices; Frames; Windows
|
|
6438
|
|
6439 @menu
|
|
6440 * Introduction to Consoles; Devices; Frames; Windows::
|
|
6441 * Point::
|
|
6442 * Window Hierarchy::
|
|
6443 * The Window Object::
|
|
6444 @end menu
|
|
6445
|
|
6446 @node Introduction to Consoles; Devices; Frames; Windows
|
|
6447 @section Introduction to Consoles; Devices; Frames; Windows
|
|
6448
|
|
6449 A window-system window that you see on the screen is called a
|
|
6450 @dfn{frame} in Emacs terminology. Each frame is subdivided into one or
|
|
6451 more non-overlapping panes, called (confusingly) @dfn{windows}. Each
|
|
6452 window displays the text of a buffer in it. (See above on Buffers.) Note
|
|
6453 that buffers and windows are independent entities: Two or more windows
|
|
6454 can be displaying the same buffer (potentially in different locations),
|
|
6455 and a buffer can be displayed in no windows.
|
|
6456
|
|
6457 A single display screen that contains one or more frames is called
|
|
6458 a @dfn{display}. Under most circumstances, there is only one display.
|
|
6459 However, more than one display can exist, for example if you have
|
|
6460 a @dfn{multi-headed} console, i.e. one with a single keyboard but
|
|
6461 multiple displays. (Typically in such a situation, the various
|
|
6462 displays act like one large display, in that the mouse is only
|
|
6463 in one of them at a time, and moving the mouse off of one moves
|
|
6464 it into another.) In some cases, the different displays will
|
|
6465 have different characteristics, e.g. one color and one mono.
|
|
6466
|
|
6467 XEmacs can display frames on multiple displays. It can even deal
|
|
6468 simultaneously with frames on multiple keyboards (called @dfn{consoles} in
|
|
6469 XEmacs terminology). Here is one case where this might be useful: You
|
|
6470 are using XEmacs on your workstation at work, and leave it running.
|
|
6471 Then you go home and dial in on a TTY line, and you can use the
|
|
6472 already-running XEmacs process to display another frame on your local
|
|
6473 TTY.
|
|
6474
|
|
6475 Thus, there is a hierarchy console -> display -> frame -> window.
|
|
6476 There is a separate Lisp object type for each of these four concepts.
|
2
|
6477 Furthermore, there is logically a @dfn{selected console},
|
0
|
6478 @dfn{selected display}, @dfn{selected frame}, and @dfn{selected window}.
|
2
|
6479 Each of these objects is distinguished in various ways, such as being the
|
|
6480 default object for various functions that act on objects of that type.
|
|
6481 Note that every containing object rememembers the ``selected'' object
|
|
6482 among the objects that it contains: e.g. not only is there a selected
|
|
6483 window, but every frame remembers the last window in it that was
|
|
6484 selected, and changing the selected frame causes the remembered window
|
|
6485 within it to become the selected window. Similar relationships apply
|
|
6486 for consoles to devices and devices to frames.
|
0
|
6487
|
|
6488 @node Point
|
|
6489 @section Point
|
|
6490
|
|
6491 Recall that every buffer has a current insertion position, called
|
|
6492 @dfn{point}. Now, two or more windows may be displaying the same buffer,
|
|
6493 and the text cursor in the two windows (i.e. @code{point}) can be in
|
|
6494 two different places. You may ask, how can that be, since each
|
|
6495 buffer has only one value of @code{point}? The answer is that each window
|
|
6496 also has a value of @code{point} that is squirreled away in it. There
|
|
6497 is only one selected window, and the value of ``point'' in that buffer
|
|
6498 corresponds to that window. When the selected window is changed
|
|
6499 from one window to another displaying the same buffer, the old
|
|
6500 value of @code{point} is stored into the old window's ``point'' and the
|
|
6501 value of @code{point} from the new window is retrieved and made the
|
|
6502 value of @code{point} in the buffer. This means that @code{window-point}
|
|
6503 for the selected window is potentially inaccurate, and if you
|
|
6504 want to retrieve the correct value of @code{point} for a window,
|
|
6505 you must special-case on the selected window and retrieve the
|
|
6506 buffer's point instead. This is related to why @code{save-window-excursion}
|
|
6507 does not save the selected window's value of @code{point}.
|
|
6508
|
|
6509 @node Window Hierarchy
|
|
6510 @section Window Hierarchy
|
|
6511 @cindex window hierarchy
|
|
6512 @cindex hierarchy of windows
|
|
6513
|
|
6514 If a frame contains multiple windows (panes), they are always created
|
|
6515 by splitting an existing window along the horizontal or vertical axis.
|
|
6516 Terminology is a bit confusing here: to @dfn{split a window
|
|
6517 horizontally} means to create two side-by-side windows, i.e. to make a
|
|
6518 @emph{vertical} cut in a window. Likewise, to @dfn{split a window
|
|
6519 vertically} means to create two windows, one above the other, by making
|
|
6520 a @emph{horizontal} cut.
|
|
6521
|
|
6522 If you split a window and then split again along the same axis, you
|
|
6523 will end up with a number of panes all arranged along the same axis.
|
|
6524 The precise way in which the splits were made should not be important,
|
|
6525 and this is reflected internally. Internally, all windows are arranged
|
|
6526 in a tree, consisting of two types of windows, @dfn{combination} windows
|
|
6527 (which have children, and are covered completely by those children) and
|
|
6528 @dfn{leaf} windows, which have no children and are visible. Every
|
|
6529 combination window has two or more children, all arranged along the same
|
|
6530 axis. There are (logically) two subtypes of windows, depending on
|
|
6531 whether their children are horizontally or vertically arrayed. There is
|
|
6532 always one root window, which is either a leaf window (if the frame
|
|
6533 contains only one window) or a combination window (if the frame contains
|
|
6534 more than one window). In the latter case, the root window will have
|
|
6535 two or more children, either horizontally or vertically arrayed, and
|
|
6536 each of those children will be either a leaf window or another
|
|
6537 combination window.
|
|
6538
|
|
6539 Here are some rules:
|
|
6540
|
|
6541 @enumerate
|
|
6542 @item
|
2
|
6543 Horizontal combination windows can never have children that are
|
|
6544 horizontal combination windows; same for vertical.
|
0
|
6545
|
|
6546 @item
|
|
6547 Only leaf windows can be split (obviously) and this splitting does one
|
|
6548 of two things: (a) turns the leaf window into a combination window and
|
|
6549 creates two new leaf children, or (b) turns the leaf window into one of
|
|
6550 the two new leaves and creates the other leaf. Rule (1) dictates which
|
|
6551 of these two outcomes happens.
|
|
6552
|
|
6553 @item
|
|
6554 Every combination window must have at least two children.
|
|
6555
|
|
6556 @item
|
|
6557 Leaf windows can never become combination windows. They can be deleted,
|
|
6558 however. If this results in a violation of (3), the parent combination
|
|
6559 window also gets deleted.
|
|
6560
|
|
6561 @item
|
|
6562 All functions that accept windows must be prepared to accept combination
|
|
6563 windows, and do something sane (e.g. signal an error if so).
|
|
6564 Combination windows @emph{do} escape to the Lisp level.
|
|
6565
|
|
6566 @item
|
|
6567 All windows have three fields governing their contents:
|
|
6568 these are @dfn{hchild} (a list of horizontally-arrayed children),
|
|
6569 @dfn{vchild} (a list of vertically-arrayed children), and @dfn{buffer}
|
|
6570 (the buffer contained in a leaf window). Exactly one of
|
|
6571 these will be non-nil. Remember that @dfn{horizontally-arrayed}
|
|
6572 means ``side-by-side'' and @dfn{vertically-arrayed} means
|
|
6573 @dfn{one above the other}.
|
|
6574
|
|
6575 @item
|
|
6576 Leaf windows also have markers in their @code{start} (the
|
|
6577 first buffer position displayed in the window) and @code{pointm}
|
|
6578 (the window's stashed value of @code{point} -- see above) fields,
|
|
6579 while combination windows have nil in these fields.
|
|
6580
|
|
6581 @item
|
|
6582 The list of children for a window is threaded through the
|
|
6583 @code{next} and @code{prev} fields of each child window.
|
|
6584
|
|
6585 @item
|
|
6586 @strong{Deleted windows can be undeleted}. This happens as a result of
|
|
6587 restoring a window configuration, and is unlike frames, displays, and
|
|
6588 consoles, which, once deleted, can never be restored. Deleting a window
|
|
6589 does nothing except set a special @code{dead} bit to 1 and clear out the
|
|
6590 @code{next}, @code{prev}, @code{hchild}, and @code{vchild} fields, for
|
|
6591 GC purposes.
|
|
6592
|
|
6593 @item
|
|
6594 Most frames actually have two top-level windows -- one for the
|
|
6595 minibuffer and one (the @dfn{root}) for everything else. The modeline
|
|
6596 (if present) separates these two. The @code{next} field of the root
|
|
6597 points to the minibuffer, and the @code{prev} field of the minibuffer
|
|
6598 points to the root. The other @code{next} and @code{prev} fields are
|
|
6599 @code{nil}, and the frame points to both of these windows.
|
|
6600 Minibuffer-less frames have no minibuffer window, and the @code{next}
|
|
6601 and @code{prev} of the root window are @code{nil}. Minibuffer-only
|
|
6602 frames have no root window, and the @code{next} of the minibuffer window
|
|
6603 is @code{nil} but the @code{prev} points to itself. (#### This is an
|
|
6604 artifact that should be fixed.)
|
|
6605 @end enumerate
|
|
6606
|
|
6607 @node The Window Object
|
|
6608 @section The Window Object
|
|
6609
|
|
6610 Windows have the following accessible fields:
|
|
6611
|
|
6612 @table @code
|
|
6613 @item frame
|
|
6614 The frame that this window is on.
|
|
6615
|
|
6616 @item mini_p
|
|
6617 Non-@code{nil} if this window is a minibuffer window.
|
|
6618
|
|
6619 @item buffer
|
|
6620 The buffer that the window is displaying. This may change often during
|
|
6621 the life of the window.
|
|
6622
|
|
6623 @item dedicated
|
|
6624 Non-@code{nil} if this window is dedicated to its buffer.
|
|
6625
|
|
6626 @item pointm
|
|
6627 @cindex window point internals
|
|
6628 This is the value of point in the current buffer when this window is
|
|
6629 selected; when it is not selected, it retains its previous value.
|
|
6630
|
|
6631 @item start
|
|
6632 The position in the buffer that is the first character to be displayed
|
|
6633 in the window.
|
|
6634
|
|
6635 @item force_start
|
|
6636 If this flag is non-@code{nil}, it says that the window has been
|
|
6637 scrolled explicitly by the Lisp program. This affects what the next
|
|
6638 redisplay does if point is off the screen: instead of scrolling the
|
|
6639 window to show the text around point, it moves point to a location that
|
|
6640 is on the screen.
|
|
6641
|
|
6642 @item last_modified
|
|
6643 The @code{modified} field of the window's buffer, as of the last time
|
|
6644 a redisplay completed in this window.
|
|
6645
|
|
6646 @item last_point
|
|
6647 The buffer's value of point, as of the last time
|
|
6648 a redisplay completed in this window.
|
|
6649
|
|
6650 @item left
|
|
6651 This is the left-hand edge of the window, measured in columns. (The
|
|
6652 leftmost column on the screen is @w{column 0}.)
|
|
6653
|
|
6654 @item top
|
|
6655 This is the top edge of the window, measured in lines. (The top line on
|
|
6656 the screen is @w{line 0}.)
|
|
6657
|
|
6658 @item height
|
|
6659 The height of the window, measured in lines.
|
|
6660
|
|
6661 @item width
|
|
6662 The width of the window, measured in columns.
|
|
6663
|
|
6664 @item next
|
|
6665 This is the window that is the next in the chain of siblings. It is
|
|
6666 @code{nil} in a window that is the rightmost or bottommost of a group of
|
|
6667 siblings.
|
|
6668
|
|
6669 @item prev
|
|
6670 This is the window that is the previous in the chain of siblings. It is
|
|
6671 @code{nil} in a window that is the leftmost or topmost of a group of
|
|
6672 siblings.
|
|
6673
|
|
6674 @item parent
|
|
6675 Internally, XEmacs arranges windows in a tree; each group of siblings has
|
|
6676 a parent window whose area includes all the siblings. This field points
|
|
6677 to a window's parent.
|
|
6678
|
|
6679 Parent windows do not display buffers, and play little role in display
|
|
6680 except to shape their child windows. Emacs Lisp programs usually have
|
|
6681 no access to the parent windows; they operate on the windows at the
|
|
6682 leaves of the tree, which actually display buffers.
|
|
6683
|
|
6684 @item hscroll
|
|
6685 This is the number of columns that the display in the window is scrolled
|
|
6686 horizontally to the left. Normally, this is 0.
|
|
6687
|
|
6688 @item use_time
|
|
6689 This is the last time that the window was selected. The function
|
|
6690 @code{get-lru-window} uses this field.
|
|
6691
|
|
6692 @item display_table
|
|
6693 The window's display table, or @code{nil} if none is specified for it.
|
|
6694
|
|
6695 @item update_mode_line
|
|
6696 Non-@code{nil} means this window's mode line needs to be updated.
|
|
6697
|
|
6698 @item base_line_number
|
|
6699 The line number of a certain position in the buffer, or @code{nil}.
|
|
6700 This is used for displaying the line number of point in the mode line.
|
|
6701
|
|
6702 @item base_line_pos
|
|
6703 The position in the buffer for which the line number is known, or
|
|
6704 @code{nil} meaning none is known.
|
|
6705
|
|
6706 @item region_showing
|
|
6707 If the region (or part of it) is highlighted in this window, this field
|
|
6708 holds the mark position that made one end of that region. Otherwise,
|
|
6709 this field is @code{nil}.
|
|
6710 @end table
|
|
6711
|
|
6712 @node The Redisplay Mechanism, Extents, Consoles; Devices; Frames; Windows, Top
|
|
6713 @chapter The Redisplay Mechanism
|
|
6714
|
|
6715 The redisplay mechanism is one of the most complicated sections of
|
|
6716 XEmacs, especially from a conceptual standpoint. This is doubly so
|
|
6717 because, unlike for the basic aspects of the Lisp interpreter, the
|
|
6718 computer science theories of how to efficiently handle redisplay are not
|
|
6719 well-developed.
|
|
6720
|
|
6721 When working with the redisplay mechanism, remember the Golden Rules
|
|
6722 of Redisplay:
|
|
6723
|
|
6724 @enumerate
|
|
6725 @item
|
|
6726 It Is Better To Be Correct Than Fast.
|
|
6727 @item
|
|
6728 Thou Shalt Not Run Elisp From Within Redisplay.
|
|
6729 @item
|
|
6730 It Is Better To Be Fast Than Not To Be.
|
|
6731 @end enumerate
|
|
6732
|
|
6733 @menu
|
|
6734 * Critical Redisplay Sections::
|
|
6735 * Line Start Cache::
|
|
6736 @end menu
|
|
6737
|
|
6738 @node Critical Redisplay Sections
|
|
6739 @section Critical Redisplay Sections
|
|
6740 @cindex critical redisplay sections
|
|
6741
|
|
6742 Within this section, we are defenseless and assume that the
|
|
6743 following cannot happen:
|
|
6744
|
|
6745 @enumerate
|
|
6746 @item
|
|
6747 garbage collection
|
|
6748 @item
|
|
6749 Lisp code evaluation
|
|
6750 @item
|
|
6751 frame size changes
|
|
6752 @end enumerate
|
|
6753
|
|
6754 We ensure (3) by calling @code{hold_frame_size_changes()}, which
|
|
6755 will cause any pending frame size changes to get put on hold
|
|
6756 till after the end of the critical section. (1) follows
|
|
6757 automatically if (2) is met. #### Unfortunately, there are
|
|
6758 some places where Lisp code can be called within this section.
|
|
6759 We need to remove them.
|
|
6760
|
|
6761 If @code{Fsignal()} is called during this critical section, we
|
|
6762 will @code{abort()}.
|
|
6763
|
|
6764 If garbage collection is called during this critical section,
|
|
6765 we simply return. #### We should abort instead.
|
|
6766
|
|
6767 #### If a frame-size change does occur we should probably
|
|
6768 actually be preempting redisplay.
|
|
6769
|
|
6770 @node Line Start Cache
|
|
6771 @section Line Start Cache
|
|
6772 @cindex line start cache
|
|
6773
|
|
6774 The traditional scrolling code in Emacs breaks in a variable height
|
|
6775 world. It depends on the key assumption that the number of lines that
|
|
6776 can be displayed at any given time is fixed. This led to a complete
|
|
6777 separation of the scrolling code from the redisplay code. In order to
|
|
6778 fully support variable height lines, the scrolling code must actually be
|
|
6779 tightly integrated with redisplay. Only redisplay can determine how
|
|
6780 many lines will be displayed on a screen for any given starting point.
|
|
6781
|
|
6782 What is ideally wanted is a complete list of the starting buffer
|
|
6783 position for every possible display line of a buffer along with the
|
|
6784 height of that display line. Maintaining such a full list would be very
|
|
6785 expensive. We settle for having it include information for all areas
|
|
6786 which we happen to generate anyhow (i.e. the region currently being
|
|
6787 displayed) and for those areas we need to work with.
|
|
6788
|
|
6789 In order to ensure that the cache accurately represents what redisplay
|
|
6790 would actually show, it is necessary to invalidate it in many
|
|
6791 situations. If the buffer changes, the starting positions may no longer
|
|
6792 be correct. If a face or an extent has changed then the line heights
|
|
6793 may have altered. These events happen frequently enough that the cache
|
|
6794 can end up being constantly disabled. With this potentially constant
|
|
6795 invalidation when is the cache ever useful?
|
|
6796
|
|
6797 Even if the cache is invalidated before every single usage, it is
|
|
6798 necessary. Scrolling often requires knowledge about display lines which
|
|
6799 are actually above or below the visible region. The cache provides a
|
|
6800 convenient light-weight method of storing this information for multiple
|
|
6801 display regions. This knowledge is necessary for the scrolling code to
|
|
6802 always obey the First Golden Rule of Redisplay.
|
|
6803
|
|
6804 If the cache already contains all of the information that the scrolling
|
|
6805 routines happen to need so that it doesn't have to go generate it, then
|
|
6806 we are able to obey the Third Golden Rule of Redisplay. The first thing
|
|
6807 we do to help out the cache is to always add the displayed region. This
|
|
6808 region had to be generated anyway, so the cache ends up getting the
|
|
6809 information basically for free. In those cases where a user is simply
|
|
6810 scrolling around viewing a buffer there is a high probability that this
|
|
6811 is sufficient to always provide the needed information. The second
|
|
6812 thing we can do is be smart about invalidating the cache.
|
|
6813
|
|
6814 TODO -- Be smart about invalidating the cache. Potential places:
|
|
6815
|
|
6816 @itemize @bullet
|
|
6817 @item
|
|
6818 Insertions at end-of-line which don't cause line-wraps do not alter the
|
|
6819 starting positions of any display lines. These types of buffer
|
|
6820 modifications should not invalidate the cache. This is actually a large
|
|
6821 optimization for redisplay speed as well.
|
|
6822 @item
|
|
6823 Buffer modifications frequently only affect the display of lines at and
|
|
6824 below where they occur. In these situations we should only invalidate
|
|
6825 the part of the cache starting at where the modification occurs.
|
|
6826 @end itemize
|
|
6827
|
|
6828 In case you're wondering, the Second Golden Rule of Redisplay is not
|
|
6829 applicable.
|
|
6830
|
|
6831 @node Extents, Faces and Glyphs, The Redisplay Mechanism, Top
|
|
6832 @chapter Extents
|
|
6833
|
|
6834 @menu
|
|
6835 * Introduction to Extents:: Extents are ranges over text, with properties.
|
|
6836 * Extent Ordering:: How extents are ordered internally.
|
|
6837 * Format of the Extent Info:: The extent information in a buffer or string.
|
|
6838 * Zero-Length Extents:: A weird special case.
|
|
6839 * Mathematics of Extent Ordering:: A rigorous foundation.
|
|
6840 * Extent Fragments:: Cached information useful for redisplay.
|
|
6841 @end menu
|
|
6842
|
|
6843 @node Introduction to Extents
|
|
6844 @section Introduction to Extents
|
|
6845
|
|
6846 Extents are regions over a buffer, with a start and an end position
|
|
6847 denoting the region of the buffer included in the extent. In
|
|
6848 addition, either end can be closed or open, meaning that the endpoint
|
|
6849 is or is not logically included in the extent. Insertion of a character
|
|
6850 at a closed endpoint causes the character to go inside the extent;
|
|
6851 insertion at an open endpoint causes the character to go outside.
|
|
6852
|
|
6853 Extent endpoints are stored using memory indices (see @file{insdel.c}),
|
|
6854 to minimize the amount of adjusting that needs to be done when
|
|
6855 characters are inserted or deleted.
|
|
6856
|
|
6857 (Formerly, extent endpoints at the gap could be either before or
|
|
6858 after the gap, depending on the open/closedness of the endpoint.
|
|
6859 The intent of this was to make it so that insertions would
|
|
6860 automatically go inside or out of extents as necessary with no
|
|
6861 further work needing to be done. It didn't work out that way,
|
|
6862 however, and just ended up complexifying and buggifying all the
|
|
6863 rest of the code.)
|
|
6864
|
|
6865 @node Extent Ordering
|
|
6866 @section Extent Ordering
|
|
6867
|
|
6868 Extents are compared using memory indices. There are two orderings
|
|
6869 for extents and both orders are kept current at all times. The normal
|
|
6870 or @dfn{display} order is as follows:
|
|
6871
|
|
6872 @example
|
|
6873 Extent A is ``less than'' extent B, that is, earlier in the display order,
|
|
6874 if: A-start < B-start,
|
|
6875 or if: A-start = B-start, and A-end > B-end
|
|
6876 @end example
|
|
6877
|
|
6878 So if two extents begin at the same position, the larger of them is the
|
|
6879 earlier one in the display order (@code{EXTENT_LESS} is true).
|
|
6880
|
|
6881 For the e-order, the same thing holds:
|
|
6882
|
|
6883 @example
|
|
6884 Extent A is ``less than'' extent B in e-order, that is, later in the buffer,
|
|
6885 if: A-end < B-end,
|
|
6886 or if: A-end = B-end, and A-start > B-start
|
|
6887 @end example
|
|
6888
|
|
6889 So if two extents end at the same position, the smaller of them is the
|
|
6890 earlier one in the e-order (@code{EXTENT_E_LESS} is true).
|
|
6891
|
|
6892 The display order and the e-order are complementary orders: any
|
|
6893 theorem about the display order also applies to the e-order if you swap
|
|
6894 all occurrences of ``display order'' and ``e-order'', ``less than'' and
|
|
6895 ``greater than'', and ``extent start'' and ``extent end''.
|
|
6896
|
|
6897 @node Format of the Extent Info
|
|
6898 @section Format of the Extent Info
|
|
6899
|
|
6900 An extent-info structure consists of a list of the buffer or string's
|
|
6901 extents and a @dfn{stack of extents} that lists all of the extents over
|
|
6902 a particular position. The stack-of-extents info is used for
|
|
6903 optimization purposes -- it basically caches some info that might
|
|
6904 be expensive to compute. Certain otherwise hard computations are easy
|
|
6905 given the stack of extents over a particular position, and if the
|
|
6906 stack of extents over a nearby position is known (because it was
|
|
6907 calculated at some prior point in time), it's easy to move the stack
|
|
6908 of extents to the proper position.
|
|
6909
|
|
6910 Given that the stack of extents is an optimization, and given that
|
|
6911 it requires memory, a string's stack of extents is wiped out each
|
|
6912 time a garbage collection occurs. Therefore, any time you retrieve
|
|
6913 the stack of extents, it might not be there. If you need it to
|
|
6914 be there, use the @code{_force} version.
|
|
6915
|
|
6916 Similarly, a string may or may not have an extent_info structure.
|
|
6917 (Generally it won't if there haven't been any extents added to the
|
|
6918 string.) So use the @code{_force} version if you need the extent_info
|
|
6919 structure to be there.
|
|
6920
|
|
6921 A list of extents is maintained as a double gap array: one gap array
|
|
6922 is ordered by start index (the @dfn{display order}) and the other is
|
|
6923 ordered by end index (the @dfn{e-order}). Note that positions in an
|
|
6924 extent list should logically be conceived of as referring @emph{to} a
|
|
6925 particular extent (as is the norm in programs) rather than sitting
|
|
6926 between two extents. Note also that callers of these functions should
|
|
6927 not be aware of the fact that the extent list is implemented as an
|
|
6928 array, except for the fact that positions are integers (this should be
|
|
6929 generalized to handle integers and linked list equally well).
|
|
6930
|
|
6931 @node Zero-Length Extents
|
|
6932 @section Zero-Length Extents
|
|
6933
|
|
6934 Extents can be zero-length, and will end up that way if their endpoints
|
|
6935 are explicitly set that way or if their detachable property is nil
|
|
6936 and all the text in the extent is deleted. (The exception is open-open
|
|
6937 zero-length extents, which are barred from existing because there is
|
|
6938 no sensible way to define their properties. Deletion of the text in
|
|
6939 an open-open extent causes it to be converted into a closed-open
|
|
6940 extent.) Zero-length extents are primarily used to represent
|
|
6941 annotations, and behave as follows:
|
|
6942
|
|
6943 @enumerate
|
|
6944 @item
|
|
6945 Insertion at the position of a zero-length extent expands the extent
|
|
6946 if both endpoints are closed; goes after the extent if it is closed-open;
|
|
6947 and goes before the extent if it is open-closed.
|
|
6948
|
|
6949 @item
|
|
6950 Deletion of a character on a side of a zero-length extent whose
|
|
6951 corresponding endpoint is closed causes the extent to be detached if
|
|
6952 it is detachable; if the extent is not detachable or the corresponding
|
|
6953 endpoint is open, the extent remains in the buffer, moving as necessary.
|
|
6954 @end enumerate
|
|
6955
|
|
6956 Note that closed-open, non-detachable zero-length extents behave
|
|
6957 exactly like markers and that open-closed, non-detachable zero-length
|
|
6958 extents behave like the ``point-type'' marker in Mule.
|
|
6959
|
|
6960 @node Mathematics of Extent Ordering
|
|
6961 @section Mathematics of Extent Ordering
|
|
6962 @cindex extent mathematics
|
|
6963 @cindex mathematics of extents
|
|
6964 @cindex extent ordering
|
|
6965
|
|
6966 @cindex display order of extents
|
|
6967 @cindex extents, display order
|
|
6968 The extents in a buffer are ordered by ``display order'' because that
|
|
6969 is that order that the redisplay mechanism needs to process them in.
|
|
6970 The e-order is an auxiliary ordering used to facilitate operations
|
|
6971 over extents. The operations that can be performed on the ordered
|
|
6972 list of extents in a buffer are
|
|
6973
|
|
6974 @enumerate
|
|
6975 @item
|
|
6976 Locate where an extent would go if inserted into the list.
|
|
6977 @item
|
|
6978 Insert an extent into the list.
|
|
6979 @item
|
|
6980 Remove an extent from the list.
|
|
6981 @item
|
|
6982 Map over all the extents that overlap a range.
|
|
6983 @end enumerate
|
|
6984
|
|
6985 (4) requires being able to determine the first and last extents
|
|
6986 that overlap a range.
|
|
6987
|
|
6988 NOTE: @dfn{overlap} is used as follows:
|
|
6989
|
|
6990 @itemize @bullet
|
|
6991 @item
|
|
6992 two ranges overlap if they have at least one point in common.
|
|
6993 Whether the endpoints are open or closed makes a difference here.
|
|
6994 @item
|
|
6995 a point overlaps a range if the point is contained within the
|
|
6996 range; this is equivalent to treating a point @math{P} as the range
|
|
6997 @math{[P, P]}.
|
|
6998 @item
|
|
6999 In the case of an @emph{extent} overlapping a point or range, the extent
|
|
7000 is normally treated as having closed endpoints. This applies
|
|
7001 consistently in the discussion of stacks of extents and such below.
|
|
7002 Note that this definition of overlap is not necessarily consistent with
|
|
7003 the extents that @code{map-extents} maps over, since @code{map-extents}
|
|
7004 sometimes pays attention to whether the endpoints of an extents are open
|
|
7005 or closed. But for our purposes, it greatly simplifies things to treat
|
|
7006 all extents as having closed endpoints.
|
|
7007 @end itemize
|
|
7008
|
|
7009 First, define @math{>}, @math{<}, @math{<=}, etc. as applied to extents
|
|
7010 to mean comparison according to the display order. Comparison between
|
|
7011 an extent @math{E} and an index @math{I} means comparison between
|
|
7012 @math{E} and the range @math{[I, I]}.
|
|
7013
|
|
7014 Also define @math{e>}, @math{e<}, @math{e<=}, etc. to mean comparison
|
|
7015 according to the e-order.
|
|
7016
|
|
7017 For any range @math{R}, define @math{R(0)} to be the starting index of
|
|
7018 the range and @math{R(1)} to be the ending index of the range.
|
|
7019
|
|
7020 For any extent @math{E}, define @math{E(next)} to be the extent directly
|
|
7021 following @math{E}, and @math{E(prev)} to be the extent directly
|
|
7022 preceding @math{E}. Assume @math{E(next)} and @math{E(prev)} can be
|
|
7023 determined from @math{E} in constant time. (This is because we store
|
|
7024 the extent list as a doubly linked list.)
|
|
7025
|
|
7026 Similarly, define @math{E(e-next)} and @math{E(e-prev)} to be the
|
|
7027 extents directly following and preceding @math{E} in the e-order.
|
|
7028
|
|
7029 Now:
|
|
7030
|
|
7031 Let @math{R} be a range.
|
|
7032 Let @math{F} be the first extent overlapping @math{R}.
|
|
7033 Let @math{L} be the last extent overlapping @math{R}.
|
|
7034
|
|
7035 Theorem 1: @math{R(1)} lies between @math{L} and @math{L(next)},
|
|
7036 i.e. @math{L <= R(1) < L(next)}.
|
|
7037
|
|
7038 This follows easily from the definition of display order. The
|
|
7039 basic reason that this theorem applies is that the display order
|
|
7040 sorts by increasing starting index.
|
|
7041
|
|
7042 Therefore, we can determine @math{L} just by looking at where we would
|
|
7043 insert @math{R(1)} into the list, and if we know @math{F} and are moving
|
|
7044 forward over extents, we can easily determine when we've hit @math{L} by
|
|
7045 comparing the extent we're at to @math{R(1)}.
|
|
7046
|
|
7047 @example
|
|
7048 Theorem 2: @math{F(e-prev) e< [1, R(0)] e<= F}.
|
|
7049 @end example
|
|
7050
|
|
7051 This is the analog of Theorem 1, and applies because the e-order
|
|
7052 sorts by increasing ending index.
|
|
7053
|
|
7054 Therefore, @math{F} can be found in the same amount of time as
|
|
7055 operation (1), i.e. the time that it takes to locate where an extent
|
|
7056 would go if inserted into the e-order list.
|
|
7057
|
|
7058 If the lists were stored as balanced binary trees, then operation (1)
|
|
7059 would take logarithmic time, which is usually quite fast. However,
|
|
7060 currently they're stored as simple doubly-linked lists, and instead we
|
|
7061 do some caching to try to speed things up.
|
|
7062
|
|
7063 Define a @dfn{stack of extents} (or @dfn{SOE}) as the set of extents
|
|
7064 (ordered in the display order) that overlap an index @math{I}, together
|
|
7065 with the SOE's @dfn{previous} extent, which is an extent that precedes
|
|
7066 @math{I} in the e-order. (Hopefully there will not be very many extents
|
|
7067 between @math{I} and the previous extent.)
|
|
7068
|
|
7069 Now:
|
|
7070
|
|
7071 Let @math{I} be an index, let @math{S} be the stack of extents on
|
|
7072 @math{I}, let @math{F} be the first extent in @math{S}, and let @math{P}
|
|
7073 be @math{S}'s previous extent.
|
|
7074
|
|
7075 Theorem 3: The first extent in @math{S} is the first extent that overlaps
|
|
7076 any range @math{[I, J]}.
|
|
7077
|
|
7078 Proof: Any extent that overlaps @math{[I, J]} but does not include
|
|
7079 @math{I} must have a start index @math{> I}, and thus be greater than
|
|
7080 any extent in @math{S}.
|
|
7081
|
|
7082 Therefore, finding the first extent that overlaps a range @math{R} is
|
|
7083 the same as finding the first extent that overlaps @math{R(0)}.
|
|
7084
|
|
7085 Theorem 4: Let @math{I2} be an index such that @math{I2 > I}, and let
|
|
7086 @math{F2} be the first extent that overlaps @math{I2}. Then, either
|
|
7087 @math{F2} is in @math{S} or @math{F2} is greater than any extent in
|
|
7088 @math{S}.
|
|
7089
|
|
7090 Proof: If @math{F2} does not include @math{I} then its start index is
|
|
7091 greater than @math{I} and thus it is greater than any extent in
|
|
7092 @math{S}, including @math{F}. Otherwise, @math{F2} includes @math{I}
|
|
7093 and thus is in @math{S}, and thus @math{F2 >= F}.
|
|
7094
|
|
7095 @node Extent Fragments
|
|
7096 @section Extent Fragments
|
|
7097 @cindex extent fragment
|
|
7098
|
|
7099 Imagine that the buffer is divided up into contiguous, non-overlapping
|
|
7100 @dfn{runs} of text such that no extent starts or ends within a run
|
|
7101 (extents that abut the run don't count).
|
|
7102
|
|
7103 An extent fragment is a structure that holds data about the run that
|
|
7104 contains a particular buffer position (if the buffer position is at the
|
|
7105 junction of two runs, the run after the position is used) -- the
|
|
7106 beginning and end of the run, a list of all of the extents in that run,
|
|
7107 the @dfn{merged face} that results from merging all of the faces
|
|
7108 corresponding to those extents, the begin and end glyphs at the
|
|
7109 beginning of the run, etc. This is the information that redisplay needs
|
|
7110 in order to display this run.
|
|
7111
|
|
7112 Extent fragments have to be very quick to update to a new buffer
|
|
7113 position when moving linearly through the buffer. They rely on the
|
|
7114 stack-of-extents code, which does the heavy-duty algorithmic work of
|
|
7115 determining which extents overly a particular position.
|
|
7116
|
|
7117 @node Faces and Glyphs, Specifiers, Extents, Top
|
|
7118 @chapter Faces and Glyphs
|
|
7119
|
|
7120 Not yet documented.
|
|
7121
|
|
7122 @node Specifiers, Menus, Faces and Glyphs, Top
|
|
7123 @chapter Specifiers
|
|
7124
|
|
7125 Not yet documented.
|
|
7126
|
|
7127 @node Menus, Subprocesses, Specifiers, Top
|
|
7128 @chapter Menus
|
|
7129
|
|
7130 A menu is set by setting the value of the variable
|
|
7131 @code{current-menubar} (which may be buffer-local) and then calling
|
|
7132 @code{set-menubar-dirty-flag} to signal a change. This will cause the
|
|
7133 menu to be redrawn at the next redisplay. The format of the data in
|
|
7134 @code{current-menubar} is described in @file{menubar.c}.
|
|
7135
|
|
7136 Internally the data in current-menubar is parsed into a tree of
|
|
7137 @code{widget_value's} (defined in @file{lwlib.h}); this is accomplished
|
|
7138 by the recursive function @code{menu_item_descriptor_to_widget_value()},
|
|
7139 called by @code{compute_menubar_data()}. Such a tree is deallocated
|
|
7140 using @code{free_widget_value()}.
|
|
7141
|
|
7142 @code{update_screen_menubars()} is one of the external entry points.
|
|
7143 This checks to see, for each screen, if that screen's menubar needs to
|
|
7144 be updated. This is the case if
|
|
7145
|
|
7146 @enumerate
|
|
7147 @item
|
|
7148 @code{set-menubar-dirty-flag} was called since the last redisplay. (This
|
|
7149 function sets the C variable menubar_has_changed.)
|
|
7150 @item
|
|
7151 The buffer displayed in the screen has changed.
|
|
7152 @item
|
|
7153 The screen has no menubar currently displayed.
|
|
7154 @end enumerate
|
|
7155
|
|
7156 @code{set_screen_menubar()} is called for each such screen. This
|
|
7157 function calls @code{compute_menubar_data()} to create the tree of
|
|
7158 widget_value's, then calls @code{lw_create_widget()},
|
|
7159 @code{lw_modify_all_widgets()}, and/or @code{lw_destroy_all_widgets()}
|
|
7160 to create the X-Toolkit widget associated with the menu.
|
|
7161
|
|
7162 @code{update_psheets()}, the other external entry point, actually
|
|
7163 changes the menus being displayed. It uses the widgets fixed by
|
|
7164 @code{update_screen_menubars()} and calls various X functions to ensure
|
|
7165 that the menus are displayed properly.
|
|
7166
|
|
7167 The menubar widget is set up so that @code{pre_activate_callback()} is
|
|
7168 called when the menu is first selected (i.e. mouse button goes down),
|
|
7169 and @code{menubar_selection_callback()} is called when an item is
|
|
7170 selected. @code{pre_activate_callback()} calls the function in
|
|
7171 activate-menubar-hook, which can change the menubar (this is described
|
|
7172 in @file{menubar.c}). If the menubar is changed,
|
|
7173 @code{set_screen_menubars()} is called.
|
|
7174 @code{menubar_selection_callback()} enqueues a menu event, putting in it
|
|
7175 a function to call (either @code{eval} or @code{call-interactively}) and
|
|
7176 its argument, which is the callback function or form given in the menu's
|
|
7177 description.
|
|
7178
|
|
7179 @node Subprocesses, Interface to X Windows, Menus, Top
|
|
7180 @chapter Subprocesses
|
|
7181
|
|
7182 The fields of a process are:
|
|
7183
|
|
7184 @table @code
|
|
7185 @item name
|
|
7186 A string, the name of the process.
|
|
7187
|
|
7188 @item command
|
|
7189 A list containing the command arguments that were used to start this
|
|
7190 process.
|
|
7191
|
|
7192 @item filter
|
|
7193 A function used to accept output from the process instead of a buffer,
|
|
7194 or @code{nil}.
|
|
7195
|
|
7196 @item sentinel
|
|
7197 A function called whenever the process receives a signal, or @code{nil}.
|
|
7198
|
|
7199 @item buffer
|
|
7200 The associated buffer of the process.
|
|
7201
|
|
7202 @item pid
|
|
7203 An integer, the Unix process @sc{id}.
|
|
7204
|
|
7205 @item childp
|
|
7206 A flag, non-@code{nil} if this is really a child process.
|
|
7207 It is @code{nil} for a network connection.
|
|
7208
|
|
7209 @item mark
|
|
7210 A marker indicating the position of the end of the last output from this
|
|
7211 process inserted into the buffer. This is often but not always the end
|
|
7212 of the buffer.
|
|
7213
|
|
7214 @item kill_without_query
|
|
7215 If this is non-@code{nil}, killing XEmacs while this process is still
|
|
7216 running does not ask for confirmation about killing the process.
|
|
7217
|
|
7218 @item raw_status_low
|
|
7219 @itemx raw_status_high
|
|
7220 These two fields record 16 bits each of the process status returned by
|
|
7221 the @code{wait} system call.
|
|
7222
|
|
7223 @item status
|
|
7224 The process status, as @code{process-status} should return it.
|
|
7225
|
|
7226 @item tick
|
|
7227 @itemx update_tick
|
|
7228 If these two fields are not equal, a change in the status of the process
|
|
7229 needs to be reported, either by running the sentinel or by inserting a
|
|
7230 message in the process buffer.
|
|
7231
|
|
7232 @item pty_flag
|
|
7233 Non-@code{nil} if communication with the subprocess uses a @sc{pty};
|
|
7234 @code{nil} if it uses a pipe.
|
|
7235
|
|
7236 @item infd
|
|
7237 The file descriptor for input from the process.
|
|
7238
|
|
7239 @item outfd
|
|
7240 The file descriptor for output to the process.
|
|
7241
|
|
7242 @item subtty
|
|
7243 The file descriptor for the terminal that the subprocess is using. (On
|
|
7244 some systems, there is no need to record this, so the value is
|
|
7245 @code{-1}.)
|
|
7246
|
|
7247 @item tty_name
|
|
7248 The name of the terminal that the subprocess is using,
|
|
7249 or @code{nil} if it is using pipes.
|
|
7250 @end table
|
|
7251
|
|
7252 @node Interface to X Windows, Index, Subprocesses, Top
|
|
7253 @chapter Interface to X Windows
|
|
7254
|
|
7255 Not yet documented.
|
|
7256
|
|
7257 @include index.texi
|
|
7258
|
|
7259 @c Print the tables of contents
|
|
7260 @summarycontents
|
|
7261 @contents
|
|
7262 @c That's all
|
|
7263
|
|
7264 @bye
|
|
7265
|