如题, xref-find-apropos 当前的界面是 *xref*
buffer.
;;; Code:
(require 'xref)
(require 'consult-xref)
(defun consult-xref-apropos--highlight-candidate (input)
"Highlight the candidates for the parts that matches INPUT."
(let ((words (string-split input "[ \t]")))
(lambda (cand)
(let* ((prefix (get-text-property 0 'consult--prefix-group cand))
(prefix-length (length prefix)))
(dolist (word words)
(when (string-match (regexp-quote word) cand prefix-length)
(add-text-properties (match-beginning 0)
(match-end 0)
'(face consult-highlight-match)
cand))))
cand)))
(defun consult-xref-apropos--compute (buffer input)
"Dynamically compute candidates for INPUT in BUFFER."
(with-current-buffer buffer
(ignore-errors
(let* ((consult-xref--fetcher
(xref--create-fetcher input 'apropos input))
(candidates (consult-xref--candidates)))
(mapc (consult-xref-apropos--highlight-candidate input)
candidates)
candidates))))
(defun consult-xref-apropos--collection (buffer)
"Return a completion table for BUFFER."
(consult--dynamic-collection
(apply-partially #'consult-xref-apropos--compute buffer)))
;;;###autoload
(defun consult-xref-apropos (initial)
"Find all meaningful symbols that match the pattern.
INITIAL is the initial input."
(interactive "P")
(xref-pop-to-location
(let ((consult-async-input-debounce .6))
(consult--read
(consult-xref-apropos--collection (current-buffer))
:prompt "Search for pattern: "
:history 'consult-xref-history
:require-match t
:sort nil
:category 'consult-xref
:initial (consult--async-split-initial initial)
:group #'consult--prefix-group
:state (consult-xref--preview #'switch-to-buffer)
:lookup (apply-partially #'consult--lookup-prop 'consult-xref)))))