From 9913acbdc4f22b2d208ea59ce5aec1e3cd722788 Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Sun, 18 Aug 2024 16:12:42 -0400 Subject: [PATCH 1/4] fix: opening tramp paths from command line args Eventually, Emacs will process any files passed to it via the command line, and will do so *really* early in the startup process. These might contain special file paths like TRAMP paths (e.g. /sudo://etc/ssh/ssh_config), so restore `file-name-handler-alist' just for this small portion of startup. --- lisp/doom.el | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lisp/doom.el b/lisp/doom.el index 857df908d..601c5c38a 100644 --- a/lisp/doom.el +++ b/lisp/doom.el @@ -382,6 +382,13 @@ users).") (set-default-toplevel-value 'file-name-handler-alist file-name-handler-alist) ;; Remember it so it can be reset where needed. (put 'file-name-handler-alist 'initial-value old-value) + ;; COMPAT: Eventually, Emacs will process any files passed to it via the + ;; command line, and will do so *really* early in the startup process. + ;; These might contain special file paths like TRAMP paths, so restore + ;; `file-name-handler-alist' just for this portion of startup. + (define-advice command-line-1 (:around (fn args-left) respect-file-handlers) + (let ((file-name-handler-alist (if args-left old-value file-name-handler-alist))) + (funcall fn args-left))) ;; COMPAT: ...but restore `file-name-handler-alist' later, because it is ;; needed for handling encrypted or compressed files, among other things. (add-hook! 'emacs-startup-hook :depth 101 From 967586fcae6260ba25da26ca4d0a4daaf85c4188 Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Sun, 18 Aug 2024 16:20:20 -0400 Subject: [PATCH 2/4] fix(dired): dirvish-{mode,header}-line-height = doom-modeline-height Ref: #8000 --- modules/emacs/dired/config.el | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/modules/emacs/dired/config.el b/modules/emacs/dired/config.el index e65b146cd..0b68f9211 100644 --- a/modules/emacs/dired/config.el +++ b/modules/emacs/dired/config.el @@ -81,15 +81,6 @@ Fixes #3939: unsortable dired entries on Windows." ;; buffers. Starting from scratch isn't even that expensive, anyway. (setq dirvish-reuse-session nil) - ;; A more reserved mode-line height that should match doom-modeline's (or the - ;; vanilla mode-line's) height. - (add-hook! 'after-setting-font-hook - (defun +dired-update-mode-line-heigth-h () - ;; REVIEW: Too hardcoded. - (setq dirvish-mode-line-height (+ (frame-char-height) 4) - dirvish-header-line-height (+ (frame-char-height) 8)))) - (+dired-update-mode-line-heigth-h) - (if (modulep! +dirvish) (setq dirvish-attributes '(file-size) dirvish-mode-line-format @@ -98,8 +89,18 @@ Fixes #3939: unsortable dired entries on Windows." dirvish-use-header-line nil dirvish-mode-line-format nil)) + ;; Match the height of `doom-modeline', if it's being used. + ;; TODO: Make this respect user changes to these variables. + (when (modulep! :ui modeline) + (add-hook! 'dired-mode-hook + (defun +dired-update-mode-line-height-h () + (when-let (height (bound-and-true-p doom-modeline-height)) + (setq dirvish-mode-line-height height + dirvish-header-line-height height))))) + (when (modulep! :ui vc-gutter) (push 'vc-state dirvish-attributes)) + (when (modulep! +icons) (setq dirvish-subtree-always-show-state t) (appendq! dirvish-attributes '(nerd-icons subtree-state))) @@ -165,7 +166,6 @@ Fixes #3939: unsortable dired entries on Windows." (and dirvish--this (selected-window))))) (delete-window win)))) - ;; HACK: If a directory has a .dir-locals.el, its settings could ;; interfere/crash Dirvish trying to preview it. ;; REVIEW: Upstream this later. From d4ad14b75d090649c0783c41082ebc4d745b76a8 Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Sun, 18 Aug 2024 16:26:08 -0400 Subject: [PATCH 3/4] fix(dired): fallback to default if dirvish-use-mode-line == nil Currently, setting `dirvish-use-mode-line` to nil blanks out the mode-line, and setting it to `t` makes Dirvish use its own mode-line. To get the default mode-line, `dirvish-mode-line-format` needs to be set to nil, but even then Dirvish will prepend a bar to the default-mode-line so it can control its height, which I think is a confusing chain of causes and effects. This changes the behavior such that `dirvish-use-mode-line` controls whether `dirvish-mode-line-format` will be used or not. I'll upstream this to hlissner/dirvish later. Fix: #8000 --- modules/emacs/dired/config.el | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/modules/emacs/dired/config.el b/modules/emacs/dired/config.el index 0b68f9211..e237b0c7d 100644 --- a/modules/emacs/dired/config.el +++ b/modules/emacs/dired/config.el @@ -87,7 +87,7 @@ Fixes #3939: unsortable dired entries on Windows." '(:left (sort file-time symlink) :right (omit yank index))) (setq dirvish-attributes nil dirvish-use-header-line nil - dirvish-mode-line-format nil)) + dirvish-use-mode-line nil)) ;; Match the height of `doom-modeline', if it's being used. ;; TODO: Make this respect user changes to these variables. @@ -156,6 +156,20 @@ Fixes #3939: unsortable dired entries on Windows." :n "S" #'dirvish-relative-symlink :n "h" #'dirvish-hardlink)) + ;; HACK: Modifies Dirvish to fall back to default `mode-line-format' if + ;; `dirvish-use-mode-line' is nil, instead of when + ;; `dirvish-mode-line-format' is nil (since the latter *still* prepends to + ;; the default `mode-line-format'), and is overall less intuitive. + ;; REVIEW: Upstream this behavior later. + (defadvice! +dired--dirvish-use-modeline-a (fn &rest args) + "Change how `dirvish-use-mode-line' and `dirvish-mode-line-format' operate." + :around #'dirvish--setup-mode-line + (when dirvish-use-mode-line + (let ((dirvish--mode-line-fmt + (if dirvish-mode-line-format + dirvish--mode-line-fmt))) + (apply fn args)))) + ;; HACK: Kill Dirvish session before switching projects/workspaces, otherwise ;; it errors out on trying to delete/change dedicated windows. (add-hook! '(persp-before-kill-functions projectile-before-switch-project-hook) From ddfb0cc3cc4326e72efb6db84c95eeb1401c7fc2 Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Mon, 19 Aug 2024 02:06:17 -0400 Subject: [PATCH 4/4] 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 --- modules/emacs/dired/config.el | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/modules/emacs/dired/config.el b/modules/emacs/dired/config.el index e237b0c7d..744598a36 100644 --- a/modules/emacs/dired/config.el +++ b/modules/emacs/dired/config.el @@ -105,17 +105,27 @@ Fixes #3939: unsortable dired entries on Windows." (setq dirvish-subtree-always-show-state t) (appendq! dirvish-attributes '(nerd-icons subtree-state))) - ;; HACK: Doom will treat an integer value for `dirvish-hide-details' to mean - ;; hide file/dir details if window is less than N characters wide (e.g. for - ;; side windows or small full-window layouts). - (setq dirvish-hide-details 50) - ;; TODO: Proc this hook sooner. The delay on `dirvish-setup-hook' is jarring. - (add-hook! 'dirvish-setup-hook - (defun +dired-hide-details-in-side-mode-h () - (when (integerp dirvish-hide-details) - (dired-hide-details-mode - (if (< (window-width dirvish--selected-window) dirvish-hide-details) - +1 -1))))) + ;; HACK: Makes `dirvish-hide-details' accept a list of symbols to instruct + ;; Dirvish in what contexts `dirvish-hide-details' should be enabled. The + ;; accepted values are: + ;; - `dired': when opening a directory directly or w/o Dirvish's full UI. + ;; - `dirvish': when opening full-frame Dirvish. + ;; - `dirvish-side': when opening Dirvish in the sidebar. + ;; REVIEW: Upstream this behavior later. (Maybe with similar treatment for + ;; `dirvish-hide-cursor'?) + (setq dirvish-hide-details '(dirvish dirvish-side)) + (defadvice! +dired--hide-details-maybe-a (fn &rest args) + :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) (after! centaur-tabs