This repository has been archived on 2024-10-22. You can view files and clone it, but cannot push or open issues or pull requests.
spacemacs/layers/+filetree/neotree/funcs.el
2018-05-11 01:28:58 -04:00

74 lines
2.5 KiB
EmacsLisp
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

;;; packages.el --- Neotree Layer functions File
;;
;; Copyright (c) 2012-2018 Sylvain Benner & Contributors
;;
;; Author: Sylvain Benner <sylvain.benner@gmail.com>
;; URL: https://github.com/syl20bnr/spacemacs
;;
;; This file is not part of GNU Emacs.
;;
;;; License: GPLv3
(defun spacemacs/neotree-expand-or-open ()
"Expand or open a neotree node."
(interactive)
(let ((node (neo-buffer--get-filename-current-line)))
(when node
(if (file-directory-p node)
(progn
(neo-buffer--set-expand node t)
(neo-buffer--refresh t)
(when neo-auto-indent-point
(next-line)
(neo-point-auto-indent)))
(let ((mru-winum (winum-get-number (get-mru-window))))
(apply 'neotree-enter (list mru-winum)))))))
(defun spacemacs/neotree-collapse ()
"Collapse a neotree node."
(interactive)
(let ((node (neo-buffer--get-filename-current-line)))
(when node
(when (file-directory-p node)
(neo-buffer--set-expand node nil)
(neo-buffer--refresh t))
(when neo-auto-indent-point
(neo-point-auto-indent)))))
(defun spacemacs/neotree-collapse-or-up ()
"Collapse an expanded directory node or go to the parent node."
(interactive)
(let ((node (neo-buffer--get-filename-current-line)))
(when node
(if (file-directory-p node)
(if (neo-buffer--expanded-node-p node)
(spacemacs/neotree-collapse)
(neotree-select-up-node))
(neotree-select-up-node)))))
(defun neotree-find-project-root ()
(interactive)
(if (neo-global--window-exists-p)
(neotree-hide)
(let ((origin-buffer-file-name (buffer-file-name)))
(neotree-find (projectile-project-root))
(neotree-find origin-buffer-file-name))))
(defun spacemacs//neotree-maybe-attach-window ()
(when (get-buffer-window (neo-global--get-buffer))
(neo-global--attach)))
;; winum
(defun spacemacs//winum-neotree-assign-func ()
"Custom number assignment for neotree."
(when (and (boundp 'neo-buffer-name)
(string= (buffer-name) neo-buffer-name)
;; in case there are two neotree windows. Example: when
;; invoking a transient state from neotree window, the new
;; window will show neotree briefly before displaying the TS,
;; causing an error message. the error is eliminated by
;; assigning 0 only to the top-left window
(eq (selected-window) (frame-first-window)))
0))