unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Xref completion
@ 2020-11-17 18:13 Pierre Neidhardt
  2020-11-17 18:22 ` [SPAM UNSURE] " Stephen Leake
                   ` (2 more replies)
  0 siblings, 3 replies; 40+ messages in thread
From: Pierre Neidhardt @ 2020-11-17 18:13 UTC (permalink / raw)
  To: emacs-devel


[-- Attachment #1.1: Type: text/plain, Size: 791 bytes --]

Hello!

Currently, when a xref query hits multiple candidates Emacs shows a Xref
buffer with the various candidates and their location.

While informative, it's a bit slow in terms of UX because the user has
to navigate an extra buffer just to confirm the candidate.

I've addressed this issue as part of my work on Helm-SLY, a Helm for the
fork of SLIME.

https://github.com/emacs-helm/helm-sly

In particular, I've overridden the behaviour with regards to Xrefs and
instead of showing the Xref buffer, I'm now offering completion: the
user can match against the symbol but also against the file and line
position.

See screenshot attached.

What do you think of adding this behaviour to upstream Emacs' xref?

Cheers!

-- 
Pierre Neidhardt
https://ambrevar.xyz/

[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 511 bytes --]

[-- Attachment #2: helm-sly-xref-demo.png --]
[-- Type: image/png, Size: 49209 bytes --]

^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: [SPAM UNSURE] Xref completion
  2020-11-17 18:13 Xref completion Pierre Neidhardt
@ 2020-11-17 18:22 ` Stephen Leake
  2020-11-17 18:32   ` Pierre Neidhardt
  2020-11-17 18:46   ` Basil L. Contovounesios
  2020-11-17 18:38 ` Eli Zaretskii
  2020-11-17 19:27 ` Juri Linkov
  2 siblings, 2 replies; 40+ messages in thread
From: Stephen Leake @ 2020-11-17 18:22 UTC (permalink / raw)
  To: Pierre Neidhardt; +Cc: emacs-devel

Pierre Neidhardt <mail@ambrevar.xyz> writes:

> Hello!
>
> Currently, when a xref query hits multiple candidates Emacs shows a Xref
> buffer with the various candidates and their location.
>
> While informative, it's a bit slow in terms of UX because the user has
> to navigate an extra buffer just to confirm the candidate.
>
> I've addressed this issue as part of my work on Helm-SLY, a Helm for the
> fork of SLIME.
>
> https://github.com/emacs-helm/helm-sly
>
> In particular, I've overridden the behaviour with regards to Xrefs and
> instead of showing the Xref buffer, I'm now offering completion: the
> user can match against the symbol but also against the file and line
> position.
>
> See screenshot attached.
>
> What do you think of adding this behaviour to upstream Emacs' xref?

Sometimes choosing a single definition is what you want, other times you
want to see the list. So this would have to use a different keybinding
or prefix.

-- 
-- Stephe

Written from unceded ancestral homelands of the Huichiun, an Ohlone
people,for which I pay Shuumi Land Tax
(https://sogoreate-landtrust.com/shuumi-land-tax) as an inadequate token
of reparation.



^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: [SPAM UNSURE] Xref completion
  2020-11-17 18:22 ` [SPAM UNSURE] " Stephen Leake
@ 2020-11-17 18:32   ` Pierre Neidhardt
  2020-11-17 18:46   ` Basil L. Contovounesios
  1 sibling, 0 replies; 40+ messages in thread
From: Pierre Neidhardt @ 2020-11-17 18:32 UTC (permalink / raw)
  To: Stephen Leake; +Cc: emacs-devel

[-- Attachment #1: Type: text/plain, Size: 170 bytes --]

Why not indeed!

Is someone interested in working on this?
I don't have the time to work on it myself, unfortunately.

-- 
Pierre Neidhardt
https://ambrevar.xyz/

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 511 bytes --]

^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: Xref completion
  2020-11-17 18:13 Xref completion Pierre Neidhardt
  2020-11-17 18:22 ` [SPAM UNSURE] " Stephen Leake
@ 2020-11-17 18:38 ` Eli Zaretskii
  2020-11-17 19:11   ` Pierre Neidhardt
  2020-11-17 19:27 ` Juri Linkov
  2 siblings, 1 reply; 40+ messages in thread
From: Eli Zaretskii @ 2020-11-17 18:38 UTC (permalink / raw)
  To: Pierre Neidhardt; +Cc: emacs-devel

> From: Pierre Neidhardt <mail@ambrevar.xyz>
> Date: Tue, 17 Nov 2020 19:13:18 +0100
> 
> Currently, when a xref query hits multiple candidates Emacs shows a Xref
> buffer with the various candidates and their location.
> 
> While informative, it's a bit slow in terms of UX because the user has
> to navigate an extra buffer just to confirm the candidate.
> 
> I've addressed this issue as part of my work on Helm-SLY, a Helm for the
> fork of SLIME.
> 
> https://github.com/emacs-helm/helm-sly
> 
> In particular, I've overridden the behaviour with regards to Xrefs and
> instead of showing the Xref buffer, I'm now offering completion: the
> user can match against the symbol but also against the file and line
> position.
> 
> See screenshot attached.

I'm not sure I understand the UI and the interaction.  When there are
several hits, they usually are spelled (almost) the same.  So how
would the user pick up what he/she wants using the completion UI?

And where are the candidates shown -- in the minibuffer? or in a
special buffer, like Xref does?



^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: [SPAM UNSURE] Xref completion
  2020-11-17 18:22 ` [SPAM UNSURE] " Stephen Leake
  2020-11-17 18:32   ` Pierre Neidhardt
@ 2020-11-17 18:46   ` Basil L. Contovounesios
  1 sibling, 0 replies; 40+ messages in thread
From: Basil L. Contovounesios @ 2020-11-17 18:46 UTC (permalink / raw)
  To: Stephen Leake; +Cc: Pierre Neidhardt, emacs-devel

Stephen Leake <stephen_leake@stephe-leake.org> writes:

> Sometimes choosing a single definition is what you want, other times you
> want to see the list. So this would have to use a different keybinding
> or prefix.

A bit off-topic, but I'd personally prefer more *xref* buffer navigation
bindings, such as next/previous file, over completion.

-- 
Basil



^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: Xref completion
  2020-11-17 18:38 ` Eli Zaretskii
@ 2020-11-17 19:11   ` Pierre Neidhardt
  0 siblings, 0 replies; 40+ messages in thread
From: Pierre Neidhardt @ 2020-11-17 19:11 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: emacs-devel

[-- Attachment #1: Type: text/plain, Size: 716 bytes --]

Eli Zaretskii <eliz@gnu.org> writes:

> I'm not sure I understand the UI and the interaction.  When there are
> several hits, they usually are spelled (almost) the same.  So how
> would the user pick up what he/she wants using the completion UI?

The file usually differs, so that's one way to narrow down.
Another way is to simply navigate the candidates (arrow keys, tab, etc.).

> And where are the candidates shown -- in the minibuffer? or in a
> special buffer, like Xref does?

In the minibuffer.

What I'm suggesting is to use Emacs' default completion framework so
that Xref completion would work with anything: ido, fido, company, Helm,
etc.

-- 
Pierre Neidhardt
https://ambrevar.xyz/

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 511 bytes --]

^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: Xref completion
  2020-11-17 18:13 Xref completion Pierre Neidhardt
  2020-11-17 18:22 ` [SPAM UNSURE] " Stephen Leake
  2020-11-17 18:38 ` Eli Zaretskii
@ 2020-11-17 19:27 ` Juri Linkov
  2020-11-17 20:00   ` Dmitry Gutov
  2020-11-17 21:16   ` William Xu
  2 siblings, 2 replies; 40+ messages in thread
From: Juri Linkov @ 2020-11-17 19:27 UTC (permalink / raw)
  To: Pierre Neidhardt; +Cc: emacs-devel

> In particular, I've overridden the behaviour with regards to Xrefs and
> instead of showing the Xref buffer, I'm now offering completion: the
> user can match against the symbol but also against the file and line
> position.

It seems this should be possible by customizing the value of
xref-show-definitions-function to a function that would redirect
a list of found results to completing-read.



^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: Xref completion
  2020-11-17 19:27 ` Juri Linkov
@ 2020-11-17 20:00   ` Dmitry Gutov
  2020-11-17 21:16   ` William Xu
  1 sibling, 0 replies; 40+ messages in thread
From: Dmitry Gutov @ 2020-11-17 20:00 UTC (permalink / raw)
  To: Juri Linkov, Pierre Neidhardt; +Cc: emacs-devel

On 17.11.2020 21:27, Juri Linkov wrote:
>> In particular, I've overridden the behaviour with regards to Xrefs and
>> instead of showing the Xref buffer, I'm now offering completion: the
>> user can match against the symbol but also against the file and line
>> position.
> It seems this should be possible by customizing the value of
> xref-show-definitions-function to a function that would redirect
> a list of found results to completing-read.

Yup.

We'd be happy to add an alternative value for this variable that the 
users who prefer this behavior can set.

Contribute away!



^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: Xref completion
  2020-11-17 19:27 ` Juri Linkov
  2020-11-17 20:00   ` Dmitry Gutov
@ 2020-11-17 21:16   ` William Xu
  2020-11-17 21:38     ` Dmitry Gutov
  1 sibling, 1 reply; 40+ messages in thread
From: William Xu @ 2020-11-17 21:16 UTC (permalink / raw)
  To: emacs-devel

Juri Linkov <juri@linkov.net> writes:

>> In particular, I've overridden the behaviour with regards to Xrefs and
>> instead of showing the Xref buffer, I'm now offering completion: the
>> user can match against the symbol but also against the file and line
>> position.
>
> It seems this should be possible by customizing the value of
> xref-show-definitions-function to a function that would redirect
> a list of found results to completing-read.

Wow, that is a life saver.

(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))))

(setq xref-show-definitions-function 'my-xref--show-defs-minibuffer)

-- 
William




^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: Xref completion
  2020-11-17 21:16   ` William Xu
@ 2020-11-17 21:38     ` Dmitry Gutov
  2020-11-18  7:35       ` William Xu
  0 siblings, 1 reply; 40+ messages in thread
From: Dmitry Gutov @ 2020-11-17 21:38 UTC (permalink / raw)
  To: William Xu, emacs-devel

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.



^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: Xref completion
  2020-11-17 21:38     ` Dmitry Gutov
@ 2020-11-18  7:35       ` William Xu
  2020-11-18 13:46         ` Dmitry Gutov
  2020-11-18 18:47         ` João Távora
  0 siblings, 2 replies; 40+ messages in thread
From: William Xu @ 2020-11-18  7:35 UTC (permalink / raw)
  To: emacs-devel

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? 

(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))))

