3

I've added some autoloads to PACKAGE with the ;;;###autoload cookie and I've run M-x update-directory-autoloads which generated PACKAGE-autoloads.el. I have the following form in my init:

(package-initialize)

;; ...
;; some stuff that needs package.el to be initialized
;; ...

(use-package PACKAGE
  :init nil
  :load-path "~/path/to/PACKAGE"
  :defer t)

What can I use as the :init form to load the autoloads as package.el would? I'm assuming package.el loads the autoloads for every directory in load-path upon activation and before each package is require'd, but perhaps this is in an incorrect assumption. This excerpt from package.el is what leads me to believe this is so:

;; At activation time we will set up the load-path and the info path,
;; and we will load the package's autoloads.  If a package's
;; dependencies are not available, we will not activate that package.

;; Conceptually a package has multiple state transitions:
;;
;; * Download.  Fetching the package from ELPA.
;; * Install.  Untar the package, or write the .el file, into
;;   ~/.emacs.d/elpa/ directory.
;; * Autoload generation.
;; * Byte compile.  Currently this phase is done during install,
;;   but we may change this.
;; * Activate.  Evaluate the autoloads for the package to make it
;;   available to the user.
;; * Load.  Actually load the package and run some code from it.
Basil
  • 12,019
  • 43
  • 69
Sean Allred
  • 6,861
  • 16
  • 85
  • 1
    If you are trying to emulate `package.el`, why not just place your `PACKAGE` in `package-user-dir` instead and have `package.el` activate it along with all your other packages for you? – Basil Jan 15 '18 at 14:52

1 Answers1

3

What can I use as the :init form to load the autoloads as package.el would?

(with-demoted-errors "Error loading autoloads: %s"
  (load "~/path/to/PACKAGE/PACKAGE-autoloads" nil t))

Refer to the function package--activate-autoloads-and-load-path.

I'm assuming package.el loads the autoloads for every directory in load-path upon activation and before each package is require'd, but perhaps this is in an incorrect assumption.

package.el does indeed go through various directories loading autoloads files, but these directories are determined by package-user-dir and package-directory-list, not load-path. In fact, package.el updates load-path as it goes along; otherwise the autoloads loaded wouldn't work when invoked.

The autoloads of built-in packages are handled when Emacs is built/installed, and are already loaded on startup, even without package-initialize. Keep in mind that package.el is a package manager for external packages, not those which ship with Emacs proper.

Basil
  • 12,019
  • 43
  • 69