2024-08-15 23:18:47 -04:00
|
|
|
;;; emacs/dired/config.el -*- lexical-binding: t; -*-
|
2017-02-19 18:53:38 -05:00
|
|
|
|
2024-08-15 23:18:47 -04:00
|
|
|
;;
|
|
|
|
;;; Packages
|
|
|
|
|
2019-07-23 12:44:03 +02:00
|
|
|
(use-package! dired
|
2018-06-01 13:46:52 +02:00
|
|
|
:commands dired-jump
|
2018-01-27 20:49:46 -05:00
|
|
|
:init
|
2022-02-14 17:19:19 +01:00
|
|
|
(setq dired-dwim-target t ; suggest a target for moving/copying intelligently
|
|
|
|
;; don't prompt to revert, just do it
|
|
|
|
dired-auto-revert-buffer #'dired-buffer-stale-p
|
2019-12-19 15:31:01 -05:00
|
|
|
;; Always copy/delete recursively
|
2018-01-27 20:49:46 -05:00
|
|
|
dired-recursive-copies 'always
|
|
|
|
dired-recursive-deletes 'top
|
2021-03-09 16:43:22 +01:00
|
|
|
;; Ask whether destination dirs should get created when copying/removing files.
|
|
|
|
dired-create-destination-dirs 'ask
|
2019-12-19 15:31:01 -05:00
|
|
|
;; Where to store image caches
|
2018-01-27 20:49:46 -05:00
|
|
|
image-dired-dir (concat doom-cache-dir "image-dired/")
|
2018-03-19 23:55:45 -04:00
|
|
|
image-dired-db-file (concat image-dired-dir "db.el")
|
2018-01-27 20:49:46 -05:00
|
|
|
image-dired-gallery-dir (concat image-dired-dir "gallery/")
|
|
|
|
image-dired-temp-image-file (concat image-dired-dir "temp-image")
|
2019-12-29 15:44:10 -05:00
|
|
|
image-dired-temp-rotate-image-file (concat image-dired-dir "temp-rotate-image")
|
|
|
|
;; Screens are larger nowadays, we can afford slightly larger thumbnails
|
|
|
|
image-dired-thumb-size 150)
|
2018-01-27 20:49:46 -05:00
|
|
|
:config
|
2019-12-29 15:44:10 -05:00
|
|
|
(set-popup-rule! "^\\*image-dired"
|
|
|
|
:slot 20 :size 0.8 :select t :quit nil :ttl 0)
|
|
|
|
(set-evil-initial-state! 'image-dired-display-image-mode 'emacs)
|
|
|
|
|
2020-05-25 02:25:14 -04:00
|
|
|
(let ((args (list "-ahl" "-v" "--group-directories-first")))
|
2023-12-05 17:05:13 -05:00
|
|
|
(when (featurep :system 'bsd)
|
2019-03-02 13:49:39 -05:00
|
|
|
;; Use GNU ls as `gls' from `coreutils' if available. Add `(setq
|
|
|
|
;; dired-use-ls-dired nil)' to your config to suppress the Dired warning
|
:boom: Replace exec-path-from-shell w/ 'bin/doom env'
IMPORTANT: This is a breaking update for Mac users, as your shell
environment will no longer be inherited correctly (with the removal of
exec-path-from-shell). The quick fix is: 'bin/doom env refresh'. Also,
the set-env! autodef now does nothing (and is deprecated), be sure to
remove calls to it in your config.
Smaller changes:
+ This update also adds --no-* switches to doom quickstart
+ Includes general improvements to the documentation of several bin/doom
commands.
+ Moves doom/reload* commands to core/autoload/config.el
+ doom/reload-project has been removed (it didn't actually do anything)
The breaking change:
This update adds an "envvar file" to Doom Emacs. This file is generated
by `doom env refresh`, populated with variables scraped from your shell
environment (from both non-interactive and interactive sessions). This
file is then (inexpensively) loaded at startup, if it exists.
+ The file is manually generated with `doom env refresh`.
+ It can be regenerated automatically whenever `doom refresh` is run by
running `doom env enable` (`doom env clear` will reverse this and
delete the env file).
+ `doom quickstart` will ask if you want to auto-generate this envvar
file. You won't need it if you're confident Emacs will always be
started from the correct environment, however.
+ Your env file can be reloaded from a running Emacs session with `M-x
doom/reload-env`. Note: this won't work if the Emacs session you're
running it in doesn't have a correct SHELL set. i.e. don't use this to
create your first env file!
The idea isn't mine -- it's borrowed from Spacemacs -- and was
introduced to me in #1053 by @yurimx. I was impressed with it. Prior to
this, I was unhappy with exec-path-from-shell (no hate to the dev, I
understand its necessity), and 'doom patch-macos' wasn't ideal for mac
users (needed to be reapplied every time you update Emacs). What's more,
many users (even Linux users) had to install exec-path-from-shell
anyway.
This solution suffers from none of their shortcomings. More reliable
than patch-macos, more performant and complete than
exec-path-from-shell, and easily handled by bin/doom.
2019-03-28 00:06:10 -04:00
|
|
|
;; when not using GNU ls.
|
2019-09-03 00:59:17 -04:00
|
|
|
(if-let (gls (executable-find "gls"))
|
2019-03-02 13:49:39 -05:00
|
|
|
(setq insert-directory-program gls)
|
2020-05-25 02:25:14 -04:00
|
|
|
;; BSD ls doesn't support -v or --group-directories-first
|
2020-05-25 22:16:11 -04:00
|
|
|
(setq args (list (car args)))))
|
2020-05-03 13:18:31 -04:00
|
|
|
(setq dired-listing-switches (string-join args " "))
|
2018-12-13 15:40:53 -05:00
|
|
|
|
2020-05-03 13:18:31 -04:00
|
|
|
(add-hook! 'dired-mode-hook
|
2021-04-14 17:40:57 -04:00
|
|
|
(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).
|
2019-10-07 22:12:16 -04:00
|
|
|
|
2021-04-14 17:40:57 -04:00
|
|
|
Fixes #1703: dired over TRAMP displays a blank screen.
|
|
|
|
Fixes #3939: unsortable dired entries on Windows."
|
|
|
|
(when (or (file-remote-p default-directory)
|
2021-04-17 00:03:20 -04:00
|
|
|
(and (boundp 'ls-lisp-use-insert-directory-program)
|
|
|
|
(not ls-lisp-use-insert-directory-program)))
|
2020-05-15 01:44:53 -04:00
|
|
|
(setq-local dired-actual-switches (car args))))))
|
2019-10-07 22:12:16 -04:00
|
|
|
|
2019-10-23 01:33:55 -04:00
|
|
|
;; Don't complain about this command being disabled when we use it
|
|
|
|
(put 'dired-find-alternate-file 'disabled nil)
|
|
|
|
|
2022-02-14 17:19:19 +01:00
|
|
|
(defadvice! +dired--no-revert-in-virtual-buffers-a (&rest args)
|
|
|
|
"Don't auto-revert in dired-virtual buffers (see `dired-virtual-revert')."
|
|
|
|
:before-while #'dired-buffer-stale-p
|
|
|
|
(not (eq revert-buffer-function #'dired-virtual-revert)))
|
|
|
|
|
2024-08-18 00:09:25 -04:00
|
|
|
;; To be consistent with vertico/ivy/helm+wgrep integration
|
|
|
|
(define-key dired-mode-map (kbd "C-c C-e") #'wdired-change-to-wdired-mode))
|
2018-12-07 22:27:03 -08:00
|
|
|
|
|
|
|
|
2022-06-23 19:47:22 +08:00
|
|
|
(use-package! dirvish
|
2024-08-18 00:09:25 -04:00
|
|
|
:commands dirvish-find-entry-a dirvish-dired-noselect-a
|
|
|
|
:general (dired-mode-map "C-c C-r" #'dirvish-rsync)
|
|
|
|
:init
|
|
|
|
(setq dirvish-cache-dir (file-name-concat doom-cache-dir "dirvish/"))
|
|
|
|
;; HACK: ...
|
|
|
|
(advice-add #'dired-find-file :override #'dirvish-find-entry-a)
|
|
|
|
(advice-add #'dired-noselect :around #'dirvish-dired-noselect-a)
|
2022-06-23 19:47:22 +08:00
|
|
|
:config
|
2024-08-18 00:09:25 -04:00
|
|
|
(dirvish-override-dired-mode)
|
|
|
|
(set-popup-rule! "^ ?\\*Dirvish.*" :ignore t)
|
|
|
|
|
|
|
|
;; Don't recycle sessions. We don't want leftover buffers lying around,
|
|
|
|
;; especially if users are reconfiguring Dirvish or trying to recover from an
|
|
|
|
;; error. It's too easy to accidentally break Dirvish (e.g. by focusing the
|
|
|
|
;; header window) at the moment, or get stuck in a focus loop with the buried
|
|
|
|
;; buffers. Starting from scratch isn't even that expensive, anyway.
|
|
|
|
(setq dirvish-reuse-session nil)
|
|
|
|
|
|
|
|
(if (modulep! +dirvish)
|
|
|
|
(setq dirvish-attributes '(file-size)
|
|
|
|
dirvish-mode-line-format
|
|
|
|
'(:left (sort file-time symlink) :right (omit yank index)))
|
|
|
|
(setq dirvish-attributes nil
|
|
|
|
dirvish-use-header-line nil
|
|
|
|
dirvish-mode-line-format nil))
|
|
|
|
|
2024-08-18 16:20:20 -04:00
|
|
|
;; 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)))))
|
|
|
|
|
2024-08-18 00:09:25 -04:00
|
|
|
(when (modulep! :ui vc-gutter)
|
|
|
|
(push 'vc-state dirvish-attributes))
|
2024-08-18 16:20:20 -04:00
|
|
|
|
2022-08-12 20:29:19 +02:00
|
|
|
(when (modulep! +icons)
|
2024-08-18 00:09:25 -04:00
|
|
|
(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)))))
|
|
|
|
|
|
|
|
(when (modulep! :ui tabs)
|
|
|
|
(after! centaur-tabs
|
|
|
|
(add-hook 'dired-mode-hook #'centaur-tabs-local-mode)
|
|
|
|
(add-hook 'dirvish-directory-view-mode-hook #'centaur-tabs-local-mode)))
|
|
|
|
|
|
|
|
;; TODO: Needs more polished keybinds for non-Evil users
|
2022-06-23 19:47:22 +08:00
|
|
|
(map! :map dirvish-mode-map
|
2024-08-18 00:09:25 -04:00
|
|
|
:n "?" #'dirvish-dispatch
|
|
|
|
:n "q" #'dirvish-quit
|
|
|
|
:n "b" #'dirvish-quick-access
|
|
|
|
:ng "f" #'dirvish-file-info-menu
|
|
|
|
:n "p" #'dirvish-yank
|
|
|
|
:ng "S" #'dirvish-quicksort
|
|
|
|
:n "F" #'dirvish-layout-toggle
|
|
|
|
:n "z" #'dirvish-history-jump
|
|
|
|
:n "gh" #'dirvish-subtree-up
|
|
|
|
:n "gl" #'dirvish-subtree-down
|
|
|
|
:m "[h" #'dirvish-history-go-backward
|
|
|
|
:m "]h" #'dirvish-history-go-forward
|
|
|
|
:m "[e" #'dirvish-emerge-next-group
|
|
|
|
:m "]e" #'dirvish-emerge-previous-group
|
|
|
|
:n "TAB" #'dirvish-subtree-toggle
|
|
|
|
:ng "M-b" #'dirvish-history-go-backward
|
|
|
|
:ng "M-f" #'dirvish-history-go-forward
|
|
|
|
:ng "M-n" #'dirvish-narrow
|
|
|
|
:ng "M-m" #'dirvish-mark-menu
|
|
|
|
:ng "M-s" #'dirvish-setup-menu
|
|
|
|
:ng "M-e" #'dirvish-emerge-menu
|
|
|
|
(:prefix ("y" . "yank")
|
|
|
|
:n "l" #'dirvish-copy-file-true-path
|
|
|
|
:n "n" #'dirvish-copy-file-name
|
|
|
|
:n "p" #'dirvish-copy-file-path
|
|
|
|
:n "r" #'dirvish-copy-remote-path
|
|
|
|
:n "y" #'dired-do-copy)
|
|
|
|
(:prefix ("s" . "symlinks")
|
|
|
|
:n "s" #'dirvish-symlink
|
|
|
|
:n "S" #'dirvish-relative-symlink
|
|
|
|
:n "h" #'dirvish-hardlink))
|
|
|
|
|
|
|
|
;; 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)
|
|
|
|
(defun +dired--cleanup-dirvish-h (&rest _)
|
|
|
|
(when-let ((win
|
|
|
|
(or (and (featurep 'dirvish-side)
|
|
|
|
(dirvish-side--session-visible-p))
|
|
|
|
(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.
|
|
|
|
(defadvice! +dired--ignore-local-vars-for-dir-previews-a (fn &rest args)
|
|
|
|
:around #'dirvish-default-dp
|
|
|
|
(let ((result (apply fn args)))
|
|
|
|
(if (and (file-directory-p (car args))
|
|
|
|
(eq (car-safe result) 'dired))
|
|
|
|
`(dired . (,@(butlast (cdr result))
|
|
|
|
,(format "(let ((enable-local-variables nil)) %s)"
|
|
|
|
(car (last (cdr result))))))
|
|
|
|
result)))
|
|
|
|
|
|
|
|
;; HACK: Dirvish will complain that pdf-tools is required to preview PDFs,
|
|
|
|
;; even if the package is installed, so I advise it to try autoloading it
|
|
|
|
;; before complaining, otherwise complain if epdfinfo hasn't been built yet.
|
|
|
|
;; REVIEW: Upstream this later.
|
|
|
|
(defadvice! +dired--autoload-pdf-tools-a (fn &rest args)
|
|
|
|
:around #'dirvish-pdf-dp
|
|
|
|
(when (equal (nth 1 args) "pdf")
|
|
|
|
(require 'pdf-tools nil t)
|
|
|
|
(if (file-exists-p pdf-info-epdfinfo-program)
|
|
|
|
(apply fn args)
|
|
|
|
'(info . "`epdfinfo' program required to preview pdfs; run `M-x pdf-tools-install'")))))
|
2022-06-23 19:47:22 +08:00
|
|
|
|
2021-07-10 15:52:19 +03:00
|
|
|
|
2024-08-18 00:09:25 -04:00
|
|
|
(use-package! diredfl
|
|
|
|
:hook (dired-mode . diredfl-mode)
|
|
|
|
:hook (dirvish-directory-view-mode . diredfl-mode))
|
2018-12-07 22:27:03 -08:00
|
|
|
|
|
|
|
|
2019-07-23 12:44:03 +02:00
|
|
|
(use-package! dired-x
|
2018-12-27 16:37:44 +13:00
|
|
|
:hook (dired-mode . dired-omit-mode)
|
|
|
|
:config
|
2019-10-19 16:34:13 -04:00
|
|
|
(setq dired-omit-verbose nil
|
|
|
|
dired-omit-files
|
|
|
|
(concat dired-omit-files
|
2021-10-23 15:01:55 +03:00
|
|
|
"\\|^\\.DS_Store\\'"
|
2024-03-05 00:11:19 -06:00
|
|
|
"\\|^flycheck_.*"
|
2021-10-23 15:01:55 +03:00
|
|
|
"\\|^\\.project\\(?:ile\\)?\\'"
|
|
|
|
"\\|^\\.\\(?:svn\\|git\\)\\'"
|
|
|
|
"\\|^\\.ccls-cache\\'"
|
2019-10-19 16:34:13 -04:00
|
|
|
"\\|\\(?:\\.js\\)?\\.meta\\'"
|
|
|
|
"\\|\\.\\(?:elc\\|o\\|pyo\\|swp\\|class\\)\\'"))
|
2019-07-21 23:46:14 +02:00
|
|
|
;; Disable the prompt about whether I want to kill the Dired buffer for a
|
|
|
|
;; deleted directory. Of course I do!
|
2019-10-19 16:34:40 -04:00
|
|
|
(setq dired-clean-confirm-killing-deleted-buffers nil)
|
|
|
|
;; Let OS decide how to open certain files
|
2023-12-05 17:05:13 -05:00
|
|
|
(when-let (cmd (cond ((featurep :system 'macos) "open")
|
|
|
|
((featurep :system 'linux) "xdg-open")
|
|
|
|
((featurep :system 'windows) "start")))
|
2019-10-19 16:34:40 -04:00
|
|
|
(setq dired-guess-shell-alist-user
|
|
|
|
`(("\\.\\(?:docx\\|pdf\\|djvu\\|eps\\)\\'" ,cmd)
|
|
|
|
("\\.\\(?:jpe?g\\|png\\|gif\\|xpm\\)\\'" ,cmd)
|
|
|
|
("\\.\\(?:xcf\\)\\'" ,cmd)
|
|
|
|
("\\.csv\\'" ,cmd)
|
|
|
|
("\\.tex\\'" ,cmd)
|
|
|
|
("\\.\\(?:mp4\\|mkv\\|avi\\|flv\\|rm\\|rmvb\\|ogv\\)\\(?:\\.part\\)?\\'" ,cmd)
|
|
|
|
("\\.\\(?:mp3\\|flac\\)\\'" ,cmd)
|
|
|
|
("\\.html?\\'" ,cmd)
|
2019-11-02 14:31:20 -04:00
|
|
|
("\\.md\\'" ,cmd))))
|
2019-11-24 14:16:46 -05:00
|
|
|
(map! :map dired-mode-map
|
|
|
|
:localleader
|
|
|
|
"h" #'dired-omit-mode))
|
2019-10-19 16:33:46 -04:00
|
|
|
|
|
|
|
|
2020-08-29 18:45:31 +05:30
|
|
|
(use-package! dired-aux
|
2020-08-29 21:08:57 +05:30
|
|
|
:defer t
|
2020-08-29 18:45:31 +05:30
|
|
|
:config
|
|
|
|
(setq dired-create-destination-dirs 'ask
|
|
|
|
dired-vc-rename-file t))
|