Emacs generate autoloads

The autoload facility lets you register the existence of a function or macro, but put off loading the file that defines it. The first call to the function automatically loads the proper library, in order to install the real definition and other associated code, then runs the real definition as if it had been loaded all along. Autoloading can also be triggered by looking up the documentation of the function or macro.

A magic autoload comment (often called an autoload cookie) consists of ;;;###autoload, on a line by itself, just before the real definition of the function in its autoloadable source file. 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.

update-file-autoloads

(let ((dotemacs-autoload-file (concat dotemacs-cache-dir "autoloads.el")))
  (update-file-autoloads file1 t dotemacs-autoload-file)
  (update-file-autoloads file2 t dotemacs-autoload-file)
  (update-file-autoloads ...   t dotemacs-autoload-file))

update-directory-autoloads

(let ((generated-autoload-file (concat dotemacs-cache-dir "autoloads.el")))
  (when (not (file-exists-p generated-autoload-file))
    (with-current-buffer (find-file-noselect generated-autoload-file)
      (insert ";;") ;; create the file with non-zero size to appease autoload

      (save-buffer)))
  (mapc #'update-directory-autoloads
        '("" "dir1" "dir2" "dir3")))

Contents

0