[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/corfu 0eac0f7: Add corfu-kind-formatter (#75)
From: |
ELPA Syncer |
Subject: |
[elpa] externals/corfu 0eac0f7: Add corfu-kind-formatter (#75) |
Date: |
Wed, 10 Nov 2021 13:57:12 -0500 (EST) |
branch: externals/corfu
commit 0eac0f7406b56607b1435b1bfa5eb8c50d495269
Author: Daniel Mendler <mail@daniel-mendler.de>
Commit: GitHub <noreply@github.com>
Add corfu-kind-formatter (#75)
---
README.org | 2 +-
corfu.el | 23 ++++++++++++++++++-----
2 files changed, 19 insertions(+), 6 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 0352957..3b9a34e 100644
--- a/corfu.el
+++ b/corfu.el
@@ -102,6 +102,13 @@ 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.
+The function takes a symbol corresponding to the kind of the candidate
+and must return a string. This function can be used to display icons in
+front of the candidates."
+ :type '(choice function (const nil)))
+
(defcustom corfu-auto-prefix 3
"Minimum length of prefix for auto completion."
:type 'integer)
@@ -588,12 +595,15 @@ 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 (and corfu-kind-formatter (plist-get corfu--extra
:company-kind))))
(cl-loop for x in cands for (c . _) = x do
- (when (funcall dep c)
+ (when kind
+ (setf (cadr x) (funcall corfu-kind-formatter (funcall kind c))))
+ (when (and dep (funcall dep c))
(setcar x (setq c (substring c)))
- (add-face-text-property 0 (length c) 'corfu-deprecated 'append
c))))
- cands)
+ (add-face-text-property 0 (length c) 'corfu-deprecated 'append
c)))
+ (cons kind cands)))
(defun corfu--metadata-get (prop)
"Return PROP from completion metadata."
@@ -637,7 +647,10 @@ A scroll bar is displayed from LO to LO+BAR."
(bar (ceiling (* corfu-count corfu-count) corfu--total))
(lo (min (- corfu-count bar 1) (floor (* corfu-count start)
corfu--total)))
(cands (funcall corfu--highlight (seq-subseq corfu--candidates
start last)))
- (`(,pw ,width ,fcands) (corfu--format-candidates
(corfu--affixate cands))))
+ (`(,kind . ,acands) (corfu--affixate cands))
+ (`(,pw ,width ,fcands) (corfu--format-candidates acands))
+ ;; Disable the left margin if a kind function is specified.
+ (corfu-left-margin-width (if kind 0 corfu-left-margin-width)))
;; Nonlinearity at the end and the beginning
(when (/= start 0)
(setq lo (max 1 lo)))
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [elpa] externals/corfu 0eac0f7: Add corfu-kind-formatter (#75),
ELPA Syncer <=