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))
(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")))
\f
;;; Commands
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))))
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
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)
(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'."