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

Add keep-selection arg to selectrum-exhibit #307

Conversation

clemera
Copy link
Collaborator

@clemera clemera commented Dec 25, 2020

@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.

@minad
Copy link
Contributor

minad commented Dec 25, 2020

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.

@clemera
Copy link
Collaborator Author

clemera commented Dec 25, 2020

As long as new candidates are added at the end this should work for your purposes, but please give it some testing.

@minad
Copy link
Contributor

minad commented Dec 25, 2020

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.

@minad
Copy link
Contributor

minad commented Dec 25, 2020

There is (nth index selectrum--refined-candidates) in the code where index=selectrum--current-candidate-index, so I think this is not correct.

@clemera
Copy link
Collaborator Author

clemera commented Dec 25, 2020

I'm not sure what you mean, my last commit was about something else.

@clemera
Copy link
Collaborator Author

clemera commented Dec 25, 2020

Can you explain your last comment a bit more?

@minad
Copy link
Contributor

minad commented Dec 25, 2020

  1. If I have the candidates "alpha beta gamma", current candidate index is i=0
  2. User enters "b", the candidates are refined to "beta", current candidate index is i=0
  3. Async pushes another candidate "base", refined candidates are "base beta", current candidate index should be i=1

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.

@minad
Copy link
Contributor

minad commented Dec 25, 2020

So what I think we need:

  1. remember the current candidate string
  2. refresh candidate list and refined candidate list
  3. recompute the current candidate index by searching the list of refined candidates

@clemera
Copy link
Collaborator Author

clemera commented Dec 25, 2020

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.

@minad
Copy link
Contributor

minad commented Dec 25, 2020

Sure, no hurry! Thanks again! Have a nice Christmas and holidays!

@clemera
Copy link
Collaborator Author

clemera commented Dec 25, 2020

Thanks and thanks for testing, I wish you the same!

@clemera clemera marked this pull request as draft December 25, 2020 21:37
@clemera clemera force-pushed the add-keep-index-arg-to-selectrum-exhibit branch 2 times, most recently from ee21b55 to 638158f Compare December 26, 2020 15:28
@clemera clemera force-pushed the add-keep-index-arg-to-selectrum-exhibit branch from 638158f to f631359 Compare December 26, 2020 15:30
@clemera
Copy link
Collaborator Author

clemera commented Dec 26, 2020

The problem you described is fixed now, is there anything else you think we should consider?

@minad
Copy link
Contributor

minad commented Dec 26, 2020

@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.

@clemera
Copy link
Collaborator Author

clemera commented Dec 26, 2020

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.

minad added a commit to minad/consult that referenced this pull request Dec 26, 2020
@minad
Copy link
Contributor

minad commented Dec 26, 2020

@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.

@minad
Copy link
Contributor

minad commented Dec 26, 2020

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

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.

Copy link
Collaborator Author

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?

@minad minad mentioned this pull request Dec 26, 2020
@clemera
Copy link
Collaborator Author

clemera commented Dec 26, 2020

Regarding the patch, I wonder if it is necessary to introduce the keep-candidate variable?

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.

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.

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.

@minad
Copy link
Contributor

minad commented Dec 26, 2020

@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 :)

@minad minad mentioned this pull request Dec 26, 2020
@clemera clemera force-pushed the add-keep-index-arg-to-selectrum-exhibit branch from 8a2f599 to 4333d0f Compare January 3, 2021 18:17
Copy link
Contributor

@minad minad left a 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 :)

@minad
Copy link
Contributor

minad commented Jan 4, 2021

I will do a test now - didn't test it before only inspected what you did and was satisfied.

@clemera
Copy link
Collaborator Author

clemera commented Jan 4, 2021

Okay, thanks!

@minad
Copy link
Contributor

minad commented Jan 4, 2021

@clemera works well! As expected! :)

@clemera clemera force-pushed the add-keep-index-arg-to-selectrum-exhibit branch 2 times, most recently from b4b167d to 9d9db62 Compare January 4, 2021 15:14
@clemera clemera force-pushed the add-keep-index-arg-to-selectrum-exhibit branch from 9d9db62 to 362d0a3 Compare January 4, 2021 15:16
@clemera clemera marked this pull request as ready for review January 4, 2021 15:19
@minad
Copy link
Contributor

minad commented Jan 4, 2021

@clemera Can you merge this or is something else missing?

@clemera clemera changed the title Add keep-index arg to selectrum-exhibit Add keep-selection arg to selectrum-exhibit Jan 4, 2021
@clemera
Copy link
Collaborator Author

clemera commented Jan 4, 2021

Nothing missing just me in front of the computer ;)

@clemera clemera merged commit 499178f into radian-software:master Jan 4, 2021
minad added a commit to minad/consult that referenced this pull request Jan 4, 2021
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.

2 participants