blob: e8bebb86e70d856c93387ec080b885ea3e5fc3f4 (
plain)
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
|
(require 'dired-x)
(put 'dired-find-alternate-file 'disabled nil)
;; .git is present as part of `dired-omit-extensions', but this seems to
;; only be taken into account if a non-exension part exists.
(setq dired-omit-files
(concat dired-omit-files
"\\|^\\.git$\\|^\\.gitignore$"
"\\|^__pycache__$\\|^\\.snakemake$"))
(defvar km/latex-omit-extensions '(".aux"
".fdb_latexmk"
".fls"
".log"
".nav"
".out"
".snm")
"Intermediate LaTeX files")
(setq dired-omit-extensions
(append dired-omit-extensions km/latex-omit-extensions))
(setq-default dired-omit-mode t)
(setq dired-dwim-target t
dired-listing-switches "-alh")
(setq dired-guess-shell-alist-user
'(("\\.pdf\\'" "zathura")))
(setq dired-recursive-copies t
dired-recursive-deletes t)
(add-hook 'dired-mode-hook 'dired-hide-details-mode)
(defun km/dired-switch-to-buffer ()
(interactive)
(switch-to-buffer (km/dired-completing-buffer)))
(defun km/dired-switch-to-buffer-other-window ()
(interactive)
(pop-to-buffer (km/dired-completing-buffer)))
(defun km/dired-completing-buffer ()
(ido-completing-read "Dired buffer: "
(-map 'buffer-name (km/dired-buffer-list))))
(defun km/dired-buffer-list ()
(--filter (with-current-buffer it
(derived-mode-p 'dired-mode))
(buffer-list)))
(defun km/org-open-dired-marked-files (&optional in-emacs)
(interactive "P")
(let* ((files (dired-get-marked-files))
(num-files (length files)))
(when (or (< num-files 5)
(yes-or-no-p (format "Open %s files?" num-files)))
(--each files (org-open-file it in-emacs)))))
(defun km/dired-view-file-other-window ()
"In Dired, view this file in another window."
(interactive)
(view-file-other-window (dired-get-file-for-visit)))
;; This overrides the binding for `list-directory'.
(global-set-key (kbd "C-x C-d") 'km/dired-switch-to-buffer)
;; This overrides `dired-do-run-mail'.
(define-key dired-mode-map "V" 'km/dired-view-file-other-window)
(define-key ctl-x-4-map "D" 'km/dired-switch-to-buffer-other-window)
(define-prefix-command 'km/dired-prefix-map)
(define-key dired-mode-map (kbd "C-c m") 'km/dired-prefix-map)
(after 'org
;; This overrides `dired-find-file', which is also bound to "f".
(define-key dired-mode-map "e" 'km/org-open-dired-marked-files))
;;; Dired Narrow
(define-key dired-mode-map "/" 'dired-narrow)
(define-prefix-command 'km/dired-narrow-prefix-map)
(define-key km/dired-prefix-map "n" 'km/dired-narrow-prefix-map)
(define-key km/dired-narrow-prefix-map "f" 'dired-narrow-fuzzy)
(define-key km/dired-narrow-prefix-map "n" 'dired-narrow)
(define-key km/dired-narrow-prefix-map "r" 'dired-narrow-regexp)
;;; Dired Subtree
(define-prefix-command 'km/dired-subtree-prefix-map)
(define-key km/dired-prefix-map "s" 'km/dired-subtree-prefix-map)
(define-key km/dired-subtree-prefix-map "@" 'dired-subtree-mark-subtree)
(define-key km/dired-subtree-prefix-map "." 'dired-subtree-unmark-subtree)
(define-key km/dired-subtree-prefix-map "<" 'dired-subtree-beginning)
(define-key km/dired-subtree-prefix-map ">" 'dired-subtree-end)
(define-key km/dired-subtree-prefix-map "g" 'dired-subtree-revert)
(define-key km/dired-subtree-prefix-map "d" 'dired-subtree-down)
(define-key km/dired-subtree-prefix-map "i" 'dired-subtree-insert)
(define-key km/dired-subtree-prefix-map "n" 'dired-subtree-next-sibling)
(define-key km/dired-subtree-prefix-map "p" 'dired-subtree-previous-sibling)
(define-key km/dired-subtree-prefix-map "r" 'dired-subtree-remove)
(define-key km/dired-subtree-prefix-map "s" 'dired-subtree-narrow)
(define-key km/dired-subtree-prefix-map "u" 'dired-subtree-up)
;;; Copying file names
(defun km/dired-copy-project-filename-as-kill ()
"Copy names of marked project files into kill ring.
This is similar to `dired-copy-filename-as-kill', but the leading
path is always relative to `projectile-project-root'."
(interactive)
(km/dired-copy-filename-relative-to-directory
(projectile-project-root)))
(defun km/dired-copy-relative-filename-as-kill ()
"Copy names of marked files into kill ring.
This is similar to `dired-copy-filename-as-kill', but the leading
path is always relative to the `default-directory' of the other
window."
(interactive)
(km/dired-copy-filename-relative-to-directory
(km/other-default-directory)))
(defun km/dired-copy-filename-relative-to-directory (directory)
"Like `dired-copy-filename-as-kill', but the filename is always
relative to DIRECTORY."
(let* ((string
(mapconcat 'identity
(--map (file-relative-name it directory)
(dired-get-marked-files t))
" ")))
(if (eq last-command 'kill-region)
(kill-append string nil)
(kill-new string))
(message "%s" string)))
(defun km/other-default-directory ()
"Get `default-directory' for result of `(other-window 1)'."
(save-window-excursion
(other-window 1)
default-directory))
(define-prefix-command 'km/dired-copy-filename-map)
;; This overrides the default binding for `dired-copy-filename-as-kill'.
(define-key dired-mode-map "w" 'km/dired-copy-filename-map)
(after 'projectile
(define-key km/dired-copy-filename-map "p"
'km/dired-copy-project-filename-as-kill))
(define-key km/dired-copy-filename-map "o" 'km/dired-copy-relative-filename-as-kill)
(define-key km/dired-copy-filename-map "w" 'dired-copy-filename-as-kill)
(provide 'init-dired)
|