-
Notifications
You must be signed in to change notification settings - Fork 33
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
Add `selectrum-update-candidates-function' #27
Add `selectrum-update-candidates-function' #27
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, good idea. Alternative approach: we could have a macro or function for automating the let-binding. But your idea is probably better, as long as we don't start doing too many magic things with the new information that's available about caller intent.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have an idea for a simpler API: for selectrum-read
(but not for higher-level functions wrapping it), CANDIDATES can be a function of no arguments that returns a list of candidates, instead of the list of candidates itself. In response to your concern, here's what I'm thinking for the control flow:
- In the minibuffer setup hook: set
selectrum--preprocessed-candidates
to CANDIDATES, transformed by the preprocessing function only if CANDIDATES is a list. In other words,selectrum--preprocessed-candidates
can also be either a function or a list. - In the minibuffer post-command hook: if
selectrum--preprocessed-candidates
is a function, call it before passing the result to the preprocessing and refinement functions. - The handling of user input transforms doesn't need to change at all.
I don't think the preprocessing function should need to take the input as an additional argument. The change can be neatly compartmentalized: it just adds a new step where CANDIDATES can be turned from a function into a list, and pushes the call to the preprocessing function to later (the post-command hook) in this case. I don't see as much of a compelling argument to change the other parts of the API.
The main reason for my proposed change was to be able to simplify the implementation of functions such as
By moving the The way I understand your last suggestion you want to take the |
Oh. Good point, sorry -- I didn't inspect your change closely enough. Here are my new thoughts. I quite like the abstraction of Here is what I suggest. Like I mentioned above, we can allow the collection to be a function. If it is a function, then it takes the input as an argument and returns an alist with keys What do you think? |
I have adjusted the code accordingly. One additional thought I had is that it would be nice to run |
I did not remove the changes for selectrum-refine-function docstring because I'm not sure how you want to proceed. |
Also note that currently buffer switching is broken because |
Yeah, I think you're right. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks perfect to me. Want to update the README and CHANGELOG?
I can do that, but you would have to help me how to proceed from here ;) When I started with this PR there was no Changelog and the Readme also changed since then. Should I merge master into this branch and then proceed? In general I'm happy for any tips if you notice I'm doing something awkward because I'm not so familiar with git/github workflows. |
No problem. Yes, you should merge |
Ok, I merged and updated the files. If I may ask another question: How do you merge this as a single commit? By that I mean what is your workflow to merge this PR as one commit in such a way that I appear in the commit list and you as a co author (as I have seen you have done in a previous PR). |
db331a7
to
330beb5
Compare
a7dd7d5
to
482b6fe
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great, this is a fantastic improvement and I appreciate your help.
Thank you! I should probably study the github UI more ;) |
This function can be used if the set of candidates needs to be
computed dynamically. This simplifies the implementation of functions like
selectrum-read-file-name
which need to compute the candidate list based on user input.The new function also takes over the transform input feature of
selectrum-refine-candidates-function
which now should always return a list of candidates. As selectrum is still at version 0 I thought it might be OK to change the API of existing functions. In general I think adding such a function would make the API a bit cleaner because the refine function now has a single job: filtering the candidates and writing functions which need to compute the candidate list dynamically can be written in a more straight forward way.If you are OK with the change I can update the docs and README, too.