doomemacs/modules/emacs/dired/config.el

254 lines
9.2 KiB
EmacsLisp
Raw Normal View History

;;; tools/dired/config.el -*- lexical-binding: t; -*-
2017-02-19 18:53:38 -05:00
(def-package! dired
:commands dired-jump
:init
(setq ;; Always copy/delete recursively
dired-recursive-copies 'always
dired-recursive-deletes 'top
;; 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))
(def-package! diredfl
:hook (dired-mode . diredfl-mode))
2017-02-19 18:53:38 -05:00
(def-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)
(defun +dired*interrupt-process (orig-fn &rest args)
"Fixes dired-k killing git processes too abruptly, leaving behind disruptive
.git/index.lock files."
(cl-letf (((symbol-function #'kill-process)
(symbol-function #'interrupt-process)))
(apply orig-fn args)))
(advice-add #'dired-k--start-git-status :around #'+dired*interrupt-process)
(defun +dired*dired-k-highlight (orig-fn &rest args)
"Butt out if the requested directory is remote (i.e. through tramp)."
(unless (file-remote-p default-directory)
(apply orig-fn args)))
(advice-add #'dired-k--highlight :around #'+dired*dired-k-highlight))
(def-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"))
:config
(unless (file-directory-p image-dired-dir)
(make-directory image-dired-dir))
(set-popup-rule! "^\\*ranger" :ignore t)
(setq ranger-override-dired t
ranger-cleanup-on-disable t
ranger-omit-regexp "^\.DS_Store$"
ranger-excluded-extensions '("mkv" "iso" "mp4")
ranger-deer-show-details nil
ranger-max-preview-size 10
2019-03-09 16:54:54 -05:00
ranger-show-literal nil
dired-omit-verbose nil))
(def-package! all-the-icons-dired
:when (featurep! +icons)
:hook (dired-mode . all-the-icons-dired-mode))
(def-package! dired-x
:hook (dired-mode . dired-omit-mode)
:config
(setq dired-omit-verbose nil))
;;
;;; Evil integration
(map! :when (featurep! :editor evil +everywhere)
:after dired
:map dired-mode-map
:n "q" #'quit-window
:m "j" #'dired-next-line
:m "k" #'dired-previous-line
:n [mouse-2] #'dired-mouse-find-file-other-window
:n [follow-link] #'mouse-face
;; Commands to mark or flag certain categories of files
:n "#" #'dired-flag-auto-save-files
:n "." #'dired-clean-directory
:n "~" #'dired-flag-backup-files
;; Upper case keys (except !) for operating on the marked files
:n "A" #'dired-do-find-regexp
:n "C" #'dired-do-copy
:n "B" #'dired-do-byte-compile
:n "D" #'dired-do-delete
:n "gG" #'dired-do-chgrp ;; FIXME: This can probably live on a better binding.
:n "H" #'dired-do-hardlink
:n "L" #'dired-do-load
:n "M" #'dired-do-chmod
:n "O" #'dired-do-chown
:n "P" #'dired-do-print
:n "Q" #'dired-do-find-regexp-and-replace
:n "R" #'dired-do-rename
:n "S" #'dired-do-symlink
:n "T" #'dired-do-touch
:n "X" #'dired-do-shell-command
:n "Z" #'dired-do-compress
:n "c" #'dired-do-compress-to
:n "!" #'dired-do-shell-command
:n "&" #'dired-do-async-shell-command
;; Comparison commands
:n "=" #'dired-diff
;; Tree Dired commands
:n "M-C-?" #'dired-unmark-all-files
:n "M-C-d" #'dired-tree-down
:n "M-C-u" #'dired-tree-up
:n "M-C-n" #'dired-next-subdir
:n "M-C-p" #'dired-prev-subdir
;; move to marked files
:n "M-{" #'dired-prev-marked-file
:n "M-}" #'dired-next-marked-file
;; Make all regexp commands share a `%' prefix:
;; We used to get to the submap via a symbol dired-regexp-prefix, but that
;; seems to serve little purpose, and copy-keymap does a better job
;; without it.
:n "%" nil
:n "%u" #'dired-upcase
:n "%l" #'dired-downcase
:n "%d" #'dired-flag-files-regexp
:n "%g" #'dired-mark-files-containing-regexp
:n "%m" #'dired-mark-files-regexp
:n "%r" #'dired-do-rename-regexp
:n "%C" #'dired-do-copy-regexp
:n "%H" #'dired-do-hardlink-regexp
:n "%R" #'dired-do-rename-regexp
:n "%S" #'dired-do-symlink-regexp
:n "%&" #'dired-flag-garbage-files
;; mark
:n "*" nil
:n "**" #'dired-mark-executables
:n "*/" #'dired-mark-directories
:n "*@" #'dired-mark-symlinks
:n "*%" #'dired-mark-files-regexp
:n "*(" #'dired-mark-sexp
:n "*." #'dired-mark-extension
:n "*O" #'dired-mark-omitted
:n "*c" #'dired-change-marks
:n "*s" #'dired-mark-subdir-files
:n "*m" #'dired-mark
:n "*u" #'dired-unmark
:n "*?" #'dired-unmark-all-files
:n "*!" #'dired-unmark-all-marks
:n "U" #'dired-unmark-all-marks
:n "* <delete>" #'dired-unmark-backward
:n "* C-n" #'dired-next-marked-file
:n "* C-p" #'dired-prev-marked-file
:n "*t" #'dired-toggle-marks
;; Lower keys for commands not operating on all the marked files
:n "a" #'dired-find-alternate-file
:n "d" #'dired-flag-file-deletion
:n "gf" #'dired-find-file
:n "C-m" #'dired-find-file
:n "gr" #'revert-buffer
:n "i" #'dired-toggle-read-only
:n "I" #'dired-maybe-insert-subdir
:n "J" #'dired-goto-file
:n "K" #'dired-do-kill-lines
:n "r" #'dired-do-redisplay
:n "m" #'dired-mark
:n "t" #'dired-toggle-marks
:n "u" #'dired-unmark ; also "*u"
:n "W" #'browse-url-of-dired-file
:n "x" #'dired-do-flagged-delete
:n "gy" #'dired-show-file-type ;; FIXME: This could probably go on a better key.
:n "Y" #'dired-copy-filename-as-kill
:n "+" #'dired-create-directory
;; open
:n "<return>" #'dired-find-file
:n "S-<return>" #'dired-find-file-other-window
:n "M-<return>" #'dired-display-file
:n "gO" #'dired-find-file-other-window
:n "go" #'dired-view-file
;; sort
:n "o" #'dired-sort-toggle-or-edit
;; moving
:m "gj" #'dired-next-dirline
:m "gk" #'dired-prev-dirline
:n "[" #'dired-prev-dirline
:n "]" #'dired-next-dirline
:n "<" #'dired-prev-dirline
:n ">" #'dired-next-dirline
:n "^" #'dired-up-directory
:n [?\S-\ ] #'dired-previous-line
:n [remap next-line] #'dired-next-line
:n [remap previous-line] #'dired-previous-line
;; hiding
:n "g$" #'dired-hide-subdir ;; FIXME: This can probably live on a better binding.
:n "M-$" #'dired-hide-all
:n "(" #'dired-hide-details-mode
;; isearch
:n "M-s a C-s" #'dired-do-isearch
:n "M-s a M-C-s" #'dired-do-isearch-regexp
:n "M-s f C-s" #'dired-isearch-filenames
:n "M-s f M-C-s" #'dired-isearch-filenames-regexp
;; misc
:n [remap read-only-mode] #'dired-toggle-read-only
;; `toggle-read-only' is an obsolete alias for `read-only-mode'
:n [remap toggle-read-only] #'dired-toggle-read-only
:n "g?" #'dired-summary
:n "<delete>" #'dired-unmark-backward
:n [remap undo] #'dired-undo
:n [remap advertised-undo] #'dired-undo
;; thumbnail manipulation (image-dired)
:n "C-t d" #'image-dired-display-thumbs
:n "C-t t" #'image-dired-tag-files
:n "C-t r" #'image-dired-delete-tag
:n "C-t j" #'image-dired-jump-thumbnail-buffer
:n "C-t i" #'image-dired-dired-display-image
:n "C-t x" #'image-dired-dired-display-external
:n "C-t a" #'image-dired-display-thumbs-append
:n "C-t ." #'image-dired-display-thumb
:n "C-t c" #'image-dired-dired-comment-files
:n "C-t f" #'image-dired-mark-tagged-files
:n "C-t C-t" #'image-dired-dired-toggle-marked-thumbs
:n "C-t e" #'image-dired-dired-edit-comment-and-tags
;; encryption and decryption (epa-dired)
:n ";d" #'epa-dired-do-decrypt
:n ";v" #'epa-dired-do-verify
:n ";s" #'epa-dired-do-sign
:n ";e" #'epa-dired-do-encrypt)