-- 
William




^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: Xref completion
  2020-11-18  7:35       ` William Xu
@ 2020-11-18 13:46         ` Dmitry Gutov
  2020-11-18 18:53           ` William Xu
  2020-11-18 18:47         ` João Távora
  1 sibling, 1 reply; 40+ messages in thread
From: Dmitry Gutov @ 2020-11-18 13:46 UTC (permalink / raw)
  To: William Xu, emacs-devel

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))))
> 




^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: Xref completion
  2020-11-18  7:35       ` William Xu
  2020-11-18 13:46         ` Dmitry Gutov
@ 2020-11-18 18:47         ` João Távora
  2020-11-19  1:43           ` Dmitry Gutov
  1 sibling, 1 reply; 40+ messages in thread
From: João Távora @ 2020-11-18 18:47 UTC (permalink / raw)
  To: William Xu; +Cc: emacs-devel

[-- Attachment #1: Type: text/plain, Size: 1498 bytes --]

On Wed, Nov 18, 2020 at 7:36 AM William Xu <william.xwl@gmail.com> 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?
>

I'd just like to note that in certain applications (like SLY/SLIME where
this request
hails from), sometimes xrefs are grouped not by file, but by type (a
symbols's
references includes "who sets", "who calls", "who reads", and so on) . So
if possible, and in general, this type of solution should be thought as
"prepend/append group name".  There can even be multiple grouping
strategies.

But one can also think about: select group first, then item within group.

Just my two cents.
João

