doomemacs/modules/ui/neotree/autoload.el

72 lines
2.4 KiB
EmacsLisp
Raw Normal View History

2018-05-12 02:16:36 +08:00
;;; ui/neotree/autoload.el -*- lexical-binding: t; -*-
2017-02-13 17:54:36 +08:00
;; `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))))
2017-02-13 17:54:36 +08:00
;;;###autoload
(defun +neotree/find-this-file ()
"Open the neotree window in the current project, and find the current file."
2017-02-13 17:54:36 +08:00
(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)
2017-02-20 07:14:46 +08:00
(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)))))
2017-02-13 17:54:36 +08:00
;;;###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))
2017-05-17 07:32:39 +08:00
(if (file-directory-p node)
(if (neo-buffer--expanded-node-p node)
(+neotree/collapse)
2017-05-17 07:32:39 +08:00
(neotree-select-up-node))
(neotree-select-up-node))))
;;;###autoload
(defun +neotree/collapse ()
"Collapse a neotree node."
(interactive)
(when-let (node (neo-buffer--get-filename-current-line))
2017-05-17 07:32:39 +08:00
(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)))))