From 0fc2ce61ca6a37bff3814b28f1f898548579ad59 Mon Sep 17 00:00:00 2001 From: Daniel Mendler Date: Wed, 10 Nov 2021 13:04:00 +0100 Subject: [PATCH] Add corfu-kind-formatter --- README.org | 2 +- corfu.el | 11 +++++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/README.org b/README.org index 6eef653..89a99e7 100644 --- a/README.org +++ b/README.org @@ -49,6 +49,7 @@ - Show candidate documentation/signature string in the echo area. - Deprecated candidates are crossed out in the display. - Support for annotations (~annotation-function~, ~affixation-function~). + - Icons can be provided by an external package via ~corfu-kind-formatter~. * Configuration @@ -158,7 +159,6 @@ - Corfu falls back to the default Completion buffer on non-graphical displays, since Corfu requires child frames. - The abort handling could be improved, for example the input could be undone. - - Some Company metadata extensions are not supported (~company-kind~, ~company-match~). - No sorting by history, since ~completion-at-point~ does not maintain a history (See branch =history= for a possible solution). diff --git a/corfu.el b/corfu.el index bcd87a5..a65994c 100644 --- a/corfu.el +++ b/corfu.el @@ -102,6 +102,10 @@ completion began less than that number of seconds ago." "Show documentation string in the echo area after that number of seconds." :type '(choice boolean float)) +(defcustom corfu-kind-formatter nil + "Formatting function for candidate kind." + :type '(choice function (const nil))) + (defcustom corfu-auto-prefix 3 "Minimum length of prefix for auto completion." :type 'integer) @@ -589,9 +593,12 @@ A scroll bar is displayed from LO to LO+BAR." suffix (propertize suffix 'face 'corfu-annotations))))) (cl-loop for cand in cands collect (list cand "" ""))))) - (when-let (dep (plist-get corfu--extra :company-deprecated)) + (let ((dep (plist-get corfu--extra :company-deprecated)) + (kind (plist-get corfu--extra :company-kind))) (cl-loop for x in cands for (c . _) = x do - (when (funcall dep c) + (when-let (k (and corfu-kind-formatter kind (funcall kind c))) + (setf (cadr x) (funcall corfu-kind-formatter k))) + (when (and dep (funcall dep c)) (setcar x (setq c (substring c))) (add-face-text-property 0 (length c) 'corfu-deprecated 'append c)))) cands)