From 3e80653d2970872c1b7cbd46cc9c5f7b289ca672 Mon Sep 17 00:00:00 2001 From: Dmitry Gutov Date: Tue, 29 Dec 2020 20:24:46 +0200 Subject: [PATCH] xref-show-definitions-completing-read: Tune up completion * lisp/minibuffer.el (completion-category-defaults) Use 'substring' completion style for 'xref-location' category by default. * lisp/progmodes/xref.el (xref-show-definitions-completing-read): Assign the 'xref-location' category to the completions. Pass REQUIRE-MATCH=t. --- lisp/minibuffer.el | 1 + lisp/progmodes/xref.el | 14 +++++++++++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/lisp/minibuffer.el b/lisp/minibuffer.el index dc37c5f4476..441eca214bd 100644 --- a/lisp/minibuffer.el +++ b/lisp/minibuffer.el @@ -956,6 +956,7 @@ styles for specific categories, such as files, buffers, etc." ;; A new style that combines substring and pcm might be better, ;; e.g. one that does not anchor to bos. (project-file (styles . (substring))) + (xref-location (styles . (substring))) (info-menu (styles . (basic substring)))) "Default settings for specific completion categories. Each entry has the shape (CATEGORY . ALIST) where ALIST is diff --git a/lisp/progmodes/xref.el b/lisp/progmodes/xref.el index b8a5d481190..6f7125670bd 100644 --- a/lisp/progmodes/xref.el +++ b/lisp/progmodes/xref.el @@ -1018,9 +1018,17 @@ between them by typing in the minibuffer with completion." (setq xref (if (not (cdr xrefs)) (car xrefs) - (cdr (assoc (completing-read "Jump to definition: " - (reverse xref-alist-with-line-info)) - xref-alist-with-line-info)))) + (let* ((collection (reverse xref-alist-with-line-info)) + (ctable + (lambda (string pred action) + (cond + ((eq action 'metadata) + '(metadata . ((category . xref-location)))) + (t + (complete-with-action action collection string pred)))))) + (cdr (assoc (completing-read "Choose definition: " + ctable nil t) + collection))))) (xref-pop-to-location xref (assoc-default 'display-action alist)))) -- 2.39.5