Subject: Re: bug#57972: 29.0.50; Autoloaded function raises (void-function org-element-cache-reset) when called within major-mode body

From: Stefan Monnier <[email-masked]>
Date: Fri, 23 Sep 2022 17:13:50 -0400

>> Side question: Could you point me towards documentation on how to
>> properly do autoloading in Emacs packages? Maybe Org is doing things
>> wrongly?
>
> I think Org basically does what other packages do, which is explicitly
> load the *-loaddefs.el in some central place.  I don't think we have
> any magic anywhere to do that any other way.

Indeed, that's the usual way (except for the weird (eq
this-command 'eval-buffer):

    % grep '(\(load\|require\).*-loaddefs' **/*.el
    lisp/calc/calc.el:(load "calc-loaddefs.el" nil t)
    lisp/calendar/calendar.el:(load "cal-loaddefs" nil t)
    lisp/calendar/diary-lib.el:(eval-and-compile (load "diary-loaddefs" nil t))
    lisp/calendar/holidays.el:(load "holiday-loaddefs" nil t)
    lisp/dired.el:(require 'dired-loaddefs nil t)
    lisp/emacs-lisp/cl-lib.el:(unless (load "cl-loaddefs" 'noerror 'quiet)
    lisp/erc/erc.el:(load "erc-loaddefs" 'noerror 'nomessage)
    lisp/ibuffer.el:(require 'ibuffer-loaddefs)
    lisp/mh-e/mh-e.el:(require 'mh-loaddefs)
    lisp/net/tramp-cache.el:(require 'tramp-loaddefs)
    lisp/net/tramp.el:(require 'tramp-loaddefs)
    lisp/ps-print.el:(require 'ps-print-loaddefs)
    lisp/textmodes/reftex.el:(require 'reftex-loaddefs)
    lisp/textmodes/texinfo.el:(require 'texinfo-loaddefs)
    %

-- Stefan