Nuke hand-written node pointers in doc/lispref
[bpt/emacs.git] / doc / lispref / internals.texi
CommitLineData
b8d4c8d0
GM
1@c -*-texinfo-*-
2@c This is part of the GNU Emacs Lisp Reference Manual.
29157371 3@c Copyright (C) 1990-1993, 1998-1999, 2001-2012 Free Software Foundation, Inc.
b8d4c8d0 4@c See the file elisp.texi for copying conditions.
ecc6530d 5@node GNU Emacs Internals
b8d4c8d0
GM
6@appendix GNU Emacs Internals
7
8This chapter describes how the runnable Emacs executable is dumped with
9the preloaded Lisp libraries in it, how storage is allocated, and some
10internal aspects of GNU Emacs that may be of interest to C programmers.
11
12@menu
13* Building Emacs:: How the dumped Emacs is made.
333f9019 14* Pure Storage:: Kludge to make preloaded Lisp functions shareable.
b8d4c8d0
GM
15* Garbage Collection:: Reclaiming space for Lisp objects no longer used.
16* Memory Usage:: Info about total size of Lisp objects made so far.
17* Writing Emacs Primitives:: Writing C code for Emacs.
18* Object Internals:: Data formats of buffers, windows, processes.
19@end menu
20
21@node Building Emacs
520f2425 22@section Building Emacs
b8d4c8d0
GM
23@cindex building Emacs
24@pindex temacs
25
26 This section explains the steps involved in building the Emacs
27executable. You don't have to know this material to build and install
28Emacs, since the makefiles do all these things automatically. This
d15aac68 29information is pertinent to Emacs developers.
b8d4c8d0
GM
30
31 Compilation of the C source files in the @file{src} directory
32produces an executable file called @file{temacs}, also called a
d15aac68
CY
33@dfn{bare impure Emacs}. It contains the Emacs Lisp interpreter and
34I/O routines, but not the editing commands.
b8d4c8d0
GM
35
36@cindex @file{loadup.el}
d15aac68
CY
37 The command @w{@command{temacs -l loadup}} would run @file{temacs}
38and direct it to load @file{loadup.el}. The @code{loadup} library
39loads additional Lisp libraries, which set up the normal Emacs editing
40environment. After this step, the Emacs executable is no longer
41@dfn{bare}.
b8d4c8d0
GM
42
43@cindex dumping Emacs
d15aac68
CY
44 Because it takes some time to load the standard Lisp files, the
45@file{temacs} executable usually isn't run directly by users.
46Instead, as one of the last steps of building Emacs, the command
47@samp{temacs -batch -l loadup dump} is run. The special @samp{dump}
48argument causes @command{temacs} to dump out an executable program,
49called @file{emacs}, which has all the standard Lisp files preloaded.
50(The @samp{-batch} argument prevents @file{temacs} from trying to
51initialize any of its data on the terminal, so that the tables of
52terminal information are empty in the dumped Emacs.)
53
54@cindex preloaded Lisp files
b578c9cc 55@vindex preloaded-file-list
d15aac68
CY
56 The dumped @file{emacs} executable (also called a @dfn{pure} Emacs)
57is the one which is installed. The variable
58@code{preloaded-file-list} stores a list of the Lisp files preloaded
59into the dumped Emacs. If you port Emacs to a new operating system,
60and are not able to implement dumping, then Emacs must load
61@file{loadup.el} each time it starts.
b8d4c8d0
GM
62
63@cindex @file{site-load.el}
b8d4c8d0 64 You can specify additional files to preload by writing a library named
520f2425
GM
65@file{site-load.el} that loads them. You may need to rebuild Emacs
66with an added definition
b8d4c8d0
GM
67
68@example
69#define SITELOAD_PURESIZE_EXTRA @var{n}
70@end example
71
72@noindent
520f2425
GM
73to make @var{n} added bytes of pure space to hold the additional files;
74see @file{src/puresize.h}.
b8d4c8d0
GM
75(Try adding increments of 20000 until it is big enough.) However, the
76advantage of preloading additional files decreases as machines get
77faster. On modern machines, it is usually not advisable.
78
79 After @file{loadup.el} reads @file{site-load.el}, it finds the
80documentation strings for primitive and preloaded functions (and
81variables) in the file @file{etc/DOC} where they are stored, by
82calling @code{Snarf-documentation} (@pxref{Definition of
83Snarf-documentation,, Accessing Documentation}).
84
85@cindex @file{site-init.el}
86@cindex preloading additional functions and variables
87 You can specify other Lisp expressions to execute just before dumping
88by putting them in a library named @file{site-init.el}. This file is
89executed after the documentation strings are found.
90
91 If you want to preload function or variable definitions, there are
92three ways you can do this and make their documentation strings
93accessible when you subsequently run Emacs:
94
95@itemize @bullet
96@item
97Arrange to scan these files when producing the @file{etc/DOC} file,
98and load them with @file{site-load.el}.
99
100@item
101Load the files with @file{site-init.el}, then copy the files into the
102installation directory for Lisp files when you install Emacs.
103
104@item
5906db45
GM
105Specify a @code{nil} value for @code{byte-compile-dynamic-docstrings}
106as a local variable in each of these files, and load them with either
107@file{site-load.el} or @file{site-init.el}. (This method has the
108drawback that the documentation strings take up space in Emacs all the
109time.)
b8d4c8d0
GM
110@end itemize
111
112 It is not advisable to put anything in @file{site-load.el} or
113@file{site-init.el} that would alter any of the features that users
114expect in an ordinary unmodified Emacs. If you feel you must override
115normal features for your site, do it with @file{default.el}, so that
116users can override your changes if they wish. @xref{Startup Summary}.
117
520f2425
GM
118 In a package that can be preloaded, it is sometimes necessary (or
119useful) to delay certain evaluations until Emacs subsequently starts
120up. The vast majority of such cases relate to the values of
121customizable variables. For example, @code{tutorial-directory} is a
122variable defined in @file{startup.el}, which is preloaded. The default
123value is set based on @code{data-directory}. The variable needs to
124access the value of @code{data-directory} when Emacs starts, not when
125it is dumped, because the Emacs executable has probably been installed
126in a different location since it was dumped.
127
128@defun custom-initialize-delay symbol value
129This function delays the initialization of @var{symbol} to the next
130Emacs start. You normally use this function by specifying it as the
131@code{:initialize} property of a customizable variable. (The argument
f003f294 132@var{value} is unused, and is provided only for compatibility with the
520f2425
GM
133form Custom expects.)
134@end defun
b8d4c8d0 135
520f2425
GM
136In the unlikely event that you need a more general functionality than
137@code{custom-initialize-delay} provides, you can use
138@code{before-init-hook} (@pxref{Startup Summary}).
b8d4c8d0
GM
139
140@defun dump-emacs to-file from-file
141@cindex unexec
142This function dumps the current state of Emacs into an executable file
143@var{to-file}. It takes symbols from @var{from-file} (this is normally
144the executable file @file{temacs}).
145
146If you want to use this function in an Emacs that was already dumped,
147you must run Emacs with @samp{-batch}.
148@end defun
149
150@node Pure Storage
520f2425 151@section Pure Storage
b8d4c8d0
GM
152@cindex pure storage
153
154 Emacs Lisp uses two kinds of storage for user-created Lisp objects:
155@dfn{normal storage} and @dfn{pure storage}. Normal storage is where
999dd333
GM
156all the new data created during an Emacs session are kept
157(@pxref{Garbage Collection}). Pure storage is used for certain data
158in the preloaded standard Lisp files---data that should never change
159during actual use of Emacs.
b8d4c8d0 160
d15aac68 161 Pure storage is allocated only while @command{temacs} is loading the
b8d4c8d0
GM
162standard preloaded Lisp libraries. In the file @file{emacs}, it is
163marked as read-only (on operating systems that permit this), so that
164the memory space can be shared by all the Emacs jobs running on the
165machine at once. Pure storage is not expandable; a fixed amount is
166allocated when Emacs is compiled, and if that is not sufficient for
167the preloaded libraries, @file{temacs} allocates dynamic memory for
999dd333
GM
168the part that didn't fit. The resulting image will work, but garbage
169collection (@pxref{Garbage Collection}) is disabled in this situation,
170causing a memory leak. Such an overflow normally won't happen unless
171you try to preload additional libraries or add features to the
172standard ones. Emacs will display a warning about the overflow when
173it starts. If this happens, you should increase the compilation
174parameter @code{SYSTEM_PURESIZE_EXTRA} in the file
175@file{src/puresize.h} and rebuild Emacs.
b8d4c8d0
GM
176
177@defun purecopy object
178This function makes a copy in pure storage of @var{object}, and returns
179it. It copies a string by simply making a new string with the same
180characters, but without text properties, in pure storage. It
181recursively copies the contents of vectors and cons cells. It does
182not make copies of other objects such as symbols, but just returns
183them unchanged. It signals an error if asked to copy markers.
184
185This function is a no-op except while Emacs is being built and dumped;
999dd333 186it is usually called only in preloaded Lisp files.
b8d4c8d0
GM
187@end defun
188
189@defvar pure-bytes-used
190The value of this variable is the number of bytes of pure storage
191allocated so far. Typically, in a dumped Emacs, this number is very
192close to the total amount of pure storage available---if it were not,
193we would preallocate less.
194@end defvar
195
196@defvar purify-flag
197This variable determines whether @code{defun} should make a copy of the
198function definition in pure storage. If it is non-@code{nil}, then the
199function definition is copied into pure storage.
200
201This flag is @code{t} while loading all of the basic functions for
333f9019 202building Emacs initially (allowing those functions to be shareable and
b8d4c8d0
GM
203non-collectible). Dumping Emacs as an executable always writes
204@code{nil} in this variable, regardless of the value it actually has
205before and after dumping.
206
207You should not change this flag in a running Emacs.
208@end defvar
209
210@node Garbage Collection
520f2425 211@section Garbage Collection
b8d4c8d0
GM
212
213@cindex memory allocation
d15aac68
CY
214 When a program creates a list or the user defines a new function
215(such as by loading a library), that data is placed in normal storage.
216If normal storage runs low, then Emacs asks the operating system to
217allocate more memory. Different types of Lisp objects, such as
218symbols, cons cells, markers, etc., are segregated in distinct blocks
219in memory. (Vectors, long strings, buffers and certain other editing
220types, which are fairly large, are allocated in individual blocks, one
221per object, while small strings are packed into blocks of 8k bytes.)
b8d4c8d0 222
d15aac68
CY
223@cindex garbage collection
224 It is quite common to use some storage for a while, then release it
225by (for example) killing a buffer or deleting the last pointer to an
226object. Emacs provides a @dfn{garbage collector} to reclaim this
227abandoned storage. The garbage collector operates by finding and
228marking all Lisp objects that are still accessible to Lisp programs.
229To begin with, it assumes all the symbols, their values and associated
230function definitions, and any data presently on the stack, are
231accessible. Any objects that can be reached indirectly through other
232accessible objects are also accessible.
b8d4c8d0
GM
233
234 When marking is finished, all objects still unmarked are garbage. No
235matter what the Lisp program or the user does, it is impossible to refer
236to them, since there is no longer a way to reach them. Their space
237might as well be reused, since no one will miss them. The second
238(``sweep'') phase of the garbage collector arranges to reuse them.
239
240@c ??? Maybe add something describing weak hash tables here?
241
242@cindex free list
243 The sweep phase puts unused cons cells onto a @dfn{free list}
244for future allocation; likewise for symbols and markers. It compacts
245the accessible strings so they occupy fewer 8k blocks; then it frees the
246other 8k blocks. Vectors, buffers, windows, and other large objects are
247individually allocated and freed using @code{malloc} and @code{free}.
248
249@cindex CL note---allocate more storage
250@quotation
251@b{Common Lisp note:} Unlike other Lisps, GNU Emacs Lisp does not
252call the garbage collector when the free list is empty. Instead, it
253simply requests the operating system to allocate more storage, and
254processing continues until @code{gc-cons-threshold} bytes have been
255used.
256
257This means that you can make sure that the garbage collector will not
258run during a certain portion of a Lisp program by calling the garbage
259collector explicitly just before it (provided that portion of the
260program does not use so much space as to force a second garbage
261collection).
262@end quotation
263
264@deffn Command garbage-collect
265This command runs a garbage collection, and returns information on
266the amount of space in use. (Garbage collection can also occur
267spontaneously if you use more than @code{gc-cons-threshold} bytes of
268Lisp data since the previous garbage collection.)
269
270@code{garbage-collect} returns a list containing the following
271information:
272
273@example
274@group
275((@var{used-conses} . @var{free-conses})
276 (@var{used-syms} . @var{free-syms})
277@end group
278 (@var{used-miscs} . @var{free-miscs})
279 @var{used-string-chars}
280 @var{used-vector-slots}
281 (@var{used-floats} . @var{free-floats})
282 (@var{used-intervals} . @var{free-intervals})
283 (@var{used-strings} . @var{free-strings}))
284@end example
285
286Here is an example:
287
288@example
289@group
290(garbage-collect)
291 @result{} ((106886 . 13184) (9769 . 0)
292 (7731 . 4651) 347543 121628
293 (31 . 94) (1273 . 168)
294 (25474 . 3569))
295@end group
296@end example
297
298Here is a table explaining each element:
299
300@table @var
301@item used-conses
302The number of cons cells in use.
303
304@item free-conses
305The number of cons cells for which space has been obtained from the
306operating system, but that are not currently being used.
307
308@item used-syms
309The number of symbols in use.
310
311@item free-syms
312The number of symbols for which space has been obtained from the
313operating system, but that are not currently being used.
314
315@item used-miscs
316The number of miscellaneous objects in use. These include markers and
317overlays, plus certain objects not visible to users.
318
319@item free-miscs
320The number of miscellaneous objects for which space has been obtained
321from the operating system, but that are not currently being used.
322
323@item used-string-chars
324The total size of all strings, in characters.
325
326@item used-vector-slots
327The total number of elements of existing vectors.
328
329@item used-floats
b8d4c8d0
GM
330The number of floats in use.
331
332@item free-floats
b8d4c8d0
GM
333The number of floats for which space has been obtained from the
334operating system, but that are not currently being used.
335
336@item used-intervals
337The number of intervals in use. Intervals are an internal
338data structure used for representing text properties.
339
340@item free-intervals
341The number of intervals for which space has been obtained
342from the operating system, but that are not currently being used.
343
344@item used-strings
345The number of strings in use.
346
347@item free-strings
348The number of string headers for which the space was obtained from the
349operating system, but which are currently not in use. (A string
350object consists of a header and the storage for the string text
351itself; the latter is only allocated when the string is created.)
352@end table
353
999dd333 354If there was overflow in pure space (@pxref{Pure Storage}),
b8d4c8d0 355@code{garbage-collect} returns @code{nil}, because a real garbage
9658dc2a 356collection cannot be done.
b8d4c8d0
GM
357@end deffn
358
359@defopt garbage-collection-messages
360If this variable is non-@code{nil}, Emacs displays a message at the
361beginning and end of garbage collection. The default value is
999dd333 362@code{nil}.
b8d4c8d0
GM
363@end defopt
364
365@defvar post-gc-hook
366This is a normal hook that is run at the end of garbage collection.
367Garbage collection is inhibited while the hook functions run, so be
368careful writing them.
369@end defvar
370
371@defopt gc-cons-threshold
372The value of this variable is the number of bytes of storage that must
373be allocated for Lisp objects after one garbage collection in order to
374trigger another garbage collection. A cons cell counts as eight bytes,
375a string as one byte per character plus a few bytes of overhead, and so
376on; space allocated to the contents of buffers does not count. Note
377that the subsequent garbage collection does not happen immediately when
378the threshold is exhausted, but only the next time the Lisp evaluator is
379called.
380
999dd333 381The initial threshold value is 800,000. If you specify a larger
b8d4c8d0
GM
382value, garbage collection will happen less often. This reduces the
383amount of time spent garbage collecting, but increases total memory use.
384You may want to do this when running a program that creates lots of
385Lisp data.
386
387You can make collections more frequent by specifying a smaller value,
388down to 10,000. A value less than 10,000 will remain in effect only
389until the subsequent garbage collection, at which time
390@code{garbage-collect} will set the threshold back to 10,000.
391@end defopt
392
393@defopt gc-cons-percentage
394The value of this variable specifies the amount of consing before a
395garbage collection occurs, as a fraction of the current heap size.
396This criterion and @code{gc-cons-threshold} apply in parallel, and
397garbage collection occurs only when both criteria are satisfied.
398
399As the heap size increases, the time to perform a garbage collection
400increases. Thus, it can be desirable to do them less frequently in
401proportion.
402@end defopt
403
404 The value returned by @code{garbage-collect} describes the amount of
405memory used by Lisp data, broken down by data type. By contrast, the
406function @code{memory-limit} provides information on the total amount of
407memory Emacs is currently using.
408
b8d4c8d0
GM
409@defun memory-limit
410This function returns the address of the last byte Emacs has allocated,
411divided by 1024. We divide the value by 1024 to make sure it fits in a
412Lisp integer.
413
414You can use this to get a general idea of how your actions affect the
415memory usage.
416@end defun
417
418@defvar memory-full
d15aac68 419This variable is @code{t} if Emacs is nearly out of memory for Lisp
b8d4c8d0
GM
420objects, and @code{nil} otherwise.
421@end defvar
422
423@defun memory-use-counts
424This returns a list of numbers that count the number of objects
425created in this Emacs session. Each of these counters increments for
426a certain kind of object. See the documentation string for details.
427@end defun
428
429@defvar gcs-done
430This variable contains the total number of garbage collections
431done so far in this Emacs session.
432@end defvar
433
434@defvar gc-elapsed
435This variable contains the total number of seconds of elapsed time
436during garbage collection so far in this Emacs session, as a floating
437point number.
438@end defvar
439
440@node Memory Usage
441@section Memory Usage
442@cindex memory usage
443
444 These functions and variables give information about the total amount
445of memory allocation that Emacs has done, broken down by data type.
446Note the difference between these and the values returned by
01a6dcc8 447@code{garbage-collect}; those count objects that currently exist, but
b8d4c8d0
GM
448these count the number or size of all allocations, including those for
449objects that have since been freed.
450
451@defvar cons-cells-consed
452The total number of cons cells that have been allocated so far
453in this Emacs session.
454@end defvar
455
456@defvar floats-consed
457The total number of floats that have been allocated so far
458in this Emacs session.
459@end defvar
460
461@defvar vector-cells-consed
462The total number of vector cells that have been allocated so far
463in this Emacs session.
464@end defvar
465
466@defvar symbols-consed
467The total number of symbols that have been allocated so far
468in this Emacs session.
469@end defvar
470
471@defvar string-chars-consed
472The total number of string characters that have been allocated so far
9658dc2a 473in this session.
b8d4c8d0
GM
474@end defvar
475
476@defvar misc-objects-consed
477The total number of miscellaneous objects that have been allocated so
9658dc2a 478far in this session. These include markers and overlays, plus
b8d4c8d0
GM
479certain objects not visible to users.
480@end defvar
481
482@defvar intervals-consed
483The total number of intervals that have been allocated so far
484in this Emacs session.
485@end defvar
486
487@defvar strings-consed
488The total number of strings that have been allocated so far in this
489Emacs session.
490@end defvar
491
492@node Writing Emacs Primitives
520f2425 493@section Writing Emacs Primitives
b8d4c8d0
GM
494@cindex primitive function internals
495@cindex writing Emacs primitives
496
497 Lisp primitives are Lisp functions implemented in C. The details of
498interfacing the C function so that Lisp can call it are handled by a few
499C macros. The only way to really understand how to write new C code is
500to read the source, but we can explain some things here.
501
502 An example of a special form is the definition of @code{or}, from
503@file{eval.c}. (An ordinary function would have the same general
504appearance.)
505
506@cindex garbage collection protection
507@smallexample
508@group
509DEFUN ("or", For, Sor, 0, UNEVALLED, 0,
d15aac68
CY
510 doc: /* Eval args until one of them yields non-nil, then return
511that value.
512The remaining args are not evalled at all.
b8d4c8d0
GM
513If all args return nil, return nil.
514@end group
515@group
516usage: (or CONDITIONS ...) */)
b88746ba 517 (Lisp_Object args)
b8d4c8d0
GM
518@{
519 register Lisp_Object val = Qnil;
520 struct gcpro gcpro1;
521@end group
522
523@group
524 GCPRO1 (args);
525@end group
526
527@group
528 while (CONSP (args))
529 @{
7d2d7cc0 530 val = eval_sub (XCAR (args));
b8d4c8d0
GM
531 if (!NILP (val))
532 break;
533 args = XCDR (args);
534 @}
535@end group
536
537@group
538 UNGCPRO;
539 return val;
540@}
541@end group
542@end smallexample
543
544@cindex @code{DEFUN}, C macro to define Lisp primitives
545 Let's start with a precise explanation of the arguments to the
546@code{DEFUN} macro. Here is a template for them:
547
548@example
549DEFUN (@var{lname}, @var{fname}, @var{sname}, @var{min}, @var{max}, @var{interactive}, @var{doc})
550@end example
551
552@table @var
553@item lname
554This is the name of the Lisp symbol to define as the function name; in
555the example above, it is @code{or}.
556
557@item fname
d15aac68
CY
558This is the C function name for this function. This is the name that
559is used in C code for calling the function. The name is, by
560convention, @samp{F} prepended to the Lisp name, with all dashes
561(@samp{-}) in the Lisp name changed to underscores. Thus, to call
562this function from C code, call @code{For}.
b8d4c8d0
GM
563
564@item sname
565This is a C variable name to use for a structure that holds the data for
566the subr object that represents the function in Lisp. This structure
567conveys the Lisp symbol name to the initialization routine that will
568create the symbol and store the subr object as its definition. By
569convention, this name is always @var{fname} with @samp{F} replaced with
570@samp{S}.
571
572@item min
573This is the minimum number of arguments that the function requires. The
574function @code{or} allows a minimum of zero arguments.
575
576@item max
577This is the maximum number of arguments that the function accepts, if
578there is a fixed maximum. Alternatively, it can be @code{UNEVALLED},
579indicating a special form that receives unevaluated arguments, or
580@code{MANY}, indicating an unlimited number of evaluated arguments (the
581equivalent of @code{&rest}). Both @code{UNEVALLED} and @code{MANY} are
9658dc2a
GM
582macros. If @var{max} is a number, it must be more than @var{min} but
583less than 8.
b8d4c8d0
GM
584
585@item interactive
586This is an interactive specification, a string such as might be used as
587the argument of @code{interactive} in a Lisp function. In the case of
588@code{or}, it is 0 (a null pointer), indicating that @code{or} cannot be
589called interactively. A value of @code{""} indicates a function that
2c30e468
EZ
590should receive no arguments when called interactively. If the value
591begins with a @samp{(}, the string is evaluated as a Lisp form.
7d2d7cc0
GM
592For examples of the last two forms, see @code{widen} and
593@code{narrow-to-region} in @file{editfns.c}.
b8d4c8d0
GM
594
595@item doc
596This is the documentation string. It uses C comment syntax rather
597than C string syntax because comment syntax requires nothing special
598to include multiple lines. The @samp{doc:} identifies the comment
599that follows as the documentation string. The @samp{/*} and @samp{*/}
600delimiters that begin and end the comment are not part of the
601documentation string.
602
603If the last line of the documentation string begins with the keyword
604@samp{usage:}, the rest of the line is treated as the argument list
605for documentation purposes. This way, you can use different argument
606names in the documentation string from the ones used in the C code.
607@samp{usage:} is required if the function has an unlimited number of
608arguments.
609
610All the usual rules for documentation strings in Lisp code
611(@pxref{Documentation Tips}) apply to C code documentation strings
612too.
613@end table
614
b88746ba 615 After the call to the @code{DEFUN} macro, you must write the
d15aac68
CY
616argument list for the C function, including the types for the
617arguments. If the primitive accepts a fixed maximum number of Lisp
618arguments, there must be one C argument for each Lisp argument, and
619each argument must be of type @code{Lisp_Object}. (Various macros and
620functions for creating values of type @code{Lisp_Object} are declared
621in the file @file{lisp.h}.) If the primitive has no upper limit on
622the number of Lisp arguments, it must have exactly two C arguments:
623the first is the number of Lisp arguments, and the second is the
624address of a block containing their values. These have types
625@code{int} and @w{@code{Lisp_Object *}} respectively.
b8d4c8d0
GM
626
627@cindex @code{GCPRO} and @code{UNGCPRO}
628@cindex protect C variables from garbage collection
629 Within the function @code{For} itself, note the use of the macros
d15aac68
CY
630@code{GCPRO1} and @code{UNGCPRO}. These macros are defined for the
631sake of the few platforms which do not use Emacs' default
632stack-marking garbage collector. The @code{GCPRO1} macro ``protects''
633a variable from garbage collection, explicitly informing the garbage
634collector that that variable and all its contents must be as
635accessible. GC protection is necessary in any function which can
636perform Lisp evaluation by calling @code{eval_sub} or @code{Feval} as
637a subroutine, either directly or indirectly.
b8d4c8d0
GM
638
639 It suffices to ensure that at least one pointer to each object is
d15aac68 640GC-protected. Thus, a particular local variable can do without
b8d4c8d0 641protection if it is certain that the object it points to will be
7d2d7cc0 642preserved by some other pointer (such as another local variable that
d15aac68
CY
643has a @code{GCPRO}). Otherwise, the local variable needs a
644@code{GCPRO}.
b8d4c8d0
GM
645
646 The macro @code{GCPRO1} protects just one local variable. If you
647want to protect two variables, use @code{GCPRO2} instead; repeating
648@code{GCPRO1} will not work. Macros @code{GCPRO3}, @code{GCPRO4},
649@code{GCPRO5}, and @code{GCPRO6} also exist. All these macros
650implicitly use local variables such as @code{gcpro1}; you must declare
651these explicitly, with type @code{struct gcpro}. Thus, if you use
652@code{GCPRO2}, you must declare @code{gcpro1} and @code{gcpro2}.
b8d4c8d0
GM
653
654 @code{UNGCPRO} cancels the protection of the variables that are
655protected in the current function. It is necessary to do this
656explicitly.
657
b8d4c8d0
GM
658 You must not use C initializers for static or global variables unless
659the variables are never written once Emacs is dumped. These variables
660with initializers are allocated in an area of memory that becomes
661read-only (on certain operating systems) as a result of dumping Emacs.
662@xref{Pure Storage}.
663
b8d4c8d0
GM
664@cindex @code{defsubr}, Lisp symbol for a primitive
665 Defining the C function is not enough to make a Lisp primitive
666available; you must also create the Lisp symbol for the primitive and
667store a suitable subr object in its function cell. The code looks like
668this:
669
670@example
7d2d7cc0 671defsubr (&@var{sname});
b8d4c8d0
GM
672@end example
673
674@noindent
7d2d7cc0 675Here @var{sname} is the name you used as the third argument to @code{DEFUN}.
b8d4c8d0
GM
676
677 If you add a new primitive to a file that already has Lisp primitives
678defined in it, find the function (near the end of the file) named
679@code{syms_of_@var{something}}, and add the call to @code{defsubr}
680there. If the file doesn't have this function, or if you create a new
681file, add to it a @code{syms_of_@var{filename}} (e.g.,
682@code{syms_of_myfile}). Then find the spot in @file{emacs.c} where all
683of these functions are called, and add a call to
684@code{syms_of_@var{filename}} there.
685
686@anchor{Defining Lisp variables in C}
687@vindex byte-boolean-vars
688@cindex defining Lisp variables in C
689@cindex @code{DEFVAR_INT}, @code{DEFVAR_LISP}, @code{DEFVAR_BOOL}
690 The function @code{syms_of_@var{filename}} is also the place to define
691any C variables that are to be visible as Lisp variables.
692@code{DEFVAR_LISP} makes a C variable of type @code{Lisp_Object} visible
693in Lisp. @code{DEFVAR_INT} makes a C variable of type @code{int}
694visible in Lisp with a value that is always an integer.
695@code{DEFVAR_BOOL} makes a C variable of type @code{int} visible in Lisp
696with a value that is either @code{t} or @code{nil}. Note that variables
697defined with @code{DEFVAR_BOOL} are automatically added to the list
698@code{byte-boolean-vars} used by the byte compiler.
699
7d2d7cc0
GM
700@cindex defining customization variables in C
701 If you want to make a Lisp variables that is defined in C behave
702like one declared with @code{defcustom}, add an appropriate entry to
703@file{cus-start.el}.
704
b8d4c8d0
GM
705@cindex @code{staticpro}, protection from GC
706 If you define a file-scope C variable of type @code{Lisp_Object},
707you must protect it from garbage-collection by calling @code{staticpro}
708in @code{syms_of_@var{filename}}, like this:
709
710@example
711staticpro (&@var{variable});
712@end example
713
714 Here is another example function, with more complicated arguments.
715This comes from the code in @file{window.c}, and it demonstrates the use
716of macros and functions to manipulate Lisp objects.
717
718@smallexample
719@group
720DEFUN ("coordinates-in-window-p", Fcoordinates_in_window_p,
7d2d7cc0
GM
721 Scoordinates_in_window_p, 2, 2, 0,
722 doc: /* Return non-nil if COORDINATES are in WINDOW.
723 ...
b8d4c8d0
GM
724@end group
725@group
7d2d7cc0
GM
726 or `right-margin' is returned. */)
727 (register Lisp_Object coordinates, Lisp_Object window)
b8d4c8d0 728@{
7d2d7cc0
GM
729 struct window *w;
730 struct frame *f;
b8d4c8d0 731 int x, y;
7d2d7cc0 732 Lisp_Object lx, ly;
b8d4c8d0
GM
733@end group
734
735@group
7d2d7cc0
GM
736 CHECK_LIVE_WINDOW (window);
737 w = XWINDOW (window);
738 f = XFRAME (w->frame);
739 CHECK_CONS (coordinates);
740 lx = Fcar (coordinates);
741 ly = Fcdr (coordinates);
742 CHECK_NUMBER_OR_FLOAT (lx);
743 CHECK_NUMBER_OR_FLOAT (ly);
744 x = FRAME_PIXEL_X_FROM_CANON_X (f, lx) + FRAME_INTERNAL_BORDER_WIDTH(f);
745 y = FRAME_PIXEL_Y_FROM_CANON_Y (f, ly) + FRAME_INTERNAL_BORDER_WIDTH(f);
b8d4c8d0
GM
746@end group
747
748@group
7d2d7cc0 749 switch (coordinates_in_window (w, x, y))
b8d4c8d0 750 @{
7d2d7cc0 751 case ON_NOTHING: /* NOT in window at all. */
b8d4c8d0
GM
752 return Qnil;
753@end group
754
7d2d7cc0 755 ...
b8d4c8d0
GM
756
757@group
7d2d7cc0 758 case ON_MODE_LINE: /* In mode line of window. */
b8d4c8d0
GM
759 return Qmode_line;
760@end group
761
7d2d7cc0
GM
762 ...
763
b8d4c8d0 764@group
7d2d7cc0
GM
765 case ON_SCROLL_BAR: /* On scroll-bar of window. */
766 /* Historically we are supposed to return nil in this case. */
767 return Qnil;
b8d4c8d0
GM
768@end group
769
770@group
771 default:
772 abort ();
773 @}
774@}
775@end group
776@end smallexample
777
778 Note that C code cannot call functions by name unless they are defined
779in C. The way to call a function written in Lisp is to use
780@code{Ffuncall}, which embodies the Lisp function @code{funcall}. Since
781the Lisp function @code{funcall} accepts an unlimited number of
782arguments, in C it takes two: the number of Lisp-level arguments, and a
783one-dimensional array containing their values. The first Lisp-level
784argument is the Lisp function to call, and the rest are the arguments to
785pass to it. Since @code{Ffuncall} can call the evaluator, you must
786protect pointers from garbage collection around the call to
787@code{Ffuncall}.
788
789 The C functions @code{call0}, @code{call1}, @code{call2}, and so on,
790provide handy ways to call a Lisp function conveniently with a fixed
791number of arguments. They work by calling @code{Ffuncall}.
792
793 @file{eval.c} is a very good file to look through for examples;
794@file{lisp.h} contains the definitions for some important macros and
795functions.
796
797 If you define a function which is side-effect free, update the code
7d2d7cc0 798in @file{byte-opt.el} that binds @code{side-effect-free-fns} and
b8d4c8d0
GM
799@code{side-effect-and-error-free-fns} so that the compiler optimizer
800knows about it.
801
802@node Object Internals
520f2425 803@section Object Internals
b8d4c8d0
GM
804@cindex object internals
805
7d2d7cc0 806@c FIXME Is this still true? Does --with-wide-int affect anything?
b8d4c8d0
GM
807 GNU Emacs Lisp manipulates many different types of data. The actual
808data are stored in a heap and the only access that programs have to it
c773345a
CY
809is through pointers. Each pointer is 32 bits wide on 32-bit machines,
810and 64 bits wide on 64-bit machines; three of these bits are used for
811the tag that identifies the object's type, and the remainder are used
812to address the object.
b8d4c8d0
GM
813
814 Because Lisp objects are represented as tagged pointers, it is always
815possible to determine the Lisp data type of any object. The C data type
816@code{Lisp_Object} can hold any Lisp object of any data type. Ordinary
817variables have type @code{Lisp_Object}, which means they can hold any
818type of Lisp value; you can determine the actual data type only at run
819time. The same is true for function arguments; if you want a function
820to accept only a certain type of argument, you must check the type
821explicitly using a suitable predicate (@pxref{Type Predicates}).
822@cindex type checking internals
823
824@menu
825* Buffer Internals:: Components of a buffer structure.
826* Window Internals:: Components of a window structure.
827* Process Internals:: Components of a process structure.
828@end menu
829
830@node Buffer Internals
520f2425 831@subsection Buffer Internals
b8d4c8d0
GM
832@cindex internals, of buffer
833@cindex buffer internals
834
7d2d7cc0
GM
835 Two structures (see @file{buffer.h}) are used to represent buffers
836in C. The @code{buffer_text} structure contains fields describing the
837text of a buffer; the @code{buffer} structure holds other fields. In
838the case of indirect buffers, two or more @code{buffer} structures
839reference the same @code{buffer_text} structure.
b8d4c8d0 840
c773345a 841Here are some of the fields in @code{struct buffer_text}:
b8d4c8d0
GM
842
843@table @code
844@item beg
c773345a 845The address of the buffer contents.
b8d4c8d0
GM
846
847@item gpt
c773345a
CY
848@itemx gpt_byte
849The character and byte positions of the buffer gap. @xref{Buffer
850Gap}.
b8d4c8d0
GM
851
852@item z
c773345a
CY
853@itemx z_byte
854The character and byte positions of the end of the buffer text.
b8d4c8d0
GM
855
856@item gap_size
c773345a 857The size of buffer's gap. @xref{Buffer Gap}.
b8d4c8d0
GM
858
859@item modiff
c773345a
CY
860@itemx save_modiff
861@itemx chars_modiff
862@itemx overlay_modiff
863These fields count the number of buffer-modification events performed
864in this buffer. @code{modiff} is incremented after each
865buffer-modification event, and is never otherwise changed;
866@code{save_modiff} contains the value of @code{modiff} the last time
867the buffer was visited or saved; @code{chars_modiff} counts only
868modifications to the characters in the buffer, ignoring all other
869kinds of changes; and @code{overlay_modiff} counts only modifications
870to the overlays.
b8d4c8d0
GM
871
872@item beg_unchanged
c773345a
CY
873@itemx end_unchanged
874The number of characters at the start and end of the text that are
875known to be unchanged since the last complete redisplay.
b8d4c8d0
GM
876
877@item unchanged_modified
c773345a
CY
878@itemx overlay_unchanged_modified
879The values of @code{modiff} and @code{overlay_modiff}, respectively,
da6062e6 880after the last complete redisplay. If their current values match
c773345a 881@code{modiff} or @code{overlay_modiff}, that means
b8d4c8d0
GM
882@code{beg_unchanged} and @code{end_unchanged} contain no useful
883information.
884
885@item markers
886The markers that refer to this buffer. This is actually a single
887marker, and successive elements in its marker @code{chain} are the other
888markers referring to this buffer text.
889
890@item intervals
c773345a 891The interval tree which records the text properties of this buffer.
b8d4c8d0
GM
892@end table
893
c773345a 894Some of the fields of @code{struct buffer} are:
b8d4c8d0
GM
895
896@table @code
7d2d7cc0
GM
897@item header
898A @code{struct vectorlike_header} structure where @code{header.next}
899points to the next buffer, in the chain of all buffers (including
c773345a
CY
900killed buffers). This chain is used only for garbage collection, in
901order to collect killed buffers properly. Note that vectors, and most
902kinds of objects allocated as vectors, are all on one chain, but
903buffers are on a separate chain of their own.
b8d4c8d0
GM
904
905@item own_text
c773345a
CY
906A @code{struct buffer_text} structure that ordinarily holds the buffer
907contents. In indirect buffers, this field is not used.
b8d4c8d0
GM
908
909@item text
c773345a
CY
910A pointer to the @code{buffer_text} structure for this buffer. In an
911ordinary buffer, this is the @code{own_text} field above. In an
912indirect buffer, this is the @code{own_text} field of the base buffer.
b8d4c8d0
GM
913
914@item pt
c773345a
CY
915@itemx pt_byte
916The character and byte positions of point in a buffer.
b8d4c8d0
GM
917
918@item begv
c773345a
CY
919@itemx begv_byte
920The character and byte positions of the beginning of the accessible
921range of text in the buffer.
b8d4c8d0
GM
922
923@item zv
c773345a
CY
924@itemx zv_byte
925The character and byte positions of the end of the accessible range of
926text in the buffer.
b8d4c8d0
GM
927
928@item base_buffer
929In an indirect buffer, this points to the base buffer. In an ordinary
930buffer, it is null.
931
c773345a
CY
932@item local_flags
933This field contains flags indicating that certain variables are local
934in this buffer. Such variables are declared in the C code using
935@code{DEFVAR_PER_BUFFER}, and their buffer-local bindings are stored
936in fields in the buffer structure itself. (Some of these fields are
b8d4c8d0
GM
937described in this table.)
938
939@item modtime
c773345a
CY
940The modification time of the visited file. It is set when the file is
941written or read. Before writing the buffer into a file, this field is
942compared to the modification time of the file to see if the file has
943changed on disk. @xref{Buffer Modification}.
b8d4c8d0
GM
944
945@item auto_save_modified
c773345a 946The time when the buffer was last auto-saved.
b8d4c8d0
GM
947
948@item last_window_start
c773345a
CY
949The @code{window-start} position in the buffer as of the last time the
950buffer was displayed in a window.
b8d4c8d0
GM
951
952@item clip_changed
c773345a
CY
953This flag indicates that narrowing has changed in the buffer.
954@xref{Narrowing}.
b8d4c8d0
GM
955
956@item prevent_redisplay_optimizations_p
c773345a
CY
957This flag indicates that redisplay optimizations should not be used to
958display this buffer.
b8d4c8d0 959
c773345a
CY
960@item overlay_center
961This field holds the current overlay center position. @xref{Managing
962Overlays}.
963
964@item overlays_before
965@itemx overlays_after
966These fields hold, respectively, a list of overlays that end at or
967before the current overlay center, and a list of overlays that end
968after the current overlay center. @xref{Managing Overlays}.
969@code{overlays_before} is sorted in order of decreasing end position,
970and @code{overlays_after} is sorted in order of increasing beginning
971position.
b8d4c8d0 972
7d2d7cc0
GM
973@c FIXME? the following are now all Lisp_Object BUFFER_INTERNAL_FIELD (foo).
974
b8d4c8d0 975@item name
c773345a
CY
976A Lisp string that names the buffer. It is guaranteed to be unique.
977@xref{Buffer Names}.
b8d4c8d0 978
c773345a
CY
979@item save_length
980The length of the file this buffer is visiting, when last read or
981saved. This and other fields concerned with saving are not kept in
982the @code{buffer_text} structure because indirect buffers are never
983saved.
b8d4c8d0
GM
984
985@item directory
c773345a
CY
986The directory for expanding relative file names. This is the value of
987the buffer-local variable @code{default-directory} (@pxref{File Name Expansion}).
b8d4c8d0 988
c773345a
CY
989@item filename
990The name of the file visited in this buffer, or @code{nil}. This is
991the value of the buffer-local variable @code{buffer-file-name}
992(@pxref{Buffer File Name}).
b8d4c8d0 993
c773345a
CY
994@item undo_list
995@itemx backed_up
996@itemx auto_save_file_name
7d2d7cc0 997@itemx auto_save_file_format
c773345a
CY
998@itemx read_only
999@itemx file_format
1000@itemx file_truename
1001@itemx invisibility_spec
1002@itemx display_count
1003@itemx display_time
1004These fields store the values of Lisp variables that are automatically
1005buffer-local (@pxref{Buffer-Local Variables}), whose corresponding
1006variable names have the additional prefix @code{buffer-} and have
1007underscores replaced with dashes. For instance, @code{undo_list}
29157371 1008stores the value of @code{buffer-undo-list}.
b8d4c8d0
GM
1009
1010@item mark
c773345a
CY
1011The mark for the buffer. The mark is a marker, hence it is also
1012included on the list @code{markers}. @xref{The Mark}.
b8d4c8d0
GM
1013
1014@item local_var_alist
c773345a
CY
1015The association list describing the buffer-local variable bindings of
1016this buffer, not including the built-in buffer-local bindings that
1017have special slots in the buffer object. (Those slots are omitted
1018from this table.) @xref{Buffer-Local Variables}.
b8d4c8d0
GM
1019
1020@item major_mode
1021Symbol naming the major mode of this buffer, e.g., @code{lisp-mode}.
1022
1023@item mode_name
c773345a 1024Pretty name of the major mode, e.g., @code{"Lisp"}.
b8d4c8d0
GM
1025
1026@item keymap
c773345a
CY
1027@itemx abbrev_table
1028@itemx syntax_table
1029@itemx category_table
1030@itemx display_table
1031These fields store the buffer's local keymap (@pxref{Keymaps}), abbrev
1032table (@pxref{Abbrev Tables}), syntax table (@pxref{Syntax Tables}),
1033category table (@pxref{Categories}), and display table (@pxref{Display
1034Tables}).
b8d4c8d0
GM
1035
1036@item downcase_table
c773345a
CY
1037@itemx upcase_table
1038@itemx case_canon_table
1039These fields store the conversion tables for converting text to lower
1040case, upper case, and for canonicalizing text for case-fold search.
b8d4c8d0
GM
1041@xref{Case Tables}.
1042
b8d4c8d0
GM
1043@item minor_modes
1044An alist of the minor modes of this buffer.
1045
b8d4c8d0 1046@item pt_marker
c773345a
CY
1047@itemx begv_marker
1048@itemx zv_marker
1049These fields are only used in an indirect buffer, or in a buffer that
1050is the base of an indirect buffer. Each holds a marker that records
1051@code{pt}, @code{begv}, and @code{zv} respectively, for this buffer
b8d4c8d0
GM
1052when the buffer is not current.
1053
c773345a
CY
1054@item mode_line_format
1055@itemx header_line_format
1056@itemx case_fold_search
1057@itemx tab_width
1058@itemx fill_column
1059@itemx left_margin
1060@itemx auto_fill_function
c773345a
CY
1061@itemx truncate_lines
1062@itemx word_wrap
1063@itemx ctl_arrow
7d2d7cc0
GM
1064@itemx bidi_display_reordering
1065@itemx bidi_paragraph_direction
c773345a
CY
1066@itemx selective_display
1067@itemx selective_display_ellipses
1068@itemx overwrite_mode
1069@itemx abbrev_mode
c773345a
CY
1070@itemx mark_active
1071@itemx enable_multibyte_characters
1072@itemx buffer_file_coding_system
c773345a
CY
1073@itemx cache_long_line_scans
1074@itemx point_before_scroll
1075@itemx left_fringe_width
1076@itemx right_fringe_width
1077@itemx fringes_outside_margins
1078@itemx scroll_bar_width
1079@itemx indicate_empty_lines
1080@itemx indicate_buffer_boundaries
1081@itemx fringe_indicator_alist
1082@itemx fringe_cursor_alist
1083@itemx scroll_up_aggressively
1084@itemx scroll_down_aggressively
1085@itemx cursor_type
1086@itemx cursor_in_non_selected_windows
1087These fields store the values of Lisp variables that are automatically
1088buffer-local (@pxref{Buffer-Local Variables}), whose corresponding
1089variable names have underscores replaced with dashes. For instance,
1090@code{mode_line_format} stores the value of @code{mode-line-format}.
b8d4c8d0
GM
1091
1092@item last_selected_window
1093This is the last window that was selected with this buffer in it, or @code{nil}
1094if that window no longer displays this buffer.
b8d4c8d0
GM
1095@end table
1096
1097@node Window Internals
520f2425 1098@subsection Window Internals
b8d4c8d0
GM
1099@cindex internals, of window
1100@cindex window internals
1101
7d2d7cc0
GM
1102 The fields of a window (for a complete list, see the definition of
1103@code{struct window} in @file{window.h}) include:
b8d4c8d0
GM
1104
1105@table @code
1106@item frame
1107The frame that this window is on.
1108
1109@item mini_p
1110Non-@code{nil} if this window is a minibuffer window.
1111
1112@item parent
1113Internally, Emacs arranges windows in a tree; each group of siblings has
1114a parent window whose area includes all the siblings. This field points
1115to a window's parent.
1116
1117Parent windows do not display buffers, and play little role in display
1118except to shape their child windows. Emacs Lisp programs usually have
1119no access to the parent windows; they operate on the windows at the
1120leaves of the tree, which actually display buffers.
1121
b8d4c8d0 1122@item hchild
ee2d5b5e
CY
1123@itemx vchild
1124These fields contain the window's leftmost child and its topmost child
1125respectively. @code{hchild} is used if the window is subdivided
1126horizontally by child windows, and @code{vchild} if it is subdivided
7d2d7cc0
GM
1127vertically. In a live window, only one of @code{hchild}, @code{vchild},
1128and @code{buffer} (q.v.) is non-@code{nil}.
b8d4c8d0
GM
1129
1130@item next
ee2d5b5e
CY
1131@itemx prev
1132The next sibling and previous sibling of this window. @code{next} is
520f2425
GM
1133@code{nil} if the window is the right-most or bottom-most in its group;
1134@code{prev} is @code{nil} if it is the left-most or top-most in its
ee2d5b5e
CY
1135group.
1136
1137@item left_col
1138The left-hand edge of the window, measured in columns, relative to the
1139leftmost column in the frame (column 0).
1140
1141@item top_line
1142The top edge of the window, measured in lines, relative to the topmost
1143line in the frame (line 0).
1144
1145@item total_cols
1146@itemx total_lines
1147The width and height of the window, measured in columns and lines
1148respectively. The width includes the scroll bar and fringes, and/or
1149the separator line on the right of the window (if any).
b8d4c8d0
GM
1150
1151@item buffer
ee2d5b5e 1152The buffer that the window is displaying.
b8d4c8d0
GM
1153
1154@item start
ee2d5b5e
CY
1155A marker pointing to the position in the buffer that is the first
1156character displayed in the window.
b8d4c8d0
GM
1157
1158@item pointm
1159@cindex window point internals
1160This is the value of point in the current buffer when this window is
1161selected; when it is not selected, it retains its previous value.
1162
1163@item force_start
1164If this flag is non-@code{nil}, it says that the window has been
1165scrolled explicitly by the Lisp program. This affects what the next
1166redisplay does if point is off the screen: instead of scrolling the
1167window to show the text around point, it moves point to a location that
1168is on the screen.
1169
1170@item frozen_window_start_p
1171This field is set temporarily to 1 to indicate to redisplay that
1172@code{start} of this window should not be changed, even if point
1173gets invisible.
1174
1175@item start_at_line_beg
1176Non-@code{nil} means current value of @code{start} was the beginning of a line
1177when it was chosen.
1178
b8d4c8d0
GM
1179@item use_time
1180This is the last time that the window was selected. The function
1181@code{get-lru-window} uses this field.
1182
1183@item sequence_number
1184A unique number assigned to this window when it was created.
1185
1186@item last_modified
1187The @code{modiff} field of the window's buffer, as of the last time
1188a redisplay completed in this window.
1189
1190@item last_overlay_modified
1191The @code{overlay_modiff} field of the window's buffer, as of the last
1192time a redisplay completed in this window.
1193
1194@item last_point
1195The buffer's value of point, as of the last time a redisplay completed
1196in this window.
1197
1198@item last_had_star
1199A non-@code{nil} value means the window's buffer was ``modified'' when the
1200window was last updated.
1201
1202@item vertical_scroll_bar
1203This window's vertical scroll bar.
1204
7d2d7cc0
GM
1205@item left_margin_cols
1206@itemx right_margin_cols
ee2d5b5e 1207The widths of the left and right margins in this window. A value of
7d2d7cc0
GM
1208@code{nil} means no margin.
1209
1210@item left_fringe_width
1211@itemx right_fringe_width
1212The widths of the left and right fringes in this window. A value of
1213@code{nil} or @code{t} means use the values of the frame.
1214
1215@item fringes_outside_margins
1216A non-@code{nil} value means the fringes outside the display margins;
1217othersize they are between the margin and the text.
b8d4c8d0
GM
1218
1219@item window_end_pos
1220This is computed as @code{z} minus the buffer position of the last glyph
1221in the current matrix of the window. The value is only valid if
1222@code{window_end_valid} is not @code{nil}.
1223
1224@item window_end_bytepos
1225The byte position corresponding to @code{window_end_pos}.
1226
1227@item window_end_vpos
1228The window-relative vertical position of the line containing
1229@code{window_end_pos}.
1230
1231@item window_end_valid
1232This field is set to a non-@code{nil} value if @code{window_end_pos} is truly
7d2d7cc0 1233valid. This is @code{nil} if nontrivial redisplay is pre-empted, since in that
b8d4c8d0
GM
1234case the display that @code{window_end_pos} was computed for did not get
1235onto the screen.
1236
b8d4c8d0
GM
1237@item cursor
1238A structure describing where the cursor is in this window.
1239
1240@item last_cursor
1241The value of @code{cursor} as of the last redisplay that finished.
1242
1243@item phys_cursor
1244A structure describing where the cursor of this window physically is.
1245
1246@item phys_cursor_type
7d2d7cc0
GM
1247@c FIXME What is this?
1248@c itemx phys_cursor_ascent
1249@itemx phys_cursor_height
1250@itemx phys_cursor_width
1251The type, height, and width of the cursor that was last displayed on
1252this window.
b8d4c8d0
GM
1253
1254@item phys_cursor_on_p
1255This field is non-zero if the cursor is physically on.
1256
1257@item cursor_off_p
7d2d7cc0
GM
1258Non-zero means the cursor in this window is logically off. This is
1259used for blinking the cursor.
b8d4c8d0
GM
1260
1261@item last_cursor_off_p
1262This field contains the value of @code{cursor_off_p} as of the time of
1263the last redisplay.
1264
1265@item must_be_updated_p
1266This is set to 1 during redisplay when this window must be updated.
1267
1268@item hscroll
1269This is the number of columns that the display in the window is scrolled
1270horizontally to the left. Normally, this is 0.
1271
1272@item vscroll
1273Vertical scroll amount, in pixels. Normally, this is 0.
1274
1275@item dedicated
1276Non-@code{nil} if this window is dedicated to its buffer.
1277
1278@item display_table
1279The window's display table, or @code{nil} if none is specified for it.
1280
1281@item update_mode_line
1282Non-@code{nil} means this window's mode line needs to be updated.
1283
1284@item base_line_number
1285The line number of a certain position in the buffer, or @code{nil}.
1286This is used for displaying the line number of point in the mode line.
1287
1288@item base_line_pos
1289The position in the buffer for which the line number is known, or
7d2d7cc0
GM
1290@code{nil} meaning none is known. If it is a buffer, don't display
1291the line number as long as the window shows that buffer.
b8d4c8d0
GM
1292
1293@item region_showing
1294If the region (or part of it) is highlighted in this window, this field
1295holds the mark position that made one end of that region. Otherwise,
1296this field is @code{nil}.
1297
1298@item column_number_displayed
1299The column number currently displayed in this window's mode line, or @code{nil}
1300if column numbers are not being displayed.
1301
1302@item current_matrix
7d2d7cc0
GM
1303@itemx desired_matrix
1304Glyph matrices describing the current and desired display of this window.
b8d4c8d0
GM
1305@end table
1306
1307@node Process Internals
520f2425 1308@subsection Process Internals
b8d4c8d0
GM
1309@cindex internals, of process
1310@cindex process internals
1311
7d2d7cc0
GM
1312 The fields of a process (for a complete list, see the definition of
1313@code{struct Lisp_Process} in @file{process.h}) include:
b8d4c8d0
GM
1314
1315@table @code
1316@item name
1317A string, the name of the process.
1318
1319@item command
1320A list containing the command arguments that were used to start this
c73e02fa
GM
1321process. For a network or serial process, it is @code{nil} if the
1322process is running or @code{t} if the process is stopped.
b8d4c8d0
GM
1323
1324@item filter
7d2d7cc0
GM
1325If non-@code{nil}, a function used to accept output from the process
1326instead of a buffer.
b8d4c8d0
GM
1327
1328@item sentinel
7d2d7cc0
GM
1329If non-@code{nil}, a function called whenever the state of the process
1330changes.
b8d4c8d0
GM
1331
1332@item buffer
1333The associated buffer of the process.
1334
1335@item pid
1336An integer, the operating system's process @acronym{ID}.
7d2d7cc0 1337Pseudo-processes such as network or serial connections use a value of 0.
b8d4c8d0
GM
1338
1339@item childp
7d2d7cc0
GM
1340A flag, @code{t} if this is really a child process. For a network or
1341serial connection, it is a plist based on the arguments to
1342@code{make-network-process} or @code{make-serial-process}.
b8d4c8d0
GM
1343
1344@item mark
1345A marker indicating the position of the end of the last output from this
1346process inserted into the buffer. This is often but not always the end
1347of the buffer.
1348
1349@item kill_without_query
ee2d5b5e
CY
1350If this is non-zero, killing Emacs while this process is still running
1351does not ask for confirmation about killing the process.
b8d4c8d0 1352
7d2d7cc0
GM
1353@item raw_status
1354The raw process status, as returned by the @code{wait} system call.
b8d4c8d0
GM
1355
1356@item status
1357The process status, as @code{process-status} should return it.
1358
1359@item tick
1360@itemx update_tick
1361If these two fields are not equal, a change in the status of the process
1362needs to be reported, either by running the sentinel or by inserting a
1363message in the process buffer.
1364
1365@item pty_flag
1366Non-@code{nil} if communication with the subprocess uses a @acronym{PTY};
1367@code{nil} if it uses a pipe.
1368
1369@item infd
1370The file descriptor for input from the process.
1371
1372@item outfd
1373The file descriptor for output to the process.
1374
b8d4c8d0
GM
1375@item tty_name
1376The name of the terminal that the subprocess is using,
1377or @code{nil} if it is using pipes.
1378
1379@item decode_coding_system
1380Coding-system for decoding the input from this process.
1381
1382@item decoding_buf
1383A working buffer for decoding.
1384
1385@item decoding_carryover
1386Size of carryover in decoding.
1387
1388@item encode_coding_system
1389Coding-system for encoding the output to this process.
1390
1391@item encoding_buf
1392A working buffer for encoding.
1393
b8d4c8d0
GM
1394@item inherit_coding_system_flag
1395Flag to set @code{coding-system} of the process buffer from the
1396coding system used to decode process output.
c73e02fa
GM
1397
1398@item type
1399Symbol indicating the type of process: @code{real}, @code{network},
7d2d7cc0 1400@code{serial}.
c73e02fa 1401
b8d4c8d0 1402@end table
7d2d7cc0
GM
1403
1404@c FIXME Mention src/globals.h somewhere in this file?