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