Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Force neotree to stay at project root

Tags:

emacs

I'm using neotree and projectile. I can open neotree at my project root using neotree-find-project-root, and it's beautiful.

When I open a file in a subfolder, it changes the neotree root to the folder that contains that file. This is less useful to me than if neotree view remained the project root.

Can I force neotree to always display the project root folder, and not automatically descend into subfolders?

(Toggling neotree off and on again using neotree-find-project-root will bring it back to the root, but it's a pain to do this manually. There must be a way to automatically do this?)

like image 854
kwnd Avatar asked Nov 08 '22 21:11

kwnd


1 Answers

I don't see a way to configure neotree to do this. You could consider submitting an issue to the developers of neotree, as this seems like it would be a common feature request.

As a sort of hacky fix, you could try something like this.

(add-hook 'find-file-hook
    (lambda ()
        (let ((buffer (current-buffer)))
            (neotree-find (projectile-project-root))
            (set-buffer buffer))))

This hook is run every time a new file is opened. It changes the neotree directory to the projectile project root, then sets the current buffer to the original buffer you were working with.

like image 119
Tim Miller Avatar answered Nov 15 '22 12:11

Tim Miller