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
|
|
|
|
(setq ;; Always copy/delete recursively
|
|
|
|
dired-recursive-copies 'always
|
|
|
|
dired-recursive-deletes 'top
|
2019-07-21 23:46:14 +02:00
|
|
|
;; Instantly revert Dired buffers on re-visiting them, with no message.
|
|
|
|
;; (A message is shown if insta-revert is either disabled or determined
|
|
|
|
;; dynamically by setting this variable to a function.)
|
|
|
|
dired-auto-revert-buffer t
|
2018-01-27 20:49:46 -05:00
|
|
|
;; Auto refresh dired, but be quiet about it
|
2018-06-01 13:46:52 +02:00
|
|
|
dired-hide-details-hide-symlink-targets nil
|
2019-10-23 12:51:49 +09:00
|
|
|
;; make dired suggest a target for moving/copying intelligently
|
|
|
|
dired-dwim-target t
|
2018-01-27 20:49:46 -05:00
|
|
|
;; files
|
|
|
|
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")
|
|
|
|
image-dired-temp-rotate-image-file (concat image-dired-dir "temp-rotate-image"))
|
|
|
|
:config
|
2019-03-02 13:49:39 -05:00
|
|
|
(let ((args (list "-aBhl" "--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
|
: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)
|
2019-05-14 18:45:38 -04:00
|
|
|
;; BSD ls doesn't support --group-directories-first
|
|
|
|
(setq args (delete "--group-directories-first" args))))
|
2019-03-02 13:49:39 -05:00
|
|
|
(setq dired-listing-switches (string-join args " ")))
|
2018-12-13 15:40:53 -05:00
|
|
|
|
2019-10-07 22:12:16 -04:00
|
|
|
(add-hook! 'dired-mode-hook
|
|
|
|
(defun +dired-disable-gnu-ls-flags-in-tramp-buffers-h ()
|
2019-10-20 13:29:29 -04:00
|
|
|
"Fix #1703: dired over TRAMP displays a blank screen.
|
2019-10-07 22:12:16 -04:00
|
|
|
|
|
|
|
This is because there's no guarantee the remote system has GNU ls, which is the
|
|
|
|
only variant that supports --group-directories-first."
|
|
|
|
(when (file-remote-p default-directory)
|
|
|
|
(setq-local dired-listing-switches
|
|
|
|
(string-join
|
|
|
|
(split-string dired-listing-switches
|
|
|
|
"--group-directories-first")
|
|
|
|
" ")))))
|
|
|
|
|
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)
|
|
|
|
|
|
|
|
(map! :map dired-mode-map
|
|
|
|
;; Kill buffer when quitting dired buffers
|
|
|
|
[remap quit-window] (λ! (quit-window t))
|
|
|
|
;; To be consistent with ivy/helm+wgrep integration
|
|
|
|
"C-c C-e" #'wdired-change-to-wdired-mode
|
|
|
|
;; Stop dired from creating new buffers when we enter a new directory or
|
|
|
|
;; travel up the tree
|
|
|
|
:n "RET" #'dired-find-alternate-file
|
|
|
|
:ng "^" (λ! (find-alternate-file ".."))))
|
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
|
2019-08-25 23:20:17 -07:00
|
|
|
:hook (dired-mode . diff-hl-dired-mode)
|
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
|
2018-12-07 22:27:03 -08:00
|
|
|
:init
|
|
|
|
;; set up image-dired to allow picture resize
|
2019-05-20 20:04:34 -04:00
|
|
|
(setq image-dired-dir (concat doom-cache-dir "image-dir")
|
|
|
|
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]))))
|
|
|
|
|
|
|
|
(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
|
|
|
|
|
|
|
|
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)
|
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.
|
|
|
|
(when EMACS27+
|
2019-10-22 03:12:45 -04:00
|
|
|
(defvar +wdired-icons-enabled -1)
|
2019-10-22 01:58:17 -04:00
|
|
|
|
|
|
|
(defadvice! +dired-disable-icons-in-wdired-mode-a (&rest _)
|
|
|
|
:before #'+wdired-before-start-advice
|
2019-10-22 03:12:45 -04:00
|
|
|
(setq-local +wdired-icons-enabled (if all-the-icons-dired-mode 1 -1))
|
2019-10-22 01:58:17 -04:00
|
|
|
(when all-the-icons-dired-mode
|
|
|
|
(all-the-icons-dired-mode -1)))
|
|
|
|
|
|
|
|
(defadvice! +dired-restore-icons-after-wdired-mode-a (&rest _)
|
|
|
|
:after #'+wdired-after-finish-advice
|
|
|
|
(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
|
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
|
|
|
|
"\\|^.DS_Store\\'"
|
|
|
|
"\\|^.project\\(?:ile\\)?\\'"
|
|
|
|
"\\|^.\\(svn\\|git\\)\\'"
|
|
|
|
"\\|^.ccls-cache\\'"
|
|
|
|
"\\|\\(?:\\.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)
|
|
|
|
("\\.md\\'" ,cmd)))))
|
2019-10-19 16:33:46 -04:00
|
|
|
|
|
|
|
|
|
|
|
(use-package! fd-dired
|
|
|
|
:when (executable-find doom-projectile-fd-binary)
|
|
|
|
:defer t
|
|
|
|
:init (advice-add #'find-dired :override #'fd-dired))
|