Function: xref-show-definitions-completing-read
xref-show-definitions-completing-read is a byte-compiled function
defined in xref.el.gz.
Signature
(xref-show-definitions-completing-read FETCHER ALIST)
Documentation
Let the user choose the target definition with completion.
When there is more than one definition, let the user choose between them by typing in the minibuffer with completion.
Probably introduced at or before Emacs version 28.1.
Aliases
xref--show-defs-minibuffer (obsolete since 28.1)
Source Code
;; Defined in /usr/src/emacs/lisp/progmodes/xref.el.gz
(defun xref-show-definitions-completing-read (fetcher alist)
"Let the user choose the target definition with completion.
When there is more than one definition, let the user choose
between them by typing in the minibuffer with completion."
(let* ((xrefs (funcall fetcher))
(xref-alist (xref--analyze xrefs))
xref-alist-with-line-info
xref
(group-prefix-length
;; FIXME: Groups are not always file names, but they often
;; are. At least this shouldn't make the other kinds of
;; groups look worse.
(let ((common-prefix (try-completion "" xref-alist)))
(if (> (length common-prefix) 0)
(length (file-name-directory common-prefix))
0))))
(cl-loop for ((group . xrefs) . more1) on xref-alist
do
(cl-loop for (xref . more2) on xrefs do
(let* ((summary (xref-item-summary xref))
(location (xref-item-location xref))
(line (xref-location-line location))
(line-fmt
(if line
(format #("%d:" 0 2 (face xref-line-number))
line)
""))
(group-prefix
(substring group group-prefix-length))
(group-fmt
(propertize group-prefix
'face 'xref-file-header
'xref--group group-prefix))
(candidate
(format "%s:%s%s" group-fmt line-fmt summary)))
(push (cons candidate xref) xref-alist-with-line-info))))
(setq xref (if (not (cdr xrefs))
(car xrefs)
(let* ((collection (reverse xref-alist-with-line-info))
(ctable
(lambda (string pred action)
(cond
((eq action 'metadata)
`(metadata
. ((category . xref-location)
(group-function . ,#'xref--completing-read-group))))
(t
(complete-with-action action collection string pred)))))
(def (caar collection)))
(cdr (assoc (completing-read "Choose definition: "
ctable nil t
nil nil
def)
collection)))))
(xref-pop-to-location xref (assoc-default 'display-action alist))))