-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmy-dired.el
105 lines (88 loc) · 3.11 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
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
;; ugly workaround because OSX ls doesn't support the -X switch
;;
;; ref:
;; http://stackoverflow.com/questions/4076360/error-in-dired-sorting-on-os-x
;;(when (eq system-type 'darwin)
;; (require 'ls-lisp)
;; (setq ls-lisp-use-insert-directory-program nil))
(put 'dired-find-alternate-file 'disabled nil)
;; on OSX, dired's ls binary doesn't support some of the required options.
;; Thankfully, I use Homebrew, so I can hack around this and tell it to use
;; the proper ls.
(if (not (my-system-is-mac))
(setq dired-listing-switches "-kABhl --group-directories-first")
(setq dired-listing-switches "-kABhl")
)
(use-package saveplace
:config
(progn
(setq save-place-file (concat user-emacs-directory ".cache/places"))
(setq-default save-place t)))
(use-package savehist
:config
(progn
(setq savehist-file (concat user-emacs-directory ".cache/savehist")
savehist-additional-variables '(search ring regexp-search-ring)
savehist-autosave-interval 60)
(savehist-mode t)))
(use-package recentf
:config
(progn
(setq recentf-save-file (concat user-emacs-directory ".cache/recentf")
recentf-max-saved-items 1000
recentf-max-menu-items 500)
(recentf-mode +1)))
(defun my-configure-dired ()
"Setup dired and dired-x.
For use with dired-mode-hook."
(dired-omit-mode 1))
(add-hook 'dired-mode-hook 'my-configure-dired)
(defun my-dired-up-directory ()
"Take dired up one directory, but behave like dired-find-alternate-file"
(interactive)
(let ((old (current-buffer)))
(dired-up-directory)
(kill-buffer old)))
(defun my-dired-next-line (count)
"Move to next line, always staying on the dired filename."
(interactive "p")
(dired-next-line count)
(dired-move-to-filename))
(defun my-dired-previous-line (count)
"Move to previous line, always staying on the dired filename."
(interactive "p")
(dired-previous-line count)
(dired-move-to-filename))
(defun my-dired-interact-with-file ()
"Interact with a dired file!"
(interactive)
(let ((this-file (dired-get-file-for-visit)))
(if (file-directory-p this-file)
(dired-maybe-insert-subdir this-file)
(dired-find-file))))
(defun my-dired-at-title ()
"Returns the current dir if point is at the title of a directory in dired.
Otherwise, returns nil."
(interactive)
(let* ((cur-dir (dired-current-directory))
(hidden-p (dired-subdir-hidden-p cur-dir))
(elt (assoc cur-dir dired-subdir-alist))
(begin-pos (save-excursion
(goto-char (dired-get-subdir-min elt))
(point)))
(end-pos (save-excursion
(goto-char (dired-get-subdir-min elt))
(skip-chars-forward "^\n\r")
(point)))
(at-title (and (> (+ 1 (point)) begin-pos)
(< (+ 1 (point)) end-pos)))
buffer-read-only)
(if at-title elt nil)))
(defun my-dired-remove-from-buffer ()
(interactive)
(if (my-dired-at-title)
(dired-kill-subdir)))
;; TODO: make this work
;; (after 'evil
;; (evil-define-key 'normal evil-normal-state-map (kbd "R") 'revert-buffer))
(provide 'my-dired)