aboutsummaryrefslogtreecommitdiffstats
path: root/lisp
diff options
context:
space:
mode:
authorStephen Leake2015-08-11 14:28:17 -0500
committerStephen Leake2015-08-11 14:29:34 -0500
commit85f7e5115f9f409126d355997e8103ea5126ada2 (patch)
treea70e6c131fa45969de0efd7dca0eca681581f7df /lisp
parent6171d5b1f9edb09ca43c219f08e7a372de8740b2 (diff)
downloademacs-85f7e5115f9f409126d355997e8103ea5126ada2.tar.gz
emacs-85f7e5115f9f409126d355997e8103ea5126ada2.zip
elisp--xref-find-definitions handle cl-defstuct default constructor
* lisp/progmodes/elisp-mode.el (elisp-xref-find): Add FIXME. (elisp--xref-format-extra): Rename from elisp--xref-format-cl-defmethod. (elisp--xref-find-definitions): Handle cl-defstuct default constructor. * test/automated/elisp-mode-tests.el (xref-elisp-test-run): Split out from xref-elisp-test for ease of debugging. (xref-elisp-deftest): Rename from xref-elisp-test. (find-defs-constructor): New test. (find-defs-defgeneric-el): Match batch test config. (compile): Required for find-defs compilation-minor-mode test. (find-defs-defvar-el): Match code change. (find-defs-face-el): Match code change. * lisp/progmodes/xref.el (xref-find-function, xref-find-definitions): Improve doc string.
Diffstat (limited to 'lisp')
-rw-r--r--lisp/progmodes/elisp-mode.el25
-rw-r--r--lisp/progmodes/xref.el15
2 files changed, 34 insertions, 6 deletions
diff --git a/lisp/progmodes/elisp-mode.el b/lisp/progmodes/elisp-mode.el
index 41ca57f668d..7ac5a5cb778 100644
--- a/lisp/progmodes/elisp-mode.el
+++ b/lisp/progmodes/elisp-mode.el
@@ -590,6 +590,10 @@ It can be quoted, or be inside a quoted form."
590 590
591(defun elisp-xref-find (action id) 591(defun elisp-xref-find (action id)
592 (require 'find-func) 592 (require 'find-func)
593 ;; FIXME: use information in source near point to filter results:
594 ;; (dvc-log-edit ...) - exclude 'feature
595 ;; (require 'dvc-log-edit) - only 'feature
596 ;; Semantic may provide additional information
593 (pcase action 597 (pcase action
594 (`definitions 598 (`definitions
595 (let ((sym (intern-soft id))) 599 (let ((sym (intern-soft id)))
@@ -606,7 +610,7 @@ It can be quoted, or be inside a quoted form."
606 (put-text-property 4 6 'face 'font-lock-function-name-face str) 610 (put-text-property 4 6 'face 'font-lock-function-name-face str)
607 str)) 611 str))
608 612
609(defconst elisp--xref-format-cl-defmethod 613(defconst elisp--xref-format-extra
610 (let ((str "(%s %s %s)")) 614 (let ((str "(%s %s %s)"))
611 (put-text-property 1 3 'face 'font-lock-keyword-face str) 615 (put-text-property 1 3 'face 'font-lock-keyword-face str)
612 (put-text-property 4 6 'face 'font-lock-function-name-face str) 616 (put-text-property 4 6 'face 'font-lock-function-name-face str)
@@ -675,7 +679,7 @@ otherwise build the summary from TYPE and SYMBOL."
675 679
676 (when (fboundp symbol) 680 (when (fboundp symbol)
677 (let ((file (find-lisp-object-file-name symbol (symbol-function symbol))) 681 (let ((file (find-lisp-object-file-name symbol (symbol-function symbol)))
678 generic) 682 generic doc)
679 (when file 683 (when file
680 (cond 684 (cond
681 ((eq file 'C-source) 685 ((eq file 'C-source)
@@ -684,11 +688,26 @@ otherwise build the summary from TYPE and SYMBOL."
684 ;; Second call will return "src/*.c" in file; handled by 't' case below. 688 ;; Second call will return "src/*.c" in file; handled by 't' case below.
685 (push (elisp--xref-make-xref nil symbol (help-C-file-name (symbol-function symbol) 'subr)) xrefs)) 689 (push (elisp--xref-make-xref nil symbol (help-C-file-name (symbol-function symbol) 'subr)) xrefs))
686 690
691 ((and (setq doc (documentation symbol t))
692 ;; This doc string is defined in cl-macs.el cl-defstruct
693 (string-match "Constructor for objects of type `\\(.*\\)'" doc))
694 ;; `symbol' is a name for the default constructor created by
695 ;; cl-defstruct, so return the location of the cl-defstruct.
696 (let* ((type-name (match-string 1 doc))
697 (type-symbol (intern type-name))
698 (file (find-lisp-object-file-name type-symbol 'define-type))
699 (summary (format elisp--xref-format-extra
700 'cl-defstruct
701 (concat "(" type-name)
702 (concat "(:constructor " (symbol-name symbol) "))"))))
703 (push (elisp--xref-make-xref 'define-type type-symbol file summary) xrefs)
704 ))
705
687 ((setq generic (cl--generic symbol)) 706 ((setq generic (cl--generic symbol))
688 (dolist (method (cl--generic-method-table generic)) 707 (dolist (method (cl--generic-method-table generic))
689 (let* ((info (cl--generic-method-info method)) 708 (let* ((info (cl--generic-method-info method))
690 (met-name (cons symbol (cl--generic-method-specializers method))) 709 (met-name (cons symbol (cl--generic-method-specializers method)))
691 (descr (format elisp--xref-format-cl-defmethod 'cl-defmethod symbol (nth 1 info))) 710 (descr (format elisp--xref-format-extra 'cl-defmethod symbol (nth 1 info)))
692 (file (find-lisp-object-file-name met-name 'cl-defmethod))) 711 (file (find-lisp-object-file-name met-name 'cl-defmethod)))
693 (when file 712 (when file
694 (push (elisp--xref-make-xref 'cl-defmethod met-name file descr) xrefs)) 713 (push (elisp--xref-make-xref 'cl-defmethod met-name file descr) xrefs))
diff --git a/lisp/progmodes/xref.el b/lisp/progmodes/xref.el
index 68f6cfffd2a..b0a8eb7a316 100644
--- a/lisp/progmodes/xref.el
+++ b/lisp/progmodes/xref.el
@@ -202,8 +202,10 @@ LOCATION is an `xref-location'."
202It can be called in several ways: 202It can be called in several ways:
203 203
204 (definitions IDENTIFIER): Find definitions of IDENTIFIER. The 204 (definitions IDENTIFIER): Find definitions of IDENTIFIER. The
205result must be a list of xref objects. If no definitions can be 205result must be a list of xref objects. If IDENTIFIER contains
206found, return nil. 206sufficient information to determine a unique definition, returns
207only that definition. If there are multiple possible definitions,
208return all of them. If no definitions can be found, return nil.
207 209
208 (references IDENTIFIER): Find references of IDENTIFIER. The 210 (references IDENTIFIER): Find references of IDENTIFIER. The
209result must be a list of xref objects. If no references can be 211result must be a list of xref objects. If no references can be
@@ -751,7 +753,14 @@ Return an alist of the form ((FILENAME . (XREF ...)) ...)."
751(defun xref-find-definitions (identifier) 753(defun xref-find-definitions (identifier)
752 "Find the definition of the identifier at point. 754 "Find the definition of the identifier at point.
753With prefix argument or when there's no identifier at point, 755With prefix argument or when there's no identifier at point,
754prompt for it." 756prompt for it.
757
758If the backend has sufficient information to determine a unique
759definition for IDENTIFIER, it returns only that definition. If
760there are multiple possible definitions, it returns all of them.
761
762If the backend returns one definition, jump to it; otherwise,
763display the list in a buffer."
755 (interactive (list (xref--read-identifier "Find definitions of: "))) 764 (interactive (list (xref--read-identifier "Find definitions of: ")))
756 (xref--find-definitions identifier nil)) 765 (xref--find-definitions identifier nil))
757 766