0

I have seen the use of ;;;###autoload when defining minor modes. Why do some modes define foo-enable and foo-disable, and could be the purpose of ;;;###autoload before all of them ?

;;;###autoload
(define-minor-mode foo-minor-mode
  "Enhances visibility of heading levels and text emphasis."
  :lighter " Foo"
  (do-this)
  (do-that)
)

;;;###autoload
(defun foo-enable ()
  "Enables `foo-minor-mode'."
  (foo-minor-mode 1))

;;;###autoload
(defun foo-disable ()
  "Disables `foo-minor-mode'."
  (foo-minor-mode 0))
1

1 Answer 1

0

Emacs defers loading of large portion of elisp code in emacs packages until it's called by the user. It's an optimization technique that speeds up start up times. On start you can only call these ;;;###autoload functions (functions that have ;;;###autoload header in the code) and they call the rest of the packaged code.

It is expected that the package authors will follow this conventions (and it's usually the case...).

From the manual:

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

4
  • What are the customary functions that would require ;;;###autoload. Besides the aforementioned for foo-minor-mode. Would a function that adds hooks to specific major modes would also benefit from ;;;###autoload ?
    – Dilna
    Jun 9, 2023 at 19:00
  • From what I've seen all interactive functions that you want to provide to the user when emacs starts fall under this category and as you mentioned all "enable", "start" and "major/minor-mode"-like functions. Jun 9, 2023 at 19:14
  • The functions with autoload are not loaded except when called. Why are the other functions related to the minor mode not autoloaded as well ? Would one not want to load them except on demand too ?
    – Dilna
    Jun 9, 2023 at 19:53
  • Someone may need to correct me on this, but I think that there may be more advanced techniques to expose functions to the user other than the ;;;###autoload header, but by default it seems like the package authors need to choose which functions to expose on start explicitely. I agree though that this can get confusing when a function in some .el file doesn't initially show up in emacs. Jun 9, 2023 at 20:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.