-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinit-dired.el
157 lines (131 loc) · 5.81 KB
/
init-dired.el
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
;(require 'dired+) ;; no longer in MELPA
;; dired order directories first
(defun sof/dired-sort ()
"Dired sort hook to list directories first."
(save-excursion
(let (buffer-read-only)
(forward-line 2) ;; beyond dir. header
(sort-regexp-fields t "^.*$" "[ ]*." (point) (point-max))))
(and (featurep 'xemacs)
(fboundp 'dired-insert-set-properties)
(dired-insert-set-properties (point-min) (point-max)))
(set-buffer-modified-p nil))
(add-hook 'dired-after-readin-hook 'sof/dired-sort)
;; dired hide hidden files
(require 'dired-x)
(setq dired-omit-files "^\\...+$")
(add-hook 'dired-mode-hook (lambda () (dired-omit-mode 1)))
;; ^ in dired mode use same buffer, use a to use same buffer when
;; opening selected dir, too
(add-hook 'dired-mode-hook
(lambda ()
(define-key dired-mode-map (kbd "^")
(lambda () (interactive) (find-alternate-file "..")))
; was dired-up-directory
))
(add-hook 'dired-mode-hook (lambda () (local-set-key (kbd "<backspace>") 'dired-kill-subdir)))
(add-hook 'dired-mode-hook (lambda () (local-set-key (kbd "/") 'dired-narrow)))
(add-hook 'dired-mode-hook (lambda () (local-set-key (kbd "\\") 'dired-narrow-regexp)))
;; if two dired buffers are open side-by-side and doing move/rename from one, auto-suggest the location of the other as destination
(setq dired-dwim-target t)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; dired-fixups.el --- fixups for dired mode
;; Author: Dino Chiesa
;; Created: Sat, 31 Mar 2012 10:31
;; Version: 0.1
;;
(require 'ls-lisp)
;; (defun ls-lisp-format-time (file-attr time-index now)
;; "################")
(defun ls-lisp-format-file-size (file-size human-readable)
"This is a redefinition of the function from `dired.el'. This
fixes the formatting of file sizes in dired mode, to support very
large files. Without this change, dired supports 8 digits max,
which is up to 10gb. Some files are larger than that.
"
(if (or (not human-readable)
(< file-size 1024))
(format (if (floatp file-size) " %11.0f" " %11d") file-size)
(do ((file-size (/ file-size 1024.0) (/ file-size 1024.0))
;; kilo, mega, giga, tera, peta, exa
(post-fixes (list "k" "M" "G" "T" "P" "E") (cdr post-fixes)))
((< file-size 1024) (format " %10.0f%s" file-size (car post-fixes))))))
(defun dired-sort-toggle ()
"This is a redefinition of the fn from dired.el. Normally,
dired sorts on either name or time, and you can swap between them
with the s key. This function one sets sorting on name, size,
time, and extension. Cycling works the same.
"
(setq dired-actual-switches
(let (case-fold-search)
(cond
((string-match " " dired-actual-switches) ;; contains a space
;; New toggle scheme: add/remove a trailing " -t" " -S",
;; or " -U"
;; -t = sort by time (date)
;; -S = sort by size
;; -X = sort by extension
(cond
((string-match " -t\\'" dired-actual-switches)
(concat
(substring dired-actual-switches 0 (match-beginning 0))
" -X"))
((string-match " -X\\'" dired-actual-switches)
(concat
(substring dired-actual-switches 0 (match-beginning 0))
" -S"))
((string-match " -S\\'" dired-actual-switches)
(substring dired-actual-switches 0 (match-beginning 0)))
(t
(concat dired-actual-switches " -t"))))
(t
;; old toggle scheme: look for a sorting switch, one of [tUXS]
;; and switch between them. Assume there is only ONE present.
(let* ((old-sorting-switch
(if (string-match (concat "[t" dired-ls-sorting-switches "]")
dired-actual-switches)
(substring dired-actual-switches (match-beginning 0)
(match-end 0))
""))
(new-sorting-switch
(cond
((string= old-sorting-switch "t") "X")
((string= old-sorting-switch "X") "S")
((string= old-sorting-switch "S") "")
(t "t"))))
(concat
"-l"
;; strip -l and any sorting switches
(dired-replace-in-string (concat "[-lt"
dired-ls-sorting-switches "]")
""
dired-actual-switches)
new-sorting-switch))))))
(dired-sort-set-modeline)
(revert-buffer))
(defun dired-sort-set-modeline ()
"This is a redefinition of the fn from `dired.el'. This one
properly provides the modeline in dired mode, supporting the new
search modes defined in the new `dired-sort-toggle'.
"
;; Set modeline display according to dired-actual-switches.
;; Modeline display of "by name" or "by date" guarantees the user a
;; match with the corresponding regexps. Non-matching switches are
;; shown literally.
(when (eq major-mode 'dired-mode)
(setq mode-name
(let (case-fold-search)
(cond ((string-match "^-[^t]*t[^t]*$" dired-actual-switches)
"Dired by time")
((string-match "^-[^X]*X[^X]*$" dired-actual-switches)
"Dired by ext")
((string-match "^-[^S]*S[^S]*$" dired-actual-switches)
"Dired by sz")
((string-match "^-[^SXUt]*$" dired-actual-switches)
"Dired by name")
(t
(concat "Dired " dired-actual-switches)))))
(force-mode-line-update)))
(provide 'dired-fixups)
;;; dired-fixups.el ends here
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;