Function: treemacs--follow
treemacs--follow is a byte-compiled function defined in
treemacs-follow-mode.el.
Signature
(treemacs--follow)
Documentation
Move point to the current file in the treemacs buffer.
Expand directories if needed. Do nothing if current file does not exist in the file system or is not below current treemacs root or if the treemacs buffer is not visible.
Source Code
;; Defined in ~/.emacs.d/elpa/treemacs-20251226.1307/treemacs-follow-mode.el
(defun treemacs--follow ()
"Move point to the current file in the treemacs buffer.
Expand directories if needed. Do nothing if current file does not exist in the
file system or is not below current treemacs root or if the treemacs buffer is
not visible."
;; Treemacs selecting files with `ace-window' results in a large amount of
;; window selections, so we should be breaking out as soon as possbile
(setq treemacs--follow-timer nil)
(when treemacs--ready-to-follow
(treemacs-without-following
(let* ((treemacs-window (treemacs-get-local-window))
(current-buffer (current-buffer))
(buffer-name (buffer-name current-buffer))
(current-file (or (buffer-file-name current-buffer)
(when (eq major-mode 'dired-mode)
(treemacs-canonical-path (dired-current-directory))))))
(when (and treemacs-window
current-file
(not (s-starts-with? treemacs-buffer-name-prefix buffer-name))
(file-exists-p current-file)
(not (string= buffer-name "COMMIT_EDITMSG"))
(--none?
(funcall it current-file)
treemacs-file-follow-ignore-functions))
(-when-let (project-for-file (treemacs--find-project-for-buffer current-file))
(with-selected-window treemacs-window
(-let [selected-file (--if-let (treemacs-current-button)
(treemacs--nearest-path it)
(treemacs-project->path project-for-file))]
(unless (treemacs-is-path selected-file :same-as current-file)
(when (treemacs-goto-file-node current-file project-for-file)
(when treemacs-project-follow-cleanup
(dolist (project (treemacs-workspace->projects (treemacs-current-workspace)))
(unless (or (not (treemacs-project->is-expanded? project))
(eq project project-for-file))
(-when-let (project-pos (treemacs-project->position project))
(goto-char project-pos)
(treemacs--collapse-root-node project-pos)))))
(when treemacs-recenter-after-file-follow
(treemacs--maybe-recenter treemacs-recenter-after-file-follow))))))))))))