28
28
29
29
(require 'ring )
30
30
(require 'button )
31
+ (require 'xref )
31
32
32
33
;;;### autoload
33
34
(defvar tags-file-name nil
@@ -141,11 +142,8 @@ Otherwise, `find-tag-default' is used."
141
142
:group 'etags
142
143
:type '(choice (const nil ) function))
143
144
144
- (defcustom find-tag-marker-ring-length 16
145
- " Length of marker rings `find-tag-marker-ring' and `tags-location-ring' ."
146
- :group 'etags
147
- :type 'integer
148
- :version " 20.3" )
145
+ (define-obsolete-variable-alias 'find-tag-marker-ring-length
146
+ 'xref-marker-ring-length " 25.1" )
149
147
150
148
(defcustom tags-tag-face 'default
151
149
" Face for tags in the output of `tags-apropos' ."
@@ -182,15 +180,18 @@ Example value:
182
180
(sexp :tag " Tags to search" )))
183
181
:version " 21.1" )
184
182
185
- (defvar find-tag-marker-ring (make-ring find-tag-marker-ring-length)
186
- " Ring of markers which are locations from which \\ [find-tag] was invoked." )
183
+ (defvaralias 'find-tag-marker-ring 'xref--marker-ring )
184
+ (make-obsolete-variable
185
+ 'find-tag-marker-ring
186
+ " use `xref-push-marker-stack' or `xref-pop-marker-stack' instead."
187
+ " 25.1" )
187
188
188
189
(defvar default-tags-table-function nil
189
190
" If non-nil, a function to choose a default tags file for a buffer.
190
191
This function receives no arguments and should return the default
191
192
tags table file to use for the current buffer." )
192
193
193
- (defvar tags-location-ring (make-ring find-tag -marker-ring-length)
194
+ (defvar tags-location-ring (make-ring xref -marker-ring-length)
194
195
" Ring of markers which are locations visited by \\ [find-tag].
195
196
Pop back to the last location with \\ [negative-argument] \\ [find-tag]." )
196
197
@@ -713,15 +714,13 @@ Returns t if it visits a tags table, or nil if there are no more in the list."
713
714
(interactive )
714
715
; ; Clear out the markers we are throwing away.
715
716
(let ((i 0 ))
716
- (while (< i find-tag -marker-ring-length)
717
+ (while (< i xref -marker-ring-length)
717
718
(if (aref (cddr tags-location-ring) i)
718
719
(set-marker (aref (cddr tags-location-ring) i) nil ))
719
- (if (aref (cddr find-tag-marker-ring) i)
720
- (set-marker (aref (cddr find-tag-marker-ring) i) nil ))
721
720
(setq i (1+ i))))
721
+ (xref-clear-marker-stack )
722
722
(setq tags-file-name nil
723
- tags-location-ring (make-ring find-tag-marker-ring-length)
724
- find-tag-marker-ring (make-ring find-tag-marker-ring-length)
723
+ tags-location-ring (make-ring xref-marker-ring-length)
725
724
tags-table-list nil
726
725
tags-table-computed-list nil
727
726
tags-table-computed-list-for nil
@@ -780,6 +779,7 @@ tags table and its (recursively) included tags tables."
780
779
(quit (message " Tags completion table construction aborted. " )
781
780
(setq tags-completion-table nil )))))
782
781
782
+ ;;;### autoload
783
783
(defun tags-lazy-completion-table ()
784
784
(let ((buf (current-buffer )))
785
785
(lambda (string pred action )
@@ -898,7 +898,7 @@ See documentation of variable `tags-file-name'."
898
898
; ; Run the user's hook. Do we really want to do this for pop?
899
899
(run-hooks 'local-find-tag-hook ))))
900
900
; ; Record whence we came.
901
- (ring-insert find-tag- marker-ring ( point-marker ) )
901
+ (xref-push- marker-stack )
902
902
(if (and next-p last-tag)
903
903
; ; Find the same table we last used.
904
904
(visit-tags-table-buffer 'same )
@@ -954,7 +954,6 @@ See documentation of variable `tags-file-name'."
954
954
(switch-to-buffer buf)
955
955
(error (pop-to-buffer buf)))
956
956
(goto-char pos)))
957
- ;;;### autoload (define-key esc-map "." 'find-tag)
958
957
959
958
;;;### autoload
960
959
(defun find-tag-other-window (tagname &optional next-p regexp-p )
@@ -995,7 +994,6 @@ See documentation of variable `tags-file-name'."
995
994
; ; the window's point from the buffer.
996
995
(set-window-point (selected-window ) tagpoint))
997
996
window-point)))
998
- ;;;### autoload (define-key ctl-x-4-map "." 'find-tag-other-window)
999
997
1000
998
;;;### autoload
1001
999
(defun find-tag-other-frame (tagname &optional next-p )
@@ -1020,7 +1018,6 @@ See documentation of variable `tags-file-name'."
1020
1018
(interactive (find-tag-interactive " Find tag other frame: " ))
1021
1019
(let ((pop-up-frames t ))
1022
1020
(find-tag-other-window tagname next-p)))
1023
- ;;;### autoload (define-key ctl-x-5-map "." 'find-tag-other-frame)
1024
1021
1025
1022
;;;### autoload
1026
1023
(defun find-tag-regexp (regexp &optional next-p other-window )
@@ -1044,25 +1041,10 @@ See documentation of variable `tags-file-name'."
1044
1041
; ; We go through find-tag-other-window to do all the display hair there.
1045
1042
(funcall (if other-window 'find-tag-other-window 'find-tag )
1046
1043
regexp next-p t ))
1047
- ;;;### autoload (define-key esc-map [?\C-.] 'find-tag-regexp)
1048
-
1049
- ;;;### autoload (define-key esc-map "*" 'pop-tag-mark)
1050
1044
1051
1045
;;;### autoload
1052
- (defun pop-tag-mark ()
1053
- " Pop back to where \\ [find-tag] was last invoked.
1046
+ (defalias 'pop-tag-mark 'xref-pop-marker-stack )
1054
1047
1055
- This is distinct from invoking \\ [find-tag] with a negative argument
1056
- since that pops a stack of markers at which tags were found, not from
1057
- where they were found."
1058
- (interactive )
1059
- (if (ring-empty-p find-tag-marker-ring)
1060
- (error " No previous locations for find-tag invocation " ))
1061
- (let ((marker (ring-remove find-tag-marker-ring 0 )))
1062
- (switch-to-buffer (or (marker-buffer marker)
1063
- (error " The marked buffer has been deleted " )))
1064
- (goto-char (marker-position marker))
1065
- (set-marker marker nil nil )))
1066
1048
1067
1049
(defvar tag-lines-already-matched nil
1068
1050
" Matches remembered between calls." ) ; Doc string: calls to what?
@@ -1859,7 +1841,6 @@ nil, we exit; otherwise we scan the next file."
1859
1841
(and messaged
1860
1842
(null tags-loop-operate)
1861
1843
(message " Scanning file %s ...found " buffer-file-name))))
1862
- ;;;### autoload (define-key esc-map "," 'tags-loop-continue)
1863
1844
1864
1845
;;;### autoload
1865
1846
(defun tags-search (regexp &optional file-list-form )
@@ -2077,6 +2058,54 @@ for \\[find-tag] (which see)."
2077
2058
(completion-in-region (car comp-data) (cadr comp-data)
2078
2059
(nth 2 comp-data)
2079
2060
(plist-get (nthcdr 3 comp-data) :predicate )))))
2061
+
2062
+
2063
+ ; ;; Xref backend
2064
+
2065
+ ; ; Stop searching if we find more than xref-limit matches, as the xref
2066
+ ; ; infrastracture is not designed to handle very long lists.
2067
+ ; ; Switching to some kind of lazy list might be better, but hopefully
2068
+ ; ; we hit the limit rarely.
2069
+ (defconst etags--xref-limit 1000 )
2070
+
2071
+ ;;;### autoload
2072
+ (defun etags-xref-find (action id )
2073
+ (pcase action
2074
+ (`definitions (etags--xref-find-definitions id))
2075
+ (`apropos (etags--xref-find-definitions id t ))))
2076
+
2077
+ (defun etags--xref-find-definitions (pattern &optional regexp? )
2078
+ ; ; This emulates the behaviour of `find-tag-in-order' but instead of
2079
+ ; ; returning one match at a time all matches are returned as list.
2080
+ ; ; NOTE: find-tag-tag-order is typically a buffer-local variable.
2081
+ (let* ((xrefs '())
2082
+ (first-time t )
2083
+ (search-fun (if regexp? #'re-search-forward #'search-forward ))
2084
+ (marks (make-hash-table :test 'equal ))
2085
+ (case-fold-search (if (memq tags-case-fold-search '(nil t ))
2086
+ tags-case-fold-search
2087
+ case-fold-search)))
2088
+ (save-excursion
2089
+ (while (visit-tags-table-buffer (not first-time))
2090
+ (setq first-time nil )
2091
+ (dolist (order-fun (cond (regexp? find-tag-regexp-tag-order)
2092
+ (t find-tag-tag-order)))
2093
+ (goto-char (point-min ))
2094
+ (while (and (funcall search-fun pattern nil t )
2095
+ (< (hash-table-count marks) etags--xref-limit))
2096
+ (when (funcall order-fun pattern)
2097
+ (beginning-of-line )
2098
+ (cl-destructuring-bind (hint line &rest pos) (etags-snarf-tag )
2099
+ (unless (eq hint t ) ; hint==t if we are in a filename line
2100
+ (let* ((file (file-of-tag ))
2101
+ (mark-key (cons file line)))
2102
+ (unless (gethash mark-key marks)
2103
+ (let ((loc (xref-make-file-location
2104
+ (expand-file-name file) line 0 )))
2105
+ (push (xref-make hint loc) xrefs)
2106
+ (puthash mark-key t marks)))))))))))
2107
+ (nreverse xrefs)))
2108
+
2080
2109
2081
2110
(provide 'etags )
2082
2111
0 commit comments