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

For Selectrum, add commands that toggle filtering methods. #72

Merged
merged 43 commits into from
Oct 26, 2020

Conversation

okamsn
Copy link
Contributor

@okamsn okamsn commented Oct 12, 2020

While using Selectrum, I sometimes want to change what filtering method the current search is using, similar to Isearch's isearch-toggle-* commands. This pull request adds commands for this to selectrum-prescient.el.

Currently, this toggling only affects the running Selectrum buffer. Using a prefix argument with a command locally sets prescient-filter-method to only use the method corresponding to that command.

Is there anything that you would like changed?

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.

Thank you, this looks great! Some comments.

README.md Outdated
@@ -64,7 +64,7 @@ ones, and then the remaining candidates are sorted by length. If you
don't like the algorithm used for filtering, you can choose a
different one by customizing `prescient-filter-method`.

## Configuration
## Configuration and Other Features
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
## Configuration and Other Features
## Configuration and other features

README.md Outdated
@@ -90,6 +90,9 @@ different one by customizing `prescient-filter-method`.
matching, regexp matching, fuzzy matching, prefix matching, or any
combination of those. See the docstring for full details.

### Ivy-Specific
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
### Ivy-Specific
### Ivy-specific

README.md Outdated
@@ -110,6 +113,33 @@ different one by customizing `prescient-filter-method`.
the Ivy documentation for information on how Ivy sorts by default,
and how to customize it manually.

### Selectrum-Specific
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
### Selectrum-Specific
### Selectrum-specific

README.md Outdated
@@ -90,6 +90,9 @@ different one by customizing `prescient-filter-method`.
matching, regexp matching, fuzzy matching, prefix matching, or any
combination of those. See the docstring for full details.

### Ivy-Specific
The following user options are specific to using Prescient with Ivy:
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
The following user options are specific to using Prescient with Ivy:
The following user options are specific to using `prescient.el` with Ivy:

The toggling of commands is temporary and does not affect the
default filtering settings determined by `prescient-filter-method'.")
;; Create a binding similar to the Isearch toggles.
(defvar selectrum-minibuffer-map)
Copy link
Member

Choose a reason for hiding this comment

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

These defvar / declare-function forms can go in stub/selectrum.el with the others, so they're all centralized.

;; Create a binding similar to the Isearch toggles.
(defvar selectrum-minibuffer-map)
(define-key selectrum-minibuffer-map
"\M-s" selectrum-prescient-filter-toggle-map)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
"\M-s" selectrum-prescient-filter-toggle-map)
(kbd "M-s") selectrum-prescient-filter-toggle-map)

Copy link
Member

Choose a reason for hiding this comment

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

Is it possible to make it so that this binding is only activated when selectrum-prescient-mode is enabled? While it's easy to do it this way, it's generally considered bad practice for simply loading a package to cause behavior changes.

I'd be happy to spend some time thinking about a good way of making this happen, if you're not sure.

(cons (quote ,filter-type)
prescient-filter-method))
(message "%s filter toggled on."
,(capitalize filter-type-name))))
Copy link
Member

Choose a reason for hiding this comment

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

Would it be a good idea to report the new value of prescient-filter-method after it's updated? It might be hard to keep track of which methods have been toggled on and off if there are multiple.

README.md Outdated
| M-s i | selectrum-prescient-toggle-initialism |
| M-s l | selectrum-prescient-toggle-literal |
| M-s p | selectrum-prescient-toggle-prefix |
| M-s r | selectrum-prescient-toggle-regexp |
Copy link
Member

Choose a reason for hiding this comment

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

Perhaps put these table entries in backticks, for consistency?

@okamsn
Copy link
Contributor Author

okamsn commented Oct 18, 2020

I have tried to address what you wrote. Where else do you think things could be improved?

@okamsn
Copy link
Contributor Author

okamsn commented Oct 21, 2020

@raxod502 Do you think it makes sense to add commands for toggling case and character folding buffer-locally? They're not Prescient features, but fit the general idea of the pull request.

@raxod502
Copy link
Member

Where else do you think things could be improved?

It looks great to me!

Do you think it makes sense to add commands for toggling case and character folding buffer-locally?

I think those probably make more sense to add on the Selectrum side, cc @clemera. They would presumably be useful even to people who don't use prescient.el.


Feel free to change anything else you like, otherwise I'm happy to merge this.

@clemera
Copy link
Collaborator

clemera commented Oct 23, 2020

They would presumably be useful even to people who don't use prescient.el

Yes, that sounds like a great feature! For orderless and other filter functions which use C completion functions internally we would need to set completion-ignore-case in addition to case-fold-search. I'm not sure ab out char folding as I'm not very familiar with it but it seems all that would be necessary would be to transform the input using char-fold-to-regexp before passing it to the filter function.

@okamsn
Copy link
Contributor Author

okamsn commented Oct 24, 2020

I think I am happy with this.

I don't have a use case for toggling the character folding, but I mentioned it because prescient.el uses it automatically for the literal filter.

@raxod502
Copy link
Member

I mentioned it because prescient.el uses it automatically for the literal filter.

You're right. This definitely complicates my idea above to just have the completion framework handle this kind of thing. Some work is required to figure out what the right interface between the two packages is. If somebody is interested in this feature, then I can see if I can come up with an idea.

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.

@raxod502 raxod502 merged commit 41443e1 into radian-software:master Oct 26, 2020
@okamsn okamsn deleted the toggle-commands branch October 26, 2020 16:55
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.

3 participants