;; xref.el --- Cross-referencing commands -*-lexical-binding:t-*-
-;; Copyright (C) 2014 Free Software Foundation, Inc.
+;; Copyright (C) 2014-2015 Free Software Foundation, Inc.
;; This file is part of GNU Emacs.
(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))
+
+(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)))))
+
\f
;;; Cross-reference
The return value must be a string or nil. nil means no
identifier at point found.
-If it's hard to determinte the identifier precisely (e.g. because
+If it's hard to determine the identifier precisely (e.g., because
it's a method call on unknown type), the implementation can
return a simple string (such as symbol at point) marked with a
special text property which `xref-find-function' would recognize
(xref--pop-to-location loc window)))
(define-derived-mode xref--xref-buffer-mode fundamental-mode "XREF"
- "Mode for displaying cross-refenences."
+ "Mode for displaying cross-references."
(setq buffer-read-only t))
(let ((map xref--xref-buffer-mode-map))
(defun xref--show-xrefs (id kind xrefs window)
(cond
((null xrefs)
- (error "No known %s for: %s" kind id))
+ (user-error "No known %s for: %s" kind id))
((not (cdr xrefs))
(xref-push-marker-stack)
(xref--pop-to-location (xref--xref-location (car xrefs)) window))
;;;###autoload
(defun xref-find-definitions (identifier)
"Find the definition of the identifier at point.
-With prefix argument, prompt for the identifier."
+With prefix argument or when there's no identifier at point,
+prompt for it."
(interactive (list (xref--read-identifier "Find definitions of: ")))
(xref--find-definitions identifier nil))