summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Mendler <mail@daniel-mendler.de>2021-04-29 23:01:19 +0200
committerDaniel Mendler <mail@daniel-mendler.de>2021-04-29 23:01:19 +0200
commit1434e7f051cb7366f6fa652913c6dbcfe015860a (patch)
treedfb61e05031ae27061066de3b92fef3ea594d6b8
parentcf6c7ce1ead0716c312896e6f309be4faa80d3ec (diff)
Align annotations (Fix #18)
-rw-r--r--corfu.el23
1 files changed, 14 insertions, 9 deletions
diff --git a/corfu.el b/corfu.el
index ad053bf..7d08dac 100644
--- a/corfu.el
+++ b/corfu.el
@@ -418,14 +418,19 @@ Set to nil in order to disable confirmation."
"Return PROP from METADATA."
(cdr (assq prop metadata)))
-(defun corfu--format-candidate (cand)
- "Format annotated CAND string."
- (if (consp cand)
- (concat (cadr cand) (car cand)
- (if (text-property-not-all 0 (length (caddr cand)) 'face nil (caddr cand))
- (caddr cand)
- (propertize (caddr cand) 'face 'completions-annotations)))
- cand))
+(defun corfu--format-candidate ()
+ "Format candidates."
+ (let ((mw (ceiling (* corfu-margin-width (frame-char-width)))))
+ (lambda (c)
+ (if (consp c)
+ (concat
+ (cadr c) (car c)
+ (propertize " " 'display
+ `(space :align-to (- right ,(length (caddr c)) (,mw))))
+ (if (text-property-not-all 0 (length (caddr c)) 'face nil (caddr c))
+ (caddr c)
+ (propertize (caddr c) 'face 'completions-annotations)))
+ c))))
(defun corfu--show-candidates (beg end str metadata)
"Update display given BEG, END, STR and METADATA."
@@ -436,7 +441,7 @@ Set to nil in order to disable confirmation."
(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)))
- (ann-cands (mapcar #'corfu--format-candidate (corfu--annotate metadata cands))))
+ (ann-cands (mapcar (corfu--format-candidate) (corfu--annotate metadata cands))))
(when corfu--overlay
(delete-overlay corfu--overlay)
(setq corfu--overlay nil))