From the package Neotree, I want to bind a key, that moves to the upper directory.
The upper directory is always on the top with
.. (up a dir). So I go to the first line of the neotree buffer, and call
neotree-enter to move to the upper directory. As a true Emacs'er, I figured out I need to modify it to my own preference.
So I created a function:
(defun neotree-go-to-upper-directory () (interactive) (evil-goto-first-line) (neotree-enter) ) (evil-define-key 'normal neotree-mode-map (kbd "h")'neotree-go-to-upper-directory)
After pressing h in NeoTree buffer, the cursor moves only to the
top. But nothing happens. Then I call M-x
neotree-enter, but still
When trace back into the source code of
neotree-enter with C-h f
then following the link, it's defined as:
(defun neotree-enter (&optional arg) "NeoTree typical open event. ARG are the same as `neo-open-file'." (interactive "P") (neo-buffer--execute arg 'neo-open-file 'neo-open-dir))
So I modified my function with adding the arguments as parameters:
(defun neotree-go-to-upper-directory (arg) (interactive "P") (evil-goto-first-line) (neo-open-dir arg) )
Re-evaluated and calling
neotree-go-to-upper-directory again inside Neotree
buffer, but still nothing happens. Something I went wrong. But can anyone tell
me where my code went wrong? It would be appreciated.
EDIT: For clarifity, as Lawlist suggested, I'm interested in a neotree solution. But some knowledge of Elisp would be also nice, because I'm struggling to understand why the function works for Neotree as well, and not in my case.
I got an working answer below:
(defun neotree-go-to-upper-directory () "Go to the parent directory in the NeoTree buffer." (interactive) (neotree-dir ".."))
But unfortunately, this is not always working and I can't figure out what the cause of this is. For example, I enter a directory with
neotree-enter and I want to call the function, then nothing will happen. It will be only working if I call
neotree-change-root-directory then calling the function afterwards, it seems. And not when I do