Mercurial > emacs
comparison lispref/loading.texi @ 69200:63fbed8d9ae0
(Loading): Include new node "Load Suffixes" in menu.
(How Programs Do Loading): Discuss the effects of Auto Compression
mode on `load'.
(Load Suffixes): New node.
(Library Search): Delete description of `load-suffixes': it was
moved to "Load Suffixes".
(Autoload, Named Features): Mention `load-suffixes'.
author | Luc Teirlinck <teirllm@auburn.edu> |
---|---|
date | Tue, 28 Feb 2006 03:01:57 +0000 |
parents | 067115a6e738 |
children | 6912dc8ee005 |
comparison
equal
deleted
inserted
replaced
69199:fa7f73c4e52d | 69200:63fbed8d9ae0 |
---|---|
34 Similarly, a ``Lisp library directory'' is a directory of files | 34 Similarly, a ``Lisp library directory'' is a directory of files |
35 containing Lisp code. | 35 containing Lisp code. |
36 | 36 |
37 @menu | 37 @menu |
38 * How Programs Do Loading:: The @code{load} function and others. | 38 * How Programs Do Loading:: The @code{load} function and others. |
39 * Load Suffixes:: Details about the suffixes that @code{load} tries. | |
39 * Library Search:: Finding a library to load. | 40 * Library Search:: Finding a library to load. |
40 * Loading Non-ASCII:: Non-@acronym{ASCII} characters in Emacs Lisp files. | 41 * Loading Non-ASCII:: Non-@acronym{ASCII} characters in Emacs Lisp files. |
41 * Autoload:: Setting up a function to autoload. | 42 * Autoload:: Setting up a function to autoload. |
42 * Repeated Loading:: Precautions about loading a file twice. | 43 * Repeated Loading:: Precautions about loading a file twice. |
43 * Named Features:: Loading a library if it isn't already loaded. | 44 * Named Features:: Loading a library if it isn't already loaded. |
70 file named @var{filename} with nothing appended, and loads it if it | 71 file named @var{filename} with nothing appended, and loads it if it |
71 exists. (The @code{load} function is not clever about looking at | 72 exists. (The @code{load} function is not clever about looking at |
72 @var{filename}. In the perverse case of a file named @file{foo.el.el}, | 73 @var{filename}. In the perverse case of a file named @file{foo.el.el}, |
73 evaluation of @code{(load "foo.el")} will indeed find it.) | 74 evaluation of @code{(load "foo.el")} will indeed find it.) |
74 | 75 |
75 If the optional argument @var{nosuffix} is non-@code{nil}, then the | 76 If Auto Compression mode is enabled, as it is by default, then |
76 suffixes @samp{.elc} and @samp{.el} are not tried. In this case, you | 77 if @code{load} can not find a file, it searches for a compressed |
77 must specify the precise file name you want. By specifying the precise | 78 version of the file before trying other file names. It decompresses |
78 file name and using @code{t} for @var{nosuffix}, you can prevent | 79 and loads it if it exists. It looks for compressed versions by |
79 perverse file names such as @file{foo.el.el} from being tried. | 80 appending the suffixes in @code{jka-compr-load-suffixes} to the file |
81 name. The value of this variable must be a list of strings. Its | |
82 standard value is @code{(".gz")}. | |
83 | |
84 If the optional argument @var{nosuffix} is non-@code{nil}, then | |
85 @code{load} does not try the suffixes @samp{.elc} and @samp{.el}. In | |
86 this case, you must specify the precise file name you want, except | |
87 that, if Auto Compression mode is enabled, @code{load} will still use | |
88 @code{jka-compr-load-suffixes} to find compressed versions. By | |
89 specifying the precise file name and using @code{t} for | |
90 @var{nosuffix}, you can prevent perverse file names such as | |
91 @file{foo.el.el} from being tried. | |
80 | 92 |
81 If the optional argument @var{must-suffix} is non-@code{nil}, then | 93 If the optional argument @var{must-suffix} is non-@code{nil}, then |
82 @code{load} insists that the file name used must end in either | 94 @code{load} insists that the file name used must end in either |
83 @samp{.el} or @samp{.elc}, unless it contains an explicit directory | 95 @samp{.el} or @samp{.elc} (possibly extended with a compression |
84 name. If @var{filename} does not contain an explicit directory name, | 96 suffix), unless it contains an explicit directory name. |
85 and does not end in a suffix, then @code{load} insists on adding one. | |
86 | 97 |
87 If @var{filename} is a relative file name, such as @file{foo} or | 98 If @var{filename} is a relative file name, such as @file{foo} or |
88 @file{baz/foo.bar}, @code{load} searches for the file using the variable | 99 @file{baz/foo.bar}, @code{load} searches for the file using the variable |
89 @code{load-path}. It appends @var{filename} to each of the directories | 100 @code{load-path}. It appends @var{filename} to each of the directories |
90 listed in @code{load-path}, and loads the first file it finds whose name | 101 listed in @code{load-path}, and loads the first file it finds whose name |
125 @end defun | 136 @end defun |
126 | 137 |
127 @deffn Command load-file filename | 138 @deffn Command load-file filename |
128 This command loads the file @var{filename}. If @var{filename} is a | 139 This command loads the file @var{filename}. If @var{filename} is a |
129 relative file name, then the current default directory is assumed. | 140 relative file name, then the current default directory is assumed. |
130 @code{load-path} is not used, and suffixes are not appended. Use this | 141 This command does not use @code{load-path}, and does not append |
131 command if you wish to specify precisely the file name to load. | 142 suffixes. However, it does look for compressed versions (if Auto |
143 Compression Mode is enabled). Use this command if you wish to specify | |
144 precisely the file name to load. | |
132 @end deffn | 145 @end deffn |
133 | 146 |
134 @deffn Command load-library library | 147 @deffn Command load-library library |
135 This command loads the library named @var{library}. It is equivalent to | 148 This command loads the library named @var{library}. It is equivalent to |
136 @code{load}, except in how it reads its argument interactively. | 149 @code{load}, except in how it reads its argument interactively. |
155 @code{eval-region}. @xref{Definition of eval-region,, Eval}. | 168 @code{eval-region}. @xref{Definition of eval-region,, Eval}. |
156 @end defvar | 169 @end defvar |
157 | 170 |
158 For information about how @code{load} is used in building Emacs, see | 171 For information about how @code{load} is used in building Emacs, see |
159 @ref{Building Emacs}. | 172 @ref{Building Emacs}. |
173 | |
174 @node Load Suffixes | |
175 @section Load Suffixes | |
176 We now describe some technical details about the exact suffixes that | |
177 @code{load} tries. | |
178 | |
179 @defvar load-suffixes | |
180 This is a list of suffixes indicating (compiled or source) Emacs Lisp | |
181 files. It should not include the empty string. @code{load} uses | |
182 these suffixes in order when it appends Lisp suffixes to the specified | |
183 file name. The standard value is @code{(".elc" "el")} which produces | |
184 the behavior described in the previous section. | |
185 @end defvar | |
186 | |
187 @defvar load-file-rep-suffixes | |
188 This is a list of suffixes that indicate representations of the same | |
189 file. This list should normally start with the empty string. | |
190 When @code{load} searches for a file it appends the suffixes in this | |
191 list, in order, to the file name, before searching for another file. | |
192 | |
193 Enabling Auto Compression mode appends the suffixes in | |
194 @code{jka-compr-load-suffixes} to this list and disabling Auto | |
195 Compression mode removes them again. The standard value of | |
196 @code{load-file-rep-suffixes} if Auto Compression mode is disabled is | |
197 @code{("")}. Given that the standard value of | |
198 @code{jka-compr-load-suffixes} is @code{(".gz")}, the standard value | |
199 of @code{load-file-rep-suffixes} if Auto Compression mode is enabled | |
200 is @code{("" ".gz")}. | |
201 @end defvar | |
202 | |
203 @defun get-load-suffixes | |
204 This function returns the list of all suffixes that @code{load} should | |
205 try, in order, when its @var{must-suffix} argument is non-@code{nil}. | |
206 This takes both @code{load-suffixes} and @code{load-file-rep-suffixes} | |
207 into account. If @code{load-suffixes}, @code{jka-compr-load-suffixes} | |
208 and @code{load-file-rep-suffixes} all have their standard values, this | |
209 function returns @code{(".elc" "elc.gz" ".el" ".el.gz")} if Auto | |
210 Compression mode is enabled and @code{(".elc" ".el")} if Auto | |
211 Compression mode is disabled. | |
212 @end defun | |
213 | |
214 To summarize, if both its @var{nosuffix} and @var{must-suffix} | |
215 arguments are @code{nil}, @code{load} first tries the suffixes in the | |
216 return value of @code{get-load-suffixes} and then those in | |
217 @code{load-file-rep-suffixes}. If @var{nosuffix} is non-@code{nil}, | |
218 it only tries the latter and is @var{must-suffix} is non-@code{nil}, | |
219 only the former. | |
160 | 220 |
161 @node Library Search | 221 @node Library Search |
162 @section Library Search | 222 @section Library Search |
163 | 223 |
164 When Emacs loads a Lisp library, it searches for the library | 224 When Emacs loads a Lisp library, it searches for the library |
285 When @code{locate-library} is called from a program, it returns the file | 345 When @code{locate-library} is called from a program, it returns the file |
286 name as a string. When the user runs @code{locate-library} | 346 name as a string. When the user runs @code{locate-library} |
287 interactively, the argument @var{interactive-call} is @code{t}, and this | 347 interactively, the argument @var{interactive-call} is @code{t}, and this |
288 tells @code{locate-library} to display the file name in the echo area. | 348 tells @code{locate-library} to display the file name in the echo area. |
289 @end deffn | 349 @end deffn |
290 | |
291 @defvar load-suffixes | |
292 This variable is a list of suffixes (strings) that @code{load} should | |
293 try adding to the specified file name. The default value is | |
294 @code{(".elc" ".elc.gz" ".el" ".el.gz" ".gz")}. There is no need to | |
295 include the null suffix. | |
296 @end defvar | |
297 | 350 |
298 @node Loading Non-ASCII | 351 @node Loading Non-ASCII |
299 @section Loading Non-@acronym{ASCII} Characters | 352 @section Loading Non-@acronym{ASCII} Characters |
300 | 353 |
301 When Emacs Lisp programs contain string constants with non-@acronym{ASCII} | 354 When Emacs Lisp programs contain string constants with non-@acronym{ASCII} |
360 specifies the file to load to get the real definition of @var{function}. | 413 specifies the file to load to get the real definition of @var{function}. |
361 | 414 |
362 If @var{filename} does not contain either a directory name, or the | 415 If @var{filename} does not contain either a directory name, or the |
363 suffix @code{.el} or @code{.elc}, then @code{autoload} insists on adding | 416 suffix @code{.el} or @code{.elc}, then @code{autoload} insists on adding |
364 one of these suffixes, and it will not load from a file whose name is | 417 one of these suffixes, and it will not load from a file whose name is |
365 just @var{filename} with no added suffix. | 418 just @var{filename} with no added suffix. (The variable |
419 @code{load-suffixes} specifies the exact required suffixes.) | |
366 | 420 |
367 The argument @var{docstring} is the documentation string for the | 421 The argument @var{docstring} is the documentation string for the |
368 function. Specifying the documentation string in the call to | 422 function. Specifying the documentation string in the call to |
369 @code{autoload} makes it possible to look at the documentation without | 423 @code{autoload} makes it possible to look at the documentation without |
370 loading the function's real definition. Normally, this should be | 424 loading the function's real definition. Normally, this should be |
697 | 751 |
698 If the feature is not present, then @code{require} loads @var{filename} | 752 If the feature is not present, then @code{require} loads @var{filename} |
699 with @code{load}. If @var{filename} is not supplied, then the name of | 753 with @code{load}. If @var{filename} is not supplied, then the name of |
700 the symbol @var{feature} is used as the base file name to load. | 754 the symbol @var{feature} is used as the base file name to load. |
701 However, in this case, @code{require} insists on finding @var{feature} | 755 However, in this case, @code{require} insists on finding @var{feature} |
702 with an added suffix; a file whose name is just @var{feature} won't be | 756 with an added @samp{el} or @samp{.elc} suffix (possibly extended with |
703 used. | 757 a compression suffix); a file whose name is just @var{feature} won't |
758 be used. (The variable @code{load-suffixes} specifies the exact | |
759 required Lisp suffixes.) | |
704 | 760 |
705 If @var{noerror} is non-@code{nil}, that suppresses errors from actual | 761 If @var{noerror} is non-@code{nil}, that suppresses errors from actual |
706 loading of the file. In that case, @code{require} returns @code{nil} | 762 loading of the file. In that case, @code{require} returns @code{nil} |
707 if loading the file fails. Normally, @code{require} returns | 763 if loading the file fails. Normally, @code{require} returns |
708 @var{feature}. | 764 @var{feature}. |