From 05fb53a16c00bd4067ddd6d6a18c6744b91bd1f2 Mon Sep 17 00:00:00 2001 From: Dmitry Gutov Date: Tue, 20 Jan 2015 04:28:50 +0200 Subject: [PATCH] Use etags-goto-tag-location in etags xref backend * progmodes/etags.el (xref-etags-location): New class. (xref-make-etags-location): New function. (etags--xref-find-definitions): Use it. (xref-location-marker): New method implementation. * lisp/progmodes/xref.el: Mention that xref-location is an EIEIO class. --- lisp/ChangeLog | 9 +++++++++ lisp/progmodes/etags.el | 24 +++++++++++++++++++++--- lisp/progmodes/xref.el | 4 +++- 3 files changed, 33 insertions(+), 4 deletions(-) diff --git a/lisp/ChangeLog b/lisp/ChangeLog index b1a3a73864c..3f7182d50dc 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,12 @@ +2015-01-20 Dmitry Gutov + + * progmodes/etags.el (xref-etags-location): New class. + (xref-make-etags-location): New function. + (etags--xref-find-definitions): Use it. + (xref-location-marker): New method implementation. + + * progmodes/xref.el: Mention that xref-location is an EIEIO class. + 2015-01-19 Dmitry Gutov * ido.el: Update Customization instructions. diff --git a/lisp/progmodes/etags.el b/lisp/progmodes/etags.el index 47b305fb081..dc3380d02f6 100644 --- a/lisp/progmodes/etags.el +++ b/lisp/progmodes/etags.el @@ -2100,17 +2100,35 @@ for \\[find-tag] (which see)." (< (hash-table-count marks) etags--xref-limit)) (when (funcall order-fun pattern) (beginning-of-line) - (cl-destructuring-bind (hint line &rest pos) (etags-snarf-tag) + (pcase-let* ((tag-info (etags-snarf-tag)) + (`(,hint ,line . _) tag-info)) (unless (eq hint t) ; hint==t if we are in a filename line (let* ((file (file-of-tag)) (mark-key (cons file line))) (unless (gethash mark-key marks) - (let ((loc (xref-make-file-location - (expand-file-name file) line 0))) + (let ((loc (xref-make-etags-location + tag-info (expand-file-name file)))) (push (xref-make hint loc) xrefs) (puthash mark-key t marks))))))))))) (nreverse xrefs))) +(defclass xref-etags-location (xref-location) + ((tag-info :type list :initarg :tag-info) + (file :type string :initarg :file + :reader xref-location-group)) + :documentation "Location of an etags tag.") + +(defun xref-make-etags-location (tag-info file) + (make-instance 'xref-etags-location :tag-info tag-info + :file (expand-file-name file))) + +(defmethod xref-location-marker ((l xref-etags-location)) + (with-slots (tag-info file) l + (let ((buffer (find-file-noselect file))) + (with-current-buffer buffer + (etags-goto-tag-location tag-info) + (point-marker))))) + (provide 'etags) diff --git a/lisp/progmodes/xref.el b/lisp/progmodes/xref.el index 12123c8f2e2..536096f612f 100644 --- a/lisp/progmodes/xref.el +++ b/lisp/progmodes/xref.el @@ -34,7 +34,9 @@ ;; ;; One would usually call `make-xref' and `xref-make-file-location', ;; `xref-make-buffer-location' or `xref-make-bogus-location' to create -;; them. +;; them. More generally, a location must be an instance of an EIEIO +;; class inheriting from `xref-location' and implementing +;; `xref-location-group' and `xref-location-marker'. ;; ;; Each identifier must be represented as a string. Implementers can ;; use string properties to store additional information about the -- 2.11.4.GIT