Where should I add autoload cookies in my Emacs Lisp package? Is there a definitive guide?

ぃ、小莉子 提交于 2019-12-14 01:25:23

问题


I maintain a somewhat popular Emacs package (ido-ubiquitous), and I would like to add the ;;;###autoload comments to my package so that it does not need to be loaded until its mode is activated. I attempted this a while ago with the same package, and it resulted in a number of cryptic errors that only occurred when the package was autoloaded, so I removed all the autoload stuff and the problems went away. I'd like to try again, but only if I can find definitive documentation on how to do it so I don't end up introducing the same bugs again.

So is there a definitive guide to adding autoload cookies to an Emacs Lisp package?

EDIT: Looking at my Git logs for my package, I see a couple of commits referring to autoloads:

  • 283f9e9 Remove unnecessary autoloads
  • 66b782f Autoload default values of override variables
  • f6086e5 Autoload fix
  • 0eed206 Remove unnecessary autoload cookie

These commits show that I was really not sure what to add autoloads to. In particular, f6086e5 and 66b782f shows that I thought I should autoload custom variables, and concluded that I also needed to autoload the defconst forms that defined their default values. If I recall correctly, this was in response to a void-variable error because the autoloaded defcustom didn't have access to the non-autoloaded default value (issue link). Finally, in 283f9e9 I had a vision of the future and took Stefan's advice by removing all autoloads except for the one on the minor mode definition.


回答1:


The ;;;###autoload cookies simply mark code which needs to be lifted into a <pkg>-autoloads.el file. This file is then loaded eagerly on startup, but that can be done quickly because it's a much smaller file. So you typically only need such a cookie on the few main entry points. E.g. I'd start by only putting one such cookie on ido-ubiquitous-mode.




回答2:


The documentation for autoloading is here:

C-hig (elisp) Autoload RET

Are you able to give any details on the errors you encountered?



来源:https://stackoverflow.com/questions/20084176/where-should-i-add-autoload-cookies-in-my-emacs-lisp-package-is-there-a-definit

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!