aboutsummaryrefslogtreecommitdiffstats
path: root/doc
diff options
context:
space:
mode:
authorChong Yidong2012-03-18 23:02:12 +0800
committerChong Yidong2012-03-18 23:02:12 +0800
commitd15aac68209502b0a4e748a3a24e4b1c6a4bc54a (patch)
tree3d1b8ebb4dc2ae5c9781787018af29398b87a06a /doc
parent4c5779ab90f6be7862604d700f4b1dee17ba10c4 (diff)
downloademacs-d15aac68209502b0a4e748a3a24e4b1c6a4bc54a.tar.gz
emacs-d15aac68209502b0a4e748a3a24e4b1c6a4bc54a.zip
Copyedits for Internals and OS chapters of Lisp manual.
* doc/lispref/internals.texi (Building Emacs, Garbage Collection): Copyedits. (Writing Emacs Primitives): Re-organize discussion of functions with variable Lisp arguments are handled. Delete an obsolete remark, previously tagged as FIXME. * doc/lispref/os.texi (Idle Timers): Minor clarification. (Idle Timers): Link to Time of Day for description of time list.
Diffstat (limited to 'doc')
-rw-r--r--doc/lispref/ChangeLog10
-rw-r--r--doc/lispref/internals.texi180
-rw-r--r--doc/lispref/os.texi50
3 files changed, 104 insertions, 136 deletions
diff --git a/doc/lispref/ChangeLog b/doc/lispref/ChangeLog
index 6c512a33978..af0cb306245 100644
--- a/doc/lispref/ChangeLog
+++ b/doc/lispref/ChangeLog
@@ -1,3 +1,13 @@
12012-03-18 Chong Yidong <cyd@gnu.org>
2
3 * internals.texi (Building Emacs, Garbage Collection): Copyedits.
4 (Writing Emacs Primitives): Re-organize discussion of functions
5 with variable Lisp arguments are handled. Delete an obsolete
6 remark, previously tagged as FIXME.
7
8 * os.texi (Idle Timers): Minor clarification.
9 (Idle Timers): Link to Time of Day for description of time list.
10
12012-03-18 Glenn Morris <rgm@gnu.org> 112012-03-18 Glenn Morris <rgm@gnu.org>
2 12
3 * os.texi (System Interface): Flow control was removed. 13 * os.texi (System Interface): Flow control was removed.
diff --git a/doc/lispref/internals.texi b/doc/lispref/internals.texi
index 55b18edf2ec..edf892e751a 100644
--- a/doc/lispref/internals.texi
+++ b/doc/lispref/internals.texi
@@ -28,42 +28,39 @@ internal aspects of GNU Emacs that may be of interest to C programmers.
28 This section explains the steps involved in building the Emacs 28 This section explains the steps involved in building the Emacs
29executable. You don't have to know this material to build and install 29executable. You don't have to know this material to build and install
30Emacs, since the makefiles do all these things automatically. This 30Emacs, since the makefiles do all these things automatically. This
31information is pertinent to Emacs maintenance. 31information is pertinent to Emacs developers.
32 32
33 Compilation of the C source files in the @file{src} directory 33 Compilation of the C source files in the @file{src} directory
34produces an executable file called @file{temacs}, also called a 34produces an executable file called @file{temacs}, also called a
35@dfn{bare impure Emacs}. It contains the Emacs Lisp interpreter and I/O 35@dfn{bare impure Emacs}. It contains the Emacs Lisp interpreter and
36routines, but not the editing commands. 36I/O routines, but not the editing commands.
37 37
38@cindex @file{loadup.el} 38@cindex @file{loadup.el}
39 The command @w{@samp{temacs -l loadup}} uses @file{temacs} to create 39 The command @w{@command{temacs -l loadup}} would run @file{temacs}
40the real runnable Emacs executable. These arguments direct 40and direct it to load @file{loadup.el}. The @code{loadup} library
41@file{temacs} to evaluate the Lisp files specified in the file 41loads additional Lisp libraries, which set up the normal Emacs editing
42@file{loadup.el}. These files set up the normal Emacs editing 42environment. After this step, the Emacs executable is no longer
43environment, resulting in an Emacs that is still impure but no longer 43@dfn{bare}.
44bare.
45 44
46@cindex dumping Emacs 45@cindex dumping Emacs
47 It takes some time to load the standard Lisp files. Luckily, 46 Because it takes some time to load the standard Lisp files, the
48you don't have to do this each time you run Emacs; @file{temacs} can 47@file{temacs} executable usually isn't run directly by users.
49dump out an executable program called @file{emacs} that has these files 48Instead, as one of the last steps of building Emacs, the command
50preloaded. @file{emacs} starts more quickly because it does not need to 49@samp{temacs -batch -l loadup dump} is run. The special @samp{dump}
51load the files. This is the Emacs executable that is normally 50argument causes @command{temacs} to dump out an executable program,
52installed. 51called @file{emacs}, which has all the standard Lisp files preloaded.
53 52(The @samp{-batch} argument prevents @file{temacs} from trying to
53initialize any of its data on the terminal, so that the tables of
54terminal information are empty in the dumped Emacs.)
55
56@cindex preloaded Lisp files
54@vindex preloaded-file-list 57@vindex preloaded-file-list
55@cindex dumped Lisp files 58 The dumped @file{emacs} executable (also called a @dfn{pure} Emacs)
56 To create @file{emacs}, use the command @samp{temacs -batch -l loadup 59is the one which is installed. The variable
57dump}. The purpose of @samp{-batch} here is to prevent @file{temacs} 60@code{preloaded-file-list} stores a list of the Lisp files preloaded
58from trying to initialize any of its data on the terminal; this ensures 61into the dumped Emacs. If you port Emacs to a new operating system,
59that the tables of terminal information are empty in the dumped Emacs. 62and are not able to implement dumping, then Emacs must load
60The argument @samp{dump} tells @file{loadup.el} to dump a new executable 63@file{loadup.el} each time it starts.
61named @file{emacs}. The variable @code{preloaded-file-list} stores a
62list of the Lisp files that were dumped with the @file{emacs} executable.
63
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.
67 64
68@cindex @file{site-load.el} 65@cindex @file{site-load.el}
69 You can specify additional files to preload by writing a library named 66 You can specify additional files to preload by writing a library named
@@ -163,7 +160,7 @@ all the new data created during an Emacs session are kept
163in the preloaded standard Lisp files---data that should never change 160in the preloaded standard Lisp files---data that should never change
164during actual use of Emacs. 161during actual use of Emacs.
165 162
166 Pure storage is allocated only while @file{temacs} is loading the 163 Pure storage is allocated only while @command{temacs} is loading the
167standard preloaded Lisp libraries. In the file @file{emacs}, it is 164standard preloaded Lisp libraries. In the file @file{emacs}, it is
168marked as read-only (on operating systems that permit this), so that 165marked as read-only (on operating systems that permit this), so that
169the memory space can be shared by all the Emacs jobs running on the 166the memory space can be shared by all the Emacs jobs running on the
@@ -214,31 +211,27 @@ You should not change this flag in a running Emacs.
214 211
215@node Garbage Collection 212@node Garbage Collection
216@section Garbage Collection 213@section Garbage Collection
217@cindex garbage collection
218 214
219@cindex memory allocation 215@cindex memory allocation
220 When a program creates a list or the user defines a new function (such 216 When a program creates a list or the user defines a new function
221as by loading a library), that data is placed in normal storage. If 217(such as by loading a library), that data is placed in normal storage.
222normal storage runs low, then Emacs asks the operating system to 218If normal storage runs low, then Emacs asks the operating system to
223allocate more memory in blocks of 1k bytes. Each block is used for one 219allocate more memory. Different types of Lisp objects, such as
224type of Lisp object, so symbols, cons cells, markers, etc., are 220symbols, cons cells, markers, etc., are segregated in distinct blocks
225segregated in distinct blocks in memory. (Vectors, long strings, 221in memory. (Vectors, long strings, buffers and certain other editing
226buffers and certain other editing types, which are fairly large, are 222types, which are fairly large, are allocated in individual blocks, one
227allocated in individual blocks, one per object, while small strings are 223per object, while small strings are packed into blocks of 8k bytes.)
228packed into blocks of 8k bytes.)
229
230 It is quite common to use some storage for a while, then release it by
231(for example) killing a buffer or deleting the last pointer to an
232object. Emacs provides a @dfn{garbage collector} to reclaim this
233abandoned storage. (This name is traditional, but ``garbage recycler''
234might be a more intuitive metaphor for this facility.)
235 224
236 The garbage collector operates by finding and marking all Lisp objects 225@cindex garbage collection
237that are still accessible to Lisp programs. To begin with, it assumes 226 It is quite common to use some storage for a while, then release it
238all the symbols, their values and associated function definitions, and 227by (for example) killing a buffer or deleting the last pointer to an
239any data presently on the stack, are accessible. Any objects that can 228object. Emacs provides a @dfn{garbage collector} to reclaim this
240be reached indirectly through other accessible objects are also 229abandoned storage. The garbage collector operates by finding and
241accessible. 230marking all Lisp objects that are still accessible to Lisp programs.
231To begin with, it assumes all the symbols, their values and associated
232function definitions, and any data presently on the stack, are
233accessible. Any objects that can be reached indirectly through other
234accessible objects are also accessible.
242 235
243 When marking is finished, all objects still unmarked are garbage. No 236 When marking is finished, all objects still unmarked are garbage. No
244matter what the Lisp program or the user does, it is impossible to refer 237matter what the Lisp program or the user does, it is impossible to refer
@@ -336,11 +329,9 @@ The total size of all strings, in characters.
336The total number of elements of existing vectors. 329The total number of elements of existing vectors.
337 330
338@item used-floats 331@item used-floats
339@c Emacs 19 feature
340The number of floats in use. 332The number of floats in use.
341 333
342@item free-floats 334@item free-floats
343@c Emacs 19 feature
344The number of floats for which space has been obtained from the 335The number of floats for which space has been obtained from the
345operating system, but that are not currently being used. 336operating system, but that are not currently being used.
346 337
@@ -417,7 +408,6 @@ memory used by Lisp data, broken down by data type. By contrast, the
417function @code{memory-limit} provides information on the total amount of 408function @code{memory-limit} provides information on the total amount of
418memory Emacs is currently using. 409memory Emacs is currently using.
419 410
420@c Emacs 19 feature
421@defun memory-limit 411@defun memory-limit
422This function returns the address of the last byte Emacs has allocated, 412This function returns the address of the last byte Emacs has allocated,
423divided by 1024. We divide the value by 1024 to make sure it fits in a 413divided by 1024. We divide the value by 1024 to make sure it fits in a
@@ -428,7 +418,7 @@ memory usage.
428@end defun 418@end defun
429 419
430@defvar memory-full 420@defvar memory-full
431This variable is @code{t} if Emacs is close to out of memory for Lisp 421This variable is @code{t} if Emacs is nearly out of memory for Lisp
432objects, and @code{nil} otherwise. 422objects, and @code{nil} otherwise.
433@end defvar 423@end defvar
434 424
@@ -519,8 +509,9 @@ appearance.)
519@smallexample 509@smallexample
520@group 510@group
521DEFUN ("or", For, Sor, 0, UNEVALLED, 0, 511DEFUN ("or", For, Sor, 0, UNEVALLED, 0,
522 doc: /* Eval args until one of them yields non-nil, then return that 512 doc: /* Eval args until one of them yields non-nil, then return
523value. The remaining args are not evalled at all. 513that value.
514The remaining args are not evalled at all.
524If all args return nil, return nil. 515If all args return nil, return nil.
525@end group 516@end group
526@group 517@group
@@ -566,14 +557,11 @@ This is the name of the Lisp symbol to define as the function name; in
566the example above, it is @code{or}. 557the example above, it is @code{or}.
567 558
568@item fname 559@item fname
569This is the C function name for this function. This is 560This is the C function name for this function. This is the name that
570the name that is used in C code for calling the function. The name is, 561is used in C code for calling the function. The name is, by
571by convention, @samp{F} prepended to the Lisp name, with all dashes 562convention, @samp{F} prepended to the Lisp name, with all dashes
572(@samp{-}) in the Lisp name changed to underscores. Thus, to call this 563(@samp{-}) in the Lisp name changed to underscores. Thus, to call
573function from C code, call @code{For}. Remember that the arguments must 564this function from C code, call @code{For}.
574be of type @code{Lisp_Object}; various macros and functions for creating
575values of type @code{Lisp_Object} are declared in the file
576@file{lisp.h}.
577 565
578@item sname 566@item sname
579This is a C variable name to use for a structure that holds the data for 567This is a C variable name to use for a structure that holds the data for
@@ -627,38 +615,35 @@ too.
627@end table 615@end table
628 616
629 After the call to the @code{DEFUN} macro, you must write the 617 After the call to the @code{DEFUN} macro, you must write the
630argument list that every C function must have, including the types for 618argument list for the C function, including the types for the
631the arguments. For a function with a fixed maximum number of 619arguments. If the primitive accepts a fixed maximum number of Lisp
632arguments, declare a C argument for each Lisp argument, and give them 620arguments, there must be one C argument for each Lisp argument, and
633all type @code{Lisp_Object}. When a Lisp function has no upper limit 621each argument must be of type @code{Lisp_Object}. (Various macros and
634on the number of arguments, its implementation in C actually receives 622functions for creating values of type @code{Lisp_Object} are declared
635exactly two arguments: the first is the number of Lisp arguments, and 623in the file @file{lisp.h}.) If the primitive has no upper limit on
636the second is the address of a block containing their values. They 624the number of Lisp arguments, it must have exactly two C arguments:
637have types @code{int} and @w{@code{Lisp_Object *}}. 625the first is the number of Lisp arguments, and the second is the
626address of a block containing their values. These have types
627@code{int} and @w{@code{Lisp_Object *}} respectively.
638 628
639@cindex @code{GCPRO} and @code{UNGCPRO} 629@cindex @code{GCPRO} and @code{UNGCPRO}
640@cindex protect C variables from garbage collection 630@cindex protect C variables from garbage collection
641 Within the function @code{For} itself, note the use of the macros 631 Within the function @code{For} itself, note the use of the macros
642@code{GCPRO1} and @code{UNGCPRO}. @code{GCPRO1} is used to 632@code{GCPRO1} and @code{UNGCPRO}. These macros are defined for the
643``protect'' a variable from garbage collection---to inform the garbage 633sake of the few platforms which do not use Emacs' default
644collector that it must look in that variable and regard its contents 634stack-marking garbage collector. The @code{GCPRO1} macro ``protects''
645as an accessible object. GC protection is necessary whenever you call 635a variable from garbage collection, explicitly informing the garbage
646@code{eval_sub} (or @code{Feval}) either directly or indirectly. 636collector that that variable and all its contents must be as
647At such a time, any Lisp object that this function may refer to again 637accessible. GC protection is necessary in any function which can
648must be protected somehow. 638perform Lisp evaluation by calling @code{eval_sub} or @code{Feval} as
639a subroutine, either directly or indirectly.
649 640
650 It suffices to ensure that at least one pointer to each object is 641 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 642GC-protected. Thus, a particular local variable can do without
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 643protection if it is certain that the object it points to will be
654preserved by some other pointer (such as another local variable that 644preserved by some other pointer (such as another local variable that
655has a @code{GCPRO}). 645has a @code{GCPRO}). Otherwise, the local variable needs a
656@ignore 646@code{GCPRO}.
657@footnote{Formerly, strings were a special exception; in older Emacs
658versions, every local variable that might point to a string needed a
659@code{GCPRO}.}.
660@end ignore
661Otherwise, the local variable needs a @code{GCPRO}.
662 647
663 The macro @code{GCPRO1} protects just one local variable. If you 648 The macro @code{GCPRO1} protects just one local variable. If you
664want to protect two variables, use @code{GCPRO2} instead; repeating 649want to protect two variables, use @code{GCPRO2} instead; repeating
@@ -667,34 +652,17 @@ want to protect two variables, use @code{GCPRO2} instead; repeating
667implicitly use local variables such as @code{gcpro1}; you must declare 652implicitly use local variables such as @code{gcpro1}; you must declare
668these explicitly, with type @code{struct gcpro}. Thus, if you use 653these explicitly, with type @code{struct gcpro}. Thus, if you use
669@code{GCPRO2}, you must declare @code{gcpro1} and @code{gcpro2}. 654@code{GCPRO2}, you must declare @code{gcpro1} and @code{gcpro2}.
670Alas, we can't explain all the tricky details here.
671 655
672 @code{UNGCPRO} cancels the protection of the variables that are 656 @code{UNGCPRO} cancels the protection of the variables that are
673protected in the current function. It is necessary to do this 657protected in the current function. It is necessary to do this
674explicitly. 658explicitly.
675 659
676 Built-in functions that take a variable number of arguments actually
677accept two arguments at the C level: the number of Lisp arguments, and
678a @code{Lisp_Object *} pointer to a C vector containing those Lisp
679arguments. This C vector may be part of a Lisp vector, but it need
680not be. The responsibility for using @code{GCPRO} to protect the Lisp
681arguments from GC if necessary rests with the caller in this case,
682since the caller allocated or found the storage for them.
683
684 You must not use C initializers for static or global variables unless 660 You must not use C initializers for static or global variables unless
685the variables are never written once Emacs is dumped. These variables 661the variables are never written once Emacs is dumped. These variables
686with initializers are allocated in an area of memory that becomes 662with initializers are allocated in an area of memory that becomes
687read-only (on certain operating systems) as a result of dumping Emacs. 663read-only (on certain operating systems) as a result of dumping Emacs.
688@xref{Pure Storage}. 664@xref{Pure Storage}.
689 665
690@c FIXME is this still true? I don't think so...
691 Do not use static variables within functions---place all static
692variables at top level in the file. This is necessary because Emacs on
693some operating systems defines the keyword @code{static} as a null
694macro. (This definition is used because those systems put all variables
695declared static in a place that becomes read-only after dumping, whether
696they have initializers or not.)
697
698@cindex @code{defsubr}, Lisp symbol for a primitive 666@cindex @code{defsubr}, Lisp symbol for a primitive
699 Defining the C function is not enough to make a Lisp primitive 667 Defining the C function is not enough to make a Lisp primitive
700available; you must also create the Lisp symbol for the primitive and 668available; you must also create the Lisp symbol for the primitive and
diff --git a/doc/lispref/os.texi b/doc/lispref/os.texi
index ee1aa88a2dd..1021787a0f4 100644
--- a/doc/lispref/os.texi
+++ b/doc/lispref/os.texi
@@ -1760,9 +1760,9 @@ certain length of time. Aside from how to set them up, idle timers
1760work just like ordinary timers. 1760work just like ordinary timers.
1761 1761
1762@deffn Command run-with-idle-timer secs repeat function &rest args 1762@deffn Command run-with-idle-timer secs repeat function &rest args
1763Set up a timer which runs when Emacs has been idle for @var{secs} 1763Set up a timer which runs the next time Emacs is idle for @var{secs}
1764seconds. The value of @var{secs} may be an integer or a floating point 1764seconds. The value of @var{secs} may be an integer or a floating
1765number; a value of the type returned by @code{current-idle-time} 1765point number; a value of the type returned by @code{current-idle-time}
1766is also allowed. 1766is also allowed.
1767 1767
1768If @var{repeat} is @code{nil}, the timer runs just once, the first time 1768If @var{repeat} is @code{nil}, the timer runs just once, the first time
@@ -1775,13 +1775,13 @@ can use in calling @code{cancel-timer} (@pxref{Timers}).
1775@end deffn 1775@end deffn
1776 1776
1777@cindex idleness 1777@cindex idleness
1778 Emacs becomes ``idle'' when it starts waiting for user input, and it 1778 Emacs becomes @dfn{idle} when it starts waiting for user input, and
1779remains idle until the user provides some input. If a timer is set for 1779it remains idle until the user provides some input. If a timer is set
1780five seconds of idleness, it runs approximately five seconds after Emacs 1780for five seconds of idleness, it runs approximately five seconds after
1781first becomes idle. Even if @var{repeat} is non-@code{nil}, this timer 1781Emacs first becomes idle. Even if @var{repeat} is non-@code{nil},
1782will not run again as long as Emacs remains idle, because the duration 1782this timer will not run again as long as Emacs remains idle, because
1783of idleness will continue to increase and will not go down to five 1783the duration of idleness will continue to increase and will not go
1784seconds again. 1784down to five seconds again.
1785 1785
1786 Emacs can do various things while idle: garbage collect, autosave or 1786 Emacs can do various things while idle: garbage collect, autosave or
1787handle data from a subprocess. But these interludes during idleness do 1787handle data from a subprocess. But these interludes during idleness do
@@ -1795,22 +1795,12 @@ minutes, and even if there have been garbage collections and autosaves.
1795input. Then it becomes idle again, and all the idle timers that are 1795input. Then it becomes idle again, and all the idle timers that are
1796set up to repeat will subsequently run another time, one by one. 1796set up to repeat will subsequently run another time, one by one.
1797 1797
1798@c Emacs 19 feature
1799@defun current-idle-time 1798@defun current-idle-time
1800If Emacs is idle, this function returns the length of time Emacs has 1799If Emacs is idle, this function returns the length of time Emacs has
1801been idle, as a list of three integers: @code{(@var{high} @var{low} 1800been idle, as a list of three integers: @code{(@var{sec-high}
1802@var{microsec})}. The integers @var{high} and @var{low} combine to 1801@var{sec-low} @var{microsec})}, where @var{high} and @var{low} are the
1803give the number of seconds of idleness, which is 1802high and low bits for the number of seconds and @var{microsec} is the
1804@ifnottex 1803additional number of microseconds (@pxref{Time of Day}).
1805@var{high} * 2**16 + @var{low}.
1806@end ifnottex
1807@tex
1808$high*2^{16}+low$.
1809@end tex
1810
1811The third element, @var{microsec}, gives the microseconds since the
1812start of the current second (or 0 for systems that return time with
1813the resolution of only one second).
1814 1804
1815When Emacs is not idle, @code{current-idle-time} returns @code{nil}. 1805When Emacs is not idle, @code{current-idle-time} returns @code{nil}.
1816This is a convenient way to test whether Emacs is idle. 1806This is a convenient way to test whether Emacs is idle.
@@ -1843,9 +1833,9 @@ Here's an example:
1843@end smallexample 1833@end smallexample
1844@end defun 1834@end defun
1845 1835
1846 Some idle timer functions in user Lisp packages have a loop that 1836 Do not write an idle timer function containing a loop which does a
1847does a certain amount of processing each time around, and exits when 1837certain amount of processing each time around, and exits when
1848@code{(input-pending-p)} is non-@code{nil}. That approach seems very 1838@code{(input-pending-p)} is non-@code{nil}. This approach seems very
1849natural but has two problems: 1839natural but has two problems:
1850 1840
1851@itemize 1841@itemize
@@ -1858,9 +1848,9 @@ It blocks out any idle timers that ought to run during that time.
1858@end itemize 1848@end itemize
1859 1849
1860@noindent 1850@noindent
1861To avoid these problems, don't use that technique. Instead, write 1851The correct approach is for the idle timer to reschedule itself after
1862such idle timers to reschedule themselves after a brief pause, using 1852a brief pause, using the method in the @code{timer-function} example
1863the method in the @code{timer-function} example above. 1853above.
1864 1854
1865@node Terminal Input 1855@node Terminal Input
1866@section Terminal Input 1856@section Terminal Input