From 469f0a65167d004ddbd7b9634c29f42079ebe963 Mon Sep 17 00:00:00 2001 From: William Xu Date: Sat, 5 Dec 2020 02:14:32 +0200 Subject: [PATCH] xref--show-defs-minibuffer: new "show definitions" UI * lisp/progmodes/xref.el (xref--show-defs-minibuffer): New function to use as xref-show-definitions-function (https://lists.gnu.org/archive/html/emacs-devel/2020-11/msg00824.html). --- lisp/progmodes/xref.el | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/lisp/progmodes/xref.el b/lisp/progmodes/xref.el index ca14f6ae6c6..363d118cf7d 100644 --- a/lisp/progmodes/xref.el +++ b/lisp/progmodes/xref.el @@ -931,6 +931,33 @@ local keymap that binds `RET' to `xref-quit-and-goto-xref'." '(display-buffer-in-direction . ((direction . below)))) (current-buffer)))))) +(defun xref--show-defs-minibuffer (fetcher alist) + (let* ((xrefs (funcall fetcher)) + (xref-alist (xref--analyze xrefs)) + xref-alist-with-line-info + xref) + + (cl-loop for ((group . xrefs) . more1) on xref-alist + do + (let ((show-summary (> (length xrefs) 1))) + (cl-loop for (xref . more2) on xrefs do + (with-slots (summary location) xref + (let* ((line (xref-location-line location)) + (line-fmt (if line (format "%s:" line) "")) + (candidate + (if show-summary + (format "%s:%s%s" group line-fmt summary) + (format "%s" group)))) + (push (cons candidate xref) xref-alist-with-line-info)))))) + + (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)))) + + (xref-pop-to-location xref (assoc-default 'display-action alist)))) + (defcustom xref-show-xrefs-function 'xref--show-xref-buffer "Function to display a list of search results. -- 2.39.5