-
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
Support completion styles #82
Comments
There's also |
Oh yes, overlooked that one. |
Is the behavior generated by the default |
No but some default completion styles also don't make complete sense for selectrum because they were not designed for the interactive narrowing selectrum does(maybe we would need to exclude those). The available completion styles are described in the description strings of the elements in For |
completion-styles
for refinementcompletion-styles
and completion metadata
completion-styles
and completion metadata
If the default behavior of |
One benefit would be that the user sets Another one is that via It's true that the current built-in |
But I agree that support of I think more important (but also easier) would be adding support for |
That seems reasonable. |
This seems like exactly what I'm missing from Selectrum currently. I'm trying to migrate from |
@mathrick, in the mean time, have you tried the package |
@okamsn: that is working great so far, thanks for the suggestion! |
Stefan Monnier sent me the following patch by personal email: diff --git a/selectrum.el b/selectrum.el
index 6d0956f..59dfb14 100644
--- a/selectrum.el
+++ b/selectrum.el
@@ -772,6 +763,9 @@ PRED defaults to `minibuffer-completion-predicate'."
selectrum--refined-candidates)))
-1)
((and selectrum--init-p
+ ;; FIXME: Check the `category' returned by
+ ;; `completion-metadata' instead of
+ ;; `minibuffer-completing-file-name'!
minibuffer-completing-file-name
(eq minibuffer-completion-predicate
'file-directory-p) I think this is the issue thread that tracks support for |
@clemera @raxod502 Would it make sense to revisit this issue - is it still necessary to have separate refinement and highlighting functions instead of using the standard completion style facilities? In particular if the idea is to move closer to the standard API with regards to configuration. EDIT: The following seems to work with orderless for example. But the selectrum API is clearly better since in that case the highlights are only applied to the visible candidates and not to all filtered candidates. (setq selectrum-refine-candidates-function
(lambda (string candidates)
(let ((result (completion-all-completions string candidates nil (length string))))
(let ((last result))
(while last
(unless (listp (cdr last))
(setcdr last nil))
(setq last (cdr last))))
result)))
(setq selectrum-highlight-candidates-function (lambda (_ candidates) candidates)) EDIT2: @oantolin told be that the function can be improved. (setq selectrum-refine-candidates-function
(lambda (string candidates)
(let* ((result (completion-all-completions string candidates nil (length string)))
(last (last result)))
(setcdr last nil)
result))) |
I think it's a fine idea to use the default facilities, as long as it does not make it a lot more difficult for a new user to configure the things that are currently supported by the refinement and highlighting functions, which seem fairly straightforward in usage to me. That could be either by making it clear how to make simple adjustments using the |
One possibility would be to keep the current |
That sounds perfect to me. |
With #390 you can now do that, when you type the pattern you automatically get offered the possible candidates of partial matches. |
@clemera: Awesome, I'll give it a spin! |
@clemera: This is looking very nice! I found one bug and one case in which selectrum's behaviour is less useful than
|
@minad: There's a small bug in your (setq! selectrum-refine-candidates-function
(lambda (string candidates)
(let ((result (completion-all-completions string candidates nil (length string))))
(when result
(setcdr (last result) nil))
result))) Without |
@mathrick
The idea is that once you typed a
That is a good observation, I don't know where these completions are coming from with icomplete, I will open an issue for it.
Did you experienced one? Because |
@minad |
Yeah, I realized that and just edited my comment above mentioning that 😆 |
@clemera: Thanks! #393 seems to fix it completely for local paths, but not for remote ones. I still see that behaviour there, in that |
@minad: indeed, my comment was about the |
@mathrick Is this only for ssh? Because |
@clemera: nevermind, I think I was accidentally testing on an Emacs instance that had the old version loaded previously. After a restart it seems to work. However, selectrum also seems to be a bit overzealous with initial expansion of TRAMP paths, as it triggers a connection as soon as the second colon is present in the input, without the user needing to press
|
Okay, thanks for your feedback again! So I guess it would be better to always wait for a TAB first, when detecting a remote path? |
I think so, since there's no way to detect whether it's valid without trying to connect, which is expensive, surprising and might have unforeseen side-effects. It probably makes sense to track "selectrum gets wedged if TRAMP connection fails" as a separate bug too, since it's likely independent of the eager expansion, that just makes it easier to surface that problem. |
@clemera What is the currently recommended orderless configuration in order to use completion-styles? Something like this? (setq selectrum-refine-candidates-function
(lambda (input cands)
(let ((orderless-skip-highlighting t))
(selectrum-refine-candidates-using-completions-styles input cands))))
(setq selectrum-highlight-candidates-function #'selectrum-refine-candidates-using-completions-styles) |
I use the following (updated the wiki accordingly): (setq orderless-skip-highlighting (lambda () selectrum-active-p))
(setq selectrum-highlight-candidates-function #'orderless-highlight-matches) |
Ah okay, makes sense I guess. This should also work nicely if you use |
I set |
Okay, good to know! I am considering to use completion-in-region now instead of company, see also minad/consult#218. Maybe I should also add a consult-completion-in-region-styles variable. I dislike a bit the duplication we are having here between Selectrum and Consult, but it is probably unavoidable for the Selectrum users, which do not also use Consult. |
Yeah I also don't like the duplication but |
@minad said:
I have to confess I don't see the point of TAB completion. Usually completion is a game of narrowing down to a single candidate or maybe a handful. TAB should only be allowed to insert some text into the minibuffer for you when the inserted text does not change the candidate list, right? But in that case you have made zero progress towards your goal of having a single candidate!
That's a good point. |
Yes, I agree about completion. But in the shell I am more accustomed to press TAB to complete or cycle between the candidates. I am not consistent here. I only want to have the basic/substring completion style for the shell/capf and not for minibuffer completion. With capf I already pressed TAB to start completion and then I can quickly cycle through candidates with subsequent TAB presses. This feels faster than going directly to the minibuffer completion. Aren't you also doing the same since you are setting completion-cycle-threshold? The cycle threshold feels less useful if you have to many candidates right away which is not the case with basic. |
The default API uses
completion-styles
andcompletion-styles-alist
to configure completions. Also if the collection passed tocompleting-read
is a function it can return metadata to configure the completion behaviour (like forcompletion-in-region
#84). It would be nice if selectrum would support those settings.The text was updated successfully, but these errors were encountered: