minad / cape

🦸cape.el - Completion At Point Extensions
GNU General Public License v3.0
592 stars 21 forks source link

Idea: select completion category interactively (cape + corfu?) #12

Closed jdtsmith closed 2 years ago

jdtsmith commented 2 years ago

This probably isn't a CAPE issue, but since CAPE will enable for the first (?) time drawing completions from many unrelated CAPF's into one result super-set...

In addition to the annotation-function idea I mentioned in #10 (which I continue to believe will be a highly desired feature), consult interaction gave me the following idea: add a binding during corfu pop-up when working with super-CAPFs (C-+) that allow you to focus down on just one category. Similar to e.g. "buffers only" in consult-buffer. So basically a multi-capf that can dynamically "de-scope" itself during completion down to a single CAPF, or vv.

minad commented 2 years ago

There are two ways to implement this:

  1. Implement a generic capf dispatcher which takes a dispatcher function and which must return a capf. This dispatcher function can dynamically chose from multiple capfs. I added the dispatcher to the wishlist for now.
;;;###autoload
(defun cape-capf-dispatcher (dispatch)
  "Call DISPATCH function which must return a Capf."
  (lambda ()
    (when-let (capf (funcall dispatch))
      (pcase (funcall capf)
        (`(,beg ,end ,table . ,plist)
         `(,beg ,end
                ,(lambda (str pred action)
                   (let ((new-capf (funcall dispatch)))
                     (unless (eq capf new-capf)
                       (pcase (funcall new-capf)
                         (`(,_beg ,_end ,new-table . ,_plist)
                          (setq table new-table capf new-capf)))))
                   (complete-with-action action table str pred))
                ,@plist))))))
  1. You can already bind cape-dict, cape-dabbrev and a dabbrev+dict super capf to different keys. Then Corfu will allow you to toggle between these different capfs. See https://github.com/minad/cape#configuration. For this reason I don't see the need to add further narrowing support as in consult-buffer.
jdtsmith commented 2 years ago

Dispatcher could also return a list of capfs for a dynamic super-capf.

minad commented 2 years ago

Dispatcher could also return a list of capfs for a dynamic super-capf.

No. Instead the dispatcher should just call cape-super-capf itself and return the constructed capf.