forked from chalmagean/emacs.d
-
Notifications
You must be signed in to change notification settings - Fork 0
/
my-dired.el
76 lines (60 loc) · 2.4 KB
/
my-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
;; I want this for dired-jump
(require 'dired-x)
;; I usually want to see just the file names
(require 'dired-details)
(dired-details-install)
;; Nice listing
(setq find-ls-option '("-print0 | xargs -0 ls -alhd" . ""))
;; Always copy/delete recursively
(setq dired-recursive-copies (quote always))
(setq dired-recursive-deletes (quote top))
;; Auto refresh dired, but be quiet about it
(setq global-auto-revert-non-file-buffers t)
(setq auto-revert-verbose nil)
;; Hide some files
;;(setq dired-omit-files "^\\..*$\\|^\\.\\.$")
(setq dired-omit-files "^\\.pdf$\\|\\.git$\\|\\.DS_Store$")
(add-hook 'dired-mode-hook (lambda () (dired-omit-mode 1)))
;; List 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)
;; Automatically create missing directories when creating new files
(defun my-create-non-existent-directory ()
(let ((parent-directory (file-name-directory buffer-file-name)))
(when (and (not (file-exists-p parent-directory))
(y-or-n-p (format "Directory `%s' does not exist! Create it?" parent-directory)))
(make-directory parent-directory t))))
(add-to-list 'find-file-not-found-functions #'my-create-non-existent-directory)
;; Use ls from emacs
(when (eq system-type 'darwin)
(require 'ls-lisp)
(setq ls-lisp-use-insert-directory-program nil))
;; Changing the way M-< and M-> work in dired
;; Instead of taking me to the very beginning or very end, they now take me to the first or last file.
(defun dired-back-to-top ()
(interactive)
(beginning-of-buffer)
(next-line 2))
(define-key dired-mode-map
(vector 'remap 'beginning-of-buffer) 'dired-back-to-top)
(defun dired-jump-to-bottom ()
(interactive)
(end-of-buffer)
(next-line -1))
(define-key dired-mode-map
(vector 'remap 'end-of-buffer) 'dired-jump-to-bottom)
;; C-a is nicer in dired if it moves back to start of files
(defun dired-back-to-start-of-files ()
(interactive)
(backward-char (- (current-column) 2)))
(define-key dired-mode-map (kbd "C-a") 'dired-back-to-start-of-files)
(provide 'my-dired)