summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Mendler <mail@daniel-mendler.de>2021-11-16 01:01:07 +0100
committerDaniel Mendler <mail@daniel-mendler.de>2021-11-16 01:02:50 +0100
commitb16143d5a7affacace05a1097ba7d8680f38dea5 (patch)
treeb1505b0ee13bf65f8fd0df063677ffcf38ffea5c
parent43c23d433c75155be0a92cfab4e3d36b1ffbc0d2 (diff)
Add corfu-kind-formatter, pass metadata to corfu-margin-formatters
-rw-r--r--corfu.el19
1 files 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.