minad / cape

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

Label super CAPFs #10

Closed jdtsmith closed 2 years ago

jdtsmith commented 2 years ago

If cape-super-capf could take an optional tag, per capf:

(setq-local completion-at-point-functions
            (list (cape-super-capf #'my-fancy-mode-capf
                   '(cape-dabbrev-capf "dab")
                   '(cape-dict-capf    "dict")
                   '(cape-keyword-capf "kw")
                   '(cape-file-capf    "file"))))

you could label the results by the capf from which they came, by wrapping the annotation function to append the (styled) tag, if any.

jdtsmith commented 2 years ago

Or, instead of user-config'd, could have the capf's themselves specify such a tag using an extra property, or use their category (possibly too long). In either case, overridability would be nice though.

minad commented 2 years ago

What is the meaning of this tag? Should it be used for annotations?

Note that you can already do this, which is a bit verbose.

(setq completion-at-point-functions (list (cape-super-capf
                                           (cape-capf-with-properties #'cape-dabbrev-capf :annotation-function (lambda (_) " Y"))
                                           (cape-capf-with-properties #'cape-dict-capf :annotation-function (lambda (_) " X")))))

But if you do this often you can write a small helper (cape-with-annotation #'cape-dict-capf "X"). I assume this answers the question?

EDIT: Reading again through your feature request - you want to concatenate the tag to the annotation function provided by the sub capfs. This is reasonable, but requires a bit more effort. My suggestion is to write your own transformer cape-capf-append-tag in the style of ~cape-capf-with-properties~:

(defun cape-capf-with-properties (capf &rest properties)
  (lambda ()
    (pcase (funcall capf)
      (`(,beg ,end ,table . ,plist)
       `(,beg ,end ,table ,@properties ,@plist)))))

If it turns out that this feature is important, we can add it to the package. In any case - I don't want to complicate the super capf function with such unnecessary details, which are better solved by an external transformer ~cape-capf-with-properties/cape-capf-append-tag~, in particular since the super capf may become more complicated in the future.

I may try to generalize the super capf to more complex completion tables. Maybe you looked at the super capf implementation? It is very primitive and only works well for static completion tables. It may even require another capf buster wrapper to avoid overly aggressive caching if you combine capfs which are not sufficiently static.