refactor(dired): dirvish-hide-details

Prior to this, I used window-width to determine whether file details
should be hidden, but there was a jarring delay on `dirvish-setup-hook`
that made the effect look awful (especially when walking up and down
file trees).

This changes `dirvish-hide-details` to accept a list of contexts where
it should be enabled, which I think is more elegant. Of course,
`dirvish-hide-details` will fall back on old behavior if set to `t` or
`nil`.

I'll consider upstreaming it later (and perhaps doing similar for
`dirvish-hide-cursor`).

Ref: #6760
This commit is contained in:
Henrik Lissner 2024-08-19 02:06:17 -04:00
parent d4ad14b75d
commit ddfb0cc3cc
No known key found for this signature in database
GPG key ID: B60957CA074D39A3

View file

@ -105,17 +105,27 @@ Fixes #3939: unsortable dired entries on Windows."
(setq dirvish-subtree-always-show-state t) (setq dirvish-subtree-always-show-state t)
(appendq! dirvish-attributes '(nerd-icons subtree-state))) (appendq! dirvish-attributes '(nerd-icons subtree-state)))
;; HACK: Doom will treat an integer value for `dirvish-hide-details' to mean ;; HACK: Makes `dirvish-hide-details' accept a list of symbols to instruct
;; hide file/dir details if window is less than N characters wide (e.g. for ;; Dirvish in what contexts `dirvish-hide-details' should be enabled. The
;; side windows or small full-window layouts). ;; accepted values are:
(setq dirvish-hide-details 50) ;; - `dired': when opening a directory directly or w/o Dirvish's full UI.
;; TODO: Proc this hook sooner. The delay on `dirvish-setup-hook' is jarring. ;; - `dirvish': when opening full-frame Dirvish.
(add-hook! 'dirvish-setup-hook ;; - `dirvish-side': when opening Dirvish in the sidebar.
(defun +dired-hide-details-in-side-mode-h () ;; REVIEW: Upstream this behavior later. (Maybe with similar treatment for
(when (integerp dirvish-hide-details) ;; `dirvish-hide-cursor'?)
(dired-hide-details-mode (setq dirvish-hide-details '(dirvish dirvish-side))
(if (< (window-width dirvish--selected-window) dirvish-hide-details) (defadvice! +dired--hide-details-maybe-a (fn &rest args)
+1 -1))))) :around #'dirvish-init-dired-buffer
(let ((dirvish-hide-details
(if (listp dirvish-hide-details)
(cond ((if dirvish--this (memq 'side (dv-type dirvish--this)))
(memq 'dirvish-side dirvish-hide-details))
((or (null dirvish--this)
(null (car (dv-layout dirvish--this))))
(memq 'dired dirvish-hide-details))
((memq 'dirvish dirvish-hide-details)))
dirvish-hide-details)))
(apply fn args)))
(when (modulep! :ui tabs) (when (modulep! :ui tabs)
(after! centaur-tabs (after! centaur-tabs