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
nothing happens.
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 neotree-enter
M-u M-x compile-defun
once your function is called, you can follow the code execution inside the debugger. This might give you some insight as to what's going on, what code is run and which doesn't (but you think it should).neotree
solution, or do you just want to better understand generally how arguments work in conjunction with the output of previously called functions that are designed to return a result? Not all arguments to functions can be functions -- in most cases, you call the function you want the value of first and store the result in a let-bound variable and pass that result to whatever function you want to call thereafter.neotree
using a single command. Perhaps it would be more clear if you renamed it?