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

From: Lars Ingebrigtsen <[email-masked]>
Date: Wed, 21 Sep 2022 14:17:48 +0200

Ihor Radchenko <[email-masked]> writes:

>> I'm not at all sure I understand myself.  A backtrace here would be
>> helpful.
>
> Debugger entered--entering a function:
> * message("File mode specification error: %s" (void-function
> org-element-cache-reset))
>   normal-mode(t)
>   after-find-file(nil t)
>   find-file-noselect-1(#<buffer bug.org> "/tmp/bug.org" nil nil
> "/tmp/bug.org" (127741036 26))
>   find-file-noselect("/tmp/bug.org" nil nil t)
>   find-file("/tmp/bug.org" t)
>   funcall-interactively(find-file "/tmp/bug.org" t)
>   command-execute(find-file)
>
> I generated the backtrace using M-x debug-on-entry org-mode and opening
> bug.org. The backtrace appears at the moment I try to step through
> org-element-cache-reset call inside org-mode.

You have some confusing stuff in org.el -- you have a

(declare-function org-element-cache-reset "org-element" (&optional all))

to suppress warnings in org.el about that function, but
org-element-cache-reset should be in org-loaddefs, which org.el loads
already, so it should be unnecessary.

If it isn't unnecessary, then something else is going wrong somewhere,
I'd have thought?  But I haven't tried debugging further.