jdtsmith / kind-icon

Completion kind text/icon prefix labelling for emacs in-region completion
GNU Affero General Public License v3.0
174 stars 4 forks source link

[Question] Does corfu/kind-icon for Elisp require Emacs 28? #10

Closed gcentauri closed 2 years ago

gcentauri commented 2 years ago

I'm just curious whether or not I should work on wiring up Elisp metadata and figuring out how all this completion stuff works, or if the documentation around Emacs 28 implies it might just work.

jdtsmith commented 2 years ago

Yes I believe that company-Kind support in emacs-lisp mode was only introduced in v28.

gcentauri commented 2 years ago

cool. fwiw i figured out a hack to get it working in Emacs 27.

(defun my-elisp-icons (candidate)
  (if (derived-mode-p 'emacs-lisp-mode 'inferior-emacs-lisp-mode)
      (let ((sym (intern candidate)))
        (cond ((fboundp sym) (propertize-icon-string "function"))
              ((featurep sym) (propertize-icon-string "file-code-outline"))
              ((facep sym) (propertize-icon-string "palette"))
              ((boundp sym) (propertize-icon-string "variable"))
              (t "")))
    ""))

(defun propertize-icon-string (icon-name)
  (propertize
     (concat " " (propertize "*" 'display (kind-icon--get-icon-safe icon-name)) " ")
     'face `(:background "black")))

(defun my-corfu-margin-formatter (metadata)
  #'my-elisp-icons)

its certainly not pretty but its what i whipped up in a few minutes. its borrowed from the method company-box uses to do something similar for elisp icons.

jdtsmith commented 2 years ago

Cool, thanks. It might be simpler to configure your function as a simple :company-kind property, appended to the output of elisp-completion-at-point, and just have it return the kind symbols function, palette, etc. Then it should "just work" without any special kind-icon config.

gcentauri commented 2 years ago

thanks for the input :) I was a bit unsure about what :company-kind was and if it was dependent on company at all.

jdtsmith commented 2 years ago

It started with company, but now many backends and frontends support it. So company is not required to make use of it. It just names a function of one argument, similar to you my-elisp-icons. And it returns a symbol (see the keys of kind-icon-mapping). Kind-icon and corfu handle the rest.