From fbe7fb054755b9bfe1375691d3c774cb84236859 Mon Sep 17 00:00:00 2001 From: Dmitry Gutov Date: Tue, 5 May 2015 15:11:14 +0300 Subject: [PATCH] Only skip some variables that have function counterparts * lisp/progmodes/elisp-mode.el (elisp--xref-identifier-location): Only skip minor-mode-named variable if it's defined in a Lisp file, and it's in minor-mode-list (bug#20506). * test/automated/elisp-mode-tests.el (elisp-xref-finds-both-function-and-variable) (elisp-xref-finds-only-function-for-minor-mode): New tests. --- lisp/progmodes/elisp-mode.el | 16 ++++++++++------ test/automated/elisp-mode-tests.el | 24 ++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 6 deletions(-) diff --git a/lisp/progmodes/elisp-mode.el b/lisp/progmodes/elisp-mode.el index 40561515ed2..f085dcfbef3 100644 --- a/lisp/progmodes/elisp-mode.el +++ b/lisp/progmodes/elisp-mode.el @@ -604,12 +604,16 @@ It can be quoted, or be inside a quoted form." (setq sym (car fun-lib)) (cdr fun-lib)))) (`defvar (and (boundp sym) - ;; Don't show minor modes twice. - ;; TODO: If TYPE ever becomes dependent on the - ;; context, move this check outside. - (not (fboundp sym)) - (or (symbol-file sym 'defvar) - (help-C-file-name sym 'var)))) + (let ((el-file (symbol-file sym 'defvar))) + (if el-file + (and + ;; Don't show minor modes twice. + ;; TODO: If TYPE ever becomes dependent on the + ;; context, move this check outside. + (not (and (fboundp sym) + (memq sym minor-mode-list))) + el-file) + (help-C-file-name sym 'var))))) (`feature (and (featurep sym) ;; Skip when a function with the same name ;; is defined, because it's probably in the diff --git a/test/automated/elisp-mode-tests.el b/test/automated/elisp-mode-tests.el index bfecfe7dc6b..7af6dfcdc03 100644 --- a/test/automated/elisp-mode-tests.el +++ b/test/automated/elisp-mode-tests.el @@ -22,6 +22,9 @@ ;;; Code: (require 'ert) +(require 'xref) + +;;; Completion (defun elisp--test-completions () (let ((data (elisp-completion-at-point))) @@ -101,5 +104,26 @@ (should (member "backup-buffer" comps)) (should-not (member "backup-inhibited" comps))))) +;;; Navigation + +(ert-deftest elisp-xref-finds-both-function-and-variable () + ;; "system-name" is both: a variable and a function + (let ((defs (elisp-xref-find 'definitions "system-name"))) + (should (= (length defs) 2)) + (should (string= (xref--xref-description (nth 0 defs)) + "(defun system-name)")) + (should (string= (xref--xref-description (nth 1 defs)) + "(defvar system-name)"))) + ;; It's a minor mode, but the variable is defined in buffer.c + (let ((defs (elisp-xref-find 'definitions "abbrev-mode"))) + (should (= (length defs) 2)))) + +(ert-deftest elisp-xref-finds-only-function-for-minor-mode () + ;; Both variable and function are defined in the same place. + (let ((defs (elisp-xref-find 'definitions "visible-mode"))) + (should (= (length defs) 1)) + (should (string= (xref--xref-description (nth 0 defs)) + "(defun visible-mode)")))) + (provide 'elisp-mode-tests) ;;; elisp-mode-tests.el ends here -- 2.11.4.GIT