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

From: Ihor Radchenko <[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).

Side question: Could you point me towards documentation on how to
properly do autoloading in Emacs packages? Maybe Org is doing things
wrongly?

-- 
Ihor Radchenko,
Org mode contributor,
Learn more about Org mode at https://orgmode.org/.
Support Org development at https://liberapay.com/org-mode,
or support my work at https://liberapay.com/yantar92