Subject: bug#61640: closed (Re: bug#61640: 30.0.50; Help Elisp xref recognize defclass parent classes)

From: [email-masked] (GNU bug Tracking System)
Date: Mon, 20 Feb 2023 01:06:02 +0000

Your bug report

#61640: 30.0.50; Help Elisp xref recognize defclass parent classes

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

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

Subject: Re: bug#61640: 30.0.50; Help Elisp xref recognize defclass parent classes
From: Dmitry Gutov <[email-masked]>
To: Eric Abrahamsen <[email-masked]>
Cc: [email-masked]
Date: Mon, 20 Feb 2023 03:05:31 +0200
List-Id: <debbugs-submit.debbugs.gnu.org>

Version: 30.1

On 20/02/2023 01:45, Eric Abrahamsen wrote:
> Shouldn't this instead be an addition to `elisp-mode-infer-namespace',
> like with p8 below?
> 
>    (elisp-mode-test--with-buffer
>        (concat "(list {p1}alpha {p2}beta)\n"
>                "(progn {p3}gamma {p4}delta)\n"
>                "(lambda ({p5}epsilon {p6}zeta) {p7}eta)\n"
>                "(defclass child-class (parent-1 {p8}parent-2)\n")
>      (should (equal (elisp--xref-infer-namespace p1) 'variable))
>      (should (equal (elisp--xref-infer-namespace p2) 'variable))
>      (should (equal (elisp--xref-infer-namespace p3) 'variable))
>      (should (equal (elisp--xref-infer-namespace p4) 'variable))
>      (should (equal (elisp--xref-infer-namespace p5) 'variable))
>      (should (equal (elisp--xref-infer-namespace p6) 'variable))
>      (should (equal (elisp--xref-infer-namespace p7) 'variable))
>      (should (equal (elisp--xref-infer-namespace p8) 'function)))
> 
> Obviously just guessing here...

It seems you're right, thanks.

I've put the test case separately and pushed the combined change to 
master, commit cac13e36054.

That fixes the bug in my testing, but please do tell if something else 
comes up.

Subject: 30.0.50; Help Elisp xref recognize defclass parent classes
From: Eric Abrahamsen <[email-masked]>
To: [email-masked]
Date: Sun, 19 Feb 2023 14:08:42 -0800
List-Id: <debbugs-submit.debbugs.gnu.org>

In a form such as this:

(defclass ebdb-field-id (ebdb-field-labeled ebdb-field-obfuscated ebdb-field-user)
  ((label-list :initform 'ebdb-id-label-list)
   ...
   ))

All the symbols in

(ebdb-field-labeled ebdb-field-obfuscated ebdb-field-user)

should be recognized by `elisp--xref-infer-namespace' as 'function.
Right now, this is treated like a function call (ie like '(function
variable variable)).

I can't promise that the attached patch is exactly the right thing, but
it ought to be pretty close.

Thanks,
Eric

diff --git a/lisp/progmodes/elisp-mode.el b/lisp/progmodes/elisp-mode.el
index 1c339d08148..f7cd9e90926 100644
--- a/lisp/progmodes/elisp-mode.el
+++ b/lisp/progmodes/elisp-mode.el
@@ -943,6 +943,10 @@ elisp--xref-infer-namespace
                                  cl-defmethod cl-defgeneric)))
             ;; (defun FUNC (... IDENT
             'variable)
+           ((and (eql j 2)
+                 (eq j-head 'defclass))
+            ;; (defclass CLASS (... IDENT
+            'function)
            ((eq j-head 'cond)
             ;; (cond ... (... IDENT
             'variable)