radian-software / prescient.el

☄️ Simple but effective sorting and filtering for Emacs.
MIT License
603 stars 25 forks source link

Using in tandem with vertico and orderless #120

Closed beetleb closed 2 years ago

beetleb commented 2 years ago

Sorry if my question is a bit on the rambling side, but I'm new to this ecosystem (migrating from helm).

I use vertico and orderless. What I would like is to use prescient for the sorting capability only. vertico will still be the interface, and orderless will do the matching. Is this doable?

Thanks.

okamsn commented 2 years ago

You can use prescient-sort for Vertico's sorting function.

You would also need a way to pass the chosen candidate to prescient-remember. There is probably a hook that can be used for this. User @minad, the author of Vertico, would know.

minad commented 2 years ago

Such a hook does not exist in Vertico. You could probably use an advice on vertico-exit. However using Prescient with Vertico for sorting doesn't bring significant benefits since Vertico alreads sorts by history position out of the box (by recency, see vertico-sort-function and vertico-sort-override-function). In comparison, Prescient sorts by frecency which is only slightly better since a flexible completion style will narrow down the candidates quickly enough anyway. Prescient has to store its own history and doesn't distinguish the completion candidate types (#85). For filtering, the Orderless completion style is more flexible and faster than Prescient and Prescient is not a completion style (#54, #89). For these reasons I am critical of Prescient and didn't add specific support to Vertico and Corfu (#112). Nevertheless it should be possible to create a vertico-prescient integration package, which glues prescient-remember to Vertico. I also think that wrapping Prescient in a completion style should be possible.

okamsn commented 2 years ago

I also think that wrapping Prescient in a completion style should be possible.

Yes, this is on my to-do list.

minad commented 2 years ago

Yes, this is on my to-do list.

Is there any advantage of Prescient filtering over Orderless filtering at this point? If something is missing in Orderless we could also add it there. Note that Orderless has a flexible matching style dispatcher mechanism which lets the user control the generated regular expressions per word.

okamsn commented 2 years ago

Yes, this is on my to-do list.

Is there any advantage of Prescient filtering over Orderless filtering at this point? If something is missing in Orderless we could also add it there. Note that Orderless has a flexible matching style dispatcher mechanism which lets the user control the generated regular expressions per word.

Off the top of my head, one thing that's unique to using Prescient with Selectrum is prescient-sort-full-matches-first, which maintains the frecency sorting because the frecency sorting happens before filtering. This moves candidates fully matched by the regexps ahead of others, which is separate from just the literal match. I find this convenient, but am not sure whether it can be impemeted as part of a completion style, since other interfaces might do sorting after filtering.

Other than that, I would have to try Orderless again.

minad commented 2 years ago

Completion styles can modify the sort function, e.g., combine some style-specific sorting with the sorting function provided by the UI, so I think one could implement this on top of the completion styles. But this sounds like an edge case feature. I like that Orderless stays completely out of sorting.

jdtsmith commented 2 years ago

corfu could also use a recency-based sort function. Nevermind, found corfu-history.

minad commented 2 years ago

corfu could also use a recency-based sort function.

Corfu already provides corfu-history for sorting by recency. Vertico also sorts by recency by default. The difference of Prescient is that Prescient factors in the frequency, such that we get an overall sorting by frecency. I argue that sorting by frecency is not significantly better than sorting by recency when quickly narrowing down to a candidate. For recency-based sorting we can simply rely on the history variable (e.g. the minibuffer history) and don't have to track the frequencies and compute a decay. Therefore I prefer the simpler and more predictable recency-based sorting which comes with Vertico/Corfu ootb.

jdtsmith commented 2 years ago

Yep thanks, playing with corfu-history now. Not sure how I missed it. Sadly it doesn't work with cape-super-capfs, since that hard-overrides the sort-functions with #'identity, cutting corfu-history out of the loop. Some comments over on cape on that.

minad commented 2 years ago

Yep thanks, playing with corfu-history now. Not sure how I missed it. Sadly it doesn't work with cape-super-capfs, since that hard-overrides the sort-functions with #'identity, cutting corfu-history out of the loop. Some comments over on cape on that.

Yes, that's always the downside if completion tables specify a sort function. We have the corfu-sort-override-function variable to override, which can be useful in rare cases.

minad commented 2 years ago

@okamsn just added a section to the vertico wiki, which explains how to use prescient sorting in vertico: https://github.com/minad/vertico/wiki#using-prescientel

minad commented 1 year ago

See also #131 for more Vertico/Prescient integration, but with Prescient for both filtering and sorting.