aboutsummaryrefslogtreecommitdiff
path: root/emacs/.emacs.d/init/ycp-dired.el
blob: 056bfce16e07e5114946b927bd079a0689071cbf (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
;;; ycp-dired.el -- My config for dired and friends -*- lexical-binding: t -*-

;; Copyright (C) 2023 Free Software Foundation.

;; Author: Yuchen Pei <id@ypei.org>
;; Package-Requires: ((emacs "28.2"))

;; This file is part of dotfiles.

;; dotfiles is free software: you can redistribute it and/or modify it under
;; the terms of the GNU Affero General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.

;; dotfiles is distributed in the hope that it will be useful, but WITHOUT
;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
;; or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Affero General
;; Public License for more details.

;; You should have received a copy of the GNU Affero General Public
;; License along with dotfiles.  If not, see <https://www.gnu.org/licenses/>.

;;; Commentary:

;; My config for dired and friends.

;;; Code:


(setq delete-by-moving-to-trash 'always)

(my-package dired
  (:delay 5)
  (put 'dired-find-alternate-file 'disabled nil)
  (setq dired-dwim-target t)
  (setq dired-recursive-copies 'always)
  (setq dired-recursive-deletes 'always)
  (setq dired-listing-switches "-alh")
  (add-hook 'dired-mode-hook (lambda () (interactive)
			                         (auto-revert-mode t)))
  (add-hook 'dired-mode-hook #'hl-line-mode)
  (setq dired-listing-switches "-al --block-size='1")
  (my-keybind dired-mode-map
    "^"  (lambda () (interactive) (find-alternate-file "..")))
  (my-keybind global-map
    "C-x C-j" #'dired-jump
    ;; to open a dir in dired, find-file is more than sufficient
    "C-x d" #'dired-jump)
  )

(my-package my-dired
  (:delay 5)
  (my-keybind dired-mode-map
    "a" #'my-dired-find-or-alternate
    "<return>" #'my-dired-find-or-alternate
    "r" #'my-dired-do-rename-and-symlink-back
    "s" #'my-dired-toggle-sorting
    "F" #'my-dired-follow-mode)
  (advice-add 'dired-do-delete :around 'my-dired-do-delete)
  (advice-add 'dired-do-rename :around 'my-dired-do-rename)
  )

;;; dired-aux
(my-package dired-aux
  (:delay 5)
  (setq dired-isearch-filenames 'dwim)
  (setq dired-create-destination-dirs 'ask) ; Emacs 27
  (setq dired-vc-rename-file t)             ; Emacs 27
  (setq dired-do-revert-buffer (lambda (dir) (not (file-remote-p dir))))
  (my-keybind dired-mode-map
    "C-+" #'dired-create-empty-file
    ;; "M-s f" #'nil
    "C-x v v" #'dired-vc-next-action)
  ) ; Emacs 28


;;; dired-x
(my-package dired-x
  (:delay 5)
  (add-hook 'dired-mode-hook #'dired-omit-mode)
  (setq dired-omit-files "\\`[.]?#")
  (setq dired-clean-up-buffers-too t)
  (setq dired-clean-confirm-killing-deleted-buffers t)
  (setq dired-x-hands-off-my-keys t)    ; easier to show the keys I use
  (setq dired-bind-man nil)
  (setq dired-bind-info nil)
  (my-keybind dired-mode-map "I" #'dired-info))

(my-package dired-hist
  (:delay 5)
  (my-keybind dired-mode-map
    "l" #'dired-hist-go-back
    "r" #'dired-hist-go-forward)
  (dired-hist-mode 1))

;;; required by dired-subtree
(my-package dash
  (:delay 5)
  (:install t))

(my-package dired-subtree
  (:delay 5)
  (setq dired-subtree-use-backgrounds nil)
  (my-keybind dired-mode-map
    "<tab>" #'dired-subtree-toggle
    "<backtab>" #'dired-subtree-remove))

;;; image-dired
(my-package image-dired
  (:delay 10)
  (setq image-dired-thumbnail-storage 'standard)
  (setq image-dired-external-viewer "xdg-open")
  (setq image-dired-thumb-size 80)
  (setq image-dired-thumb-margin 2)
  (setq image-dired-thumb-relief 0)
  (setq image-dired-thumbs-per-row 4)
  (my-keybind image-dired-thumbnail-mode-map
    "<return>" #'image-dired-thumbnail-display-external))


;;; dired-du
(my-package dired-du
  (:install t)
  (require 'dired-du)
  (setq dired-du-size-format 'comma))

(provide 'ycp-dired)