[-- Attachment #2: Type: text/html, Size: 2195 bytes --]

^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: Xref completion
  2020-11-18 13:46         ` Dmitry Gutov
@ 2020-11-18 18:53           ` William Xu
  2020-11-18 19:22             ` Dmitry Gutov
  0 siblings, 1 reply; 40+ messages in thread
From: William Xu @ 2020-11-18 18:53 UTC (permalink / raw)
  To: emacs-devel

Dmitry Gutov <dgutov@yandex.ru> writes:

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

In my case, some directory/file names are extremely long... But either
way is fine.

> 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)

Thanks for catching that. I didn't know that "%s" prints not only
strings, but any types.. 

It would be nice if the change can be merged. Then I only need one line
setting.

-- 
William




^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: Xref completion
  2020-11-18 18:53           ` William Xu
@ 2020-11-18 19:22             ` Dmitry Gutov
  2020-11-18 20:39               ` Juri Linkov
  0 siblings, 1 reply; 40+ messages in thread
From: Dmitry Gutov @ 2020-11-18 19:22 UTC (permalink / raw)
  To: William Xu, emacs-devel

On 18.11.2020 20:53, William Xu wrote:
> It would be nice if the change can be merged.

As soon as we get some confirmation from other people that this is the 
Xref completion behavior that they like.



^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: Xref completion
  2020-11-18 19:22             ` Dmitry Gutov
@ 2020-11-18 20:39               ` Juri Linkov
  2020-11-19  1:34                 ` Dmitry Gutov
  0 siblings, 1 reply; 40+ messages in thread
From: Juri Linkov @ 2020-11-18 20:39 UTC (permalink / raw)
  To: Dmitry Gutov; +Cc: William Xu, emacs-devel

>> It would be nice if the change can be merged.
>
> As soon as we get some confirmation from other people that this is the Xref
> completion behavior that they like.

+1.  Whereas (format "%s:%s:%s" group line summary) is like grep format,
when 'line' is 'nil', better to remove useless ':nil:' string from completions.



^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: Xref completion
  2020-11-18 20:39               ` Juri Linkov
@ 2020-11-19  1:34                 ` Dmitry Gutov
  0 siblings, 0 replies; 40+ messages in thread
From: Dmitry Gutov @ 2020-11-19  1:34 UTC (permalink / raw)
  To: Juri Linkov; +Cc: William Xu, emacs-devel

On 18.11.2020 22:39, Juri Linkov wrote:
> +1.  Whereas (format "%s:%s:%s" group line summary) is like grep format,
> when 'line' is 'nil', better to remove useless ':nil:' string from completions.

Fair point.



^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: Xref completion
  2020-11-18 18:47         ` João Távora
@ 2020-11-19  1:43           ` Dmitry Gutov
  2020-11-19  8:19             ` William Xu
  0 siblings, 1 reply; 40+ messages in thread
From: Dmitry Gutov @ 2020-11-19  1:43 UTC (permalink / raw)
  To: João Távora, William Xu; +Cc: emacs-devel

On 18.11.2020 20:47, João Távora wrote:

> I'd just like to note that in certain applications (like SLY/SLIME where 
> this request
> hails from), sometimes xrefs are grouped not by file, but by type (a 
> symbols's
> references includes "who sets", "who calls", "who reads", and so on) . So
> if possible, and in general, this type of solution should be thought as
> "prepend/append group name".  There can even be multiple grouping
> strategies.

We don't currently support group nesting, do we? I'm not sure how this 
can work without showing the file name or an equivalent substitute (like 
the package name) in the group. Does the file name go in each item's 
summaries?

In any case, we're currently discussing xref-show-definitions-function, 
and not xref-show-xrefs-function.

It's only used for the results of xref-find-definitions, so "who calls" 
and "who reads" won't be there. Only "who sets/defines".

> But one can also think about: select group first, then item within group.

I feel that might be under-utilizing the fuzzy matching capabilities of 
the existing completion frameworks: it should be usually quicker to 
match on both in one step.

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?).



^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: Xref completion
  2020-11-19  1:43           ` Dmitry Gutov
@ 2020-11-19  8:19             ` William Xu
  2020-11-19 13:30               ` Dmitry Gutov
  2020-12-02 21:44               ` Juri Linkov
  0 siblings, 2 replies; 40+ messages in thread
From: William Xu @ 2020-11-19  8:19 UTC (permalink / raw)
  To: emacs-devel

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




^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: Xref completion
  2020-11-19  8:19             ` William Xu
@ 2020-11-19 13:30               ` Dmitry Gutov
  2020-12-02 21:44               ` Juri Linkov
  1 sibling, 0 replies; 40+ messages in thread
From: Dmitry Gutov @ 2020-11-19 13:30 UTC (permalink / raw)
  To: William Xu, emacs-devel

On 19.11.2020 10:19, William Xu wrote:
> 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.

Looking good!

> 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.

Not sure all completion UIs will keep that order, but sure.



^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: Xref completion
  2020-11-19  8:19             ` William Xu
  2020-11-19 13:30               ` Dmitry Gutov
@ 2020-12-02 21:44               ` Juri Linkov
  2020-12-03  0:25                 ` Dmitry Gutov
  1 sibling, 1 reply; 40+ messages in thread
From: Juri Linkov @ 2020-12-02 21:44 UTC (permalink / raw)
  To: William Xu; +Cc: emacs-devel

> 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.

Yes, better to keep the same order.

One additional question: is it possible to use only relative file names,
relative to the project root dir?  Absolute file names are too long.

BTW, like you created xref--show-defs-minibuffer
as a possible option for xref-show-definitions-function,
wouldn't it be also nice to do the same and create
xref--show-xref-minibuffer as a possible option for
xref-show-xrefs-function?



^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: Xref completion
  2020-12-02 21:44               ` Juri Linkov
@ 2020-12-03  0:25                 ` Dmitry Gutov
  2020-12-03 21:09                   ` Juri Linkov
  0 siblings, 1 reply; 40+ messages in thread
From: Dmitry Gutov @ 2020-12-03  0:25 UTC (permalink / raw)
  To: Juri Linkov, William Xu; +Cc: emacs-devel

On 02.12.2020 23:44, Juri Linkov wrote:
>> 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.
> 
> Yes, better to keep the same order.
> 
> One additional question: is it possible to use only relative file names,
> relative to the project root dir?  Absolute file names are too long.

Not always possible to do it against the project root 
(xref-find-definitions does not depend on project.el), but you can still 
find the longest parent directory and cut it off, similarly to how it's 
done in project--read-file-cpd-relative.

> BTW, like you created xref--show-defs-minibuffer
> as a possible option for xref-show-definitions-function,
> wouldn't it be also nice to do the same and create
> xref--show-xref-minibuffer as a possible option for
> xref-show-xrefs-function?

