Skip to content

Commit

Permalink
Add corfu-kind-formatter
Browse files Browse the repository at this point in the history
  • Loading branch information
minad committed Nov 10, 2021
1 parent 18ff726 commit 0fc2ce6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
2 changes: 1 addition & 1 deletion README.org
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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).

Expand Down
11 changes: 9 additions & 2 deletions corfu.el
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 0fc2ce6

Please sign in to comment.