From: Mattias EngdegÄrd Date: Mon, 18 Oct 2021 15:06:22 +0000 (+0200) Subject: Fix xref elisp identifier namespace mistake X-Git-Tag: emacs-28.0.90~259 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=bb4209a5a5337f9c09c4ebb2a65415a41361d8da;p=emacs.git Fix xref elisp identifier namespace mistake Pressing `M-.` on ALPHA in (let ((ALPHA BETA)) ...) would incorrectly search for ALPHA as a function rather than a variable. * lisp/progmodes/elisp-mode.el (elisp--xref-infer-namespace): Fix logic. * test/lisp/progmodes/elisp-mode-tests.el (elisp-mode-infer-namespace): Add test case. --- diff --git a/lisp/progmodes/elisp-mode.el b/lisp/progmodes/elisp-mode.el index 10a37942571..9522055670d 100644 --- a/lisp/progmodes/elisp-mode.el +++ b/lisp/progmodes/elisp-mode.el @@ -877,17 +877,17 @@ namespace but with lower confidence." ;; ^ index K ^ index J ^ index I (let* ((i (elisp--xref-list-index)) (i-head (looking-at-sym)) - (i-paren (and i-head (eq (char-before) ?\() + (i-paren (and i (eq (char-before) ?\() (progn (backward-char) t))) (i-quoted (and i-paren (memq (char-before) '(?\' ?`)))) (j (and i-paren (elisp--xref-list-index))) (j-head (and j (looking-at-sym))) - (j-paren (and j-head (eq (char-before) ?\() + (j-paren (and j (eq (char-before) ?\() (progn (backward-char) t))) (j-quoted (and j-paren (memq (char-before) '(?\' ?`)))) (k (and j-paren (elisp--xref-list-index))) (k-head (and k (looking-at-sym))) - (k-paren (and k-head (eq (char-before) ?\() + (k-paren (and k (eq (char-before) ?\() (progn (backward-char) t))) (k-quoted (and k-paren (memq (char-before) '(?\' ?`))))) (cond diff --git a/test/lisp/progmodes/elisp-mode-tests.el b/test/lisp/progmodes/elisp-mode-tests.el index 400c76c187f..f887bb1dca5 100644 --- a/test/lisp/progmodes/elisp-mode-tests.el +++ b/test/lisp/progmodes/elisp-mode-tests.el @@ -976,6 +976,17 @@ evaluation of BODY." (should (equal (elisp--xref-infer-namespace p6) 'maybe-variable)) (should (equal (elisp--xref-infer-namespace p7) 'variable))) + (elisp-mode-test--with-buffer + (concat "(let (({p1}alpha {p2}beta)\n" + " ({p3}gamma ({p4}delta {p5}epsilon)))\n" + " ({p6}zeta))\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) 'function)) + (should (equal (elisp--xref-infer-namespace p5) 'maybe-variable)) + (should (equal (elisp--xref-infer-namespace p6) 'function))) + (elisp-mode-test--with-buffer (concat "(defun {p1}alpha () {p2}beta)\n" "(defface {p3}gamma ...)\n"