Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using in tandem with vertico and orderless #120

Closed
beetleb opened this issue Apr 22, 2022 · 12 comments
Closed

Using in tandem with vertico and orderless #120

beetleb opened this issue Apr 22, 2022 · 12 comments

Comments

@beetleb
Copy link

beetleb commented Apr 22, 2022

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
Copy link
Contributor

okamsn commented Apr 22, 2022

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
Copy link

minad commented Apr 23, 2022

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
Copy link
Contributor

okamsn commented Apr 23, 2022

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

Yes, this is on my to-do list.

@minad
Copy link

minad commented Apr 23, 2022

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
Copy link
Contributor

okamsn commented Apr 24, 2022

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
Copy link

minad commented Apr 24, 2022

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
Copy link

jdtsmith commented May 18, 2022

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

@minad
Copy link

minad commented May 18, 2022 via email

@jdtsmith
Copy link

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
Copy link

minad commented May 18, 2022 via email

@minad
Copy link

minad commented Jul 9, 2022

@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

okamsn added a commit to okamsn/prescient.el that referenced this issue Sep 10, 2022
This completion style can optionally modify a completion table's
metadata to use `prescient.el` sorting, including
`prescient-sort-full-matches-first`.

- Update the CHANGELOG.
- Update the README.

- Prescient changes:
  - Add faces `prescient-primary-highlight` and
    `prescient-secondary-highlight`. Add a function to apply them.
  - Add user options `prescient-highlight-completions` and
    `prescient-completion-enable-sort`.
  - Make `prescient-filter` work with completion tables by using
    `all-completions` instead of assuming lists.
    - `prescient-filter` now propertizes all returned candidates
      with the regexps prescient used and whether it ignored case.
      This is needed for sorting after filtering.
  - Add filtering functions `prescient-all-completions`,
    `prescient-try-completion`, which use `prescient-filter`.
  - Add sorting functions `prescient--completion-modify-sort`,
    `prescient-sort-full-matches-first`, and
    `prescient-completion-sort`.
  - Define a completion style `prescient` that uses those functions.
  - The completion style can modify unsorted tables to use
    `prescient-completion-sort`, which wraps `prescient-sort` and
    `prescient-sort-full-matches-first`.
    - This requires Emacs 27+.
    - This is off by default to more easily work with multiple
      completion UIs. Some UIs (such as Vertico and Corfu) allow
      setting the sorting function to use after filtering.  Setting
      that option to the function `prescient-completion-sort` works
      and applies to the output of all completion styles and backends,
      not just `prescient`.

- Selectrum Prescient changes:
  - Old faces are now aliases of the completion faces.
  - Since Selectrum seems to remove the text properties of candidates
    after filtering, we use a function `selectrum-prescient--refine`
    that combines `prescient-filter` with
    `prescient-sort-full-matches-first`.
  - Move `selectrum-prescient--highlight` into Prescient for the
    completion style as `prescient--highlight-matches`. Use that
    instead.

- Company Prescient changes:
  - Change `company-prescient-transformer` so that uses
    `prescient-completion-sort` instead of just `prescient-sort`. This
    should allow for moving full matches when using CAPFs and will
    always at least do `prescient-sort`.

See also the PR radian-software#125. For various discussions about implementing a
`prescient` completion style, see also radian-software#125, radian-software#120, radian-software#112, radian-software#89, radian-software#58, and
radian-software#54.
okamsn added a commit that referenced this issue Sep 11, 2022
This completion style can optionally modify a completion table's
metadata to use `prescient.el` sorting, including
`prescient-sort-full-matches-first`.

- Update the CHANGELOG.
- Update the README.

- Prescient changes:
  - Add faces `prescient-primary-highlight` and
    `prescient-secondary-highlight`. Add a function to apply them.
  - Add user options `prescient-highlight-completions` and
    `prescient-completion-enable-sort`.
  - Make `prescient-filter` work with completion tables by using
    `all-completions` instead of assuming lists.
    - `prescient-filter` now propertizes all returned candidates
      with the regexps prescient used and whether it ignored case.
      This is needed for sorting after filtering.
  - Add filtering functions `prescient-all-completions`,
    `prescient-try-completion`, which use `prescient-filter`.
  - Add sorting functions `prescient--completion-modify-sort`,
    `prescient-sort-full-matches-first`, and
    `prescient-completion-sort`.
  - Define a completion style `prescient` that uses those functions.
  - The completion style can modify unsorted tables to use
    `prescient-completion-sort`, which wraps `prescient-sort` and
    `prescient-sort-full-matches-first`.
    - This requires Emacs 27+.
    - This is off by default to more easily work with multiple
      completion UIs. Some UIs (such as Vertico and Corfu) allow
      setting the sorting function to use after filtering.  Setting
      that option to the function `prescient-completion-sort` works
      and applies to the output of all completion styles and backends,
      not just `prescient`.

- Selectrum Prescient changes:
  - Old faces are now aliases of the completion faces.
  - Since Selectrum seems to remove the text properties of candidates
    after filtering, we use a function `selectrum-prescient--refine`
    that combines `prescient-filter` with
    `prescient-sort-full-matches-first`.
  - Move `selectrum-prescient--highlight` into Prescient for the
    completion style as `prescient--highlight-matches`. Use that
    instead.

- Company Prescient changes:
  - Change `company-prescient-transformer` so that uses
    `prescient-completion-sort` instead of just `prescient-sort`. This
    should allow for moving full matches when using CAPFs and will
    always at least do `prescient-sort`.

See also the PR #125. For various discussions about implementing a
`prescient` completion style, see also #125, #120, #112, #89, #58, and
#54.
@minad minad closed this as completed Sep 11, 2022
@minad
Copy link

minad commented Oct 12, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

4 participants