forked from doomemacs/doomemacs
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathautoload.el
70 lines (64 loc) · 2.42 KB
/
autoload.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
;;; ui/neotree/autoload.el -*- lexical-binding: t; -*-
;; `neotree-show' and `neotree-find' don't respect the current project, and open
;; neotree in `default-directory'. `+neotree/open' and `neotree/find-this-file'
;; will ensure the neotree pane is always rooted in the project root.
;;;###autoload
(defun +neotree/open ()
"Open the neotree window in the current project."
(interactive)
(require 'neotree)
(if (neo-global--window-exists-p)
(neotree-hide)
(neotree-dir (or (doom-project-root)
default-directory))))
;;;###autoload
(defun +neotree/find-this-file ()
"Open the neotree window in the current project, and find the current file."
(interactive)
(let ((path buffer-file-name)
(project-root (or (doom-project-root)
default-directory)))
(require 'neotree)
(cond ((and (neo-global--window-exists-p)
(get-buffer-window neo-buffer-name t))
(neotree-find path project-root)
(neotree-refresh))
((not (and (neo-global--window-exists-p)
(equal (file-truename (neo-global--with-buffer neo-buffer--start-node))
(file-truename project-root))))
(neotree-dir project-root)
(neotree-find path project-root))
(t
(neotree-find path project-root)))))
;;;###autoload
(defun +neotree/collapse-or-up ()
"Collapse an expanded directory node or go to the parent node."
(interactive)
(when-let (node (neo-buffer--get-filename-current-line))
(if (and (file-directory-p node)
(neo-buffer--expanded-node-p node))
(+neotree/collapse)
(neotree-select-up-node))))
;;;###autoload
(defun +neotree/collapse ()
"Collapse a neotree node."
(interactive)
(when-let (node (neo-buffer--get-filename-current-line))
(when (file-directory-p node)
(neo-buffer--set-expand node nil)
(neo-buffer--refresh t))
(when neo-auto-indent-point
(neo-point-auto-indent))))
;;;###autoload
(defun +neotree/expand-or-open ()
"Expand or open a neotree node."
(interactive)
(when-let (node (neo-buffer--get-filename-current-line))
(cond ((file-directory-p node)
(neo-buffer--set-expand node t)
(neo-buffer--refresh t)
(when neo-auto-indent-point
(forward-line)
(neo-point-auto-indent)))
(t
(call-interactively #'neotree-enter)))))