diff --git a/modules/config/default/+emacs-bindings.el b/modules/config/default/+emacs-bindings.el index 15c4789a6a87..3d704bc7e3cb 100644 --- a/modules/config/default/+emacs-bindings.el +++ b/modules/config/default/+emacs-bindings.el @@ -81,6 +81,8 @@ :desc "Find file from here" "F" #'+default/find-file-under-here :desc "Locate file" "l" #'locate :desc "Rename/move this file" "m" #'doom/move-this-file + (:when (modulep! :emacs dired) + :desc "Find file names in dired" "n" #'dirvish-fd) :desc "Find file in private config" "p" #'doom/find-file-in-private-config :desc "Browse private config" "P" #'doom/open-private-config :desc "Recent files" "r" #'recentf-open-files @@ -236,6 +238,10 @@ :desc "REPL" "r" #'+eval/open-repl-other-window :desc "REPL (same window)" "R" #'+eval/open-repl-same-window :desc "Dired" "-" #'dired-jump + (:when (modulep! :emacs dired) + ;; REVIEW: shall we bind dirvish-side here? + ;; :desc "Project sidebar" "p" #'dirvish-side + :desc "Dired w/ preview" "v" #'dirvish) (:when (modulep! :ui neotree) :desc "Project sidebar" "p" #'+neotree/open :desc "Find file in project sidebar" "P" #'+neotree/find-this-file) diff --git a/modules/config/default/+evil-bindings.el b/modules/config/default/+evil-bindings.el index 7a34fd63c638..4ae906fc5fed 100644 --- a/modules/config/default/+evil-bindings.el +++ b/modules/config/default/+evil-bindings.el @@ -431,6 +431,8 @@ :desc "Find file" "f" #'find-file :desc "Find file from here" "F" #'+default/find-file-under-here :desc "Locate file" "l" #'locate + (:when (modulep! :emacs dired) + :desc "Find file names in dired" "n" #'dirvish-fd) :desc "Find file in private config" "p" #'doom/find-file-in-private-config :desc "Browse private config" "P" #'doom/open-private-config :desc "Recent files" "r" #'recentf-open-files @@ -605,6 +607,10 @@ :desc "REPL" "r" #'+eval/open-repl-other-window :desc "REPL (same window)" "R" #'+eval/open-repl-same-window :desc "Dired" "-" #'dired-jump + (:when (modulep! :emacs dired) + ;; REVIEW: resolve conflict between dirvish-side and neotree/treemacs + ;; :desc "Project sidebar" "p" #'dirvish-side + :desc "Dired w/ preview" "v" #'dirvish) (:when (modulep! :ui neotree) :desc "Project sidebar" "p" #'+neotree/open :desc "Find file in project sidebar" "P" #'+neotree/find-this-file) diff --git a/modules/emacs/dired/README.org b/modules/emacs/dired/README.org index 04d12e4f0cf8..0a943e43144a 100644 --- a/modules/emacs/dired/README.org +++ b/modules/emacs/dired/README.org @@ -7,21 +7,19 @@ This module provides reasonable defaults and augmentations for dired. ** Maintainers -/This module has no dedicated maintainers./ [[doom-contrib-maintainer:][Become a maintainer?]] +- [[doom-user:][@alexluigit]] + +[[doom-contrib-maintainer:][Become a maintainer?]] ** Module flags - +icons :: Enables the display of fancy icons depending on file types in dired buffers. -- +ranger :: - Enables dired to be more like [[https://github.com/ranger/ranger][ranger]]. +- +bindings :: + Enables some sensible keybindings in dired buffers, see below. ** Packages -- [[doom-package:][all-the-icons-dired]] if [[doom-module:][+icons]] -- [[doom-package:][diff-hl]] +- [[doom-package:][dirvish]] - [[doom-package:][diredfl]] -- [[doom-package:][dired-rsync]] -- [[doom-package:][fd-dired]] -- [[doom-package:][ranger]] if [[doom-module:][+ranger]] ** TODO Hacks #+begin_quote @@ -38,25 +36,80 @@ This module provides reasonable defaults and augmentations for dired. This module has no requirements *except on BSDs* like MacOS or FreeBSD, where =GNU ls= (aka ~gls~) is required. +Optionally, you can install these dependencies to improve the preview +experience: + ++ =fd= as a faster alternative to =find= ++ =imagemagick= for image preview ++ =poppler= | =pdf-tools= for pdf preview ++ =ffmpegthumbnailer= for video preview ++ =mediainfo= for audio/video metadata generation ++ =tar= and =unzip= for archive files preview + +** macOS +#+begin_src bash + brew install coreutils fd poppler ffmpegthumbnailer mediainfo imagemagick +#+end_src + +** Debian-based +#+begin_src bash + apt install fd-find poppler-utils ffmpegthumbnailer mediainfo imagemagick tar unzip +#+end_src + +** Arch-based +#+begin_src bash + pacman -S fd poppler ffmpegthumbnailer mediainfo imagemagick tar unzip +#+end_src + +** FreeBSD +#+begin_src bash + pkg install gnuls fd-find poppler ffmpegthumbnailer ImageMagick7 gtar +#+end_src + +** Windows (not tested, may not work) +#+begin_src bash + # install via Scoop: https://scoop.sh/ + scoop install coreutils fd poppler imagemagick unzip +#+end_src + * TODO Usage #+begin_quote 🔨 /This module's usage documentation is incomplete./ [[doom-contrib-module:][Complete it?]] #+end_quote -| Keybind | Description | -|---------+----------------------------| -| [[kbd:][SPC f d]] | Find directory with dired | -| [[kbd:][q]] | Exit dired buffer | -| [[kbd:][C-c C-r]] | Run [[doom-package:][dired-rsync]] | -| [[kbd:][C-c C-e]] | Rename entries with [[doom-package:][wdired]] | +** Global bindings +| Keybind | Description | +|---------+---------------------------| +| [[kbd:][SPC f d]] | Find directory with dired | +| [[kbd:][SPC f n]] | Find file names in dired | +| [[kbd:][SPC o v]] | Open dired with preview | + +** Dired/Dirvish bindings +| Keybind | Description | +|---------+-----------------------------| +| [[kbd:][q]] | Exit dired buffer | +| [[kbd:][?]] | Ask for help | +| [[kbd:][M-t]] | Toggle fullscreen (preview) | +| [[kbd:][C-c C-e]] | Rename entries with [[doom-package:][wdired]] | + +If [[doom-module:][+bindings]] is enabled, these bindings are available as well. + +| Keybind | Description | +|---------+-----------------------------------------------| +| [[kbd:][a]] | Quick access frequently used directories | +| [[kbd:][f]] | Get file information under the cursor | +| [[kbd:][y]] | Paste/link/move marked files here | +| [[kbd:][s]] | Sort buffer with different criteria | +| [[kbd:][TAB]] | Expand or contract directory under the cursor | +| [[kbd:][M-f]] | Jump to next dired history entry | +| [[kbd:][M-b]] | Jump to previous dired history entry | +| [[kbd:][M-m]] | Mark files in different ways | +| [[kbd:][M-s]] | Setup user interface for dirvish | +| [[kbd:][M-n]] | Narrow the buffer with user input | +| [[kbd:][C-c C-e]] | Rename entries with [[doom-package:][wdired]] | Other keybindings can be found on the official [[https://www.gnu.org/software/emacs/refcards/pdf/dired-ref.pdf][Dired reference card]]. -** Ranger -If [[doom-module:][+ranger]] is enabled often a buffer will be opened in minimal ranger mode -(~deer-mode~). In this case [[kbd:][z P]] can be used to toggle between full ranger and -~deer-mode~. - * TODO Configuration #+begin_quote 🔨 This module has no configuration documentation yet. [[doom-contrib-module:][Write some?]] diff --git a/modules/emacs/dired/autoload.el b/modules/emacs/dired/autoload.el deleted file mode 100644 index e44d3dda0dd7..000000000000 --- a/modules/emacs/dired/autoload.el +++ /dev/null @@ -1,15 +0,0 @@ -;;; emacs/dired/autoload.el -*- lexical-binding: t; -*- - -;;;###autoload -(defun +dired/quit-all () - "Kill all `dired-mode' buffers." - (interactive) - (mapc #'kill-buffer (doom-buffers-in-mode 'dired-mode)) - (message "Killed all dired buffers")) - -;;;###autoload -(defun +dired-enable-git-info-h () - "Enable `dired-git-info-mode' in git repos." - (and (not (file-remote-p default-directory)) - (locate-dominating-file "." ".git") - (dired-git-info-mode 1))) diff --git a/modules/emacs/dired/config.el b/modules/emacs/dired/config.el index 26e5e74e20b4..e5b6f17177da 100644 --- a/modules/emacs/dired/config.el +++ b/modules/emacs/dired/config.el @@ -1,10 +1,9 @@ -;;; tools/dired/config.el -*- lexical-binding: t; -*- +;;; emacs/dired/config.el -*- lexical-binding: t; -*- (use-package! dired :commands dired-jump :init (setq dired-dwim-target t ; suggest a target for moving/copying intelligently - dired-hide-details-hide-symlink-targets nil ;; don't prompt to revert, just do it dired-auto-revert-buffer #'dired-buffer-stale-p ;; Always copy/delete recursively @@ -25,31 +24,21 @@ :slot 20 :size 0.8 :select t :quit nil :ttl 0) (set-evil-initial-state! 'image-dired-display-image-mode 'emacs) - (let ((args (list "-ahl" "-v" "--group-directories-first"))) - (when IS-BSD - ;; Use GNU ls as `gls' from `coreutils' if available. Add `(setq - ;; dired-use-ls-dired nil)' to your config to suppress the Dired warning - ;; when not using GNU ls. - (if-let (gls (executable-find "gls")) - (setq insert-directory-program gls) - ;; BSD ls doesn't support -v or --group-directories-first - (setq args (list (car args))))) - (setq dired-listing-switches (string-join args " ")) - - (add-hook! 'dired-mode-hook - (defun +dired-disable-gnu-ls-flags-maybe-h () - "Remove extraneous switches from `dired-actual-switches' when it's -uncertain that they are supported (e.g. over TRAMP or on Windows). - -Fixes #1703: dired over TRAMP displays a blank screen. -Fixes #3939: unsortable dired entries on Windows." - (when (or (file-remote-p default-directory) - (and (boundp 'ls-lisp-use-insert-directory-program) - (not ls-lisp-use-insert-directory-program))) - (setq-local dired-actual-switches (car args)))))) - - ;; Don't complain about this command being disabled when we use it - (put 'dired-find-alternate-file 'disabled nil) + (let ((non-gnu-args "-alh") + (gnu-args + "-l --almost-all --human-readable --group-directories-first")) + (cond ((and (boundp 'ls-lisp-use-insert-directory-program) + (not ls-lisp-use-insert-directory-program) + (< emacs-major-version 28)) + ;; Fixes #3939: unsortable dired entries on Windows + (setq dired-listing-switches non-gnu-args)) + (IS-BSD + ;; BSD ls doesn't support long options + (if-let (gls (executable-find "gls")) + (setq insert-directory-program gls + dired-listing-switches gnu-args) + (setq dired-listing-switches non-gnu-args))) + (t (setq dired-listing-switches gnu-args)))) (defadvice! +dired--no-revert-in-virtual-buffers-a (&rest args) "Don't auto-revert in dired-virtual buffers (see `dired-virtual-revert')." @@ -57,127 +46,11 @@ Fixes #3939: unsortable dired entries on Windows." (not (eq revert-buffer-function #'dired-virtual-revert))) (map! :map dired-mode-map - ;; Kill all dired buffers on q - :ng "q" #'+dired/quit-all ;; To be consistent with ivy/helm+wgrep integration "C-c C-e" #'wdired-change-to-wdired-mode)) -(use-package! dired-rsync - :general (dired-mode-map "C-c C-r" #'dired-rsync)) - - -(use-package! diredfl - :hook (dired-mode . diredfl-mode)) - - -(use-package! ranger - :when (modulep! +ranger) - :after dired - :init (setq ranger-override-dired t) - :config - (unless (file-directory-p image-dired-dir) - (make-directory image-dired-dir)) - - (set-popup-rule! "^\\*ranger" :ignore t) - - (defadvice! +dired--cleanup-header-line-a () - "Ranger fails to clean up `header-line-format' when it is closed, so..." - :before #'ranger-revert - (dolist (buffer (buffer-list)) - (when (buffer-live-p buffer) - (with-current-buffer buffer - (when (equal header-line-format '(:eval (ranger-header-line))) - (setq header-line-format nil)))))) - - (defadvice! +dired--cleanup-mouse1-bind-a () - "Ranger binds an anonymous function to mouse-1 after previewing a buffer -that prevents the user from escaping the window with the mouse. This command is -never cleaned up if the buffer already existed before ranger was initialized, so -we have to clean it up ourselves." - :after #'ranger-setup-preview - (when (window-live-p ranger-preview-window) - (with-current-buffer (window-buffer ranger-preview-window) - (local-unset-key [mouse-1])))) - - (defadvice! +dired--ranger-travel-a () - "Temporary fix for this function until ralesi/ranger.el#236 gets merged." - :override #'ranger-travel - (interactive) - (let ((prompt "Travel: ")) - (cond - ((bound-and-true-p helm-mode) - (ranger-find-file (helm-read-file-name prompt))) - ((bound-and-true-p ivy-mode) - (ivy-read prompt 'read-file-name-internal - :matcher #'counsel--find-file-matcher - :action - (lambda (x) - (with-ivy-window - (ranger-find-file (expand-file-name x default-directory)))))) - ((bound-and-true-p ido-mode) - (ranger-find-file (ido-read-file-name prompt))) - (t - (ranger-find-file (read-file-name prompt)))))) - - (setq ranger-cleanup-on-disable t - ranger-excluded-extensions '("mkv" "iso" "mp4") - ranger-deer-show-details t - ranger-max-preview-size 10 - ranger-show-literal nil - ranger-hide-cursor nil)) - - -(use-package! dirvish - :when (modulep! +dirvish) - :defer t - :init (after! dired (dirvish-override-dired-mode)) - :hook (dired-mode . dired-omit-mode) - :config - (setq dirvish-cache-dir (concat doom-cache-dir "dirvish/") - dirvish-hide-details nil - dirvish-attributes '(git-msg) - dired-omit-files (concat dired-omit-files "\\|^\\..*$")) - (when (modulep! +icons) - (push 'all-the-icons dirvish-attributes)) - (map! :map dirvish-mode-map - :n "b" #'dirvish-goto-bookmark - :n "z" #'dirvish-show-history - :n "f" #'dirvish-file-info-menu - :n "F" #'dirvish-toggle-fullscreen - :n "l" #'dired-find-file - :n "h" #'dired-up-directory - :localleader - "h" #'dired-omit-mode)) - - -(use-package! all-the-icons-dired - :when (modulep! +icons) - :unless (modulep! +dirvish) - :hook (dired-mode . all-the-icons-dired-mode) - :config - ;; HACK Fixes #1929: icons break file renaming in Emacs 27+, because the icon - ;; is considered part of the filename, so we disable icons while we're in - ;; wdired-mode. - (defvar +wdired-icons-enabled -1) - - ;; display icons with colors - (setq all-the-icons-dired-monochrome nil) - - (defadvice! +dired-disable-icons-in-wdired-mode-a (&rest _) - :before #'wdired-change-to-wdired-mode - (setq-local +wdired-icons-enabled (if all-the-icons-dired-mode 1 -1)) - (when all-the-icons-dired-mode - (all-the-icons-dired-mode -1))) - - (defadvice! +dired-restore-icons-after-wdired-mode-a (&rest _) - :after #'wdired-change-to-dired-mode - (all-the-icons-dired-mode +wdired-icons-enabled))) - - (use-package! dired-x - :unless (modulep! +dirvish) - :unless (modulep! +ranger) :hook (dired-mode . dired-omit-mode) :config (setq dired-omit-verbose nil @@ -211,37 +84,50 @@ we have to clean it up ourselves." "h" #'dired-omit-mode)) -(use-package! fd-dired - :when doom-projectile-fd-binary - :defer t - :init - (global-set-key [remap find-dired] #'fd-dired) - (set-popup-rule! "^\\*F\\(?:d\\|ind\\)\\*$" :ignore t)) - (use-package! dired-aux :defer t :config (setq dired-create-destination-dirs 'ask dired-vc-rename-file t)) -;;;###package dired-git-info -(map! :after dired - :map (dired-mode-map ranger-mode-map) - :ng ")" #'dired-git-info-mode) -(setq dgi-commit-message-format "%h %cs %s" - dgi-auto-hide-details-p nil) -(after! wdired - ;; Temporarily disable `dired-git-info-mode' when entering wdired, due to - ;; reported incompatibilities. - (defvar +dired--git-info-p nil) - (defadvice! +dired--disable-git-info-a (&rest _) - :before #'wdired-change-to-wdired-mode - (setq +dired--git-info-p (bound-and-true-p dired-git-info-mode)) - (when +dired--git-info-p - (dired-git-info-mode -1))) - (defadvice! +dired--reactivate-git-info-a (&rest _) - :after '(wdired-exit - wdired-abort-changes - wdired-finish-edit) - (when +dired--git-info-p - (dired-git-info-mode +1)))) + +(use-package! diredfl + :hook (dired-mode . diredfl-mode)) + + +(use-package! dirvish + :defer t + :general (dired-mode-map "C-c C-r" #'dirvish-yank) ; for backward compatibility + :after-call dired-noselect dirvish-fd + :config + (dirvish-override-dired-mode) + (set-popup-rule! "^ ?\\*Dirvish.*" :ignore t) + (map! :map dirvish-mode-map + :n "q" #'dirvish-quit + :n "?" #'dirvish-dispatch + :n "M-t" #'dirvish-layout-toggle) + (setq dirvish-cache-dir (concat doom-cache-dir "dirvish/") + dirvish-mode-line-format + '(:left (sort file-time symlink) :right (omit yank index))) + (when (modulep! :ui tabs) + (after! centaur-tabs + (add-hook! 'dirvish-mode-hook 'centaur-tabs-local-mode) + (add-hook! 'dirvish-parent-mode-hook 'centaur-tabs-local-mode))) + (when (modulep! :ui vc-gutter) + (push 'vc-state dirvish-attributes)) + (when (modulep! +icons) + (appendq! dirvish-attributes '(all-the-icons subtree-state))) + (when (modulep! +bindings) + (map! :map dirvish-mode-map + :n "a" #'dirvish-quick-access + :n "f" #'dirvish-file-info-menu + :n "y" #'dirvish-yank-menu + :n "s" #'dirvish-quicksort + :n "TAB" #'dirvish-subtree-toggle + :n "M-f" #'dirvish-history-go-forward + :n "M-b" #'dirvish-history-go-backward + :n "M-n" #'dirvish-narrow + :n "M-m" #'dirvish-mark-menu + :n "M-s" #'dirvish-setup-menu + :n "M-e" #'dirvish-emerge-menu + :n "M-j" #'dirvish-fd-jump))) diff --git a/modules/emacs/dired/doctor.el b/modules/emacs/dired/doctor.el index 2c2e77b29abf..3c0c77a8cfdc 100644 --- a/modules/emacs/dired/doctor.el +++ b/modules/emacs/dired/doctor.el @@ -2,3 +2,6 @@ (when (and IS-BSD (not (executable-find "gls"))) (warn! "Cannot find gls (GNU ls). This may cause issues with dired")) + +(when (modulep! +ranger) + (warn! "The +ranger flag has been removed from this module")) diff --git a/modules/emacs/dired/packages.el b/modules/emacs/dired/packages.el index 06e5659a5925..abd1f2192abe 100644 --- a/modules/emacs/dired/packages.el +++ b/modules/emacs/dired/packages.el @@ -2,13 +2,4 @@ ;;; emacs/dired/packages.el (package! diredfl :pin "f9140b2c42151dca669003d685c9f079b2e3dc37") -(package! dired-git-info :pin "9461476a28a5fec0784260f6e318237c662c3430") -(package! dired-rsync :pin "7940d9154d0a908693999b0e1ea351a6d365c93d") -(when (modulep! +ranger) - (package! ranger :pin "2498519cb21dcd5791d240607a72a204d1761668")) -(when (modulep! +dirvish) - (package! dirvish :pin "73dcaa404da9ab84d25f2919e6e3af4b1f8e7f37")) -(when (and (modulep! +icons) - (not (modulep! +dirvish))) - (package! all-the-icons-dired :pin "5e9b097f9950cc9f86de922b07903a4e5fefc733")) -(package! fd-dired :pin "458464771bb220b6eb87ccfd4c985c436e57dc7e") +(package! dirvish :pin "eaf8a0e03955433fa9816cda8e67355dfd7b2035") diff --git a/modules/ui/vc-gutter/config.el b/modules/ui/vc-gutter/config.el index c555f9d08f73..25c3f904bbee 100644 --- a/modules/ui/vc-gutter/config.el +++ b/modules/ui/vc-gutter/config.el @@ -148,7 +148,6 @@ is deferred until the file is saved. Respects `git-gutter:disabled-modes'." :when (modulep! +diff-hl) :hook (find-file . diff-hl-mode) :hook (vc-dir-mode . diff-hl-dir-mode) - :hook (dired-mode . diff-hl-dired-mode) :hook (diff-hl-mode . diff-hl-flydiff-mode) :config (set-popup-rule! "^\\*diff-hl" :select nil :size '+popup-shrink-to-fit)