]> code.delx.au - gnu-emacs/blobdiff - lisp/progmodes/xref.el
Update copyright year to 2015
[gnu-emacs] / lisp / progmodes / xref.el
index 30d28ffe4c9fdd0c3731a8d0c266bf69ba1b5ffe..a5ff5ee55ad8a5389747ea9c6f8ec5d0e2cd3ea1 100644 (file)
@@ -1,6 +1,6 @@
 ;; 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.
 
@@ -136,6 +136,31 @@ actual location is not known.")
 
 (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
 
@@ -187,7 +212,7 @@ To create an xref object, call `xref-make'.")
 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
@@ -348,7 +373,7 @@ WINDOW controls how the buffer is displayed:
     (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))
@@ -414,7 +439,7 @@ Return an alist of the form ((FILENAME . (XREF ...)) ...)."
 (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))
@@ -442,7 +467,8 @@ Return an alist of the form ((FILENAME . (XREF ...)) ...)."
 ;;;###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))