]> git.eshelyaron.com Git - emacs.git/commitdiff
xref--show-defs-minibuffer: new "show definitions" UI
authorWilliam Xu <william.xwl@gmail.com>
Sat, 5 Dec 2020 00:14:32 +0000 (02:14 +0200)
committerDmitry Gutov <dgutov@yandex.ru>
Sat, 5 Dec 2020 01:00:38 +0000 (03:00 +0200)
* 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

index ca14f6ae6c6bb9dccd13074194d0227a316b4191..363d118cf7d7e0da27b3c31b98811d9d20ad3196 100644 (file)
@@ -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))))
+
 \f
 (defcustom xref-show-xrefs-function 'xref--show-xref-buffer
   "Function to display a list of search results.