Support `dired-subtree` (No icons showed in `dired-subtree`)
milanglacier opened this issue · 2 comments
milanglacier commented
example setup
(require 'package)
(setq package-user-dir "~/Downloads/emacs-package-dir")
(setq package-list '(dired-subtree))
(add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/"))
(package-initialize)
(add-to-list 'load-path "~/Downloads/open-project-fork/nerd-icons.el")
(add-to-list 'load-path "~/Downloads/open-project-fork/nerd-icons-dired")
(unless package-archive-contents
(package-refresh-contents))
(dolist (package package-list)
(unless (package-installed-p package)
(package-install package)))
(require 'nerd-icons)
(require 'nerd-icons-dired)
(require 'dired-subtree)
(add-hook 'dired-mode-hook #'nerd-icons-dired-mode)
(define-key dired-mode-map (kbd "TAB") #'dired-subtree-toggle)
(load-theme 'modus-operandi t)
step to reproduce:
- open any directory by
C-x d
- move point to a folder and tap
TAB
key, the subtree is expanded. - No icons showed in the subtree.
zhenhua-wang commented
This should add icons to the dired subtrees
(advice-add 'dired-subtree-toggle :after (lambda ()
(interactive)
(when nerd-icons-dired-mode
(revert-buffer))))
milanglacier commented
This should add icons to the dired subtrees
(advice-add 'dired-subtree-toggle :after (lambda () (interactive) (when nerd-icons-dired-mode (revert-buffer))))
Thanks for the insight! This hack works for me!
Using a anonymous function in an advice makes it hard to be removed later, I have made a slightly modification of this piece of code to make it less intrusive:
(defun my:dired-subtree-add-nerd-icons ()
(interactive)
(revert-buffer))
(defun my:dired-subtree-toggle-nerd-icons ()
(when (require 'dired-subtree nil t)
(if nerd-icons-dired-mode
(advice-add #'dired-subtree-toggle :after #'my:dired-subtree-add-nerd-icons)
(advice-remove #'dired-subtree-toggle #'my:dired-subtree-add-nerd-icons))))
(use-package nerd-icons-dired
:hook ((dired-mode . nerd-icons-dired-mode)
(nerd-icons-dired-mode . my:dired-subtree-toggle-nerd-icons)))