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

From: [email-masked] (GNU bug Tracking System)
Date: Fri, 23 Sep 2022 07:15:02 +0000

Your bug report

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

which was filed against the emacs package, has been closed.

The explanation is attached below, along with your original report.
If you require more details, please reply to [email-masked].

-- 
57972: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=57972
GNU Bug Tracking System
Contact [email-masked] with problems

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]>
To: Ihor Radchenko <[email-masked]>, Stefan Monnier <[email-masked]>
Cc: [email-masked]
Date: Fri, 23 Sep 2022 10:14:17 +0300
List-Id: <debbugs-submit.debbugs.gnu.org>

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

Subject: 29.0.50; Autoloaded function raises (void-function org-element-cache-reset) when called within major-mode body
From: Ihor Radchenko <[email-masked]>
To: [email-masked]
Date: Wed, 21 Sep 2022 16:33:39 +0800
List-Id: <debbugs-submit.debbugs.gnu.org>

Hi,

I am forwarding a bug report from Org mode.
https://list.orgmode.org/[email-masked]/T/#u

I am able to reproduce the reported steps (see below) and I find that
the void-function error is raised when calling (org-mode). `org-mode'
body calls `org-element-cache-reset', which should be autoloaded from
org-element.el. Yet, void-function error is raised.

I either misunderstand something about autoload or it is some kind of
Emacs bug.

Steps to reproduce:

https://list.orgmode.org/[email-masked]/T/#u

Org mode version is the latest from
https://git.savannah.gnu.org/cgit/emacs/org-mode.git/

> I ran this:
> dortmann@ddo-linux:.emacs.d$ emacs -Q --debug-init asdf.el
> ... and then ran eval-buffer.
> 
> Where asdf.el has this content:
> (add-to-list 'load-path "/home/dortmann/src/git-org-mode/lisp")
> (require 'org)
> 
> (setq org-capture-templates
>        `(("c" "Item to current clocked task" checkitem
>         (clock)
>         "%i%?" :prepend t :empty-lines 1)))
> 
> Then I loaded asdf.org which has this:
> * TODO start clock on this test item

> These two lines are in my *Messages* buffer:
> File mode specification error: (void-function org-element-cache-reset)
> Error during redisplay: (jit-lock-function 1) signaled (void-variable 
> org-element-citation-prefix-re)

In GNU Emacs 29.0.50 (build 1, x86_64-pc-linux-gnu, GTK+ Version
 3.24.34, cairo version 1.16.0) of 2022-09-07 built on localhost
Repository revision: 473313d2a85a7ae73daf5cc7c205f6285286eecf
Repository branch: master
Windowing system distributor 'The X.Org Foundation', version 11.0.12101004
System Description: Gentoo Linux

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