]> git.eshelyaron.com Git - dotfiles.git/commitdiff
Add a margin-formatter function for corfu
authorEshel Yaron <eshel@dazz.io>
Tue, 14 Jun 2022 21:07:09 +0000 (00:07 +0300)
committerEshel Yaron <eshel@dazz.io>
Tue, 14 Jun 2022 21:07:09 +0000 (00:07 +0300)
.emacs.d/esy.org

index be922b5a6a333d065adf97d5244fff19793e6c2b..fa29d1d867d6b26272c2044972dce15d113b8260 100644 (file)
@@ -1087,10 +1087,21 @@ does in the shell.
                (file  (buffer-substring-no-properties start end)))
           `(,start ,end completion--file-name-table . (:exclusive no))))))
 
+  (defun esy/margin-formatter (metadata)
+    "Margin formatter for `corfu-margin-formatters'."
+    (pcase (cdr (assoc 'category metadata))
+      ('file (lambda (string)
+               (concat (if (string-suffix-p "/" string)
+                           (all-the-icons-icon-for-dir string)
+                         (all-the-icons-icon-for-file string))
+                       " ")))
+      ('dabbrev (lambda (_) "… "))))
+
   (defun esy/setup-completion-at-point ()
     "Setup `completion-at-point'."
     (require 'corfu)
-    (setq corfu-cycle t)
+    (setq corfu-cycle t
+          corfu-margin-formatters '(esy/margin-formatter))
     (global-corfu-mode)
     (add-to-list 'completion-at-point-functions #'esy/dabbrev-capf)
     (add-to-list 'completion-at-point-functions #'esy/file-capf))