summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWilliam Xu <william.xwl@gmail.com>2020-12-05 02:14:32 +0200
committerDmitry Gutov <dgutov@yandex.ru>2020-12-05 03:00:38 +0200
commit469f0a65167d004ddbd7b9634c29f42079ebe963 (patch)
tree6e6d9632c2353389fc97d926f4eff2c66d895835
parent39915c708435cefd1c3eaddeec54d3b365d36515 (diff)
downloademacs-469f0a65167d004ddbd7b9634c29f42079ebe963.tar.gz
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).
-rw-r--r--lisp/progmodes/xref.el27
1 files changed, 27 insertions, 0 deletions
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.