Go to the first, previous, next, last section, table of contents.


Autoloading

Instead of installing a function by loading the file that contains it, or by evaluating the function definition, you can make the function available but not actually install it until it is first called. This is called autoloading.

When you execute an autoloaded function, Emacs automatically evaluates the file that contains the definition, and then calls the function.

Emacs starts quicker with autoloaded functions, since their libraries are not loaded right away; but you need to wait a moment when you first use such a function, while its containing file is evaluated.

Rarely used functions are frequently autoloaded. The `loaddefs.el' library contains hundreds of autoloaded functions, from bookmark-set to wordstar-mode. Of course, you may come to use a `rare' function frequently. In this case, you should load that function's file with a load expression in your `.emacs' file.

In my `.emacs' file for Emacs version 19.23, I load 17 libraries that contain functions that would otherwise be autoloaded. (Actually, it would have been better to include these files in my `dumped' Emacs when I built it, but I forgot. See section `Building Emacs' in The GNU Emacs Lisp Reference Manual, and the `INSTALL' file for more about dumping.)

You may also want to include autoloaded expressions in your `.emacs' file. autoload is a built-in function that takes up to five arguments, the final three of which are optional. The first argument is the name of the function to be autoloaded; the second is the name of the file to be loaded. The third argument is documentation for the function, and the fourth tells whether the function can be called interactively. The fifth argument tells what type of object---autoload can handle a keymap or macro as well as a function (the default is a function).

Here is a typical example:

(autoload 'html-helper-mode
  "html-helper-mode" "Edit HTML documents" t)

This expression autoloads the html-helper-mode function from the `html-helper-mode.el' file (or, if it exists, from the byte compiled file `html-helper-mode.elc'.) The file must be located in a directory specified by load-path. The documentation says that this is a mode to help you edit documents written in the HyperText Markup Language. You can call this mode interactively by typing M-x html-helper-mode. (You need to duplicate the function's regular documentation in the autoload expression because the regular function is not yet loaded, so its documentation is not available.)

See section `Autoload' in The GNU Emacs Lisp Reference Manual, for more information.


Go to the first, previous, next, last section, table of contents.