Move xref-elisp-location to elisp-mode.el

* lisp/progmodes/xref.el (xref-elisp-location)
(xref-make-elisp-location, xref-location-marker): Remove here.
(xref--xref): Don't limit the type of the location slot.

* lisp/progmodes/elisp-mode.el (xref-elisp-location):
Define as a cl-struct here.
(xref-location-marker): Move here.
This commit is contained in:
Dmitry Gutov 2015-06-01 22:45:15 +03:00
parent 98cb43fb0d
commit 64f2d346b7
2 changed files with 19 additions and 27 deletions

View file

@ -579,7 +579,6 @@ It can be quoted, or be inside a quoted form."
;;; Xref backend
(declare-function xref-make-elisp-location "xref" (symbol type file))
(declare-function xref-make-bogus-location "xref" (message))
(declare-function xref-make "xref" (description location))
(declare-function xref-collect-matches "xref" (input dir &optional kind))
@ -697,6 +696,24 @@ It can be quoted, or be inside a quoted form."
(defun elisp--xref-identifier-completion-table ()
elisp--xref-identifier-completion-table)
(cl-defstruct (xref-elisp-location
(:constructor xref-make-elisp-location (symbol type file)))
"Location of an Emacs Lisp symbol definition."
symbol type file)
(cl-defmethod xref-location-marker ((l xref-elisp-location))
(pcase-let (((cl-struct xref-elisp-location symbol type file) l))
(let ((buffer-point
(pcase type
(`defun (find-function-search-for-symbol symbol nil file))
((or `defvar `defface)
(find-function-search-for-symbol symbol type file))
(`feature
(cons (find-file-noselect file) 1)))))
(with-current-buffer (car buffer-point)
(goto-char (or (cdr buffer-point) (point-min)))
(point-marker)))))
;;; Elisp Interaction mode
(defvar lisp-interaction-mode-map

View file

@ -143,38 +143,13 @@ actual location is not known.")
(cl-defmethod xref-location-group ((_ xref-bogus-location)) "(No location)")
;; This should be in elisp-mode.el, but it's preloaded, and we can't
;; preload defclass and defmethod (at least, not yet).
(defclass xref-elisp-location (xref-location)
((symbol :type symbol :initarg :symbol)
(type :type symbol :initarg :type)
(file :type string :initarg :file
:reader xref-location-group))
:documentation "Location of an Emacs Lisp symbol definition.")
(defun xref-make-elisp-location (symbol type file)
(make-instance 'xref-elisp-location :symbol symbol :type type :file file))
(cl-defmethod xref-location-marker ((l xref-elisp-location))
(with-slots (symbol type file) l
(let ((buffer-point
(pcase type
(`defun (find-function-search-for-symbol symbol nil file))
((or `defvar `defface)
(find-function-search-for-symbol symbol type file))
(`feature
(cons (find-file-noselect file) 1)))))
(with-current-buffer (car buffer-point)
(goto-char (or (cdr buffer-point) (point-min)))
(point-marker)))))
;;; Cross-reference
(defclass xref--xref ()
((description :type string :initarg :description
:reader xref--xref-description)
(location :type xref-location :initarg :location
(location :initarg :location
:reader xref--xref-location))
:comment "An xref is used to display and locate constructs like
variables or functions.")