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