Function: treemacs--init

treemacs--init is a byte-compiled function defined in treemacs-core-utils.el.

Signature

(treemacs--init &optional ROOT NAME)

Documentation

Initialise a treemacs buffer from the current workspace.

Add a project for ROOT and NAME if they are non-nil.

Source Code

;; Defined in ~/.emacs.d/elpa/treemacs-20251226.1307/treemacs-core-utils.el
(defun treemacs--init (&optional root name)
  "Initialise a treemacs buffer from the current workspace.
Add a project for ROOT and NAME if they are non-nil."
  (treemacs--maybe-load-workspaces)
  (let ((origin-buffer (current-buffer))
        (current-workspace (treemacs-current-workspace))
        (run-hook? nil)
        (visibility (treemacs-current-visibility)))
    (pcase visibility
      ('visible (treemacs--select-visible-window))
      ('exists (treemacs--select-not-visible-window))
      ('none
       (treemacs--setup-buffer)
       (treemacs-mode)
       ;; Render the projects even if there are none. This ensures that top-level
       ;; extensions are always rendered, and the project markers are initialized.
       (treemacs--render-projects (treemacs-workspace->projects current-workspace))
       (when (treemacs-workspace->is-empty?)
         (let* ((path (-> (treemacs--read-first-project-path)
                          (treemacs-canonical-path)))
                (name (treemacs--filename path)))
           (treemacs-do-add-project-to-workspace path name)
           (treemacs-log "Created first project.")))
       (goto-char 2)
       (run-hooks 'treemacs-post-buffer-init-hook)
       (setf run-hook? t)))
    (when root (treemacs-do-add-project-to-workspace (treemacs-canonical-path root) name))
    (with-no-warnings (setq treemacs--ready-to-follow t))
    (let* ((origin-file (buffer-file-name origin-buffer))
           (file-project (treemacs-is-path origin-file :in-workspace)))
      (cond
       ((and (or treemacs-follow-after-init (with-no-warnings treemacs-follow-mode))
             file-project)
        (treemacs-goto-file-node origin-file file-project))
       (treemacs-expand-after-init
        (treemacs-toggle-node))))
    ;; The hook should run at the end of the setup, but also only
    ;; if a new buffer was created, as the other cases are already covered
    ;; in their respective setup functions.
    (when run-hook? (run-hook-with-args 'treemacs-select-functions visibility))))