[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/corfu b16143d: Add corfu-kind-formatter, pass metadata
From: |
ELPA Syncer |
Subject: |
[elpa] externals/corfu b16143d: Add corfu-kind-formatter, pass metadata to corfu-margin-formatters |
Date: |
Mon, 15 Nov 2021 19:57:13 -0500 (EST) |
branch: externals/corfu
commit b16143d5a7affacace05a1097ba7d8680f38dea5
Author: Daniel Mendler <mail@daniel-mendler.de>
Commit: Daniel Mendler <mail@daniel-mendler.de>
Add corfu-kind-formatter, pass metadata to corfu-margin-formatters
---
corfu.el | 19 ++++++++++++++-----
1 file changed, 14 insertions(+), 5 deletions(-)
diff --git a/corfu.el b/corfu.el
index 3185ee5..a942a36 100644
--- a/corfu.el
+++ b/corfu.el
@@ -113,9 +113,10 @@ completion began less than that number of seconds ago."
(defcustom corfu-margin-formatters nil
"Registry for margin formatter functions.
-Each function of the list is called until an appropriate formatter is found.
-The function should return a formatter function, which takes the candidate
-string and must return a string, possibly an icon."
+Each function of the list is called with the completion metadata as
+argument until an appropriate formatter is found. The function should
+return a formatter function, which takes the candidate string and must
+return a string, possibly an icon."
:type 'hook)
(defcustom corfu-auto-prefix 3
@@ -611,8 +612,9 @@ 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 "" "")))))
- (let ((dep (plist-get corfu--extra :company-deprecated))
- (mf (run-hook-with-args-until-success 'corfu-margin-formatters)))
+ (let* ((dep (plist-get corfu--extra :company-deprecated))
+ (completion-extra-properties corfu--extra)
+ (mf (run-hook-with-args-until-success 'corfu-margin-formatters
corfu--metadata)))
(cl-loop for x in cands for (c . _) = x do
(when mf
(setf (cadr x) (funcall mf c)))
@@ -621,6 +623,13 @@ A scroll bar is displayed from LO to LO+BAR."
(add-face-text-property 0 (length c) 'corfu-deprecated 'append
c)))
(cons mf cands)))
+(defun corfu-kind-formatter (fun)
+ "Create a margin formatter from FUN.
+FUN takes a kind symbol as argument and must return a string."
+ (lambda (_metadata)
+ (when-let (kind (plist-get completion-extra-properties :company-kind))
+ (lambda (cand) (funcall fun (funcall kind cand))))))
+
(defun corfu--metadata-get (prop)
"Return PROP from completion metadata."
;; Note: Do not use `completion-metadata-get' in order to avoid Marginalia.
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [elpa] externals/corfu b16143d: Add corfu-kind-formatter, pass metadata to corfu-margin-formatters,
ELPA Syncer <=