jaypei / emacs-neotree

A emacs tree plugin like NerdTree for Vim.
GNU General Public License v3.0
1.56k stars 147 forks source link

neo-enter-hook on moving #312

Open Nondv opened 5 years ago

Nondv commented 5 years ago

Hello,

From #77 I found out about neo-enter-hook and used it like this:

(defun neotree-hide-if-file (type & rest) (if (equal type 'file) (neotree-hide)))
(add-hook 'neo-enter-hook 'neotree-hide-if-file)

Though it is being triggered even by moving in neotree buffer via n or p.

Arguments are the same as when using RET:

Debugger entered--entering a function:
* neotree-hide-if-file(file "/Users/nondv/my-configs/.emacs" nil)

Is this expected behavior?

Nondv commented 5 years ago

This is what I found in the package

(defun neo-buffer--execute (arg &optional file-fn dir-fn)
  "Define the behaviors for keyboard event.
ARG is the parameter for command.
If FILE-FN is non-nil, it will executed when a file node.
If DIR-FN is non-nil, it will executed when a dir node."
  (interactive "P")
  (let* ((btn-full-path (neo-buffer--get-filename-current-line))
         is-file-p
         enter-fn)
    (unless (null btn-full-path)
      (setq is-file-p (not (file-directory-p btn-full-path))
            enter-fn (if is-file-p file-fn dir-fn))
      (unless (null enter-fn)
        (funcall enter-fn btn-full-path arg)
        (run-hook-with-args
         'neo-enter-hook
         (if is-file-p 'file 'directory)
         btn-full-path
         arg)))
    btn-full-path))

I guess the described behavior is expected but confusing. Is there a hook for opening files?

Abdisalan commented 1 year ago

Yea looks like the behavior is expected. I think the intention with this one is if you click on a file with your mouse then it'll auto hide neotree.

You do bring up a good point that neotree could use a hook for opening files.