Mercurial > emacs
comparison lispref/loading.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 |
---|---|
86 | 86 |
87 If you get a warning that @file{foo.elc} is older than @file{foo.el}, it | 87 If you get a warning that @file{foo.elc} is older than @file{foo.el}, it |
88 means you should consider recompiling @file{foo.el}. @xref{Byte | 88 means you should consider recompiling @file{foo.el}. @xref{Byte |
89 Compilation}. | 89 Compilation}. |
90 | 90 |
91 When loading a source file (not compiled), @code{load} performs | |
92 character set translation just as Emacs would do when visiting the file. | |
93 @xref{Coding Systems}. | |
94 | |
91 Messages like @samp{Loading foo...} and @samp{Loading foo...done} appear | 95 Messages like @samp{Loading foo...} and @samp{Loading foo...done} appear |
92 in the echo area during loading unless @var{nomessage} is | 96 in the echo area during loading unless @var{nomessage} is |
93 non-@code{nil}. | 97 non-@code{nil}. |
94 | 98 |
95 @cindex load errors | 99 @cindex load errors |
168 In this example, the path searches the current working directory first, | 172 In this example, the path searches the current working directory first, |
169 followed then by the @file{/user/bil/emacs} directory, the | 173 followed then by the @file{/user/bil/emacs} directory, the |
170 @file{/usr/local/lisplib} directory, and the @file{~/emacs} directory, | 174 @file{/usr/local/lisplib} directory, and the @file{~/emacs} directory, |
171 which are then followed by the standard directories for Lisp code. | 175 which are then followed by the standard directories for Lisp code. |
172 | 176 |
173 The command line options @samp{-l} or @samp{-load} specify a Lisp | |
174 library to load as part of Emacs startup. Since this file might be in | |
175 the current directory, Emacs 18 temporarily adds the current directory | |
176 to the front of @code{load-path} so the file can be found there. Newer | |
177 Emacs versions also find such files in the current directory, but | |
178 without altering @code{load-path}. | |
179 | |
180 Dumping Emacs uses a special value of @code{load-path}. If the value of | 177 Dumping Emacs uses a special value of @code{load-path}. If the value of |
181 @code{load-path} at the end of dumping is unchanged (that is, still the | 178 @code{load-path} at the end of dumping is unchanged (that is, still the |
182 same special value), the dumped Emacs switches to the ordinary | 179 same special value), the dumped Emacs switches to the ordinary |
183 @code{load-path} value when it starts up, as described above. But if | 180 @code{load-path} value when it starts up, as described above. But if |
184 @code{load-path} has any other value at the end of dumping, that value | 181 @code{load-path} has any other value at the end of dumping, that value |
231 | 228 |
232 Normally, the variable's value is @code{nil}, which means those | 229 Normally, the variable's value is @code{nil}, which means those |
233 functions should use @code{read}. | 230 functions should use @code{read}. |
234 @end defvar | 231 @end defvar |
235 | 232 |
236 To learn how @code{load} is used to build Emacs, see @ref{Building Emacs}. | 233 For how @code{load} is used to build Emacs, see @ref{Building Emacs}. |
237 | 234 |
238 @deffn Command locate-library library &optional nosuffix path interactive-call | 235 @deffn Command locate-library library &optional nosuffix path interactive-call |
239 This command finds the precise file name for library @var{library}. It | 236 This command finds the precise file name for library @var{library}. It |
240 searches for the library in the same way @code{load} does, and the | 237 searches for the library in the same way @code{load} does, and the |
241 argument @var{nosuffix} has the same meaning as in @code{load}: don't | 238 argument @var{nosuffix} has the same meaning as in @code{load}: don't |
263 | 260 |
264 There are two ways to set up an autoloaded function: by calling | 261 There are two ways to set up an autoloaded function: by calling |
265 @code{autoload}, and by writing a special ``magic'' comment in the | 262 @code{autoload}, and by writing a special ``magic'' comment in the |
266 source before the real definition. @code{autoload} is the low-level | 263 source before the real definition. @code{autoload} is the low-level |
267 primitive for autoloading; any Lisp program can call @code{autoload} at | 264 primitive for autoloading; any Lisp program can call @code{autoload} at |
268 any time. Magic comments do nothing on their own; they serve as a guide | 265 any time. Magic comments are the most convenient way to make a function |
269 for the command @code{update-file-autoloads}, which constructs calls to | 266 autoload, for packages installed along with Emacs. They do nothing on |
270 @code{autoload} and arranges to execute them when Emacs is built. Magic | 267 their own, but they serve as a guide for the command |
271 comments are the most convenient way to make a function autoload, but | 268 @code{update-file-autoloads}, which constructs calls to @code{autoload} |
272 only for packages installed along with Emacs. | 269 and arranges to execute them when Emacs is built. |
273 | 270 |
274 @defun autoload function filename &optional docstring interactive type | 271 @defun autoload function filename &optional docstring interactive type |
275 This function defines the function (or macro) named @var{function} so as | 272 This function defines the function (or macro) named @var{function} so as |
276 to load automatically from @var{filename}. The string @var{filename} | 273 to load automatically from @var{filename}. The string @var{filename} |
277 specifies the file to load to get the real definition of @var{function}. | 274 specifies the file to load to get the real definition of @var{function}. |
285 function. Normally, this should be identical to the documentation string | 282 function. Normally, this should be identical to the documentation string |
286 in the function definition itself. Specifying the documentation string | 283 in the function definition itself. Specifying the documentation string |
287 in the call to @code{autoload} makes it possible to look at the | 284 in the call to @code{autoload} makes it possible to look at the |
288 documentation without loading the function's real definition. | 285 documentation without loading the function's real definition. |
289 | 286 |
290 If @var{interactive} is non-@code{nil}, then the function can be called | 287 If @var{interactive} is non-@code{nil}, that says @var{function} can be |
291 interactively. This lets completion in @kbd{M-x} work without loading | 288 called interactively. This lets completion in @kbd{M-x} work without |
292 the function's real definition. The complete interactive specification | 289 loading its real definition. The complete interactive specification is |
293 is not given here; it's not needed unless the user actually calls | 290 not given here; it's not needed unless the user actually calls |
294 @var{function}, and when that happens, it's time to load the real | 291 @var{function}, and when that happens, it's time to load the real |
295 definition. | 292 definition. |
296 | 293 |
297 You can autoload macros and keymaps as well as ordinary functions. | 294 You can autoload macros and keymaps as well as ordinary functions. |
298 Specify @var{type} as @code{macro} if @var{function} is really a macro. | 295 Specify @var{type} as @code{macro} if @var{function} is really a macro. |
363 @file{loaddefs.el}. If the form following the magic comment is not a | 360 @file{loaddefs.el}. If the form following the magic comment is not a |
364 function definition, it is copied verbatim. You can also use a magic | 361 function definition, it is copied verbatim. You can also use a magic |
365 comment to execute a form at build time @emph{without} executing it when | 362 comment to execute a form at build time @emph{without} executing it when |
366 the file itself is loaded. To do this, write the form @emph{on the same | 363 the file itself is loaded. To do this, write the form @emph{on the same |
367 line} as the magic comment. Since it is in a comment, it does nothing | 364 line} as the magic comment. Since it is in a comment, it does nothing |
368 when you load the source file; but @code{update-file-autoloads} copies | 365 when you load the source file; but @kbd{M-x update-file-autoloads} |
369 it to @file{loaddefs.el}, where it is executed while building Emacs. | 366 copies it to @file{loaddefs.el}, where it is executed while building |
367 Emacs. | |
370 | 368 |
371 The following example shows how @code{doctor} is prepared for | 369 The following example shows how @code{doctor} is prepared for |
372 autoloading with a magic comment: | 370 autoloading with a magic comment: |
373 | 371 |
374 @smallexample | 372 @smallexample |
398 | 396 |
399 @node Repeated Loading | 397 @node Repeated Loading |
400 @section Repeated Loading | 398 @section Repeated Loading |
401 @cindex repeated loading | 399 @cindex repeated loading |
402 | 400 |
403 You may load one file more than once in an Emacs session. For | 401 You can load one file more than once in an Emacs session. For |
404 example, after you have rewritten and reinstalled a function definition | 402 example, after you have rewritten and reinstalled a function definition |
405 by editing it in a buffer, you may wish to return to the original | 403 by editing it in a buffer, you may wish to return to the original |
406 version; you can do this by reloading the file it came from. | 404 version; you can do this by reloading the file it came from. |
407 | 405 |
408 When you load or reload files, bear in mind that the @code{load} and | 406 When you load or reload files, bear in mind that the @code{load} and |
409 @code{load-library} functions automatically load a byte-compiled file | 407 @code{load-library} functions automatically load a byte-compiled file |
410 rather than a non-compiled file of similar name. If you rewrite a file | 408 rather than a non-compiled file of similar name. If you rewrite a file |
411 that you intend to save and reinstall, you need to byte-compile the new | 409 that you intend to save and reinstall, you need to byte-compile the new |
412 version; otherwise Emacs will load the older, byte-compiled file instead | 410 version; otherwise Emacs will load the older, byte-compiled file instead |
413 of your newer, non-compiled file! If that happens, the message | 411 of your newer, non-compiled file! If that happens, the message |
414 displayed when loading the file says, ``(compiled; source is newer'', to | 412 displayed when loading the file includes, @samp{(compiled; source is |
415 remind you to recompile. | 413 newer)}, to remind you to recompile it. |
416 | 414 |
417 When writing the forms in a Lisp library file, keep in mind that the | 415 When writing the forms in a Lisp library file, keep in mind that the |
418 file might be loaded more than once. For example, think about whether | 416 file might be loaded more than once. For example, think about whether |
419 each variable should be reinitialized when you reload the library; | 417 each variable should be reinitialized when you reload the library; |
420 @code{defvar} does not change the value if the variable is already | 418 @code{defvar} does not change the value if the variable is already |
443 Occasionally you will want to test explicitly whether a library has | 441 Occasionally you will want to test explicitly whether a library has |
444 already been loaded. Here's one way to test, in a library, whether it | 442 already been loaded. Here's one way to test, in a library, whether it |
445 has been loaded before: | 443 has been loaded before: |
446 | 444 |
447 @example | 445 @example |
448 (defvar foo-was-loaded) | 446 (defvar foo-was-loaded nil) |
449 | 447 |
450 (if (not (boundp 'foo-was-loaded)) | 448 (unless foo-was-loaded |
451 @var{execute-first-time-only}) | 449 @var{execute-first-time-only} |
452 | 450 (setq foo-was-loaded t)) |
453 (setq foo-was-loaded t) | |
454 @end example | 451 @end example |
455 | 452 |
456 @noindent | 453 @noindent |
457 If the library uses @code{provide} to provide a named feature, you can | 454 If the library uses @code{provide} to provide a named feature, you can |
458 use @code{featurep} to test whether the library has been loaded. | 455 use @code{featurep} earlier in the file to test whether the |
456 @code{provide} call has been executed before. | |
459 @ifinfo | 457 @ifinfo |
460 @xref{Named Features}. | 458 @xref{Named Features}. |
461 @end ifinfo | 459 @end ifinfo |
462 | 460 |
463 @node Named Features | 461 @node Named Features |
484 already. If not, it loads the feature from the appropriate file. This | 482 already. If not, it loads the feature from the appropriate file. This |
485 file should call @code{provide} at the top level to add the feature to | 483 file should call @code{provide} at the top level to add the feature to |
486 @code{features}; if it fails to do so, @code{require} signals an error. | 484 @code{features}; if it fails to do so, @code{require} signals an error. |
487 @cindex load error with require | 485 @cindex load error with require |
488 | 486 |
489 Features are normally named after the files that provide them, so that | |
490 @code{require} need not be given the file name. | |
491 | |
492 For example, in @file{emacs/lisp/prolog.el}, | 487 For example, in @file{emacs/lisp/prolog.el}, |
493 the definition for @code{run-prolog} includes the following code: | 488 the definition for @code{run-prolog} includes the following code: |
494 | 489 |
495 @smallexample | 490 @smallexample |
496 (defun run-prolog () | 491 (defun run-prolog () |
502 @end smallexample | 497 @end smallexample |
503 | 498 |
504 @noindent | 499 @noindent |
505 The expression @code{(require 'comint)} loads the file @file{comint.el} | 500 The expression @code{(require 'comint)} loads the file @file{comint.el} |
506 if it has not yet been loaded. This ensures that @code{make-comint} is | 501 if it has not yet been loaded. This ensures that @code{make-comint} is |
507 defined. | 502 defined. Features are normally named after the files that provide them, |
503 so that @code{require} need not be given the file name. | |
508 | 504 |
509 The @file{comint.el} file contains the following top-level expression: | 505 The @file{comint.el} file contains the following top-level expression: |
510 | 506 |
511 @smallexample | 507 @smallexample |
512 (provide 'comint) | 508 (provide 'comint) |
539 | 535 |
540 @noindent | 536 @noindent |
541 The compiler ignores the @code{provide}, then processes the | 537 The compiler ignores the @code{provide}, then processes the |
542 @code{require} by loading the file in question. Loading the file does | 538 @code{require} by loading the file in question. Loading the file does |
543 execute the @code{provide} call, so the subsequent @code{require} call | 539 execute the @code{provide} call, so the subsequent @code{require} call |
544 does nothing while loading. | 540 does nothing when the file is loaded. |
545 | 541 |
546 @defun provide feature | 542 @defun provide feature |
547 This function announces that @var{feature} is now loaded, or being | 543 This function announces that @var{feature} is now loaded, or being |
548 loaded, into the current Emacs session. This means that the facilities | 544 loaded, into the current Emacs session. This means that the facilities |
549 associated with @var{feature} are or will be available for other Lisp | 545 associated with @var{feature} are or will be available for other Lisp |
587 provided}. | 583 provided}. |
588 @end defun | 584 @end defun |
589 | 585 |
590 @defun featurep feature | 586 @defun featurep feature |
591 This function returns @code{t} if @var{feature} has been provided in the | 587 This function returns @code{t} if @var{feature} has been provided in the |
592 current Emacs session (i.e., @var{feature} is a member of | 588 current Emacs session (i.e., if @var{feature} is a member of |
593 @code{features}.) | 589 @code{features}.) |
594 @end defun | 590 @end defun |
595 | 591 |
596 @defvar features | 592 @defvar features |
597 The value of this variable is a list of symbols that are the features | 593 The value of this variable is a list of symbols that are the features |
610 @code{unload-feature}: | 606 @code{unload-feature}: |
611 | 607 |
612 @deffn Command unload-feature feature &optional force | 608 @deffn Command unload-feature feature &optional force |
613 This command unloads the library that provided feature @var{feature}. | 609 This command unloads the library that provided feature @var{feature}. |
614 It undefines all functions, macros, and variables defined in that | 610 It undefines all functions, macros, and variables defined in that |
615 library with @code{defconst}, @code{defvar}, @code{defun}, | 611 library with @code{defun}, @code{defalias}, @code{defsubst}, |
616 @code{defmacro}, @code{defsubst} and @code{defalias}. It then restores | 612 @code{defmacro}, @code{defconst}, @code{defvar}, and @code{defcustom}. |
617 any autoloads formerly associated with those symbols. (Loading | 613 It then restores any autoloads formerly associated with those symbols. |
618 saves these in the @code{autoload} property of the symbol.) | 614 (Loading saves these in the @code{autoload} property of the symbol.) |
619 | 615 |
620 Ordinarily, @code{unload-feature} refuses to unload a library on which | 616 Ordinarily, @code{unload-feature} refuses to unload a library on which |
621 other loaded libraries depend. (A library @var{a} depends on library | 617 other loaded libraries depend. (A library @var{a} depends on library |
622 @var{b} if @var{a} contains a @code{require} for @var{b}.) If the | 618 @var{b} if @var{a} contains a @code{require} for @var{b}.) If the |
623 optional argument @var{force} is non-@code{nil}, dependencies are | 619 optional argument @var{force} is non-@code{nil}, dependencies are |
684 outside use), and (2) call the library's functions. If you wish to | 680 outside use), and (2) call the library's functions. If you wish to |
685 do (1), you can do it immediately---there is no need to wait for when | 681 do (1), you can do it immediately---there is no need to wait for when |
686 the library is loaded. To do (2), you must load the library (preferably | 682 the library is loaded. To do (2), you must load the library (preferably |
687 with @code{require}). | 683 with @code{require}). |
688 | 684 |
689 But it is ok to use @code{eval-after-load} in your personal customizations | 685 But it is OK to use @code{eval-after-load} in your personal |
690 if you don't feel they must meet the design standards of programs to be | 686 customizations if you don't feel they must meet the design standards for |
691 released. | 687 programs meant for wider use. |
692 | 688 |
693 @defvar after-load-alist | 689 @defvar after-load-alist |
694 An alist of expressions to evaluate if and when particular libraries are | 690 An alist of expressions to evaluate if and when particular libraries are |
695 loaded. Each element looks like this: | 691 loaded. Each element looks like this: |
696 | 692 |