Skip to content

Commit

Permalink
Fix xref elisp identifier namespace mistake
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mattiase committed Oct 18, 2021
1 parent c163fd9 commit bb4209a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lisp/progmodes/elisp-mode.el
Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions test/lisp/progmodes/elisp-mode-tests.el
Expand Up @@ -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"
Expand Down

0 comments on commit bb4209a

Please sign in to comment.