Better h behavior: collapse expanded dir of go to parent node

This commit is contained in:
syl20bnr 2015-01-04 01:49:53 -05:00
parent ba91893c5f
commit 21c9e3c606
2 changed files with 13 additions and 2 deletions

View file

@ -1171,7 +1171,7 @@ experience like in [ranger][]:
Key Binding | Description
---------------------------------|----------------------------------------------------------------
<kbd>h</kbd> | collapse directory
<kbd>h</kbd> | collapse expanded directory or go to parent node
<kbd>H</kbd> | previous sibling
<kbd>j</kbd> | next file or directory
<kbd>J</kbd> | next expanded directory on level down

View file

@ -1468,6 +1468,17 @@ determine the state to enable when escaping from the insert state.")
(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 spacemacs//neotree-key-bindings ()
"Set the key bindings for a neotree buffer."
(define-key evil-motion-state-local-map (kbd "TAB") 'neotree-stretch-toggle)
@ -1478,7 +1489,7 @@ determine the state to enable when escaping from the insert state.")
(define-key evil-motion-state-local-map (kbd "c") 'neotree-create-node)
(define-key evil-motion-state-local-map (kbd "d") 'neotree-delete-node)
(define-key evil-motion-state-local-map (kbd "g") 'neotree-refresh)
(define-key evil-motion-state-local-map (kbd "h") 'spacemacs/neotree-collapse)
(define-key evil-motion-state-local-map (kbd "h") 'spacemacs/neotree-collapse-or-up)
(define-key evil-motion-state-local-map (kbd "H") 'neotree-select-previous-sibling-node)
(define-key evil-motion-state-local-map (kbd "J") 'neotree-select-down-node)
(define-key evil-motion-state-local-map (kbd "K") 'neotree-select-up-node)