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

Support function as the value of prescient-filter-method #110

Merged
merged 4 commits into from
Jul 24, 2021
Merged

Support function as the value of prescient-filter-method #110

merged 4 commits into from
Jul 24, 2021

Conversation

peterstuart
Copy link
Contributor

@peterstuart peterstuart commented Jun 23, 2021

Fixes #83. The use case is to be able to use different filter methods depending on the type of completions. I am testing this with the following config:

(defun ps/filter-method ()
  (let ((completion-category
         (completion-metadata-get
          (completion-metadata (minibuffer-contents)
                               minibuffer-completion-table
                               minibuffer-completion-predicate)
          'category)))
    (cond ((eql completion-category 'file)          '(fuzzy))
          ((eql completion-category 'command)       '(fuzzy))
          ((eql completion-category 'consult-multi) '(fuzzy))
          (t                                        '(literal regexp initialism)))))


(setq prescient-filter-method 'ps/filter-method)

I am an elisp beginner—hopefully I've done this correctly 😄

@okamsn
Copy link
Contributor

okamsn commented Jun 28, 2021

Does this work with the toggling commands in the Selectrum-Prescient package?

@peterstuart
Copy link
Contributor Author

@okamsn Whoops, no—I was not familiar with that feature. I just added a commit which makes it work with the selectrum-prescient-toggle-* functions.

@okamsn
Copy link
Contributor

okamsn commented Jul 4, 2021

@okamsn Whoops, no—I was not familiar with that feature. I just added a commit which makes it work with the selectrum-prescient-toggle-* functions.

Thank you. This seems to work for me.

Maybe, in addition to allowing the function value and the flat list it is currently, it might also make sense to just allow prescient-filter-method to be an association list? What are your thoughts on this, @raxod502?

That way, instead of everyone needing to copy a function like that which @peterstuart has written, they could just do

(setq prescient-filter-method 
      '((file          . (fuzzy))
        (command       . (fuzzy))
        (consult-multi . (fuzzy))
        (t             . (literal regexp initialism))))

where the key is the completion category and the value is a symbol or list of symbols.

Or, if one wanted to mimic completion-category-overrides, then one could also do something like

(setq prescient-filter-method 
      '((file    . ((style     . (fuzzy))
                    (case-fold . nil)
                    (char-fold . t)))
        (command . ((full-matches-first . t)))
        (t       . ((style     . (literal regexp initialism))
                    (case-fold . smart)))))

which could also locally bind the variables prescient-use-char-folding, prescient-use-case-folding, and prescient-sort-full-matches-first.

Copy link
Member

@raxod502 raxod502 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✨ Looks great, thank you!

@raxod502
Copy link
Member

Maybe, in addition to allowing the function value and the flat list it is currently, it might also make sense to just allow prescient-filter-method to be an association list?

I see the motivation for this, but I'd prefer not to do that at this time. I think that depending on the user's Emacs configuration there are quite a few potentially reasonable different ways to determine what the "current completion context" is, and I don't really want to tie prescient.el to one of them officially.

That said, I remember there was discussion about this in the Selectrum project where I took a similar position---did you end up finding a reasonable solution that was deemed not too fragile to endorse officially?

@raxod502 raxod502 merged commit 027c213 into radian-software:master Jul 24, 2021
@peterstuart peterstuart deleted the prescient-filter-method-function branch July 24, 2021 17:59
@okamsn
Copy link
Contributor

okamsn commented Jul 24, 2021

That said, I remember there was discussion about this in the Selectrum project where I took a similar position---did you end up finding a reasonable solution that was deemed not too fragile to endorse officially?

Not that I recall. Re-reading the discussions, it doesn't look like any option was found to be the clear best.

My understanding of things is that packages like Consult, Embark, and Marginalia make good use of the "completion category" metadata, which might or might not encourage its use in other places. There's also the new variable current-minibuffer-command, which is similar to this-command.

I see the motivation for this, but I'd prefer not to do that at this time. I think that depending on the user's Emacs configuration there are quite a few potentially reasonable different ways to determine what the "current completion context" is, and I don't really want to tie prescient.el to one of them officially.

I understand. Hopefully a clear best approach arises in the future.

@aspiers
Copy link

aspiers commented Jun 3, 2023

That said, I remember there was discussion about this in the Selectrum project where I took a similar position---did you end up finding a reasonable solution that was deemed not too fragile to endorse officially?

Not that I recall. Re-reading the discussions, it doesn't look like any option was found to be the clear best.

The discussion (or at least some of it) was actually in this project:

#83 (comment)

My understanding of things is that packages like Consult, Embark, and Marginalia make good use of the "completion category" metadata, which might or might not encourage its use in other places. There's also the new variable current-minibuffer-command, which is similar to this-command.

I see the motivation for this, but I'd prefer not to do that at this time. I think that depending on the user's Emacs configuration there are quite a few potentially reasonable different ways to determine what the "current completion context" is, and I don't really want to tie prescient.el to one of them officially.

I understand. Hopefully a clear best approach arises in the future.

As reported in #146 just now, I haven't yet found any workable solution for my needs based on the above.

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

Successfully merging this pull request may close these issues.

equivalent of ivy-re-builders-alist for selectrum?
4 participants