Subject: 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: Thu, 15 Dec 2022 02:24:00 +0900

Hi Eli,

Eli Zaretskii <[email-masked]> writes:

> I'm not sure I understand the issue, and I'm not familiar with
> straight.el, but if the above somehow prevents the function from being
> loaded, it is expected that M-. will fail.  Its ELisp backend works
> only for loaded functions.  If you want it to work for functions that
> aren't loaded, you need to manually switch the backend to etags.
>

The function `loadhist--foo-inc' is definitely loaded by autoload,
but M-. fails to find defun in the source file loadhist--foo.el.

> So if the above scenario worked with Emacs 28, I suggest to check
> whether the function was being loaded with Emacs 28.

I've tried to check the state of load-history (both 28 and 29) and
function-history (29-only).  The following is the difference between
Emacs 28 and 29:

;;==========================================
;; Emacs 28.2.50

;; Step 1: Create ~/.emacs.d/site-lisp/loadhist--foo.el
;;------------------------------------------
;; (defun loadhist--foo-inc (x) (1+ x))
;; (provide 'loadhist--foo)
;;------------------------------------------

;; Step 2: emacs -Q

;; Step 3: In *scratch*, M-x eval-buffer

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

;;------------------------------------------
;; Step 4: Check load-history

(symbol-file 'loadhist--foo-inc 'defun)
=> "/home/naofumi/.emacs.d/site-lisp/loadhist--foo.el"

(let (matches)
  (pcase-dolist (`(,file . ,elems) load-history)
    (when (rassq 'loadhist--foo-inc elems)
      (push (cons file elems) matches)))
  (nreverse matches))
=> ((nil (autoload . loadhist--foo-inc)) ("/home/naofumi/.emacs.d/site-lisp/loadhist--foo.el" (t . loadhist--foo-inc) (defun . loadhist--foo-inc) (provide . loadhist--foo)))

;;==========================================

;;==========================================
;; Emacs 29.0.60

;; Step 1: Create ~/.emacs.d/site-lisp/loadhist--foo.el
;;------------------------------------------
;; (defun loadhist--foo-inc (x) (1+ x))
;; (provide 'loadhist--foo)
;;------------------------------------------

;; Step 2: emacs -Q

;; Step 3: In *scratch*, M-x eval-buffer

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

;;------------------------------------------
;; Step 4: Check load-history and function-history

(symbol-file 'loadhist--foo-inc 'defun)
=> nil

(let (matches)
  (pcase-dolist (`(,file . ,elems) load-history)
    (when (rassq 'loadhist--foo-inc elems)
      (push (cons file elems) matches)))
  (nreverse matches))
=> ((nil (defun . loadhist--foo-inc)) ("/home/naofumi/.emacs.d/site-lisp/loadhist--foo.el" (defun . loadhist--foo-inc) (provide . loadhist--foo)))

(get 'loadhist--foo-inc 'function-history)
=> ("/home/naofumi/.emacs.d/site-lisp/loadhist--foo.el" (autoload "loadhist--foo" nil nil nil))

;;==========================================

Best regaards,
  Naofumi