feat(icons): use nerd-fonts to display icons in terminals

Uses the new nerd-icons package to display icons in various places
similar to all-the-icons. But it works in a terminal too as long as the
terminal is using a Nerd Font.
This commit is contained in:
2023-04-30 23:42:51 +01:00
parent b38a6abc4f
commit a78e417e6f
5 changed files with 91 additions and 21 deletions

View File

@@ -22,15 +22,17 @@
;; When running in GUI mode.
(when window-system
;; Set default font based on priority list
(let* ((families '("Menlo Nerd Font Mono"
(let* ((families '("Menlo Nerd Font"
"Menlo Nerd Font Mono"
"Menlo for Powerline"
"Menlo"
"Monaco Nerd Font Mono"
"Monaco for Powerline"
"Monaco"))
(available (font-family-list))
(family (catch 'found
(dolist (f families)
(if (member f (font-family-list))
(if (member f available)
(throw 'found f))))))
(set-face-attribute 'default nil :family family :height 120))

View File

@@ -18,29 +18,43 @@
(use-package all-the-icons-ibuffer
:after all-the-icons
:if window-system
:init
(all-the-icons-ibuffer-mode 1))
:hook
(ibuffer-mode . all-the-icons-ibuffer-mode))
(use-package all-the-icons-dired
:after all-the-icons
:if window-system
:hook
(dired-mode . all-the-icons-dired-mode))
(use-package treemacs-all-the-icons
:after (all-the-icons treemacs)
:if window-system
:config
(treemacs-load-theme "all-the-icons"))
(use-package all-the-icons-completion
:after (marginalia all-the-icons)
:after (all-the-icons marginalia)
:if window-system
:hook (marginalia-mode . all-the-icons-completion-marginalia-setup)
:init
(all-the-icons-completion-mode)
:demand t
:hook
(marginalia-mode . all-the-icons-completion-marginalia-setup)
:config
(all-the-icons-completion-mode)
;; Using original all-the-icons-completion package.
(when (fboundp 'all-the-icons-completion-get-file-icon)
;; Override default category lookup function to add support for
;; project-buffer and project-file.
(defun all-the-icons-completion-get-icon (cand cat)
"Return the icon for the candidate CAND of completion category CAT."
(cl-case cat
(file (all-the-icons-completion-get-file-icon cand))
(project-file (all-the-icons-completion-get-file-icon cand))
(buffer (all-the-icons-completion-get-buffer-icon cand))
(project-buffer (all-the-icons-completion-get-buffer-icon cand))
(t ""))))
;; Override default category lookup function to add support for
;; project-buffer and project-file.
(defun all-the-icons-completion-get-icon (cand cat)
"Return the icon for the candidate CAND of completion category CAT."
(cl-case cat
(file (all-the-icons-completion-get-file-icon cand))
(project-file (all-the-icons-completion-get-file-icon cand))
(buffer (all-the-icons-completion-get-buffer-icon cand))
(project-buffer (all-the-icons-completion-get-buffer-icon cand))
(t ""))))
;; Using MintSoup's fork of all-the-icons-completion.
(when (not (fboundp 'all-the-icons-completion-get-file-icon))
@@ -50,6 +64,11 @@
(cl-defmethod all-the-icons-completion-get-icon ((cand string) (cat (eql 'project-buffer)))
(all-the-icons-completion-get-icon cand 'buffer))))
;; (defun siren-all-icons-complete-wrap (orig-fun &rest args)
;; "Wrap `all-the-icons-completion' to use `siren-all-icons-complete' instead."
;; (message "args: %s" args)
;; (apply orig-fun args))
;; (advice-add 'all-the-icons-completion-get-icon :around #'siren-all-icons-complete-wrap)
(provide 'siren-all-the-icons)
;;; siren-all-the-icons.el ends here

View File

@@ -0,0 +1,51 @@
;;; siren-nerd-icons.el --- jimeh's Emacs Siren: nerd-icons configuration.
;;; Commentary:
;; Basic configuration for nerd-icons.
;;; Code:
(use-package nerd-icons
:if (not window-system)
:config
(if (and window-system
(member "Menlo Nerd Font" (font-family-list)))
(setq nerd-nerd-icons-font-family "Menlo Nerd Font")))
(use-package nerd-icons-completion
:straight (nerd-icons-completion :type git :host github
:repo "rainstormstudio/nerd-icons-completion")
:after nerd-icons
:if (not window-system)
:demand t
:hook
(marginalia-mode . nerd-icons-completion-marginalia-setup)
:config
(nerd-icons-completion-mode))
(use-package nerd-icons-dired
:straight (nerd-icons-dired :type git :host github
:repo "rainstormstudio/nerd-icons-dired")
:after nerd-icons
:if (not window-system)
:hook
(dired-mode . nerd-icons-dired-mode))
(use-package nerd-icons-ibuffer
:after nerd-icons
:if (not window-system)
:hook
(ibuffer-mode . nerd-icons-ibuffer-mode))
(use-package treemacs-nerd-icons
:straight (treemacs-nerd-icons
:type git :host github :repo "rainstormstudio/treemacs-nerd-icons")
:after (nerd-icons treemacs)
:if (not window-system)
:config
(treemacs-load-theme "nerd-icons"))
(provide 'siren-nerd-icons)
;;; siren-nerd-icons.el ends here

View File

@@ -61,9 +61,6 @@
(treemacs-define-RET-action
'file-node-closed #'treemacs-visit-node-in-most-recently-used-window))
(use-package treemacs-all-the-icons
:after (treemacs))
(use-package treemacs-projectile
:after (treemacs projectile)
:custom

View File

@@ -8,6 +8,7 @@
(require 'siren-all-the-icons)
(require 'siren-doom-modeline)
(require 'siren-nerd-icons)
(use-package doom-themes
:custom