基本的にafter-readin-hookのタイミングで更新すれば十分なはず。……だけど、すでにdired-readinはadviceをかけてるな……。不十分だったらこれはキャンセル。
-(defun all-the-icons-dired--refresh-advice (fn &rest args)
- "Advice function for FN with ARGS."
- (prog1 (apply fn args)
- (when all-the-icons-dired-mode
- (all-the-icons-dired--refresh))))
-
-(defvar all-the-icons-dired-advice-alist
- '((dired-aux dired-create-directory all-the-icons-dired--refresh-advice)
- (dired-aux dired-do-create-files all-the-icons-dired--refresh-advice)
- (dired-aux dired-do-kill-lines all-the-icons-dired--refresh-advice)
- (dired-aux dired-do-rename all-the-icons-dired--refresh-advice)
- (dired-aux dired-insert-subdir all-the-icons-dired--refresh-advice)
- (dired-aux dired-kill-subdir all-the-icons-dired--refresh-advice)
- (dired wdired-abort-changes all-the-icons-dired--refresh-advice)
- (dired dired-internal-do-deletions all-the-icons-dired--refresh-advice)
- (dired-narrow dired-narrow--internal all-the-icons-dired--refresh-advice)
- (dired-subtree dired-subtree-insert all-the-icons-dired--refresh-advice)
- (dired-subtree dired-subtree-remove all-the-icons-dired--refresh-advice)
- (dired dired-readin all-the-icons-dired--refresh-advice)
- (dired dired-revert all-the-icons-dired--refresh-advice)
- (find-dired find-dired-sentinel all-the-icons-dired--refresh-advice))
- "A list of file, adviced function, and advice function.")
+(defun all-the-icons-dired--after-readin-hook ()
+ (when all-the-icons-dired-mode
+ (if (> (line-number-at-pos (point-max)) 1000)
+ ;; If there are many files, it will be very slow, so disable icons.
+ (all-the-icons-dired--remove-all-overlays)
+ (all-the-icons-dired--refresh))))
(defun all-the-icons-dired--setup ()
"Setup `all-the-icons-dired'."
(setq-local tab-width 1)
- (pcase-dolist (`(,file ,sym ,fn) all-the-icons-dired-advice-alist)
- (with-eval-after-load file
- (advice-add sym :around fn)))
- (all-the-icons-dired--refresh))
+ (add-hook 'dired-after-readin-hook #'all-the-icons-dired--after-readin-hook nil t))
(defun all-the-icons-dired--teardown ()
"Functions used as advice when redisplaying buffer."
(kill-local-variable 'tab-width)
- (pcase-dolist (`(,file ,sym ,fn) all-the-icons-dired-advice-alist)
- (with-eval-after-load file
- (advice-remove sym fn)))
+ (remove-hook 'dired-after-readin-hook #'all-the-icons-dired--after-readin-hook t)
(all-the-icons-dired--remove-all-overlays))
(2023-04-10追記: ファイル数が1000を超えたらアイコンを表示しないようにした。重いので)