From: Eshel Yaron Date: Thu, 27 Jun 2024 19:18:16 +0000 (+0200) Subject: Cease using etags as a default Xref backend X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=d56e6281c0c598a35224305e54748132454c7412;p=emacs.git Cease using etags as a default Xref backend --- diff --git a/lisp/progmodes/xref.el b/lisp/progmodes/xref.el index eacb2ea8f5c..abc7d7a3fc7 100644 --- a/lisp/progmodes/xref.el +++ b/lisp/progmodes/xref.el @@ -241,11 +241,6 @@ and should return either nil to mean that it is not applicable, or an xref backend, which is a value to be used to dispatch the generic functions.") -;; We make the etags backend the default for now, until something -;; better comes along. Use APPEND so that any `add-hook' calls made -;; before this package is loaded put new items before this one. -(add-hook 'xref-backend-functions #'etags--xref-backend t) - ;;;###autoload (defun xref-find-backend () (run-hook-with-args-until-success 'xref-backend-functions)) @@ -1658,34 +1653,23 @@ The meanings of both arguments are the same as documented in (memq command xref-prompt-for-identifier)))) (defun xref--read-identifier (prompt) - "Return the identifier at point or read it from the minibuffer." - (let* ((backend (xref-find-backend)) - (def (xref-backend-identifier-at-point backend)) - (completion-ignore-case - (xref-backend-identifier-completion-ignore-case backend))) - (cond ((or current-prefix-arg - (not def) - (xref--prompt-p this-command)) - (let ((id - (completing-read - ;; `format-prompt' is new in Emacs 28.1 - (if (fboundp 'format-prompt) - (format-prompt (substring prompt 0 (string-match - "[ :]+\\'" prompt)) - def) - (if def - (format "%s (default %s): " - (substring prompt 0 (string-match - "[ :]+\\'" prompt)) - def) - prompt)) - (xref-backend-identifier-completion-table backend) - nil nil nil - 'xref--read-identifier-history def t))) - (if (equal id "") - (or def (user-error "No default identifier")) - id))) - (t def)))) + "Return the identifier at point or prompt for it with PROMPT." + (if-let* ((backend (xref-find-backend))) + (let ((def (xref-backend-identifier-at-point backend)) + (completion-ignore-case + (xref-backend-identifier-completion-ignore-case backend))) + (cond ((or current-prefix-arg (not def) (xref--prompt-p this-command)) + (let ((id + (completing-read + (format-prompt prompt def) + (xref-backend-identifier-completion-table backend) + nil nil nil + 'xref--read-identifier-history def t))) + (if (string-empty-p id) + (user-error "You didn't specify an identifier") + id))) + (t def))) + (user-error "No Xref backend available"))) ;;; Commands @@ -1740,7 +1724,7 @@ The fetcher function returns a list of xrefs, and sets It revisits the saved position and delegates the finding logic to the xref backend method indicated by KIND and passes ARG to it." - (xref-make-fetcher (xref-find-backend) + (xref-make-fetcher (or (xref-find-backend) (error "No Xref backend found")) input kind arg (current-buffer) (copy-marker (point)))) @@ -1760,19 +1744,19 @@ Otherwise, display the list of the possible definitions in a buffer where the user can select from the list. Use \\[xref-go-back] to return back to where you invoked this command." - (interactive (list (xref--read-identifier "Find definitions of: "))) + (interactive (list (xref--read-identifier "Find definitions of"))) (xref--find-definitions identifier nil)) ;;;###autoload (defun xref-find-definitions-other-window (identifier) "Like `xref-find-definitions' but switch to the other window." - (interactive (list (xref--read-identifier "Find definitions of: "))) + (interactive (list (xref--read-identifier "Find definitions of"))) (xref--find-definitions identifier 'window)) ;;;###autoload (defun xref-find-definitions-other-frame (identifier) "Like `xref-find-definitions' but switch to the other frame." - (interactive (list (xref--read-identifier "Find definitions of: "))) + (interactive (list (xref--read-identifier "Find definitions of"))) (xref--find-definitions identifier 'frame)) ;;;###autoload @@ -1783,7 +1767,7 @@ offering the symbol at point as the default. With prefix argument, or if `xref-prompt-for-identifier' is t, always prompt for the identifier. If `xref-prompt-for-identifier' is nil, prompt only if there's no usable symbol at point." - (interactive (list (xref--read-identifier "Find references of: "))) + (interactive (list (xref--read-identifier "Find references of"))) (xref--find-xrefs identifier 'references identifier nil)) (defun xref-find-references-and-replace (from to) @@ -1846,15 +1830,7 @@ output of this command when the backend is etags." (xref-backend-identifier-at-point (xref-find-backend))))) (require 'apropos) - (let* ((newpat - (if (and (version< emacs-version "28.0.50") - (memq (xref-find-backend) '(elisp etags))) - ;; Handle backends in older Emacs. - (xref-apropos-regexp pattern) - ;; Delegate pattern handling to the backend fully. - ;; The old way didn't work for "external" backends. - pattern))) - (xref--find-xrefs pattern 'apropos newpat nil))) + (xref--find-xrefs pattern 'apropos pattern nil)) (defun xref-apropos-regexp (pattern) "Return an Emacs regexp from PATTERN similar to `apropos'."