Mercurial > emacs
comparison lispref/internals.texi @ 21682:90da2489c498
*** empty log message ***
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Mon, 20 Apr 1998 17:43:57 +0000 |
parents | 66d807bdc5b4 |
children | d4ac295a98b3 |
comparison
equal
deleted
inserted
replaced
21681:11eafe90b842 | 21682:90da2489c498 |
---|---|
10 This chapter describes how the runnable Emacs executable is dumped with | 10 This chapter describes how the runnable Emacs executable is dumped with |
11 the preloaded Lisp libraries in it, how storage is allocated, and some | 11 the preloaded Lisp libraries in it, how storage is allocated, and some |
12 internal aspects of GNU Emacs that may be of interest to C programmers. | 12 internal aspects of GNU Emacs that may be of interest to C programmers. |
13 | 13 |
14 @menu | 14 @menu |
15 * Building Emacs:: How to preload Lisp libraries into Emacs. | 15 * Building Emacs:: How to the dumped Emacs is made. |
16 * Pure Storage:: A kludge to make preloaded Lisp functions sharable. | 16 * Pure Storage:: A kludge to make preloaded Lisp functions sharable. |
17 * Garbage Collection:: Reclaiming space for Lisp objects no longer used. | 17 * Garbage Collection:: Reclaiming space for Lisp objects no longer used. |
18 * Memory Usage:: Info about total size of Lisp objects made so far. | |
18 * Writing Emacs Primitives:: Writing C code for Emacs. | 19 * Writing Emacs Primitives:: Writing C code for Emacs. |
19 * Object Internals:: Data formats of buffers, windows, processes. | 20 * Object Internals:: Data formats of buffers, windows, processes. |
20 @end menu | 21 @end menu |
21 | 22 |
22 @node Building Emacs, Pure Storage, GNU Emacs Internals, GNU Emacs Internals | 23 @node Building Emacs |
23 @appendixsec Building Emacs | 24 @appendixsec Building Emacs |
24 @cindex building Emacs | 25 @cindex building Emacs |
25 @pindex temacs | 26 @pindex temacs |
26 | 27 |
27 This section explains the steps involved in building the Emacs | 28 This section explains the steps involved in building the Emacs |
116 | 117 |
117 If you want to use this function in an Emacs that was already dumped, | 118 If you want to use this function in an Emacs that was already dumped, |
118 you must run Emacs with @samp{-batch}. | 119 you must run Emacs with @samp{-batch}. |
119 @end defun | 120 @end defun |
120 | 121 |
121 @deffn Command emacs-version | 122 @node Pure Storage |
122 This function returns a string describing the version of Emacs that is | |
123 running. It is useful to include this string in bug reports. | |
124 | |
125 @example | |
126 @group | |
127 (emacs-version) | |
128 @result{} "GNU Emacs 20.2.5 (i486-pc-linux-gnulibc1, X toolkit) | |
129 of Sat Feb 14 1998 on psilocin.gnu.org" | |
130 @end group | |
131 @end example | |
132 | |
133 Called interactively, the function prints the same information in the | |
134 echo area. | |
135 @end deffn | |
136 | |
137 @defvar emacs-build-time | |
138 The value of this variable is the time at which Emacs was built at the | |
139 local site. | |
140 | |
141 @example | |
142 @group | |
143 emacs-build-time | |
144 @result{} "Tue Jun 6 14:55:57 1995" | |
145 @end group | |
146 @end example | |
147 @end defvar | |
148 | |
149 @defvar emacs-version | |
150 The value of this variable is the version of Emacs being run. It is a | |
151 string such as @code{"20.3.1"}. The last number in this string is not | |
152 really part of the Emacs release version number; it is incremented each | |
153 time you build Emacs in any given directory. | |
154 @end defvar | |
155 | |
156 The following two variables have existed since Emacs version 19.23, | |
157 | |
158 @defvar emacs-major-version | |
159 The major version number of Emacs, as an integer. For Emacs version | |
160 20.2, the value is 20. | |
161 @end defvar | |
162 | |
163 @defvar emacs-minor-version | |
164 The minor version number of Emacs, as an integer. For Emacs version | |
165 20.2, the value is 2. | |
166 @end defvar | |
167 | |
168 @node Pure Storage, Garbage Collection, Building Emacs, GNU Emacs Internals | |
169 @appendixsec Pure Storage | 123 @appendixsec Pure Storage |
170 @cindex pure storage | 124 @cindex pure storage |
171 | 125 |
172 Emacs Lisp uses two kinds of storage for user-created Lisp objects: | 126 Emacs Lisp uses two kinds of storage for user-created Lisp objects: |
173 @dfn{normal storage} and @dfn{pure storage}. Normal storage is where | 127 @dfn{normal storage} and @dfn{pure storage}. Normal storage is where |
219 before and after dumping. | 173 before and after dumping. |
220 | 174 |
221 You should not change this flag in a running Emacs. | 175 You should not change this flag in a running Emacs. |
222 @end defvar | 176 @end defvar |
223 | 177 |
224 @node Garbage Collection, Writing Emacs Primitives, Pure Storage, GNU Emacs Internals | 178 @node Garbage Collection |
225 @appendixsec Garbage Collection | 179 @appendixsec Garbage Collection |
226 @cindex garbage collector | 180 @cindex garbage collector |
227 | 181 |
228 @cindex memory allocation | 182 @cindex memory allocation |
229 When a program creates a list or the user defines a new function (such | 183 When a program creates a list or the user defines a new function (such |
289 @example | 243 @example |
290 @group | 244 @group |
291 ((@var{used-conses} . @var{free-conses}) | 245 ((@var{used-conses} . @var{free-conses}) |
292 (@var{used-syms} . @var{free-syms}) | 246 (@var{used-syms} . @var{free-syms}) |
293 @end group | 247 @end group |
294 (@var{used-markers} . @var{free-markers}) | 248 (@var{used-miscs} . @var{free-miscs}) |
295 @var{used-string-chars} | 249 @var{used-string-chars} |
296 @var{used-vector-slots} | 250 @var{used-vector-slots} |
297 (@var{used-floats} . @var{free-floats}) | 251 (@var{used-floats} . @var{free-floats}) |
298 (@var{used-intervals} . @var{free-intervals})) | 252 (@var{used-intervals} . @var{free-intervals})) |
253 @end example | |
254 | |
255 Here is an example: | |
256 | |
257 @example | |
299 @group | 258 @group |
300 (garbage-collect) | 259 (garbage-collect) |
301 @result{} ((106886 . 13184) (9769 . 0) | 260 @result{} ((106886 . 13184) (9769 . 0) |
302 (7731 . 4651) 347543 121628 | 261 (7731 . 4651) 347543 121628 |
303 (31 . 94) (1273 . 168)) | 262 (31 . 94) (1273 . 168)) |
319 | 278 |
320 @item free-syms | 279 @item free-syms |
321 The number of symbols for which space has been obtained from the | 280 The number of symbols for which space has been obtained from the |
322 operating system, but that are not currently being used. | 281 operating system, but that are not currently being used. |
323 | 282 |
324 @item used-markers | 283 @item used-miscs |
325 The number of markers in use. | 284 The number of miscellaneous objects in use. These include markers and |
326 | 285 overlays, plus certain objects not visible to users. |
327 @item free-markers | 286 |
328 The number of markers for which space has been obtained from the | 287 @item free-miscs |
329 operating system, but that are not currently being used. | 288 The number of miscellaneous objects for which space has been obtained |
289 from the operating system, but that are not currently being used. | |
330 | 290 |
331 @item used-string-chars | 291 @item used-string-chars |
332 The total size of all strings, in characters. | 292 The total size of all strings, in characters. |
333 | 293 |
334 @item used-vector-slots | 294 @item used-vector-slots |
371 down to 10,000. A value less than 10,000 will remain in effect only | 331 down to 10,000. A value less than 10,000 will remain in effect only |
372 until the subsequent garbage collection, at which time | 332 until the subsequent garbage collection, at which time |
373 @code{garbage-collect} will set the threshold back to 10,000. | 333 @code{garbage-collect} will set the threshold back to 10,000. |
374 @end defopt | 334 @end defopt |
375 | 335 |
336 The value return by @code{garbage-collect} describes the amount of | |
337 memory used by Lisp data, broken down by data type. By contrast, the | |
338 function @code{memory-limit} provides information on the total amount of | |
339 memory Emacs is currently using. | |
340 | |
376 @c Emacs 19 feature | 341 @c Emacs 19 feature |
377 @defun memory-limit | 342 @defun memory-limit |
378 This function returns the address of the last byte Emacs has allocated, | 343 This function returns the address of the last byte Emacs has allocated, |
379 divided by 1024. We divide the value by 1024 to make sure it fits in a | 344 divided by 1024. We divide the value by 1024 to make sure it fits in a |
380 Lisp integer. | 345 Lisp integer. |
381 | 346 |
382 You can use this to get a general idea of how your actions affect the | 347 You can use this to get a general idea of how your actions affect the |
383 memory usage. | 348 memory usage. |
384 @end defun | 349 @end defun |
385 | 350 |
386 @node Writing Emacs Primitives, Object Internals, Garbage Collection, GNU Emacs Internals | 351 @node Memory Usage |
352 @section Memory Usage | |
353 | |
354 These functions and variables give information about the total amount | |
355 of memory allocation that Emacs has done, broken down by data type. | |
356 Note the difference between these and the values returned by | |
357 @code{(garbage-collect)}; those count objects that currently exist, but | |
358 these count the number or size of all allocations, including those for | |
359 objects that have since been freed. | |
360 | |
361 @defvar cons-cells-consed | |
362 The total number of cons cells that have been allocated so far | |
363 in this Emacs session. | |
364 @end defvar | |
365 | |
366 @defvar floats-consed | |
367 The total number of floats that have been allocated so far | |
368 in this Emacs session. | |
369 @end defvar | |
370 | |
371 @defvar vector-cells-consed | |
372 The total number of vector cells that have been allocated so far | |
373 in this Emacs session. | |
374 @end defvar | |
375 | |
376 @defvar symbols-consed | |
377 The total number of symbols that have been allocated so far | |
378 in this Emacs session. | |
379 @end defvar | |
380 | |
381 @defvar string-chars-consed | |
382 The total number of string characters that have been allocated so far | |
383 in this Emacs session. | |
384 @end defvar | |
385 | |
386 @defvar misc-objects-consed | |
387 The total number of miscellaneous objects that have been allocated so | |
388 far in this Emacs session. These include markers and overlays, plus | |
389 certain objects not visible to users. | |
390 @end defvar | |
391 | |
392 @defvar intervals-consed | |
393 The total number of intervals that have been allocated so far | |
394 in this Emacs session. | |
395 @end defvar | |
396 | |
397 @node Writing Emacs Primitives | |
387 @appendixsec Writing Emacs Primitives | 398 @appendixsec Writing Emacs Primitives |
388 @cindex primitive function internals | 399 @cindex primitive function internals |
389 | 400 |
390 Lisp primitives are Lisp functions implemented in C. The details of | 401 Lisp primitives are Lisp functions implemented in C. The details of |
391 interfacing the C function so that Lisp can call it are handled by a few | 402 interfacing the C function so that Lisp can call it are handled by a few |
574 in Lisp. @code{DEFVAR_INT} makes a C variable of type @code{int} | 585 in Lisp. @code{DEFVAR_INT} makes a C variable of type @code{int} |
575 visible in Lisp with a value that is always an integer. | 586 visible in Lisp with a value that is always an integer. |
576 @code{DEFVAR_BOOL} makes a C variable of type @code{int} visible in Lisp | 587 @code{DEFVAR_BOOL} makes a C variable of type @code{int} visible in Lisp |
577 with a value that is either @code{t} or @code{nil}. | 588 with a value that is either @code{t} or @code{nil}. |
578 | 589 |
590 If you define a file-scope C variable of type @code{Lisp_Object}, | |
591 you must protect it for garbage-collection by calling @code{staticpro} | |
592 in @code{syms_of_@var{filename}}, like this: | |
593 | |
594 @example | |
595 staticpro (&@var{variable}); | |
596 @end example | |
597 | |
579 Here is another example function, with more complicated arguments. | 598 Here is another example function, with more complicated arguments. |
580 This comes from the code for the X Window System, and it demonstrates | 599 This comes from the code in @file{window.c}, and it demonstrates the use |
581 the use of macros and functions to manipulate Lisp objects. | 600 of macros and functions to manipulate Lisp objects. |
582 | 601 |
583 @smallexample | 602 @smallexample |
584 @group | 603 @group |
585 DEFUN ("coordinates-in-window-p", Fcoordinates_in_window_p, | 604 DEFUN ("coordinates-in-window-p", Fcoordinates_in_window_p, |
586 Scoordinates_in_window_p, 2, 2, | 605 Scoordinates_in_window_p, 2, 2, |
587 "xSpecify coordinate pair: \nXExpression which evals to window: ", | 606 "xSpecify coordinate pair: \nXExpression which evals to window: ", |
588 "Return non-nil if POSITIONS is in WINDOW.\n\ | 607 "Return non-nil if COORDINATES is in WINDOW.\n\ |
589 \(POSITIONS is a list, (SCREEN-X SCREEN-Y)\)\n\ | 608 COORDINATES is a cons of the form (X . Y), X and Y being distances\n\ |
590 @end group | 609 ... |
591 @group | 610 @end group |
592 Returned value is list of positions expressed\n\ | 611 @group |
593 relative to window upper left corner.") | 612 If they are on the border between WINDOW and its right sibling,\n\ |
594 (coordinate, window) | 613 `vertical-line' is returned.") |
595 register Lisp_Object coordinate, window; | 614 (coordinates, window) |
615 register Lisp_Object coordinates, window; | |
596 @{ | 616 @{ |
597 register Lisp_Object xcoord, ycoord; | 617 int x, y; |
598 @end group | 618 @end group |
599 | 619 |
600 @group | 620 @group |
601 if (!CONSP (coordinate)) wrong_type_argument (Qlistp, coordinate); | 621 CHECK_LIVE_WINDOW (window, 0); |
602 CHECK_WINDOW (window, 2); | 622 CHECK_CONS (coordinates, 1); |
603 xcoord = Fcar (coordinate); | 623 x = XINT (Fcar (coordinates)); |
604 ycoord = Fcar (Fcdr (coordinate)); | 624 y = XINT (Fcdr (coordinates)); |
605 CHECK_NUMBER (xcoord, 0); | 625 @end group |
606 CHECK_NUMBER (ycoord, 1); | 626 |
607 @end group | 627 @group |
608 @group | 628 switch (coordinates_in_window (XWINDOW (window), &x, &y)) |
609 if ((XINT (xcoord) < XINT (XWINDOW (window)->left)) | 629 @{ |
610 || (XINT (xcoord) >= (XINT (XWINDOW (window)->left) | 630 case 0: /* NOT in window at all. */ |
611 + XINT (XWINDOW (window)->width)))) | 631 return Qnil; |
612 return Qnil; | 632 @end group |
613 /* @r{Subtracting from XFASTINT (xcoord) is safe} | 633 |
614 @r{as long as we know the result is not negative.} */ | 634 @group |
615 XFASTINT (xcoord) -= XFASTINT (XWINDOW (window)->left); | 635 case 1: /* In text part of window. */ |
616 @end group | 636 return Fcons (make_number (x), make_number (y)); |
617 @group | 637 @end group |
618 if (XINT (ycoord) == (screen_height - 1)) | 638 |
619 return Qnil; | 639 @group |
620 @end group | 640 case 2: /* In mode line of window. */ |
621 @group | 641 return Qmode_line; |
622 if ((XINT (ycoord) < XINT (XWINDOW (window)->top)) | 642 @end group |
623 || (XINT (ycoord) >= (XINT (XWINDOW (window)->top) | 643 |
624 + XINT (XWINDOW (window)->height)) - 1)) | 644 @group |
625 return Qnil; | 645 case 3: /* On right border of window. */ |
626 @end group | 646 return Qvertical_line; |
627 @group | 647 @end group |
628 XFASTINT (ycoord) -= XFASTINT (XWINDOW (window)->top); | 648 |
629 return (Fcons (xcoord, Fcons (ycoord, Qnil))); | 649 @group |
650 default: | |
651 abort (); | |
652 @} | |
630 @} | 653 @} |
631 @end group | 654 @end group |
632 @end smallexample | 655 @end smallexample |
633 | 656 |
634 Note that C code cannot call functions by name unless they are defined | 657 Note that C code cannot call functions by name unless they are defined |
648 | 671 |
649 @file{eval.c} is a very good file to look through for examples; | 672 @file{eval.c} is a very good file to look through for examples; |
650 @file{lisp.h} contains the definitions for some important macros and | 673 @file{lisp.h} contains the definitions for some important macros and |
651 functions. | 674 functions. |
652 | 675 |
653 @node Object Internals, , Writing Emacs Primitives, GNU Emacs Internals | 676 @node Object Internals |
654 @appendixsec Object Internals | 677 @appendixsec Object Internals |
655 @cindex object internals | 678 @cindex object internals |
656 | 679 |
657 GNU Emacs Lisp manipulates many different types of data. The actual | 680 GNU Emacs Lisp manipulates many different types of data. The actual |
658 data are stored in a heap and the only access that programs have to it | 681 data are stored in a heap and the only access that programs have to it |
676 * Buffer Internals:: Components of a buffer structure. | 699 * Buffer Internals:: Components of a buffer structure. |
677 * Window Internals:: Components of a window structure. | 700 * Window Internals:: Components of a window structure. |
678 * Process Internals:: Components of a process structure. | 701 * Process Internals:: Components of a process structure. |
679 @end menu | 702 @end menu |
680 | 703 |
681 @node Buffer Internals, Window Internals, Object Internals, Object Internals | 704 @node Buffer Internals |
682 @appendixsubsec Buffer Internals | 705 @appendixsubsec Buffer Internals |
683 @cindex internals, of buffer | 706 @cindex internals, of buffer |
684 @cindex buffer internals | 707 @cindex buffer internals |
685 | 708 |
686 Buffers contain fields not directly accessible by the Lisp programmer. | 709 Buffers contain fields not directly accessible by the Lisp programmer. |
715 @item syntax_table_v | 738 @item syntax_table_v |
716 This field contains the syntax table for the buffer. @xref{Syntax Tables}. | 739 This field contains the syntax table for the buffer. @xref{Syntax Tables}. |
717 | 740 |
718 @item downcase_table | 741 @item downcase_table |
719 This field contains the conversion table for converting text to lower case. | 742 This field contains the conversion table for converting text to lower case. |
720 @xref{Case Table}. | 743 @xref{Case Tables}. |
721 | 744 |
722 @item upcase_table | 745 @item upcase_table |
723 This field contains the conversion table for converting text to upper case. | 746 This field contains the conversion table for converting text to upper case. |
724 @xref{Case Table}. | 747 @xref{Case Tables}. |
725 | 748 |
726 @item case_canon_table | 749 @item case_canon_table |
727 This field contains the conversion table for canonicalizing text for | 750 This field contains the conversion table for canonicalizing text for |
728 case-folding search. @xref{Case Table}. | 751 case-folding search. @xref{Case Tables}. |
729 | 752 |
730 @item case_eqv_table | 753 @item case_eqv_table |
731 This field contains the equivalence table for case-folding search. | 754 This field contains the equivalence table for case-folding search. |
732 @xref{Case Table}. | 755 @xref{Case Tables}. |
733 | 756 |
734 @item display_table | 757 @item display_table |
735 This field contains the buffer's display table, or @code{nil} if it doesn't | 758 This field contains the buffer's display table, or @code{nil} if it doesn't |
736 have one. @xref{Display Tables}. | 759 have one. @xref{Display Tables}. |
737 | 760 |
751 | 774 |
752 @item mark_active | 775 @item mark_active |
753 This field is non-@code{nil} if the buffer's mark is active. | 776 This field is non-@code{nil} if the buffer's mark is active. |
754 | 777 |
755 @item local_var_alist | 778 @item local_var_alist |
756 This field contains the association list describing the variables local | 779 This field contains the association list describing the buffer-local |
757 in this buffer, and their values, with the exception of local variables | 780 variable bindings of this buffer, not including the built-in |
758 that have special slots in the buffer object. (Those slots are omitted | 781 buffer-local bindings that that have special slots in the buffer object. |
759 from this table.) @xref{Buffer-Local Variables}. | 782 (Those slots are omitted from this table.) @xref{Buffer-Local |
783 Variables}. | |
760 | 784 |
761 @item base_buffer | 785 @item base_buffer |
762 This field holds the buffer's base buffer (if it is an indirect buffer), | 786 This field holds the buffer's base buffer (if it is an indirect buffer), |
763 or @code{nil}. | 787 or @code{nil}. |
764 | 788 |
775 | 799 |
776 @item overlays_after | 800 @item overlays_after |
777 This field holds a list of the overlays in this buffer that end after | 801 This field holds a list of the overlays in this buffer that end after |
778 the current overlay center position. They are sorted in order of | 802 the current overlay center position. They are sorted in order of |
779 increasing beginning position. | 803 increasing beginning position. |
804 | |
805 @item enable_multibyte_characters | |
806 This field holds the buffer's local value of | |
807 @code{enable-multibyte-characters}---either @code{t} or @code{nil}. | |
780 @end table | 808 @end table |
781 | 809 |
782 @node Window Internals, Process Internals, Buffer Internals, Object Internals | 810 @node Window Internals |
783 @appendixsubsec Window Internals | 811 @appendixsubsec Window Internals |
784 @cindex internals, of window | 812 @cindex internals, of window |
785 @cindex window internals | 813 @cindex window internals |
786 | 814 |
787 Windows have the following accessible fields: | 815 Windows have the following accessible fields: |
884 If the region (or part of it) is highlighted in this window, this field | 912 If the region (or part of it) is highlighted in this window, this field |
885 holds the mark position that made one end of that region. Otherwise, | 913 holds the mark position that made one end of that region. Otherwise, |
886 this field is @code{nil}. | 914 this field is @code{nil}. |
887 @end table | 915 @end table |
888 | 916 |
889 @node Process Internals, , Window Internals, Object Internals | 917 @node Process Internals |
890 @appendixsubsec Process Internals | 918 @appendixsubsec Process Internals |
891 @cindex internals, of process | 919 @cindex internals, of process |
892 @cindex process internals | 920 @cindex process internals |
893 | 921 |
894 The fields of a process are: | 922 The fields of a process are: |