Maintaining Emacs autoload files for user-installed elisp?
Asked Answered
S

2

9

Emacs has this seemingly very nice facility for building autoload files based on magic source code comments ("autoload cookies") of the form ;;;###autoload, which are to be placed on lines by themselves immediately above each definition to be autoloaded; see (elisp)Autoload.

This would seem to be an ideal tool for maintaining autoloads for those little one-file packages that Emacs users inevitably end up installing in their profiles. There's just one small problem: this facility (in GNU Emacs, anyway) appears to be almost entirely focused on generating the loaddefs.el file for Emacs itself, with very little (if any) concession to other uses.

This doesn't stop largish packages from using the autoloads.el machinery to build their own autoload files, but those that I've looked at have a fair bit of rather hairy code devoted to making it do what is needed, though some of the hairiness might be due to GNU Emacs/XEmacs divergence.

(I think XEmacs is a bit better on this front, probably due at least in part to the fact that its official package system uses this machinery to make separate autoload files for each package. Hopefully GNU Emacs' inclusion of the ELPA package system, which also uses this machinery, leads to similar improvements on their side.)

So, my question for you is:

How should I maintain an autoload file for all .el files in a directory, assuming they have all the necessary ;;;###autoload comments (autoload cookies) in place already?

[Hmm. block quotes look a lot coolor on tex.SE...]

I'm currently using GNU Emacs 23.2.1, though the farther back an answer works, the better. (For that matter, it'd be nice if it would also work with XEmacs.)

I'm on Windows, but have MSYS installed alongside Emacs so sh/bash scripts will probably be fine as long as they don't call anything terribly exotic.

[I'm not entirely certain this doesn't belong on superuser rather than on SO. If there is already a package that can take care of this with only a small amount of configuration, it probably does; on the other hand if (as I suspect) there are only fairly rough snippets of code that might require a good deal of direct changes, I think it probably belongs here on SO.]

Salol answered 5/1, 2011 at 19:36 Comment(1)
Huh, it seems that someone other than me has favorited this but not upvoted it: 2 users have favorited it (one of which is me, I think), but there are no votes at all. I wonder why that is — forgetfulness?Salol
T
2

Check out this answer to "emacs23 / elisp: how to properly autoload this library?".

In summary, you dump all the packages in a particular directory, and create a package of your own update-auto-loads.el, which builds the loaddefs.el and provides a function you can regularly run to rebuild the loaddefs.el file whenever you want.

Transpicuous answered 5/1, 2011 at 19:43 Comment(0)
B
0

In 2017, you don't have to maintain it yourself. Instead, you can use a modern package manager such as straight.el which is specifically designed to take care of this (as well as many other things) for you.

You could use package.el instead of straight.el, but package.el has a number of serious problems, and a particularly relevant one is that it's very awkward to get package.el to load a local package you've written yourself, and in particular package.el has absolutely no support for making modifications to a package once it's been installed.

You could use other package managers, as well. I wrote an extensive section comparing straight.el to other package managers.

Bosporus answered 9/8, 2017 at 17:30 Comment(2)
"it's very awkward to get package.el to load a local package you've written yourself" ... erm, no, it isn't; in fact it's incredibly easy: M-x package-install-fileTahiti
@Tahiti Then you have to re-run that command every time you make a modification to the file, and furthermore you have to jump through hoops when using M-x find-function and friends in order to make sure you are editing the real file, and not the copy that package.el created. I do not call this easy.Bosporus

© 2022 - 2024 — McMap. All rights reserved.