Don't you usually want to iterate across multiple results, when the 
command is project-find-regexp or xref-find-references? Then the same 
logic will not work.

I mean, sometimes you probably want to find just one match, but changing 
xref-show-xrefs-function will affect all invocations.

Or maybe I should ask: how will xref--show-xref-minibuffer be different 
from xref--show-defs-minibuffer?



^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: Xref completion
  2020-12-03  0:25                 ` Dmitry Gutov
@ 2020-12-03 21:09                   ` Juri Linkov
  2020-12-05  1:12                     ` Dmitry Gutov
  0 siblings, 1 reply; 40+ messages in thread
From: Juri Linkov @ 2020-12-03 21:09 UTC (permalink / raw)
  To: Dmitry Gutov; +Cc: William Xu, emacs-devel

>> BTW, like you created xref--show-defs-minibuffer
>> as a possible option for xref-show-definitions-function,
>> wouldn't it be also nice to do the same and create
>> xref--show-xref-minibuffer as a possible option for
>> xref-show-xrefs-function?
>
> Don't you usually want to iterate across multiple results, when the command
> is project-find-regexp or xref-find-references? Then the same logic will
> not work.

Right, xref--show-xref-minibuffer would be not as useful as
xref--show-defs-minibuffer is.  Hope to see xref--show-defs-minibuffer
in xref.el soon.



^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: Xref completion
  2020-12-03 21:09                   ` Juri Linkov
@ 2020-12-05  1:12                     ` Dmitry Gutov
  2020-12-05 12:21                       ` William Xu
                                         ` (2 more replies)
  0 siblings, 3 replies; 40+ messages in thread
From: Dmitry Gutov @ 2020-12-05  1:12 UTC (permalink / raw)
  To: Juri Linkov; +Cc: William Xu, emacs-devel

On 03.12.2020 23:09, Juri Linkov wrote:
>>> BTW, like you created xref--show-defs-minibuffer
>>> as a possible option for xref-show-definitions-function,
>>> wouldn't it be also nice to do the same and create
>>> xref--show-xref-minibuffer as a possible option for
>>> xref-show-xrefs-function?
>>
>> Don't you usually want to iterate across multiple results, when the command
>> is project-find-regexp or xref-find-references? Then the same logic will
>> not work.
> 
> Right, xref--show-xref-minibuffer would be not as useful as
> xref--show-defs-minibuffer is.  Hope to see xref--show-defs-minibuffer
> in xref.el soon.

I've pushed it now with some changes, hope you all like the result.

Shortening the group part (in most common cases) is among them.

Also added some highlighting with corresponding xref faces. It now looks 
closer to Pierre's original screenshot.

Removed the bit of logic that hid the summaries when they are 
technically unnecessary because in my testing it made completion 
slightly less useful by hiding information (sorry). Anybody who really 
preferred the previous version, please try it again with c86dc8d488 
reverted locally, and maybe propose a user option for that behavior.

BTW, Juri, how do you think this new function compares against 
xref--show-defs-buffer-at-bottom?

On the one hand, it feels kinda faster, on the other, it lacks the 
ability to "look around" when you really need it. In an ideal world, I 
guess the UI would be somewhere in the middle.



^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: Xref completion
  2020-12-05  1:12                     ` Dmitry Gutov
@ 2020-12-05 12:21                       ` William Xu
  2020-12-05 21:02                         ` Dmitry Gutov
  2020-12-05 19:52                       ` Juri Linkov
  2020-12-07  9:27                       ` Daniel Martín
  2 siblings, 1 reply; 40+ messages in thread
From: William Xu @ 2020-12-05 12:21 UTC (permalink / raw)
  To: emacs-devel

Dmitry Gutov <dgutov@yandex.ru> writes:

> I've pushed it now with some changes, hope you all like the result.
>
> Shortening the group part (in most common cases) is among them.
>
> Also added some highlighting with corresponding xref faces. It now
> looks closer to Pierre's original screenshot.

The result looks nice.

> Removed the bit of logic that hid the summaries when they are
> technically unnecessary because in my testing it made completion 
> slightly less useful by hiding information (sorry).

If the summary contains different info, like the actual line from the
group (in case it is a file), that may be useful to show it, for
example:

/foo.cpp:40:struct Foo : Bar
/foo2.cpp:42:struct Foo : Foo2

However, at the moment it only shows the same summary info for each
line, which doesn't seem really useful:

/foo.cpp:40:Foo
/foo2.cpp:42:Foo

Or one can also just add this info into the reading prompt:
    (format "Jump to definition of `%s': " summary)

-- 
William




^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: Xref completion
  2020-12-05  1:12                     ` Dmitry Gutov
  2020-12-05 12:21                       ` William Xu
@ 2020-12-05 19:52                       ` Juri Linkov
  2020-12-05 21:44                         ` Dmitry Gutov
  2020-12-07  9:27                       ` Daniel Martín
  2 siblings, 1 reply; 40+ messages in thread
From: Juri Linkov @ 2020-12-05 19:52 UTC (permalink / raw)
  To: Dmitry Gutov; +Cc: William Xu, emacs-devel

> I've pushed it now with some changes, hope you all like the result.
>
> Shortening the group part (in most common cases) is among them.
>
> Also added some highlighting with corresponding xref faces. It now looks
> closer to Pierre's original screenshot.

Thanks, everything works well.  Would be nicer to add all available
choices to xref-show-definitions-function (i.e. "at bottom", "minibuffer").

> BTW, Juri, how do you think this new function compares against
> xref--show-defs-buffer-at-bottom?
>
> On the one hand, it feels kinda faster, on the other, it lacks the ability
> to "look around" when you really need it. In an ideal world, I guess the UI
> would be somewhere in the middle.

There are still too many differences between them.  The most noteworthy
is that xref--show-defs-minibuffer doesn't show completions by default,
only after TAB TAB.



^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: Xref completion
  2020-12-05 12:21                       ` William Xu
@ 2020-12-05 21:02                         ` Dmitry Gutov
  2020-12-06  8:30                           ` William Xu
  0 siblings, 1 reply; 40+ messages in thread
From: Dmitry Gutov @ 2020-12-05 21:02 UTC (permalink / raw)
  To: William Xu, emacs-devel

