-
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
Handle minibuffer completion table, predicate and metadata #95
Handle minibuffer completion table, predicate and metadata #95
Conversation
This PR fails with CI for emacs-master but I can't check why because I don't want to give them read and write access for all my repos which they apparently require to show me the results for some reason. |
de64ebb
to
428328c
Compare
428328c
to
850ef7a
Compare
Thanks, it's fixed now. |
See #94 (comment). |
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.
Okay, seems fine. Could you add a changelog entry?
selectrum.el
Outdated
For MINIBUFFER-COMPLETION-TABLE and | ||
MINIBUFFER-COMPLETION-PREDICATE see `minibuffer-completion-table' | ||
and `minibuffer-completion-predicate'. They are used for internal | ||
purposes and compatibility to Emacs completion API." |
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.
This should probably explicitly mention that passing the keyword arguments will dynamically bind the corresponding variables, as otherwise you have to be extremely familiar with binding semantics and the implementation of cl-defun
to guess that it has this effect.
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.
Good idea, have done it.
The embark package has made a lot of progress and can be used with selectrum for occur and actions. Currently there is one last issue with selectrum: One of the tricks embark uses is to call a command, insert a candidate into the minibuffer and exit with it. With default completion there is no extensive computation when a With this PR standard completion tables are now computed once in (add-hook 'embark-setup-hook
(defun embark-selectrum-handle-inject ()
(when selectrum--active-p
;; use the injected candidate and make sure selectrum doesn't
;; update afterwards
(setq selectrum--current-candidate-index -1)
(setq selectrum--previous-input-string
(buffer-substring
selectrum--start-of-input-marker
selectrum--end-of-input-marker))))) Another benefit of computing the table in post command hook is that we could offer an (defun selectrum-exhibit ()
"Refresh completion."
(when-let ((mini (active-minibuffer-window)))
(with-selected-window mini
(when minibuffer-completion-table
;; trigger recomputation and display update
(setq selectrum--preprocessed-candidates nil)
(setq selectrum--previous-input-string nil)
(selectrum--minibuffer-post-command-hook))))) This can for example be used for creating simple async completion tables. If you want to checkout embark yourself here is my current setup to configure it for selectrum (at current PR), you should omit the which-key section if you don't use it. |
6aecf47
to
38d7a59
Compare
38d7a59
to
58a31e6
Compare
I also added support for (completing-read "Check: "
(lambda (string pred action)
(if (eq action 'metadata)
`(metadata
(display-sort-function
. ,(lambda (seq) (sort seq #'string<))))
(complete-with-action action '("c" "b" "a") string pred)))) |
dec4daa
to
370f37d
Compare
370f37d
to
f08fb78
Compare
822aac0
to
9e4390f
Compare
9e4390f
to
2193ad0
Compare
Thanks, I finished updating the CHANGELOG and also added the mentioned |
2d876b5
to
4a926b8
Compare
Co-authored-by: Radon Rosborough <radon.neon@gmail.com>
Co-authored-by: Radon Rosborough <radon.neon@gmail.com>
Co-authored-by: Radon Rosborough <radon.neon@gmail.com>
Turned out that |
89ea467
to
47b4631
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.
Thanks very much!
Thanks for the feedback and review! |
This will allow us to access the metadata for purposes as discussed in #15 and #82 and allows other packages and commands to access those variables (see #94). With this patch we can retrieve the metadata like:
We could also decide to only pass the metadata instead (which would probably reduce garbage collection when exiting the minibuffer I guess). But the metadata can depend on the current input and the predicate passed to the completion table. Having metadata dependent on the input or predicate sounds like a crazy idea and I don't know if it actually happens in practice.