feat(corfu): general move-to-minibuffer impl

We previously implemented only consult/vertico as a target for export,
now we have all of them. It was necessary to use case-by-case
conditions, unfortunately, because other UIs have subtle quirks that
prevent a single generalized approach to work.

Ivy is almost compliant, but it needs beg and end to not be markers.

Helm doesn't replace `completion-in-region-function`, it expects to go
around the default `completion--in-region`, so a small addition was made
to its module, because we weren't doing that. This was likely an
oversight due to the non-standard usage. This was fixed here because we
need it working for this feature.

Ido doesn't implement `completion-in-region` and its `completing-read`
is retricted to a list of strings as table, so it's treated the same as
absence of a framework, because it lacks the needed features.
This commit is contained in:
Luigi Sartor Piucco 2024-02-04 17:17:13 -03:00
parent a5db530622
commit 70c327a4f1
No known key found for this signature in database
GPG key ID: 6FF1A01853A47A66
4 changed files with 31 additions and 11 deletions

View file

@ -10,12 +10,30 @@
;;;###autoload
(defun +corfu-move-to-minibuffer ()
;; Taken from corfu's README.
;; TODO: extend this to other completion front-ends.
"Move the current list of candidates to your choice of minibuffer completion UI."
(interactive)
(let ((completion-extra-properties corfu--extra)
(completion-cycle-threshold completion-cycling))
(apply #'consult-completion-in-region completion-in-region--data)))
(pcase completion-in-region--data
(`(,beg ,end ,table ,pred ,extras)
(let ((completion-extra-properties extras)
completion-cycle-threshold completion-cycling)
(cond ((and (modulep! :completion vertico)
(fboundp #'consult-completion-in-region))
(consult-completion-in-region beg end table pred))
((and (modulep! :completion ivy)
(fboundp #'ivy-completion-in-region))
(ivy-completion-in-region (marker-position beg) (marker-position end) table pred))
;; Helm is special and wants to _wrap_ `completion--in-region'
;; instead of replacing it in `completion-in-region-function'.
((and (modulep! :completion helm)
(fboundp #'helm--completion-in-region)
(advice-member-p #'helm--completion-in-region #'completion--in-region))
;; Important: `completion-in-region-function' is set to corfu at
;; this moment, so `completion-in-region' (single -) doesn't work.
(completion--in-region beg end table pred))
;; Ido doesn't implement `completion-in-region', and its
;; `completing-read' only accepts a plain list of strings as table,
;; so there's not much we can do with it.
(t (error "No minibuffer completion UI available for moving to!")))))))
;;;###autoload
(defun +corfu-smart-sep-toggle-escape ()