4

I have installed number of packages using elpa, and wanted to appropriately generate autoloads for them. To that end, i added to my init file:

(apply 'update-directory-autoloads (directory-files package-user-dir t "[^\.].*"))

However, i get failures with the following backtrace:

Debugger entered--Lisp error: (wrong-type-argument stringp nil)
  expand-file-name(nil "/build/buildd/emacs24-24.3+1/debian/build-x/lisp")
  autoload-generated-file()
  autoload-find-generated-file()
  update-directory-autoloads("/home/survivor/.emacs.d/elpa/ahg-20140818.130")
  eval((update-directory-autoloads "/home/survivor/.emacs.d/elpa/ahg-20140818.130") nil)
  eval-last-sexp-1(nil)
  eval-last-sexp(nil)
  call-interactively(eval-last-sexp nil nil)

Is the way i am trying to do this wrong? Should i just put require for every of my packages?

Rainer Joswig
  • 136,269
  • 10
  • 221
  • 346
Srv19
  • 3,458
  • 6
  • 44
  • 75
  • 1
    Unless you're doing something special, you shouldn't need to generate autoloads for ELPA packages. This is done automatically during package installation. – legoscia Oct 14 '14 at 10:05
  • You probably need to add `(package-initialize)` to your `init.el`, though, to actually load package autoloads for use in your `init.el`. –  Oct 14 '14 at 14:45

3 Answers3

7

You can use package-generate-autoloads:

(package-generate-autoloads "async" "~/.emacs.d/elpa/async-1.9.3/")

It calls update-directory-autoloads internally. I found it useful in case you manually replace an already installed package with a different release, and want to generate its autoloads the same way package.el does on installation.

See also this question: https://emacs.stackexchange.com/questions/33627/how-to-generate-and-activate-autoloads-for-local-packages/41274

Andreas Raster
  • 642
  • 7
  • 9
3

TL;DR: You likely need to add (package-initialize) to your init file.

You do not need to generate autoloads for your packages. The package manager does that automatically upon installation. You'll find the corresponding -autoloads.el files in the package directories of your ~/.emacs.d/elpa/ directory.

You also do not need to require every package. Like every other Emacs Lisp file, however, the autoload files of installed packages need to be loaded (confusing, I know) before the autoload declarations contained therein are available.

The Emacs package manager automatically loads the autoloads file of a package, when it “activates” a package. Emacs also automatically initializes the package manager and activates all installed packages, but only after your init.el was processed.

Hence, packages (and this their autoloads as well) are not available while your init.el is loaded, so you can't use packages in your init.el.

To address this, you can either postpone all your setup to after-init-hook, or force Emacs to initialize the package manager by adding (package-initialize) at the top of your init file.

  • Srv19: See also http://stackoverflow.com/questions/11127109/emacs-24-package-system-initialization-problems – phils Oct 15 '14 at 10:57
  • BTW, in Emacs-27 we have changed this so that `package-initialize` is called *before* loading `~/.emacs`. – Stefan Apr 30 '18 at 12:59
2
  1. I think that installing a package should take care of autoloads, at least those declared in the package itself (i.e., autoloads to be generated). (I could be wrong about this. Someone will correct me, if so.)

  2. Your error message comes from generated-autoload-file being nil. You need to set it to specify the output file to use. See the doc string of update-directory-autoloads.

Drew
  • 29,895
  • 7
  • 74
  • 104