-
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 keep-selection arg to selectrum-exhibit #307
Add keep-selection arg to selectrum-exhibit #307
Conversation
Thank you for working on this! Is this correct? I do not want to preserve the index, but the selected candidate string. Otherwise the candidate could magically change when new candidates come in. See the discussion in minad/consult#91. |
As long as new candidates are added at the end this should work for your purposes, but please give it some testing. |
Or does the index correspond to the index in the original (non refined) candidate list. Then it would be okay given we append only. This is the case right now with the consult async implementation. |
There is |
I'm not sure what you mean, my last commit was about something else. |
Can you explain your last comment a bit more? |
So if you just retain the index while candidates are appended, it is not sufficient. Does this explain it? But this makes only sense if you sort. |
So what I think we need:
|
Thanks, so it can break with sorting, too bad. I hope I find time to look at it tomorrow, the next few days I won't be online as much. |
Sure, no hurry! Thanks again! Have a nice Christmas and holidays! |
Thanks and thanks for testing, I wish you the same! |
ee21b55
to
638158f
Compare
638158f
to
f631359
Compare
The problem you described is fixed now, is there anything else you think we should consider? |
@clemera Thank you. Great to hear. I did not test it yet, but I will try it soon and then I will come back to you in case more is needed! Originally I had a problem with pressing the up down keys before entering some string for filtering. In that case the up down keys don't work directly. |
Great, I had not noticed the up/down key issue before and currently I can not see it so when you give it a try please let me know if it still exists. |
@clemera I just tried it and it works very well - thank you! Regarding the patch, I wonder if it is necessary to introduce the keep-candidate variable? I generally try to reduce global state since it can easily get messed up. I am increasingly worried by the number of global variables in selectrum. If there is a possibility to reduce this or avoid introducing new ones, it would probably be good. @oantolin also recently reduced global state in Embark. Then there is this macro to save global state. Would it be possible to replace this all with closures or minibuffer local state, which would work automatically with recursive minibuffers? This is at least the route I am taking in Consult - everything should be minibuffer-local. |
@clemera The global state avoidance is also one thing why I dislike configuring selectrum via setting global variables, instead preferring selectrum-metadata if calling via completing-read or keyword arguments if calling via selectrum-read. |
selectrum.el
Outdated
(if keep-selection | ||
(selectrum-get-current-candidate) | ||
selectrum--keep-candidate))) | ||
(selectrum--minibuffer-post-command-hook))))) |
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.
why not call the hook here with the current candidate to keep as argument? Maybe the selectrum--minibuffer-post-command-hook should be extracted into a separate selectrum--post-command function which is then called from both here and from the selectrum--minibuffer-post-command-hook. I don't think it is the best style to call hook functions from somewhere else, they should only be called via run-hooks after putting them in the appropriate hook list.
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 followed your suggestions, I also don't want to add an argument to the hook function itself. Could you test this with your async function?
I agree, it works both ways and the variable allows other use cases we haven't thought of but I also don't see any other ones so I think adding an argument to the hook instead is good.
I have described the benefits I see with this approach here. I think its very important to let other callers reuse your code but adjust the settings for their purposes. |
@clemera I agree that using a variable gives more flexibility. But I would avoid this kind of premature globalisation if possible. In the case of the configuration I agree. I am only not fond of it. But it is not that I don't see why it is useful :) |
8a2f599
to
4333d0f
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.
Looks good from my side! This is the last missing piece for perfect async support in Consult :)
I will do a test now - didn't test it before only inspected what you did and was satisfied. |
Okay, thanks! |
@clemera works well! As expected! :) |
b4b167d
to
9d9db62
Compare
9d9db62
to
362d0a3
Compare
@clemera Can you merge this or is something else missing? |
Nothing missing just me in front of the computer ;) |
@minad As we discussed this lets you call
selectrum-exhibit
without updating the index which is allows for better handling of async completions as shown in #306.