From 64f2d346b762a6e3180eba92b5cc96f82f370687 Mon Sep 17 00:00:00 2001 From: Dmitry Gutov Date: Mon, 1 Jun 2015 22:45:15 +0300 Subject: [PATCH] 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. --- lisp/progmodes/elisp-mode.el | 19 ++++++++++++++++++- lisp/progmodes/xref.el | 27 +-------------------------- 2 files changed, 19 insertions(+), 27 deletions(-) diff --git a/lisp/progmodes/elisp-mode.el b/lisp/progmodes/elisp-mode.el index bcbf1d57edc..968bb21f08a 100644 --- a/lisp/progmodes/elisp-mode.el +++ b/lisp/progmodes/elisp-mode.el @@ -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 diff --git a/lisp/progmodes/xref.el b/lisp/progmodes/xref.el index c9bffc6fc6f..3bc66f884eb 100644 --- a/lisp/progmodes/xref.el +++ b/lisp/progmodes/xref.el @@ -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.") -- 2.39.5