-
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
Provide better api for configuration if using completing-read #243
Comments
I could hack something like this myself by advising the selectrum api, but I would prefer if I don't have to! See https://github.com/minad/consult/blob/8453761de8f4048be941f88a164f0dd6c71880f5/consult.el#L193 (defmacro consult--selectrum-no-sort (body)
`(minibuffer-with-setup-hook
(lambda () (setq-local selectrum-should-sort-p nil))
,body))
(defmacro consult--selectrum-no-move-default (body)
(let ((advice (make-symbol "advice")))
`(if (bound-and-true-p selectrum-mode)
(letrec ((,advice (lambda (args)
(advice-remove #'selectrum-read ,advice)
(append args '(:no-move-default-candidate t)))))
(advice-add #'selectrum-read :filter-args ,advice)
(unwind-protect
,body
(advice-remove #'selectrum-read ,advice)))
,body))) |
What about providing a wrapper to make calling (cl-defun selectrum-cr (prompt candidates
&key predicate require-match initial-input
hist def inherit-input-method
sort no-move-default-candidate)
(minibuffer-with-setup-hook
(lambda ()
(setq-local selectrum-should-sort-p sort)
(setq-local selectrum--move-default-candidate-p
(not no-move-default-candidate)))
(completing-read prompt candidates
predicate require-match initial-input
hist def inherit-input-method))) |
Oh there is selectrum--move-default-candidate-p :) I should read the selectrum code at some point, currently doing the blackbox thing... I agree that the proposed code is ok! I think this resolves this for me. This idiom should be documented prominently somewhere. Since this is how selectrum should actually be invoked I guess instead of selectrum-read - with graceful fallback to any other completion system! |
But in your example above, should-sort-p should actually not be used there. Instead the completion metadata should be used as in my consult--read wrapper. |
Could we at least make EDIT: @clemera I am not yet fully convinced. Things are getting mega ugly. If you look at my consult--read function, there is already the mess needed for preview. Then another minibuffer-with-setup-hook block, it is getting out of the hands. Maybe we could think a bit more about this... |
Maybe we could even use something like this as
Yes, whenever the official API supports settings we should use it, my bad.
If we decide something like the proposed wrapper this is the way to go I think.
I think the mess is the reason we provide wrappers so users don't have to deal with it so maybe it's okay? Let's wait a bit if we can think of a better approach and also until @raxod502 has the chance to react. |
Making selectrum-read private would be the greatest if we can make it work. But only if I can get a working
There is one thing however. The wrapper cannot be part of the selectrum package, in order to not incur a hard dependency. The wrapper must be simple enough for the users to write themselves :) Take a look at my consult--configure-minibuffer macro which I am using for now https://github.com/minad/consult/blob/da4ca11855edb95ee91a6a842f5b19f753e3b0e9/consult.el#L196.
I am not expecting anything to be done here in a hurry. But maybe we can profit of the experiences to improve the selectrum api! I would very much like to hear what @raxod502 has to say about the api. |
I don't think we can/need to avoid introducing a hard dependency here. You have to install selectrum but the benefit would be you don't have to use it for commands written with the wrapper, those would work fine with any |
Why not? As of now I don't have a hard dependency in consult and I would like it that way. I rather sacrifice nice API in order to avoid the dependency. So what I am looking for - the best possible API which works with completing-read only and which works without the hard dependency. My Therefore my proposal was to provide a single selectrum option variable (a plist) which the user can set to add options for the next selectrum-read call. Even if the selectrum--read call is not even happen publicly. (setq selectrum-options '(:sort nil :move-default-candidate nil)) Then this would work nicely without incurring a hard dependency. The user would only have to defvar this one variable. |
Alternatively, maybe this is a better idea! What about adding a 'selectrum-metadata command which is queried from the candidates function? This would feel better. But I am not sure if the completing-read api allows for such extensions. Probably not... |
If we reset the options on each call that could work, I did not think of that. So it would be a one off, you can let bind this to some value and the options only last for the very next call. That sounds nice! |
Let's see what @raxod502 says about that. I think something like this could replace selectrum-read completely for me and we could indeed make it private which would be kind of bold. Note that consult-buffer still won't work then and this is kind of a show-stopper for me. I think in that case I could still use selectrum--read. Regarding making api private, selectrum also makes another parts of its api public (selectrum-read-file etc and the reason is not entirely clear to me). But let's keep the issues separate. Making api private is orthogonal to allowing small selectrum configuration tweaks together with completing-read, which what I would like to achieve here. |
Closed in favor of #244, where the discussion continued. |
I would like to set the
no-move-default-candidate
option for the nextcompleting-read
call (this would be helpful forconsult-line
for example). The goal is that I don't have to use the selectrum api, but could still enhance it while degrading gracefully if not using selectrum. I don't see a possibility to do this using thecompleting-read
api. It is important that the setting is not set in the whole block, since that would apply to all recursive invocations. Therefore theselectrum-should-sort-p
api should be changed too I guess.Could something like this work?
See also issue #242 by @clemera
Sorry for flooding you with issues!
The text was updated successfully, but these errors were encountered: