doomemacs/modules/emacs/dired/config.el

126 lines
4.6 KiB
EmacsLisp
Raw Normal View History

;;; tools/dired/config.el -*- lexical-binding: t; -*-
2017-02-19 18:53:38 -05:00
(use-package! dired
:commands dired-jump
:init
(setq ;; Always copy/delete recursively
dired-recursive-copies 'always
dired-recursive-deletes 'top
;; 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
;; Auto refresh dired, but be quiet about it
dired-hide-details-hide-symlink-targets nil
;; files
image-dired-dir (concat doom-cache-dir "image-dired/")
image-dired-db-file (concat image-dired-dir "db.el")
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
(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.
(if-let* ((gls (executable-find "gls")))
(setq insert-directory-program gls)
;; BSD ls doesn't support --group-directories-first
(setq args (delete "--group-directories-first" args))))
(setq dired-listing-switches (string-join args " ")))
(define-key! 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))
(use-package! dired-rsync
:general (dired-mode-map "C-c C-r" #'dired-rsync))
(use-package! diredfl
:hook (dired-mode . diredfl-mode))
2017-02-19 18:53:38 -05:00
(use-package! dired-k
2018-07-21 01:29:38 +02:00
:hook (dired-initial-position . dired-k)
:hook (dired-after-readin . dired-k-no-revert)
2017-02-19 18:53:38 -05:00
:config
(setq dired-k-style 'git
dired-k-padding 1)
;; Don't highlight based on mtime, this interferes with diredfl and is more
;; confusing than helpful.
(advice-add #'dired-k--highlight-by-file-attribyte :override #'ignore)
(def-advice! +dired-interrupt-process-a (orig-fn &rest args)
"Fixes dired-k killing git processes too abruptly, leaving behind disruptive
.git/index.lock files."
:around #'dired-k--start-git-status
(cl-letf (((symbol-function #'kill-process)
(symbol-function #'interrupt-process)))
(apply orig-fn args)))
(def-advice! +dired-dired-k-highlight-a (orig-fn &rest args)
"Butt out if the requested directory is remote (i.e. through tramp)."
:around #'dired-k--highlight
(unless (file-remote-p default-directory)
(apply orig-fn args))))
(use-package! ranger
:when (featurep! +ranger)
:after dired
:init
;; set up image-dired to allow picture resize
(setq image-dired-dir (concat doom-cache-dir "image-dir")
ranger-override-dired t)
:config
(unless (file-directory-p image-dired-dir)
(make-directory image-dired-dir))
(set-popup-rule! "^\\*ranger" :ignore t)
(def-advice! +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))))))
(def-advice! +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]))))
(setq ranger-cleanup-on-disable t
ranger-excluded-extensions '("mkv" "iso" "mp4")
ranger-deer-show-details t
ranger-max-preview-size 10
2019-03-09 16:54:54 -05:00
ranger-show-literal nil
ranger-hide-cursor nil))
(use-package! all-the-icons-dired
:when (featurep! +icons)
:hook (dired-mode . all-the-icons-dired-mode))
(use-package! dired-x
:hook (dired-mode . dired-omit-mode)
:config
(setq dired-omit-verbose nil)
;; Disable the prompt about whether I want to kill the Dired buffer for a
;; deleted directory. Of course I do!
(setq dired-clean-confirm-killing-deleted-buffers nil))