Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nerd font support #220

Open
its-a-unixsystem opened this issue Jul 17, 2020 · 5 comments
Open

Nerd font support #220

its-a-unixsystem opened this issue Jul 17, 2020 · 5 comments

Comments

@its-a-unixsystem
Copy link

using a nerd font as emacs font face breaks all-the-icons functionality (renders wrong icon).
Considering the usage and font contents seem to be 90% the same and nerd font is a cross platform project. is it possible to get support for nerd fonts into all the icons?

@wyuenho
Copy link
Collaborator

wyuenho commented Jul 18, 2020

nerd font is nice, but it doesn't have a emacs logo, so this probably won't happen until they have one

@mohkale
Copy link
Contributor

mohkale commented Dec 24, 2020

doesn't have a emacs logo

Wow what a travesty? 😞

Is this the only hang-up though? You mention in #143 that combining together will be hard because the same code-points are used by different fonts. This makes life a lot harder for terminal users like me because icons are reliant on the order in which fonts are configured and in my case a-lot of the buffer-mode-icons are incorrect, but fixing that makes the emacs and org-mode icons incorrect 😢.

S.N. Links to relevent issues nerd-fonts/#342, #143.

@mohkale
Copy link
Contributor

mohkale commented Dec 24, 2020

I've managed to override a lot of the all-the-icon fonts with nerd-font like so:

(defvar +icons-prefer-nerd-font t)

(use-package nerd-fonts
  :straight (nerd-fonts :type git :host github :repo "twlz0ne/nerd-fonts.el")
  :after all-the-icons
  :demand t
  :config
  (require 'nerd-fonts-data)

  (defvar nerd-fonts-families+
    (eval-when-compile
      (seq-uniq
       (cl-loop with pos = nil
                for (icon . _) in nerd-fonts-alist
                do (setq pos (cl-loop with count = 0
                                      for char across icon
                                      when (eq char ?-)
                                      return count
                                      else
                                      do (setq count (1+ count))))
                collect (substring icon 0 pos)))))

  (defmacro all-the-icons-nerd-font-family+ (family)
    (let* ((nerd-family (concat "nerd-" family))
           (font-alist (intern (concat "all-the-icons-data/" nerd-family "-alist")))
           (name (intern nerd-family)))
      `(progn
         (defvar ,font-alist
           (eval-when-compile
             (cl-loop for (name . icon) in nerd-fonts-alist
                      when (string-prefix-p ,family name)
                      collect (cons (substring name ,(1+ (length family)))
                                    icon))))

         (all-the-icons-define-icon ,name ,font-alist ,nerd-family
           ;; The font on my linux machine, maybe needs updating depending on platform
           "Symbols-2048-em Nerd Font Complete.ttf"))))

  (dolist (it nerd-fonts-families+)
    (eval
     `(all-the-icons-nerd-font-family+ ,it)))

  ;; Replace any none nerd-font lookups with nerd-font lookups.
  (when +icons-prefer-nerd-font
    (let ((subs (eval-when-compile
                  (cl-loop for (family . ati-var) in '(("fa" . all-the-icons-faicon)
                                                       ("mdi" . all-the-icons-material)
                                                       ("oct" . all-the-icons-octicon)
                                                       ("weather" . all-the-icons-wicon))
                           when (member family nerd-fonts-families+)
                           collect (cons ati-var
                                         (intern (concat "all-the-icons-nerd-" family)))))))
      ;; When we have a key-value mapping setup in subs
      (when subs
        ;; For each variable all-the-icons uses to lookup contextual icons.
        (dolist (var '(all-the-icons-icon-alist
                       all-the-icons-dir-icon-alist
                       all-the-icons-weather-icon-alist
                       all-the-icons-mode-icon-alist
                       all-the-icons-url-alist))
          ;; For each entry in those lists do key-value substitution with `subs'.
          (dolist (assoc (symbol-value var))
            (when-let ((new-icon-func (alist-get (nth 1 assoc) subs)))
              (setcar (cdr assoc) new-icon-func))))))))

This defines a bunch of all-the-icon font families with nerd- prefixes (eg. all-the-icons-nerd-fa for fontawesome fonts). When +icons-prefer-nerd-font is true it also goes through a bunch of allthe-icons-icon alists and replaces icon lookups with nerd-font equivalents.

Sadly the alltheicon and fileicon families don't seem to have nerd-font equivalents (at least none that can be found in the nerd-font package). These you'll have to setup manually :(

EDIT:

I've ended up using a fork of the nerd-fonts package because there're issues with the default version and this setup. See nerd-fonts#2.

@mohkale
Copy link
Contributor

mohkale commented Nov 13, 2021

See all-the-icons-nerd-fonts.

@sunhs
Copy link

sunhs commented Jan 14, 2023

Really want icons in the terminal. Neovim's working well with Nerd Font.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants