2

Given a variable or a function symbol not currently bound, what would be the variable that holds the auto-loading association I could use to search for the symbol and find out what file would get loaded when it is invoked?

2

You can use symbol-function to get the function associated with a symbol. If the function hasn’t been loaded yet, then this will be a list starting with the symbol autoload rather than an actual function object. The other elements in this list mean other things; in particular, the second element of the list is the name of the file to load. For example, if you run (symbol-function '5x5), you may see something like this:

(autoload "5x5" 810998 t nil)

autoloadp will check that first element and return t if it is 'autoload, but as far as I know the rest of the elements don’t have named accessor functions. Just use cadr or second or (nth 2 …) or whatever you prefer.

3
  • Aside from telling if the symbol is autoloaded, the info in the list does not include the name of the file that will be loaded, or something that could be used to identify it, does it?
    – PRouleau
    Sep 16 at 11:15
  • 1
    @PRouleau The file name is the second element of the list. It's just the base name: Emacs will decide the full path when the loading happens, based on the value of load-path and the presence of files on the system at that time. The logic that load uses to search through the load path and add extensions isn't exposed as a separate function. Sep 16 at 21:01
  • Ahh.. I thought it was the name of the function... I should have known . I just looked it up. Thanks!!
    – PRouleau
    Sep 16 at 21:10
0

Neither variable nor function. Autoloads are defined in (one or more) files. The default file for this is loaddefs.el, provided with Emacs.

This is explained in the Elisp manual, node Autoload:

The command M-x update-file-autoloads writes a corresponding autoload call into loaddefs.el. (The string that serves as the autoload cookie and the name of the file generated by update-file-autoloads can be changed from the above defaults, see below.) Building Emacs loads loaddefs.el and thus calls autoload. M-x update-directory-autoloads is even more powerful; it updates autoloads for all files in the current directory.

So you can have autoloads in any file you like, if you generate (or update) the file. Packages can provide an autoloads file as part of their recipe, for example. But the main - the default - autoloads file is loaddefs.el.


If you or some program has never updated loaddefs.el then it is no doubt in the state in which it was delivered as part of Emacs.

If you install some packages then likely associated autoloads files exist for some of them, and those autoload files are loaded when you install those packages.

Then, when you invoke something that's autoloaded via one of those autoload files, the associated package gets loaded.

If you know the package of some object (function, var, or other) you're interested in, then look for that package's autoloads file (e.g. in the package's directory). It contains the autoload associations you're asking about (for that package).


On the other hand, if you just want to know if something is an autoload object (function or variable or sexp), use predicate autoloadp.

2
  • I start Emacs and look at generated-autoload-file and it's nil. The loadefs.el is loaded but that file is old, it was most probably created when I installed that instance of Emacs. I can find out that a symbol is autoloaded with autoloadp but I'd like to find out what file will be loaded for it. Why? Because I'm checking the validity of minor-mode activated by a hook for a major-mode and want to detect if it is a local minor-mode or a global minor-mode. The local-variable-p will always return nil if the mode variable is not loaded yet.
    – PRouleau
    Sep 15 at 23:03
  • I updated the answer to mention autoloads files for packages. If you or some program has not updated loaddefs.el then it will be in the state in which it was delivered as part of Emacs. If you install packages then likely associated autoloads files exist for some of them, and those autoload files are loaded when you install those packages. Then, when you invoke something that's autoloaded via one of those files, the associated package is loaded. If you know the package of the object (function, var, or other) then look for that package's autoloads file (e.g. in the package's directory).
    – Drew
    Sep 16 at 2:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.