iyefrat / all-the-icons-completion Goto Github PK
View Code? Open in Web Editor NEWAdd icons to completion candidates in Emacs
License: GNU General Public License v3.0
Add icons to completion candidates in Emacs
License: GNU General Public License v3.0
It would be quite easy to add icon support for Corfu to all-the-icons-completion, in particular for the :company-kind
metadata. Maybe there is interest in this? Could also be a separate package of course. See also https://github.com/jdtsmith/kind-icon.
Example:
(add-hook 'corfu-margin-formatters #'kind-example)
(add-hook 'corfu-margin-formatters #'file-example)
;; works in prog-mode buffers, if `:company-kind` metadata is available.
(defun kind-example (_metadata)
(when-let (kind (plist-get completion-extra-properties :company-kind))
(lambda (cand)
(format "<%s> " (funcall kind cand)))))
;; works in eshell
(defun file-example (metadata)
(when (eq (completion-metadata-get metadata 'category) 'file)
(lambda (cand)
(format "<%s> " (file-name-extension cand)))))
Probably it makes sense to add a function all-the-icons-icon-for-kind
to the all-the-icons package which maps from company/lsp kinds to the icons. Or the mapping could take place here since it is a completion feature.
In the same way all-the-icons-color-icons
does, but related only to icons from this package. I want to see my icons in minibuffer with a foreground (default) color.
This is working very well out of the box for most things, but I have noticed it doesn't apply to find-file-rg
from https://github.com/muffinmad/emacs-find-file-rg
Is this something that needs to be done here or on the find-file-rg
-side? Haven't looked into how this is working.
Hi, after the recent updates, using all-the-icons-completions
together with selectrum and marginalia gives me the following error problem when I try certain commands:
Error in post-command-hook (selectrum--update): (error "Lisp nesting exceeds ‘max-lisp-eval-depth’")
This happens e.g., when I open info and type m
to select a menu item, but not with find-file
or consult-buffer
.
The problem appears to be caused by this commit: 055b386. If I undo it, everything starts working again.
The cases where the problem occurs all seem to involve completion candidates that do not have any associated icons: Like I said, find-file
and consult-buffer
are fine, and they both show icons. Commands that I've found so far trigger the error are Info-menu
, projectile-find-file
and consult-yank-pop
, and these don't show any icons if I undo the problematic commit.
(For reference, I already posted issues to selectrum here and marginalia here, but those packages don't seem to have anything to do with the issue.)
Sometimes it is quite unstable to update Emacs package in a rolling way. So I usually use Melpa-Stable, nongnu, and gnu elpa repositories. If there were stable releases, I won't anymore worry about the occurrence of incompatibility after the update. Thanks.
Hey,
I am using Doom Emacs with (vertico +icons)
enabled. I have a projectile
project that I access remotely over SSH through a (company) VPN (/sshx:VPN:/some/path
). If the VPN is not enabled, I experience that Emacs hangs (i.e. no response, but C-g
aborts) when I call projectile-switch-project
.
If I disable +icons
(or remove projectile-switch-project
from marginalia-command-categories
), these hangs do not occur, which brought me to your package.
Additionally, if I am connected to the VPN and call projectile-switch-project
, I get first asked for a password for authinfo
and then I can type and select one of the projects. Without +icons
, I have to enter the passphrase only after I have selected the remote project.
Could it be that icon-fetching fails when the remote path cannot be accessed?
This is to cross-reference issuse #166 I filed in bibtex-actions. That issue is closed but I'm still unable to get icons working in that package when all-the-icons-completion is in use. It's not clear to me whether this is best filed here or there but I figured I'd check.
It'd be nice if it was easier to add categories without having to fully override all-the-icons-completion-get-icon
. For instance, let's assume I define a new category via marginalia like:
(add-to-list 'marginalia-command-categories
'(eradio-play . radiostation))
If I wanted to add a custom icon for candidates of this type I'd have to:
(defun all-the-icons-completion-get-radiostation-icon (cand)
"Return the icon for the candidate CAND of completion category radiostation."
(concat (all-the-icons-octicon "megaphone" :face 'all-the-icons-completion-dir-face) " "))
all-the-icons-completion-get-icon
@@ -55,6 +55,7 @@ defun all-the-icons-completion-get-icon
(project-file (all-the-icons-completion-get-file-icon cand))
(buffer (all-the-icons-completion-get-buffer-icon cand))
(bookmark (all-the-icons-completion-get-bookmark-icon cand))
+ (radiostation (all-the-icons-completion-get-radiostation-icon cand))
(t "")))
(defun all-the-icons-completion-get-file-icon (cand)
I think it'd make things easier for users if all-the-icons-completion-get-icon
consumed an alist defined as defcustom
and mapping categories to functions.
Would that make sense? Happy to send a patch myself.
Thanks.
Hello @iyefrat!
I have prepared two minor patches and would like to share them with you.
I copy them below. If you prefer a pull request, I will make it happen.
From e794669fe55718d5d7346a925a5a7f4f1afa31ce Mon Sep 17 00:00:00 2001
Message-Id: <e794669fe55718d5d7346a925a5a7f4f1afa31ce.1642752720.git.info@protesilaos.com>
From: Protesilaos Stavrou <[email protected]>
Date: Fri, 21 Jan 2022 10:02:25 +0200
Subject: [PATCH] Use file-directory-p instead of string checking
---
all-the-icons-completion.el | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/all-the-icons-completion.el b/all-the-icons-completion.el
index 878bc37..56bde66 100644
--- a/all-the-icons-completion.el
+++ b/all-the-icons-completion.el
@@ -53,7 +53,7 @@ (defun all-the-icons-completion-get-icon (cand cat)
(defun all-the-icons-completion-get-file-icon (cand)
"Return the icon for the candidate CAND of completion category file."
- (cond ((string-match-p "\\/$" cand) (concat (all-the-icons-icon-for-dir cand) " "))
+ (cond ((file-directory-p cand) (concat (all-the-icons-icon-for-dir cand) " "))
(t (concat (all-the-icons-icon-for-file cand) " "))))
(defun all-the-icons-completion-get-buffer-icon (cand)
--
2.34.1
From c0628787c3e5616cc29c745d6aba2900c4f28d36 Mon Sep 17 00:00:00 2001
Message-Id: <c0628787c3e5616cc29c745d6aba2900c4f28d36.1642752725.git.info@protesilaos.com>
From: Protesilaos Stavrou <[email protected]>
Date: Fri, 21 Jan 2022 10:04:59 +0200
Subject: [PATCH] Add face for directory icon
The current face definition inherits from the 'default', meaning that it
should look the same it did before.
This allows users/themes to apply the same style between
all-the-icons-completion.el, all-the-icons-dired.el, and
all-the-icons-ibuffer.el.
---
all-the-icons-completion.el | 10 +++++++++-
1 file changed, 9 insertions(+), 1 deletion(-)
diff --git a/all-the-icons-completion.el b/all-the-icons-completion.el
index 56bde66..609e147 100644
--- a/all-the-icons-completion.el
+++ b/all-the-icons-completion.el
@@ -43,6 +43,11 @@ (defgroup all-the-icons-completion nil
:group 'convenience
:prefix "all-the-icons-completion")
+(defface all-the-icons-completion-dir-face
+ '((t :inherit default))
+ "Face for the directory icon."
+ :group 'all-the-icons-faces)
+
(defun all-the-icons-completion-get-icon (cand cat)
"Return the icon for the candidate CAND of completion category CAT."
(cl-case cat
@@ -53,7 +58,10 @@ (defun all-the-icons-completion-get-icon (cand cat)
(defun all-the-icons-completion-get-file-icon (cand)
"Return the icon for the candidate CAND of completion category file."
- (cond ((file-directory-p cand) (concat (all-the-icons-icon-for-dir cand) " "))
+ (cond ((file-directory-p cand)
+ (concat
+ (all-the-icons-icon-for-dir cand :face 'all-the-icons-completion-dir-face)
+ " "))
(t (concat (all-the-icons-icon-for-file cand) " "))))
(defun all-the-icons-completion-get-buffer-icon (cand)
--
2.34.1
See marginalia#115.
Many thanks for providing this package. When installing and native compiling with Emacs 29, the compiler nags with:
In all-the-icons-completion-completion-metadata-get:
all-the-icons-completion.el:103:33: Warning: Unused lexical variable `orig'
which is this line:
I'm not really familiar with the code but orig
isn't used in the (and cat aff)
clause. Maybe the let
-binding can be dropped?
Following up from my comment here, when vertico +icons
is enabled in the Doom Vertico PR along with the vertico-buffer, the line spacing is broken, with each entry spanning multiple display lines.
Per @minad's comment, I tried his latest commit of vertico by unpinning the package in doom, but the issue persists.
Step by step instructions:
b5cf7aa
(#4664))vertico-buffer
extension:(after! vertico
(vertico-buffer-mode))
I've only noticed this in file annotations, but I assume this is a general problem.
Probably stems from the marginalia alignment logic assuming that there will no extra things it doesn't know about.
cc @minad
See here for a demonstration and possible solution. all-the-icons-dired
might have a good way to solve this.
cc @protesilaos
I just setup marginalia and all-the-icons-completion to work together, and during the load process I am recieving this error:
'apply: Autoloading file /home/user/.emacs.d/straight/build/all-the-icons-completion/all-the-icons-completion.elc failed to define function all-the-icons-marginalia-setup'
I added the icon-setup function, not sure if that is needed anymore, from here --> minad/marginalia#59 (comment)_
My configuration looks like below:
(use-package all-the-icons-completion
:after (marginalia all-the-icons)
:hook (marginalia-mode . all-the-icons-marginalia-setup)
:init
(all-the-icons-completion-mode))
(use-package marginalia
:after all-the-icons
:general
(:keymaps 'minibuffer-local-map
"M-A" 'marginalia-cycle)
:custom
(marginalia-max-relative-age 0)
(marginalia-align 'right)
:init
(defun icon-setup ()
(if marginalia-mode
(advice-add 'completion-metadata-get :around 'icon-completion-metadata-get)
(advice-remove 'completion-metadata-get 'icon-completion-metadata-get)))
(add-hook 'marginalia-mode-hook 'icon-setup)
(marginalia-mode))
Is there some critical step I am missing?
The example in the readme is missing parens. Also it would be nice if that lambda was provided as an autoloaded function in this package.
Hi,
I managed to get a proof of concept for adding thumbnails instead of icons when a file is an image.
I just added a clause to all-the-icons-completion-get-file-icon
:
((string-match-p "png$" cand)
(concat (file-image-string (f-join (minibuffer-contents) cand)) " "))
with some utils to get a string with an image as a display text property:
(defun image-string (image string)
(with-temp-buffer
(insert-image image string)
(buffer-string)))
(defun file-image-string (path)
(image-string (create-image path 'png) "image"))
The result with a small image:
I think a proper implementation of this with image resizing and caching (a bit like dired-image does) would require it's own package. But it seems like I could reuse most of the code here. So I was wondering if you or @minad could help me get started here? I must say I am quite afraid by the all-the-icons-completion-completion-metadata-get
monster function !
Cheers,
Théo
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.