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

From: Eli Zaretskii <[email-masked]>
Date: Fri, 23 Sep 2022 10:14:17 +0300

> From: Ihor Radchenko <[email-masked]>
> Cc: [email-masked]
> Date: Fri, 23 Sep 2022 10:10:32 +0800
> 
> Eli Zaretskii <[email-masked]> writes:
> 
> >   (or (eq this-command 'eval-buffer)  <<<<<<<<<<<<<<<<<<<<<
> >       (condition-case nil
> > 	  (load (concat (file-name-directory load-file-name)
> > 			"org-loaddefs")
> > 		nil t nil t)
> > 	(error
> > 	 (message "WARNING: No org-loaddefs.el file could be found from where org.el is loaded.")
> > 	 (sit-for 3)
> > 	 (message "You need to run \"make\" or \"make autoloads\" from Org lisp directory")
> > 	 (sit-for 3))))
> >
> > explicitly avoids loading org-loaddefs.el if org.el was loaded via
> > eval-buffer.  Which is exactly the case here, isn't it, and explains
> > why the loaddefs aren't loaded?
> >
> > So now the question becomes: why does org.el treat eval-buffer in this
> > special way?  Perhaps because of byte-compilation or something?
> 
> I have no clue. I will ask Bastien (he authored this piece of code).
> 
> I hence see this Emacs bug report as resolved (it is not an Emacs bug).

Thanks, so I'm closing this bug.

> 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.

Lars, Stefan: am I missing something?