Function: etags--xref-find-definitions

etags--xref-find-definitions is a byte-compiled function defined in etags.el.gz.

Signature

(etags--xref-find-definitions PATTERN &optional REGEXP?)

Source Code

;; Defined in /usr/src/emacs/lisp/progmodes/etags.el.gz
(defun etags--xref-find-definitions (pattern &optional regexp?)
  ;; This emulates the behavior of `find-tag-in-order' but instead of
  ;; returning one match at a time all matches are returned as list.
  ;; NOTE: find-tag-tag-order is typically a buffer-local variable.
  (let* ((xrefs '())
         (first-time t)
         (search-fun (if regexp? #'re-search-forward #'search-forward))
         (marks (make-hash-table :test 'equal))
         (case-fold-search (find-tag--completion-ignore-case))
         (cbuf (current-buffer)))
    (save-excursion
      (while (visit-tags-table-buffer (not first-time) cbuf)
        (setq first-time nil)
        (dolist (order-fun (cond (regexp? find-tag-regexp-tag-order)
                                 (t etags-xref-find-definitions-tag-order)))
          (goto-char (point-min))
          (while (and (funcall search-fun pattern nil t)
                      (< (hash-table-count marks) etags--xref-limit))
            (when (funcall order-fun pattern)
              (beginning-of-line)
              (pcase-let* ((tag-info (etags-snarf-tag))
                           (`(,hint ,line . _) tag-info))
                (let* ((file (etags--ensure-file (file-of-tag)))
                       (mark-key (cons file line)))
                  (unless (gethash mark-key marks)
                    (let ((loc (xref-make-etags-location
                                tag-info (expand-file-name file))))
                      (push (xref-make (if (eq hint t) "(filename match)" hint)
                                       loc)
                            xrefs)
                      (puthash mark-key t marks))))))))))
    (nreverse xrefs)))