Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions modules/ui/neotree/README.org
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,14 @@ NERDTree.
󱌣 This module has no usage documentation yet. [[doom-contrib-module:][Write some?]]
#+end_quote

* TODO Configuration
#+begin_quote
󱌣 This module has no configuration documentation yet. [[doom-contrib-module:][Write some?]]
#+end_quote
* Configuration
** Keeping neotree synchronized
To keep neotree up to date whenever you switch to another buffer or project,
add or integrate the following snippet to your =config.el=:
#+begin_src elisp
(after! neotree
(add-hook 'doom-switch-buffer-hook #'+neotree/refresh))
#+end_src

* Troubleshooting
/There are no known problems with this module./ [[doom-report:][Report one?]]
Expand Down
29 changes: 29 additions & 0 deletions modules/ui/neotree/autoload.el
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,32 @@
(neo-point-auto-indent)))
(t
(call-interactively #'neotree-enter)))))

;;;###autoload
(defun +neotree/refresh ()
"Refresh neotree to show the current file's project if
neotree is open, the current buffer belongs to a file,
that file belongs to a project, and neotree is not
already showing that project."
(interactive)
(let* ((cur-buffer (current-buffer))
(cur-buffer-file (buffer-file-name cur-buffer)))
;; We refresh neotree only when all of the following conditions are met.
;; 1. The current buffer belongs to a file. This condition avoids updates
;; when switching to buffers such as *doom* or *scratch*.
;; 2. Neotree is open.
;; 3. The current buffer is in a project that neotree can show.
;; 4. Neotree is not already showing that buffer's project.
(when (and cur-buffer-file
(neo-global--window-exists-p)
(projectile-project-root)
(not (neo-global--file-in-root-p cur-buffer-file)))
;; Refresh neotree by:
;; 1. Explicitly changing the directory to the current project root because
;; neotree sometimes picks the wrong root (e.g., chooses a subdirectory).
(neotree-dir (doom-project-root))
;; 2. Opening our current file in neotree. This is the actual refresh.
(+neotree/find-this-file)
;; 3. Focusing the current buffer because +neotree/find-this-file switches
;; focus to the neotree window.
(select-window (get-buffer-window cur-buffer)))))