emacs-devel
[Top][All Lists]
Advanced

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

Re: Xref completion


From: Dmitry Gutov
Subject: Re: Xref completion
Date: Wed, 18 Nov 2020 15:46:03 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0

On 18.11.2020 09:35, William Xu wrote:
Dmitry Gutov <dgutov@yandex.ru> writes:

On 17.11.2020 23:16, William Xu wrote:
(defun my-xref--show-defs-minibuffer (fetcher alist)
    (let* ((xrefs (funcall fetcher))
           (xref-alist (xref--analyze xrefs))
           (xref (if (not (cdr xrefs))
                     (car xrefs)
                   (cadr (assoc (completing-read "Jump to definition: " 
xref-alist)
                                xref-alist)))))
      (xref-pop-to-location xref (assoc-default 'display-action alist))))

A solid try, but note you might have a problem when there are several
matches in the same file: you won't be able to navigate to any but the
first one.

Of course, depending on your current programming language, this might
be not important.

In that case, we can just prepend the line and summary in front of the filename?

Yup.

I'm not sure why prepend and not append, but I suppose it's a matter of preference.

Also, xref-location-line can return nil (then format will error out because of %d). So after a little experimenting, this is the form I ended up with:

  (format "%s:%s: %s" group line summary)

(defun my-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
              (cl-loop for (xref . more2) on xrefs do
                       (with-slots (summary location) xref
                         (let ((line (xref-location-line location)))
                           (push (cons (format "%d: %s %s" line summary group) 
xref)
                                 xref-alist-with-line-info)))))

     (setq xref (if (not (cdr xrefs))
                    (car xrefs)
                  (cdr (assoc (completing-read "Jump to definition: " 
xref-alist-with-line-info)
                              xref-alist-with-line-info))))

     (xref-pop-to-location xref (assoc-default 'display-action alist))))





reply via email to

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