Subject: Re: bug#59813: 29.0.60; function-history: M-. fails to jump to defun if straight.el straight-cache-autoloads is enabled

From: Naofumi Yasufuku <[email-masked]>
Date: Wed, 14 Dec 2022 05:20:20 +0900

Hello Stefan,

Stefan Kangas <[email-masked]> writes:
>>
>> M-. fails to jump to defun if autoload forms are evaluated in init.el
>> without `load'; it is the way of straight.el autoloads cache feature
>> (enabled by default):
>>
>>   https://github.com/radian-software/straight.el/blob/master/straight.el
>>
>>   straight--activate-package-autoloads
>>   straight--read-package-autoloads
>
> What makes you think this is a bug in Emacs, and not in straight?
>

I thought that it could be an issue of Emacs-side because:

a) What straight.el does is just `eval' of autoload forms;
b) M-. failure is reproducible without straight.el;
c) Autoloading itself works fine even if autoload forms are evaluated
   without `load';
d) It works well with Emacs <= 28;

> Did you report this to the straight developers first?
>

No, I didn't.  But the following Github issue might be the same:

  C-h f for some functions link to the loading file instead of their source file:
  https://github.com/radian-software/straight.el/issues/1022

I tried to find more simple recipe.  Could you try this with emacs-29
or master?

----------------------------------------
1. Create the following file

~/.emacs.d/site-lisp/loadhist--foo.el

#+begin_src emacs-lisp
(defun loadhist--foo-inc (x) (1+ x))
(provide 'loadhist--foo)
#+end_src

----------------------------------------
2. emacs -Q

----------------------------------------
3. Insert the following to *scratch*

#+begin_src emacs-lisp
(setq load-path (cons (locate-user-emacs-file "site-lisp") load-path))
(autoload 'loadhist--foo-inc "loadhist--foo")
(message "(loadhist--foo-inc 1): %s" (loadhist--foo-inc 1))
#+end_src

----------------------------------------
4. In *scratch*, M-x eval-buffer

----------------------------------------
5. M-. on `loadhist--foo-inc'
=>
xref--not-found-error: No definitions found for: loadhist--foo-inc

----------------------------------------
6. In *scratch*, M-x eval-buffer again

----------------------------------------
5. M-. on `loadhist--foo-inc'
=>
Jumps to defun in ~/.emacs.d/site-lisp/loadhist--foo.el

----------------------------------------

Best regards,
  Naofumi