emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Xref completion


From: William Xu
Subject: Re: Xref completion
Date: Thu, 19 Nov 2020 09:19:57 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (darwin)

Dmitry Gutov <dgutov@yandex.ru> writes:

> OTOH, we should create a shortcut for the case when every group
> contains only one element: then completion would only show the group
> names (meaning file/package names), without summaries. That might work
> well in certain environments (like Java?).

I like this idea. So we can display a mix of both.

One more point, I'm not sure if the order of the candidates are
important or not, but we can keep it the same order as in xref 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))))

-- 
William




reply via email to

[Prev in Thread] Current Thread [Next in Thread]