From 21c9e3c606879b1ec68bcac4992c95d7ba2e229c Mon Sep 17 00:00:00 2001 From: syl20bnr Date: Sun, 4 Jan 2015 01:49:53 -0500 Subject: [PATCH] Better `h` behavior: collapse expanded dir of go to parent node --- doc/DOCUMENTATION.md | 2 +- spacemacs/packages.el | 13 ++++++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/doc/DOCUMENTATION.md b/doc/DOCUMENTATION.md index 3058b8c42..1761e4d72 100644 --- a/doc/DOCUMENTATION.md +++ b/doc/DOCUMENTATION.md @@ -1171,7 +1171,7 @@ experience like in [ranger][]: Key Binding | Description ---------------------------------|---------------------------------------------------------------- -h | collapse directory +h | collapse expanded directory or go to parent node H | previous sibling j | next file or directory J | next expanded directory on level down diff --git a/spacemacs/packages.el b/spacemacs/packages.el index 3939da53c..ad89475f7 100644 --- a/spacemacs/packages.el +++ b/spacemacs/packages.el @@ -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)