jtbm37 / all-the-icons-dired

Adds dired support to all-the-icons
GNU General Public License v3.0
197 stars 26 forks source link

does not work with dired-subtree #22

Closed yilkalargaw closed 4 years ago

yilkalargaw commented 5 years ago

I am having trouble getting the all-the-icons-dired to work with dired-subtree. The main directory has icons but the subtree will not render any icons. I would appreciate any help.

mtekman commented 5 years ago
(use-package all-the-icons
  :ensure t
  :init
  (unless (file-exists-p
       (concat (or (getenv "XDG_DATA_HOME")
               (concat (getenv "HOME") "/.local/share"))
           "/fonts/"))
    (all-the-icons-install-fonts)))
(use-package all-the-icons-dired
  :after all-the-icons
  :hook dired)

and

(use-package dired
  :ensure nil
  :delight "Dired "
  :custom
  (dired-auto-revert-buffer t)
  (dired-dwim-target t)
  (dired-hide-details-hide-symlink-targets nil)
  (dired-listing-switches "-alh")
  (dired-ls-F-marks-symlinks nil)
  (dired-recursive-copies 'always))
(use-package dired-subtree
  :bind (:map dired-mode-map
              ("<backtab>" . dired-subtree-cycle)
              ("<tab>" . dired-subtree-toggle)))
yilkalargaw commented 5 years ago

I used the config you provided but still the subdirectories listed by dired-subtree(the ones listed when you press tab) do not have icons rendered for them.

mtekman commented 5 years ago

I updated the config, please try it again and let me know if it works.

yilkalargaw commented 5 years ago

I tried the config with the slight modification of using hook (dired-mode . all-the-icons-dired-mode) instead of :hook dired. The reasult is the same all the items in the top directory have icons but those in the subtree show up without an icon in the main dired buffer. In dired-sidebar items in the sub tree listing also have icons rendered for them and I wanted my main dired buffer to have a similar behavior. Is the behavior not reproducible on other computers. I tried it in three of my machines with similar reasults.

mtekman commented 5 years ago

that's really strange. What version of emacs are you using? I am 27.0.50

yilkalargaw commented 5 years ago

I am using 26.2

yilkalargaw commented 5 years ago

Finally figured out the issue. The icons will be displayed if you do revert-buffer(g) after listing subtrees with dired-subtree(tab). I am wondering if it is programmatically possible to revert buffer after every dired-subtree listing. I am willing to help.

Kungsgeten commented 4 years ago

I also had this problem and found the following solution. Don't know if its the best way to do it, since it sometimes show details of the subtree even if I have that turned off. Anyway:

(with-eval-after-load 'all-the-icons-dired
    (defun ess/dired-subtree-icons ()
      (dired-subtree-down)
      (dired-subtree-narrow)
      (when (fboundp 'dired-insert-set-properties)
        (let ((inhibit-read-only t)
              (ov (dired-subtree--get-ov)))
          (dired-insert-set-properties (overlay-start ov) (overlay-end ov))))
      (all-the-icons-dired--reset)
      (all-the-icons-dired--display)
      (widen))

    (remove-hook 'dired-subtree-after-insert-hook 'dired-subtree--after-insert)
    (add-hook 'dired-subtree-after-insert-hook 'ess/dired-subtree-icons))

Also a shoutout to @Fuco1 if he has any ideas.

Fuco1 commented 4 years ago

I can't say much without seeing how this package here works, but if the solution of @Kungsgeten works I have no problem adding this directly into the package so it just works out of the box (with a proper feature check of course).

mohkale commented 4 years ago

If anyones having the same issue with dired-insert-subdir instead of dired-subtree-insert (which is from the dired-hacks library BTW), I've adapted @Kungsgeten 's solution to work with that as well. You have to do a little extra work because dired-insert-subdir doesn't provide an after hook, but I've gotten this working for myself.

(defvar dired-subdir-after-insert-hook nil
  "hook which is run after dired inserts a subtree.")

(advice-add 'dired-insert-subdir
            :after
            (defun dired-insert-subdir--run-hook+ (&rest _)
              (run-hook-with-args 'dired-subdir-after-insert-hook)))

(defun all-the-icons-dired--subdir-icons+ ()
  "insert icons for subdirectories in dired sessions."
  (save-excursion
    (unwind-protect
        (progn
          (narrow-to-region
           (line-beginning-position)
           (condition-case nil
               (dired-next-subdir 1)
             (error (point-max))))
          (all-the-icons-dired--reset)
          (all-the-icons-dired--display))
      (widen))))

(add-hook 'dired-subdir-after-insert-hook 'all-the-icons-dired--subdir-icons+)
yilkalargaw commented 4 years ago

For emacs27 the issue is not present but for emacs 26 adding the following advice corrected every thing for me.

  (defadvice dired-subtree-toggle (after dired-icons-refreash ())
    "Insert an empty line when moving up from the top line."         
      (revert-buffer))

  (ad-activate 'dired-subtree-toggle)