emacs-nerd-icons 一个all-the-icons的替代方案(支持GUI和terminal)

Symbols Nerd Font 字体可以显示完整的图标,不过图标和all-the-icons一样大小不一了。

反而 Symbols Nerd Font Mono 图标宽度一致,也不会像其他字体一样小。下图是我在MacOS 13.2 上测试的效果,不知道其他平台上效果怎么样?如果效果好的话建议将这个设置为默认字体。

1 个赞

nice,这样是最好的了,感谢您的测试!感觉设置这个为默认挺好,也可以像all-the-icons那样自动下载这个字体,毕竟nerd的图标都是一样的

symbols之所以有用是因为其他字体在patch的时候没有将variable-width算进去,导致比较严格的字体渲染方式会不渲染大于默认字体width的部分。而symbols是把variable-width保留了的,所以可以完整渲染。

symbols 似乎要比其他nerd font的图标大一点点。不过这个问题不大,可以自行进行微调。nerd font 在terminal下表现很好,如果图标够用的话,我可以将Centaur Emacs 里用到的图标都逐步用nerd font 替换。前提是emacs-nerd-icons赶紧上melpa :grinning:

1 个赞

能代替 all-the-icons-completion 么

我看了一下,改一个emacs-nerd-icons-completion应该很快的,我过两天就写一个 :stuck_out_tongue_winking_eye:

如果有 svg 素材, 可以尝试让 ChatGPT 批量改一下 svg 内图标的宽度和大小, 这样可以快速把所有不同来源的图标弄成一样宽。

由于Emacs对package命名的一些要求,我把emacs-nerd-icons改成nerd-icons

帮楼主去 reddit 做了一波宣传,反响热烈。

顺便说一句,目前 nerd-icons 对 dired-sidebar 的支持还是有问题,折叠展开后的二级树没有办法显示图标。此外会有图标堆叠在一起的问题。(装了 dired-sidebar 会自动装上 dired-subtree)然后 dired 就变成可折叠的了。(按 tab 来展开树)。

我用的字体是 caskydia code nerd font,不管是在 wezterm (终端)底下还是 emacs-plus (mac GUI)底下都会有这个问题。

(straight-use-package '(nerd-icons :host github
                                   :repo "rainstormstudio/nerd-icons.el"
                                   :files (:defaults "data")))
(straight-use-package 'dired-sidebar)
(straight-use-package '(nerd-icons-dired :host github
                                         :repo "rainstormstudio/nerd-icons-dired"
                                         :files (:defaults "data")))

1 个赞

感谢支持。

请问图标堆叠的问题去掉dired-sidebar也会有吗?我没有用过dired-sidebar和dired-subtree所以没有做过测试实在不好意思。我要花点时间研究一下这个问题。

请问你可以在github上创一个issue阐述一下这个问题吗?麻烦了!

图标堆叠的问题解决了,是我自己的 whitespace mode 开启了 导致的问题。关掉 whitespace mode以后就没问题了。但是 dired-subtree 不显示图标的问题还是有的。我稍后会去 github 开一个 issue。

2 个赞

贴主,我平时是用这个来替换原来的nerd-icons-icon-for-modenerd-icons-icon-for-file的,这个可以在参数中设置:background而不会影响原有的:foreground,目前在我的平台运行良好,你可以试一下。

(defun nerd-icons-icon-for-mode (mode &rest arg-overrides)
  "Get the formatted icon for MODE.
ARG-OVERRIDES should be a plist containining `:height',
`:v-adjust' or `:face' properties like in the normal icon
inserting functions."
  (let* ((icon (or (cdr (or (assoc mode nerd-icons-mode-icon-alist)
                            (assoc (get mode 'derived-mode-parent) nerd-icons-mode-icon-alist)))
                   nerd-icons-default-file-icon))
		 (args (cdr icon)))
	(when arg-overrides
      (if (nthcdr 2 args)
          (setq args (append
				      `(,(car args))
				      (cons (car arg-overrides)
						    `(,(append (car (cdr arg-overrides))
                                       (append
                                        '(:foreground)
								        `(,(face-attribute (car (nthcdr 2 args)) :foreground))))))))
        (setq args (append `(,(car args)) arg-overrides (cdr args)))))
    (if icon (apply (car icon) args) mode)))


(defun nerd-icons-icon-for-file (file &rest arg-overrides)
  "Get the formatted icon for FILE.
ARG-OVERRIDES should be a plist containining `:height',
`:v-adjust' or `:face' properties like in the normal icon
inserting functions."
  (let* ((ext (file-name-extension file))
         (icon (or (nerd-icons-match-to-alist file nerd-icons-regexp-icon-alist)
                   (and ext
                        (cdr (assoc (downcase ext)
                                    nerd-icons-extension-icon-alist)))
                   nerd-icons-default-file-icon))
         (args (cdr icon)))
	(when arg-overrides
      (if (nthcdr 2 args)
	      (setq args (append
				      `(,(car args))
				      (cons (car arg-overrides)
						    `(,(append (car (cdr arg-overrides))
								       '(:foreground)
								       `(,(face-attribute (car (nthcdr 2 args)) :foreground))))
						    )))
        (setq args (append `(,(car args)) arg-overrides (cdr args)))
        ))
    (apply (car icon) args)))
1 个赞

感谢!让我康康

用上了,比 all-the-icons 好用 :+1:t2:

基本上 all-the-icons 提供的功能都有一比一对应,直接改名 all-the-icons-*nerd-icons-* 就可以搞定大部分迁移。但是图标名称和 face 名称是不一样的,想找到图标对应的名字可以用 M-x nerd-icons-insert-* 系列来找。

我支持這個插件, 覺得很好用! :slight_smile:

treemacs 是不是还得安转 all-the-icons 这个这包,尽管不用它?

fixed: 在 doom-themes 的配置中,去掉:
;; (setq doom-themes-treemacs-theme “doom-atom”) ; use “doom-colors” for less minimal icon theme
;; (doom-themes-treemacs-config)
;; (doom-themes-org-config)

2 个赞

果然如此,我改了几次都没有成功,后面改了doom里面的代码搞定。

想请教大家如果出现这种极高的竖线,有可能是什么原因呀?

看一下nerd-icons有没有升级到最新版本,然后用nerd-icons-install-fonts更新一下字体试试,有的时候可能需要把本地的包和字体删了重新装

已经完全按照描述操作过(更新 nerd-fonts 版本,卸载字体后重新安装,刷新过字体,重启过电脑),但是依然出现这个问题。

我是 manjaro 系统,请问还有什么办法可以继续 debug 呀。

另外在我不知道怎么捣鼓的时候(我也不确定是不是捣鼓 nerd-icons 的时候),似乎 message 出现了这个信息,不知道有没有帮助

Selection owner couldn’t convert: UTF8_STRING
Selection owner couldn’t convert: COMPOUND_TEXT
Selection owner couldn’t convert: STRING
Selection owner couldn’t convert: text/plain;charset=utf-8