On 05.12.2020 14:21, William Xu wrote:
> Dmitry Gutov <dgutov@yandex.ru> writes:
> 
>> I've pushed it now with some changes, hope you all like the result.
>>
>> Shortening the group part (in most common cases) is among them.
>>
>> Also added some highlighting with corresponding xref faces. It now
>> looks closer to Pierre's original screenshot.
> 
> The result looks nice.

Thanks.

>> Removed the bit of logic that hid the summaries when they are
>> technically unnecessary because in my testing it made completion
>> slightly less useful by hiding information (sorry).
> 
> If the summary contains different info, like the actual line from the
> group (in case it is a file), that may be useful to show it, for
> example:
> 
> /foo.cpp:40:struct Foo : Bar
> /foo2.cpp:42:struct Foo : Foo2

That's how it usually looks in my testing, with the etags backend. E.g.:

Possible completions are:
dispextern.h:2703:  int vpos;
indent.h:29:    EMACS_INT vpos;
window.h:97:  int hpos, vpos;

(After I try to navigate to the definitions 'vpos' from xdisp.c:1499).

Of course, in the end it depends on each backend to put useful into into 
summaries. And in the case of etags, that depends on how the definition 
is written (that the identifier is not alone on its line).

> However, at the moment it only shows the same summary info for each
> line, which doesn't seem really useful:
> 
> /foo.cpp:40:Foo
> /foo2.cpp:42:Foo

Which backend is this? Also etags?

> Or one can also just add this info into the reading prompt:
>      (format "Jump to definition of `%s': " summary)

I suppose it could be a special case, but we'd have to pipe through the 
initial input as well (it's not currently available). So hopefully there 
is some better solution.



^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: Xref completion
  2020-12-05 19:52                       ` Juri Linkov
@ 2020-12-05 21:44                         ` Dmitry Gutov
  2020-12-06 20:46                           ` Juri Linkov
  0 siblings, 1 reply; 40+ messages in thread
From: Dmitry Gutov @ 2020-12-05 21:44 UTC (permalink / raw)
  To: Juri Linkov; +Cc: William Xu, emacs-devel

[-- Attachment #1: Type: text/plain, Size: 1849 bytes --]

On 05.12.2020 21:52, Juri Linkov wrote:
>> I've pushed it now with some changes, hope you all like the result.
>>
>> Shortening the group part (in most common cases) is among them.
>>
>> Also added some highlighting with corresponding xref faces. It now looks
>> closer to Pierre's original screenshot.
> 
> Thanks, everything works well.  Would be nicer to add all available
> choices to xref-show-definitions-function (i.e. "at bottom", "minibuffer").

Of course, a bit later.

BTW, when we do that, should we also rename all involved functions to 
"public" names?

Putting them into the :type of a defcustom probably involves some kind 
of social contract.

>> BTW, Juri, how do you think this new function compares against
>> xref--show-defs-buffer-at-bottom?
>>
>> On the one hand, it feels kinda faster, on the other, it lacks the ability
>> to "look around" when you really need it. In an ideal world, I guess the UI
>> would be somewhere in the middle.
> 
> There are still too many differences between them.  The most noteworthy
> is that xref--show-defs-minibuffer doesn't show completions by default,
> only after TAB TAB.

That depends on the completion UI in use.

To see them right away, just start with 'M-x fido-mode'.

Or here is the config I'm currently trying out. It needs both ivy and 
ivy-posframe installed, though:

(setq xref-show-definitions-function 'xref--show-defs-minibuffer)

(defun complete-with-ivy (fun &rest args)
   (let ((completing-read-function #'ivy-completing-read))
     (apply fun args)))

(advice-add #'xref--show-defs-minibuffer :around #'complete-with-ivy)

;; These last two forms are unrelated, here for completeness:

(advice-add #'project-find-file-in :around #'complete-with-ivy)

(advice-add #'project-prompt-project-dir :around #'complete-with-ivy)

;; See the result on the attached screenshot.

[-- Attachment #2: Screenshot from 2020-12-05 23-25-42.png --]
[-- Type: image/png, Size: 271527 bytes --]

^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: Xref completion
  2020-12-05 21:02                         ` Dmitry Gutov
@ 2020-12-06  8:30                           ` William Xu
  2020-12-06 11:00                             ` Dmitry Gutov
  0 siblings, 1 reply; 40+ messages in thread
From: William Xu @ 2020-12-06  8:30 UTC (permalink / raw)
  To: emacs-devel

Dmitry Gutov <dgutov@yandex.ru> writes:

> Of course, in the end it depends on each backend to put useful into
> into summaries. And in the case of etags, that depends on how the
> definition is written (that the identifier is not alone on its line).

You are right. It is backend specific. So it makes more sense, showing
the summary by default as you are currently doing.

>> However, at the moment it only shows the same summary info for each
>> line, which doesn't seem really useful:
>> /foo.cpp:40:Foo
>> /foo2.cpp:42:Foo
>
> Which backend is this? Also etags?

Eglot with ccls. Sounds like something to improve in either eglot or ccls. 

-- 
William




^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: Xref completion
  2020-12-06  8:30                           ` William Xu
@ 2020-12-06 11:00                             ` Dmitry Gutov
  2020-12-06 14:00                               ` William Xu
  0 siblings, 1 reply; 40+ messages in thread
From: Dmitry Gutov @ 2020-12-06 11:00 UTC (permalink / raw)
  To: William Xu, emacs-devel

On 06.12.2020 10:30, William Xu wrote:
> Dmitry Gutov <dgutov@yandex.ru> writes:
> 
>> Of course, in the end it depends on each backend to put useful into
>> into summaries. And in the case of etags, that depends on how the
>> definition is written (that the identifier is not alone on its line).
> 
> You are right. It is backend specific. So it makes more sense, showing
> the summary by default as you are currently doing.
> 
>>> However, at the moment it only shows the same summary info for each
>>> line, which doesn't seem really useful:
>>> /foo.cpp:40:Foo
>>> /foo2.cpp:42:Foo
>>
>> Which backend is this? Also etags?
> 
> Eglot with ccls. Sounds like something to improve in either eglot or ccls.

Seems like.

It could also be a limitation of the LSP protocol (looking at 
https://microsoft.github.io/language-server-protocol/specifications/specification-3-15/#location, 
it doesn't have a field for "line text").

But if so, maybe Eglot could visit the files preemptively and extract 
the line contents. Unlike some other operations, there's unlikely to be 
many results in that list, so it shouldn't take long.

It seems to be trying to do something like this already: 
https://github.com/joaotavora/eglot/blob/master/eglot.el#L1927, maybe 
file a report for this particular case.



^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: Xref completion
  2020-12-06 11:00                             ` Dmitry Gutov
@ 2020-12-06 14:00                               ` William Xu
  2020-12-06 21:01                                 ` Dmitry Gutov
  0 siblings, 1 reply; 40+ messages in thread
From: William Xu @ 2020-12-06 14:00 UTC (permalink / raw)
  To: emacs-devel

Dmitry Gutov <dgutov@yandex.ru> writes:

> It could also be a limitation of the LSP protocol (looking at
> https://microsoft.github.io/language-server-protocol/specifications/specification-3-15/#location,
> it doesn't have a field for "line text").

Would have been nicer if the protocol supports it, then one won't have
to look into the file manually. 

> But if so, maybe Eglot could visit the files preemptively and extract
> the line contents. Unlike some other operations, there's unlikely to
> be many results in that list, so it shouldn't take long.
>
> It seems to be trying to do something like this already:
> https://github.com/joaotavora/eglot/blob/master/eglot.el#L1927, maybe
> file a report for this particular case.

Thanks for the info. My usecase is running the ccls via docker, so the
file path reported by ccls is inside the docker. No wonder Eglot fails
to find the file, thus falling back to so called "dumb strategy".

I could work around it by changing the file path: 

---------------------------------8<------------------------------------- 
(defun xwl-convert-to-docker-path (file)
  (if (and (string-match "foo" (cdr (project-current)))
           (string-match "^/usr/include/" file))
      (concat "/docker:foo:" file)
    file))

(defun xwl-check-docker (orig-fun file &rest args)
  (or (ignore-errors (apply orig-fun (cons file args)))
      (apply orig-fun (cons (xwl-convert-to-docker-path file) args))))

(advice-add 'file-readable-p :around 'xwl-check-docker)
(advice-add 'insert-file-contents :around 'xwl-check-docker)
---------------------------------8<------------------------------------- 

-- 
William




^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: Xref completion
  2020-12-05 21:44                         ` Dmitry Gutov
@ 2020-12-06 20:46                           ` Juri Linkov
  2020-12-06 21:20                             ` Dmitry Gutov
  0 siblings, 1 reply; 40+ messages in thread
From: Juri Linkov @ 2020-12-06 20:46 UTC (permalink / raw)
  To: Dmitry Gutov; +Cc: William Xu, emacs-devel

>>> Also added some highlighting with corresponding xref faces. It now looks
>>> closer to Pierre's original screenshot.
>> Thanks, everything works well.  Would be nicer to add all available
>> choices to xref-show-definitions-function (i.e. "at bottom", "minibuffer").
>
> Of course, a bit later.
>
> BTW, when we do that, should we also rename all involved functions to
> "public" names?

Indeed, these functions are not "internal".

>>> On the one hand, it feels kinda faster, on the other, it lacks the ability
>>> to "look around" when you really need it. In an ideal world, I guess the UI
>>> would be somewhere in the middle.
>> There are still too many differences between them.  The most noteworthy
>> is that xref--show-defs-minibuffer doesn't show completions by default,
>> only after TAB TAB.
>
> That depends on the completion UI in use.
>
> To see them right away, just start with 'M-x fido-mode'.
>
> Or here is the config I'm currently trying out. It needs both ivy and
> ivy-posframe installed, though:

> ;; See the result on the attached screenshot.

But matches are not highlighted on your screenshot, whereas on Pierre's screenshot
matches are highlighted.



^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: Xref completion
  2020-12-06 14:00                               ` William Xu
@ 2020-12-06 21:01                                 ` Dmitry Gutov
  0 siblings, 0 replies; 40+ messages in thread
From: Dmitry Gutov @ 2020-12-06 21:01 UTC (permalink / raw)
  To: William Xu, emacs-devel

On 06.12.2020 16:00, William Xu wrote:
> Dmitry Gutov <dgutov@yandex.ru> writes:
> 
>> It could also be a limitation of the LSP protocol (looking at
>> https://microsoft.github.io/language-server-protocol/specifications/specification-3-15/#location,
>> it doesn't have a field for "line text").
> 
> Would have been nicer if the protocol supports it, then one won't have
> to look into the file manually.

Someone should probably look into bringing that up to LSP folks, but 
even if successful, that's going to be a long process.

>> But if so, maybe Eglot could visit the files preemptively and extract
>> the line contents. Unlike some other operations, there's unlikely to
>> be many results in that list, so it shouldn't take long.
>>
>> It seems to be trying to do something like this already:
>> https://github.com/joaotavora/eglot/blob/master/eglot.el#L1927, maybe
>> file a report for this particular case.
> 
> Thanks for the info. My usecase is running the ccls via docker, so the
> file path reported by ccls is inside the docker. No wonder Eglot fails
> to find the file, thus falling back to so called "dumb strategy".

IDK, if Eglot knows how to navigate to a file, it will know how to read 
a line from it. So it should be possible to add that behavior.

What the performance is going to be, however, is something we'll only 
know after we try.

> I could work around it by changing the file path:
> 
> ---------------------------------8<-------------------------------------
> (defun xwl-convert-to-docker-path (file)
>    (if (and (string-match "foo" (cdr (project-current)))
>             (string-match "^/usr/include/" file))
>        (concat "/docker:foo:" file)
>      file))
> 
> (defun xwl-check-docker (orig-fun file &rest args)
>    (or (ignore-errors (apply orig-fun (cons file args)))
>        (apply orig-fun (cons (xwl-convert-to-docker-path file) args))))
> 
> (advice-add 'file-readable-p :around 'xwl-check-docker)
> (advice-add 'insert-file-contents :around 'xwl-check-docker)
> ---------------------------------8<-------------------------------------

Advising these common functions looks suspicious to me. But hey, if it 
works, it works. You could also try editing the project via Tramp. Not 
sure if Eglot supports that (if it does not, adding support shouldn't be 
too hard), but apparently lsp-mode does.



^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: Xref completion
  2020-12-06 20:46                           ` Juri Linkov
@ 2020-12-06 21:20                             ` Dmitry Gutov
  2020-12-06 21:34                               ` Juri Linkov
  0 siblings, 1 reply; 40+ messages in thread
From: Dmitry Gutov @ 2020-12-06 21:20 UTC (permalink / raw)
  To: Juri Linkov; +Cc: William Xu, emacs-devel

On 06.12.2020 22:46, Juri Linkov wrote:
>>>> Also added some highlighting with corresponding xref faces. It now looks
>>>> closer to Pierre's original screenshot.
>>> Thanks, everything works well.  Would be nicer to add all available
>>> choices to xref-show-definitions-function (i.e. "at bottom", "minibuffer").
>>
>> Of course, a bit later.
>>
>> BTW, when we do that, should we also rename all involved functions to
>> "public" names?
> 
> Indeed, these functions are not "internal".

All right.

>>>> On the one hand, it feels kinda faster, on the other, it lacks the ability
>>>> to "look around" when you really need it. In an ideal world, I guess the UI
>>>> would be somewhere in the middle.
>>> There are still too many differences between them.  The most noteworthy
>>> is that xref--show-defs-minibuffer doesn't show completions by default,
>>> only after TAB TAB.
>>
>> That depends on the completion UI in use.
>>
>> To see them right away, just start with 'M-x fido-mode'.
>>
>> Or here is the config I'm currently trying out. It needs both ivy and
>> ivy-posframe installed, though:
> 
>> ;; See the result on the attached screenshot.
> 
> But matches are not highlighted on your screenshot, whereas on Pierre's screenshot
> matches are highlighted.

That's only because there is no input on my screenshot (I aimed to show 
other things). And Pierre's features input "noti".

Ivy, of course, highlights the matches.



^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: Xref completion
  2020-12-06 21:20                             ` Dmitry Gutov
@ 2020-12-06 21:34                               ` Juri Linkov
  2020-12-06 21:40                                 ` Dmitry Gutov
  0 siblings, 1 reply; 40+ messages in thread
From: Juri Linkov @ 2020-12-06 21:34 UTC (permalink / raw)
  To: Dmitry Gutov; +Cc: William Xu, emacs-devel

>>>>> On the one hand, it feels kinda faster, on the other, it lacks the ability
>>>>> to "look around" when you really need it. In an ideal world, I guess the UI
>>>>> would be somewhere in the middle.
>>>> There are still too many differences between them.  The most noteworthy
>>>> is that xref--show-defs-minibuffer doesn't show completions by default,
>>>> only after TAB TAB.
>>>
>>> That depends on the completion UI in use.
>>>
>>> To see them right away, just start with 'M-x fido-mode'.
>>>
>>> Or here is the config I'm currently trying out. It needs both ivy and
>>> ivy-posframe installed, though:
>> 
>>> ;; See the result on the attached screenshot.
>> But matches are not highlighted on your screenshot, whereas on Pierre's
>> screenshot
>> matches are highlighted.
>
> That's only because there is no input on my screenshot (I aimed to show
> other things). And Pierre's features input "noti".
>
> Ivy, of course, highlights the matches.

But why 'M-.' doesn't highlight the identifier name in the *xref* buffer,
neither in the *Completions* buffer when xref--show-defs-minibuffer is used?



^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: Xref completion
  2020-12-06 21:34                               ` Juri Linkov
@ 2020-12-06 21:40                                 ` Dmitry Gutov
  0 siblings, 0 replies; 40+ messages in thread
From: Dmitry Gutov @ 2020-12-06 21:40 UTC (permalink / raw)
  To: Juri Linkov; +Cc: William Xu, emacs-devel

On 06.12.2020 23:34, Juri Linkov wrote:
>> That's only because there is no input on my screenshot (I aimed to show
>> other things). And Pierre's features input "noti".
>>
>> Ivy, of course, highlights the matches.
> 
> But why 'M-.' doesn't highlight the identifier name in the *xref* buffer,
> neither in the *Completions* buffer when xref--show-defs-minibuffer is used?

I don't know, never saw the need? And it might be non-trivial to 
implement in many cases.

The identifier name that was searched for might not even appear in the 
list verbatim.

Like, the user could have searched for the qualified name, but the line 
only contains its "local" name. Or the user might have searched for an 
alias. Similarly, it won't be in the definition's file.



^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: Xref completion
  2020-12-05  1:12                     ` Dmitry Gutov
  2020-12-05 12:21                       ` William Xu
  2020-12-05 19:52                       ` Juri Linkov
@ 2020-12-07  9:27                       ` Daniel Martín
  2020-12-07 15:12                         ` jixiuf
  2020-12-07 21:53                         ` Dmitry Gutov
  2 siblings, 2 replies; 40+ messages in thread
From: Daniel Martín @ 2020-12-07  9:27 UTC (permalink / raw)
  To: Dmitry Gutov; +Cc: Juri Linkov, William Xu, emacs-devel

Dmitry Gutov <dgutov@yandex.ru> writes:
>
> On the one hand, it feels kinda faster, on the other, it lacks the
> ability to "look around" when you really need it. In an ideal world, I 
> guess the UI would be somewhere in the middle.

One of the reasons I see people integrate Ivy/Helm with Xref is to have
fuzzy filtering of the results, but I don't see why we couldn't have
that in the *xref* buffer.

First I thought if we could implement this by extending an existing
Emacs command like flush-lines or occur to "teach" it about the
specificities of the *xref* buffer, but that doesn't seem very clean.

So perhaps we could add a new command that asks for a regexp in the
minibuffer and filters the results in the *xref* buffer to only contain
those items from a group that matches that regular expression.  With q
you will go back to show the complete list of xref items and groups.  Is
there any core Emacs package that performs a similar filtering?  We
could learn from its workflow, then.

Why matching the group exclusively? In my opinion, matching the group
only is better because the typical use case I have in mind is a big
codebase with thousands of xref results that are spread around hundreds
of files.  You usually want to filter by the string that varies the
most, which in most cases is the group (eg. if I only want to see
results from unit tests, then I'd filter the *xref* buffer by
"*Tests.cpp"; If I only want to see results from header files, I'd
filter by "*.h").

Thoughts?



^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: Xref completion
  2020-12-07  9:27                       ` Daniel Martín
@ 2020-12-07 15:12                         ` jixiuf
  2020-12-07 21:57                           ` Dmitry Gutov
  2020-12-07 21:53                         ` Dmitry Gutov
  1 sibling, 1 reply; 40+ messages in thread
From: jixiuf @ 2020-12-07 15:12 UTC (permalink / raw)
  To: Daniel Martín; +Cc: emacs-devel



> 2020年12月7日 下午5:27,Daniel Martín <mardani29@yahoo.es> 写道:
> 
> Dmitry Gutov <dgutov@yandex.ru> writes:
>> 
>> On the one hand, it feels kinda faster, on the other, it lacks the
>> ability to "look around" when you really need it. In an ideal world, I 
>> guess the UI would be somewhere in the middle.
> 
> One of the reasons I see people integrate Ivy/Helm with Xref is to have
> fuzzy filtering of the results, but I don't see why we couldn't have
> that in the *xref* buffer.
> 
> First I thought if we could implement this by extending an existing
> Emacs command like flush-lines or occur to "teach" it about the
> specificities of the *xref* buffer, but that doesn't seem very clean.
I think it’s great to make *xref*  supporting wgrep or occur-edit-mode.





^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: Xref completion
  2020-12-07  9:27                       ` Daniel Martín
  2020-12-07 15:12                         ` jixiuf
@ 2020-12-07 21:53                         ` Dmitry Gutov
  1 sibling, 0 replies; 40+ messages in thread
From: Dmitry Gutov @ 2020-12-07 21:53 UTC (permalink / raw)
  To: Daniel Martín; +Cc: William Xu, emacs-devel, Juri Linkov

On 07.12.2020 11:27, Daniel Martín wrote:
> Dmitry Gutov <dgutov@yandex.ru> writes:
>>
>> On the one hand, it feels kinda faster, on the other, it lacks the
>> ability to "look around" when you really need it. In an ideal world, I
>> guess the UI would be somewhere in the middle.
> 
> One of the reasons I see people integrate Ivy/Helm with Xref is to have
> fuzzy filtering of the results, but I don't see why we couldn't have
> that in the *xref* buffer.

I think xref buffers have other ways of reaching the same goal. E.g., if 
we're talking about the results of project-find-regexp or 
xref-find-apropos, those commands themselves allow you to enter search 
queries where you can choose the appropriate amount of "fuzziness".

That said...

> First I thought if we could implement this by extending an existing
> Emacs command like flush-lines or occur to "teach" it about the
> specificities of the *xref* buffer, but that doesn't seem very clean.

...adding a command like xref-flush-groups shouldn't hurt. You can file 
a feature request with 'M-x report-emacs-bug' and perhaps even attach a 
patch?

> So perhaps we could add a new command that asks for a regexp in the
> minibuffer and filters the results in the *xref* buffer to only contain
> those items from a group that matches that regular expression.  With q
> you will go back to show the complete list of xref items and groups.

Hmm, if mean dynamically? That sounds a bit more complicated but hey, 
there can be some way to implement this without too much effort.

> Is
> there any core Emacs package that performs a similar filtering?  We
> could learn from its workflow, then.

swiper, perhaps?

Not a core package, but it is in GNU ELPA.

> Why matching the group exclusively? In my opinion, matching the group
> only is better because the typical use case I have in mind is a big
> codebase with thousands of xref results that are spread around hundreds
> of files.  You usually want to filter by the string that varies the
> most, which in most cases is the group (eg. if I only want to see
> results from unit tests, then I'd filter the *xref* buffer by
> "*Tests.cpp"; If I only want to see results from header files, I'd
> filter by "*.h").

Sounds reasonable. If you wanted to filter by summary contents anyway, 
you can just use swiper.



^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: Xref completion
  2020-12-07 15:12                         ` jixiuf
@ 2020-12-07 21:57                           ` Dmitry Gutov
  0 siblings, 0 replies; 40+ messages in thread
From: Dmitry Gutov @ 2020-12-07 21:57 UTC (permalink / raw)
  To: jixiuf, Daniel Martín; +Cc: emacs-devel

On 07.12.2020 17:12, jixiuf wrote:

> I think it’s great to make *xref*  supporting wgrep or occur-edit-mode.

Given the abstraction level, it might be a fair amount of work. If 
someone wanted to work on that patch, though, I'd be happy to give some 
advice.

In the meantime, I think the xref-query-replace-in-results command 
covers 90% of use cases.



^ permalink raw reply	[flat|nested] 40+ messages in thread

end of thread, other threads:[~2020-12-07 21:57 UTC | newest]

Thread overview: 40+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-17 18:13 Xref completion Pierre Neidhardt
2020-11-17 18:22 ` [SPAM UNSURE] " Stephen Leake
2020-11-17 18:32   ` Pierre Neidhardt
2020-11-17 18:46   ` Basil L. Contovounesios
2020-11-17 18:38 ` Eli Zaretskii
2020-11-17 19:11   ` Pierre Neidhardt
2020-11-17 19:27 ` Juri Linkov
2020-11-17 20:00   ` Dmitry Gutov
2020-11-17 21:16   ` William Xu
2020-11-17 21:38     ` Dmitry Gutov
2020-11-18  7:35       ` William Xu
2020-11-18 13:46         ` Dmitry Gutov
2020-11-18 18:53           ` William Xu
2020-11-18 19:22             ` Dmitry Gutov
2020-11-18 20:39               ` Juri Linkov
2020-11-19  1:34                 ` Dmitry Gutov
2020-11-18 18:47         ` João Távora
2020-11-19  1:43           ` Dmitry Gutov
2020-11-19  8:19             ` William Xu
2020-11-19 13:30               ` Dmitry Gutov
2020-12-02 21:44               ` Juri Linkov
2020-12-03  0:25                 ` Dmitry Gutov
2020-12-03 21:09                   ` Juri Linkov
2020-12-05  1:12                     ` Dmitry Gutov
2020-12-05 12:21                       ` William Xu
2020-12-05 21:02                         ` Dmitry Gutov
2020-12-06  8:30                           ` William Xu
2020-12-06 11:00                             ` Dmitry Gutov
2020-12-06 14:00                               ` William Xu
2020-12-06 21:01                                 ` Dmitry Gutov
2020-12-05 19:52                       ` Juri Linkov
2020-12-05 21:44                         ` Dmitry Gutov
2020-12-06 20:46                           ` Juri Linkov
2020-12-06 21:20                             ` Dmitry Gutov
2020-12-06 21:34                               ` Juri Linkov
2020-12-06 21:40                                 ` Dmitry Gutov
2020-12-07  9:27                       ` Daniel Martín
2020-12-07 15:12                         ` jixiuf
2020-12-07 21:57                           ` Dmitry Gutov
2020-12-07 21:53                         ` Dmitry Gutov

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).