2017-06-08 11:47:56 +02:00
|
|
|
;;; tools/dired/config.el -*- lexical-binding: t; -*-
|
2017-02-19 18:53:38 -05:00
|
|
|
|
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
|
2019-12-19 15:31:01 -05:00
|
|
|
dired-hide-details-hide-symlink-targets nil
|
2022-02-14 17:19:19 +01:00
|
|
|
;; 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")))
|
2019-03-02 13:49:39 -05:00
|
|
|
(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
|
: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)))
|
|
|
|
|
2019-10-23 01:33:55 -04:00
|
|
|
(map! :map dired-mode-map
|
2019-10-26 13:39:52 -04:00
|
|
|
;; Kill all dired buffers on q
|
|
|
|
:ng "q" #'+dired/quit-all
|
2019-10-23 01:33:55 -04:00
|
|
|
;; To be consistent with ivy/helm+wgrep integration
|
2019-10-26 13:39:52 -04:00
|
|
|
"C-c C-e" #'wdired-change-to-wdired-mode))
|
2019-05-20 16:04:01 -04:00
|
|
|
|
|
|
|
|
2019-07-23 12:44:03 +02:00
|
|
|
(use-package! dired-rsync
|
2019-05-20 17:40:16 -04:00
|
|
|
:general (dired-mode-map "C-c C-r" #'dired-rsync))
|
|
|
|
|
|
|
|
|
2019-07-23 12:44:03 +02:00
|
|
|
(use-package! diredfl
|
2019-05-20 16:04:01 -04:00
|
|
|
:hook (dired-mode . diredfl-mode))
|
2017-02-19 18:53:38 -05:00
|
|
|
|
|
|
|
|
2019-09-02 00:51:52 -04:00
|
|
|
(use-package! diff-hl
|
2020-01-27 23:50:05 +01:00
|
|
|
:hook (dired-mode . diff-hl-dired-mode-unless-remote)
|
2019-09-02 12:42:02 -04:00
|
|
|
:hook (magit-post-refresh . diff-hl-magit-post-refresh)
|
2017-02-19 18:53:38 -05:00
|
|
|
:config
|
2019-08-25 23:20:17 -07:00
|
|
|
;; use margin instead of fringe
|
|
|
|
(diff-hl-margin-mode))
|
2018-05-31 13:10:34 +02:00
|
|
|
|
|
|
|
|
2019-07-23 12:44:03 +02:00
|
|
|
(use-package! ranger
|
2018-12-07 22:27:03 -08:00
|
|
|
:when (featurep! +ranger)
|
2018-12-13 15:40:53 -05:00
|
|
|
:after dired
|
2020-01-06 04:49:57 -05:00
|
|
|
:init (setq ranger-override-dired t)
|
2018-12-13 15:40:53 -05:00
|
|
|
:config
|
2018-12-07 22:27:03 -08:00
|
|
|
(unless (file-directory-p image-dired-dir)
|
|
|
|
(make-directory image-dired-dir))
|
2018-12-13 15:40:53 -05:00
|
|
|
|
|
|
|
(set-popup-rule! "^\\*ranger" :ignore t)
|
|
|
|
|
2019-07-23 17:24:56 +02:00
|
|
|
(defadvice! +dired--cleanup-header-line-a ()
|
2019-05-20 20:04:34 -04:00
|
|
|
"Ranger fails to clean up `header-line-format' when it is closed, so..."
|
2019-07-23 12:30:47 +02:00
|
|
|
:before #'ranger-revert
|
2019-05-20 20:04:34 -04:00
|
|
|
(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))))))
|
|
|
|
|
2019-07-23 17:24:56 +02:00
|
|
|
(defadvice! +dired--cleanup-mouse1-bind-a ()
|
2019-05-20 20:04:34 -04:00
|
|
|
"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."
|
2019-07-23 12:30:47 +02:00
|
|
|
:after #'ranger-setup-preview
|
2019-05-20 20:04:34 -04:00
|
|
|
(when (window-live-p ranger-preview-window)
|
|
|
|
(with-current-buffer (window-buffer ranger-preview-window)
|
|
|
|
(local-unset-key [mouse-1]))))
|
|
|
|
|
2021-10-04 18:41:24 +03:00
|
|
|
(defadvice! +dired--ranger-travel-a ()
|
2022-01-09 17:16:57 +01:00
|
|
|
"Temporary fix for this function until ralesi/ranger.el#236 gets merged."
|
2021-10-04 18:41:24 +03:00
|
|
|
: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))))))
|
|
|
|
|
2019-05-20 20:04:34 -04:00
|
|
|
(setq ranger-cleanup-on-disable t
|
2018-12-07 22:27:03 -08:00
|
|
|
ranger-excluded-extensions '("mkv" "iso" "mp4")
|
2019-05-20 20:04:34 -04:00
|
|
|
ranger-deer-show-details t
|
2018-12-13 15:40:53 -05:00
|
|
|
ranger-max-preview-size 10
|
2019-03-09 16:54:54 -05:00
|
|
|
ranger-show-literal nil
|
2019-05-20 20:04:34 -04:00
|
|
|
ranger-hide-cursor nil))
|
2018-12-07 22:27:03 -08:00
|
|
|
|
|
|
|
|
2022-06-23 19:47:22 +08:00
|
|
|
(use-package! dirvish
|
|
|
|
:when (featurep! +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 (featurep! +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))
|
|
|
|
|
|
|
|
|
2019-07-23 12:44:03 +02:00
|
|
|
(use-package! all-the-icons-dired
|
2018-12-07 22:27:03 -08:00
|
|
|
:when (featurep! +icons)
|
2022-06-23 19:47:22 +08:00
|
|
|
:unless (featurep! +dirvish)
|
2019-10-22 01:58:17 -04:00
|
|
|
: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.
|
2021-07-10 15:52:19 +03:00
|
|
|
(defvar +wdired-icons-enabled -1)
|
|
|
|
|
2021-10-29 11:10:10 +07:00
|
|
|
;; display icons with colors
|
|
|
|
(setq all-the-icons-dired-monochrome nil)
|
|
|
|
|
2021-07-10 15:52:19 +03:00
|
|
|
(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)))
|
2018-12-07 22:27:03 -08:00
|
|
|
|
|
|
|
|
2019-07-23 12:44:03 +02:00
|
|
|
(use-package! dired-x
|
2022-06-23 19:47:22 +08:00
|
|
|
:unless (featurep! +dirvish)
|
2019-08-27 00:14:51 -07:00
|
|
|
:unless (featurep! +ranger)
|
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\\'"
|
|
|
|
"\\|^\\.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
|
|
|
|
(when-let (cmd (cond (IS-MAC "open")
|
|
|
|
(IS-LINUX "xdg-open")
|
|
|
|
(IS-WINDOWS "start")))
|
|
|
|
(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
|
|
|
|
|
|
|
|
|
|
|
(use-package! fd-dired
|
2020-07-17 01:08:30 -04:00
|
|
|
:when doom-projectile-fd-binary
|
2019-10-19 16:33:46 -04:00
|
|
|
:defer t
|
2019-12-08 00:21:29 -05:00
|
|
|
:init
|
2019-12-13 14:23:44 -05:00
|
|
|
(global-set-key [remap find-dired] #'fd-dired)
|
2019-12-08 00:21:29 -05:00
|
|
|
(set-popup-rule! "^\\*F\\(?:d\\|ind\\)\\*$" :ignore t))
|
2019-10-27 17:31:53 -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))
|
2019-10-27 17:31:53 -04:00
|
|
|
|
2019-11-25 02:02:57 -05:00
|
|
|
;;;###package dired-git-info
|
|
|
|
(map! :after dired
|
|
|
|
:map (dired-mode-map ranger-mode-map)
|
|
|
|
:ng ")" #'dired-git-info-mode)
|
2020-08-19 18:28:27 +05:30
|
|
|
(setq dgi-commit-message-format "%h %cs %s"
|
|
|
|
dgi-auto-hide-details-p nil)
|
2019-11-25 02:02:57 -05:00
|
|
|
(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))))
|