Subject: bug#54343: 28.0.91; find-function goes to a wrong place for erc

From: "J.P." <[email-masked]>
Date: Fri, 11 Mar 2022 16:16:44 -0800

Hi Jian,

Lin Jian <[email-masked]> writes:

> steps to reproduce this bug:
>
> step 1: run: emacs -Q
> step 2: eval (find-function 'erc)
> step 3: the point goes to the defgroup of erc instead of the cl-defun of
> it, which I think is wrong
>
> wasamasa at #emacs:libera.chat helps to verify that this bug happens on
> the master of emacs on March 11, 2022.
>
> erc version is 5.4

Thanks for reporting this. I guess I felt obliged to say something since
ERC is in the subject line. But it looks like this bug affects more than
just ERC, so I'm going to cowardly defer to the experts here, if that's
all right.

But just as a dumb experiment, adding something like

  (let ((find-function-regexp
         (rx bol
             (* (syntax -))
             "("
             (? "cl-") ; <~~~~~~~~~~~~~~~~ THIS
             "def"
             (| (| "ine-skeleton"
                   "ine-generic-mode"
                   "ine-derived-mode"
                   "ine"
                   (? "-global")
                   "-minor-mode"
                   "ine-compilation-mode"
                   "un-cvs-mode"
                   "foo"
                   (: (| (not (any "icfgv")) (: "g" (not ?r)))
                      (| (+ word) (syntax symbol))
                      (? ?*)))
                (: "easy-mmode-define-" (+ (in (?a . ?z) ?-)))
                "easy-menu-define"
                "menu-bar-make-toggle"
                "menu-bar-make-toggle-command")
             (+ (| (syntax -) "\n" (: ";" (* nonl) "\n")))
             (: (? (| ?' "(quote ")) "%s" (| (syntax -) eol (in "()"))))))
    (find-function 'erc))

seems to work with emacs -Q. (That rx form is bogus, BTW; it doesn't
retain the capture groups and probably has other bugs.)

Anyway, naively splicing in the "cl-" prefix part doesn't seem to break
test/lisp/emacs-lisp/find-func-tests.el, but I didn't look closely
enough to see if that even factors in to the existing coverage. I also
have no clue whether such an addition might put a noticeable strain on
folks using `find-function-search-for-symbol' heavily in lisp code. If
so, another option might be to include it in the fallback regexp[1]
instead.

Hopefully someone in the know will chime in.

Thanks again!

[1] https://git.savannah.gnu.org/cgit/emacs.git/tree/lisp/emacs-lisp/find-func.el?id=0470a4a9#n442