Closed yilkalargaw closed 2 years ago
emacs -Q recipe would be helpful!
the problem persists with only this setup too
(use-package all-the-icons-dired
:ensure t
:defer t
:hook (dired-mode . all-the-icons-dired-mode)
)
(use-package dired-sidebar
:bind (("C-c n t" . dired-sidebar-toggle-sidebar))
:ensure t
:commands (dired-sidebar-toggle-sidebar)
:init
(add-hook 'dired-sidebar-mode-hook
(lambda ()
(unless (file-remote-p default-directory)
(auto-revert-mode))))
(add-hook 'dired-sidebar-mode-hook (lambda () (display-line-numbers-mode -1)))
(add-hook 'dired-sidebar-mode-hook (lambda () (nlinum-mode -1)))
;; (add-hook 'dired-sidebar-mode-hook (lambda () (all-the-icons-dired-mode -1)))
(add-hook 'dired-sidebar-mode-hook
(lambda ()
(unless (file-remote-p default-directory)
(auto-revert-mode))))
Can you go from an emacs -Q to the problem?
E.g. move emacs.d folder to a backup, start emacs, eval package-install/use-package and then run dired-sidebar.
Even with what you pasted above, it still looks like there may be something else going on.
I did as you said and tried it with a clean config file and the problem still persists. After installing the icons necessary fonts with M-x all-the-icons-install-fonts
and restarting emacs if you open dired-sidebar directly from the scratch buffer two icons are shown for every listing.I have also noticed the same thing happens when opening a directory directly from the sidebar by pressing Enter. The full emacs config I used is as follows.
NB. the top part is just to automate package installation
(require 'package)
(setq package-archives '( ;; ("marmalade" . "http://marmalade-repo.org/packages/")
("gnu" . "http://elpa.gnu.org/packages/")
("melpa-stable" . "https://stable.melpa.org/packages/")
("melpa" . "http://melpa.org/packages/")))
(setq package-list
'(
;;packages
use-package all-the-icons-dired all-the-icons dired-sidebar))
(if (version< emacs-version "27.0")
(package-initialize))
;; fetch the list of packages available
(unless package-archive-contents
(package-refresh-contents))
;; install the missing packages
(dolist (package package-list)
(unless (package-installed-p package)
(package-install package)))
(require 'use-package)
(require 'all-the-icons)
(use-package all-the-icons-dired
:ensure t
:defer t
:hook (dired-mode . all-the-icons-dired-mode)
)
(use-package dired-sidebar
:bind (("C-x C-n" . dired-sidebar-toggle-sidebar))
:ensure t
:commands (dired-sidebar-toggle-sidebar)
:init
(add-hook 'dired-sidebar-mode-hook
(lambda ()
(unless (file-remote-p default-directory)
(auto-revert-mode))))
:config
(push 'toggle-window-split dired-sidebar-toggle-hidden-commands)
(push 'rotate-windows dired-sidebar-toggle-hidden-commands)
(setq dired-sidebar-subtree-line-prefix "__")
(setq dired-sidebar-theme 'icons)
(setq dired-sidebar-use-term-integration t)
(setq dired-sidebar-use-custom-font t))
Thanks for the -Q. I think it's related to this:
:hook (dired-mode . all-the-icons-dired-mode)
You can remove the hook (but that will remove the icons for regular dired-mode) or do something like:
(use-package all-the-icons-dired
:ensure t
:defer t
:init
(add-hook 'dired-mode-hook (lambda ()
(unless (eq major-mode 'dired-sidebar-mode)
(all-the-icons-dired-mode)))))
(Didn't test that but it should be pretty close...)
I might have to update the documentation for that but I'm short on time these days so PR welcome!
Closing for now, but please reopen if that doesn't fix the issue for you.
For me this worked:
(defun malb/dired-sidebar-drop-icons (orig-fun &rest args)
(if (member 'all-the-icons-dired-mode dired-mode-hook)
(progn
(remove-hook 'dired-mode-hook 'all-the-icons-dired-mode)
(let ((r (apply orig-fun args)))
(add-hook 'dired-mode-hook 'all-the-icons-dired-mode)
r))
(apply orig-fun args)))
(advice-add #'dired-sidebar-get-or-create-buffer :around #'malb/dired-sidebar-drop-icons)
in contrast to the (eq major-mode 'dired-sidebar-mode)
hook check. I think this is due to the call to (dired-noselect root)
in dired-sidebar-get-or-create-buffer
which means the major mode on buffer creation is dired-mode
. Perhaps such calls could be wrapped inside some (let ((dired-sidebar-dired-called-inside-dired-sidebar t)) (dired-call))
which would permit to test for dired-sidebar-dired-called-inside-dired-sidebar
in hooks?
Is above not desirable or doesn't work for you @malb ?
@jojojames the solution you suggested did not work for me either. I just started using the nerd icons for dired-sidebar. This allowed for the all-the-icons-dired to render icons while the side bar just shows preceding arrows and '+' signs. I preferred this behaviour. If any body wants to try it here is my code.
(use-package dired-sidebar
:bind (("C-c n t" . dired-sidebar-toggle-sidebar))
:ensure t
:commands (dired-sidebar-toggle-sidebar)
:init
(add-hook 'dired-sidebar-mode-hook
(lambda ()
(unless (file-remote-p default-directory)
(auto-revert-mode))))
(add-hook 'dired-sidebar-mode-hook (lambda () (display-line-numbers-mode -1)))
(add-hook 'dired-sidebar-mode-hook (lambda () (nlinum-mode -1)))
;; (add-hook 'dired-sidebar-mode-hook (lambda () (all-the-icons-dired-mode -1)))
(add-hook 'dired-sidebar-mode-hook
(lambda ()
(unless (file-remote-p default-directory)
(auto-revert-mode))))
:config
(push 'toggle-window-split dired-sidebar-toggle-hidden-commands)
(push 'rotate-windows dired-sidebar-toggle-hidden-commands)
(setq dired-sidebar-theme 'nerd)
(setq dired-sidebar-width 25))
It would look something like
Is above not desirable or doesn't work for you @malb ?
Indeed, it didn't work for me.
@malb I wonder if it's worth adding that advice to dired-sidebar (if it's been continually working well for you).
It does seem to work for me here, but I haven't really stress tested it, i.e. I occasionally use dired-sidebar but it's not open all the time.
Sounds good, if you can report back after using it for a while, definitely do so. I'm open to using that advice.
Hi. this problem continues on the doom emacs configuration as well.
The root cause is the same as described by others.
@ferhaterata @malb If that advice has continued to work (and you've continued to use dired-sidebar), please report back and I will look into incorporating that advice.
It's still in my config, but I don't think I'm using it enough to say I've done extensive testing. Sorry, not much useful data I can provide here.
I have dired-mode-hook
automatically use all-the-icons, and to conditionally disable that for the sidebar when using a different theme, I have this:
(defun ct/dired-sidebar-mode-hook ()
(visual-line-mode -1) ;; do not wrap lines
;; Refresh buffer when visiting local directory.
(unless (file-remote-p default-directory)
(auto-revert-mode))
;; Deactivate all-the-icons (on by default for dired) when using different theme
(unless (eq dired-sidebar-theme 'icons)
(all-the-icons-dired-mode -1)))
(add-hook 'dired-sidebar-mode-hook #'ct/dired-sidebar-mode-hook)
This just deactivates all-the-icons-dired-mode
, no matter if it's on or off, if using any other theme.
Added something for this, please try.
Looks good!
It works fine when open dired-sidebar from projects or directories but when calling it from the scratch buffer it renders two icons for every item in the directory. When I press g to reload it returns back to normal. My set up is similar to the one given on the README.