doomemacs/modules/ui/neotree/autoload.el
Henrik Lissner 53fe7a1f04 Refactor Project API to reflect changes upstream
projectile-project-root no longer returns `default-directory` if not in
a project (it returns nil). As such, doom-project-* functions (and their
uses) have been refactored.

+ doom-project-p & doom-project-root are aliases for
  projectile-project-p & projectile-project-root.
+ doom-project-{p,root,name,expand} now has a DIR argument (for
  consistency, since projectile-project-name and
  projectile-project-expand do not).
+ The nocache parameter is no longer necessary, as projectile's caching
  behavior is now more sane.
+ Removed some projectile advice/hacks that are no longer necessary.
+ Updated unit tests
2018-09-28 21:13:27 -04:00

70 lines
2.4 KiB
EmacsLisp

;;; 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)
(let ((project-root (doom-project-root)))
(require 'neotree)
(if (neo-global--window-exists-p)
(neotree-hide)
(neotree-dir project-root))))
;;;###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 (doom-project-root)))
(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 (file-directory-p node)
(if (neo-buffer--expanded-node-p node)
(+neotree/collapse)
(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)))
(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)))))