Function: treemacs-do-add-project-to-workspace

treemacs-do-add-project-to-workspace is a byte-compiled function defined in treemacs-workspaces.el.

Signature

(treemacs-do-add-project-to-workspace PATH NAME)

Documentation

Add project at PATH to the current workspace.

NAME is provided during ad-hoc navigation only. Return values may be as follows:

* If the given path is invalid (is nil or does not exist)
  - the symbol invalid-path
  - a string describing the problem
* If the project for the given path already exists:
  - the symbol duplicate-project
  - the project the PATH falls into
* If a project under given path already exists:
  - the symbol includes-project
  - the project the PATH contains
* If a project for the given name already exists:
  - the symbol duplicate-name
  - the project with the duplicate name
* If the given name is invalid:
  - the symbol invalid-name
  - the name
* If everything went well:
  - the symbol success
  - the created project

PATH: Filepath NAME: String

Aliases

treemacs-add-project-at (obsolete since v.2.2.1)

Source Code

;; Defined in ~/.emacs.d/elpa/treemacs-20251226.1307/treemacs-workspaces.el
(defun treemacs-do-add-project-to-workspace (path name)
  "Add project at PATH to the current workspace.
NAME is provided during ad-hoc navigation only.
Return values may be as follows:

* If the given path is invalid (is nil or does not exist)
  - the symbol `invalid-path'
  - a string describing the problem
* If the project for the given path already exists:
  - the symbol `duplicate-project'
  - the project the PATH falls into
* If a project under given path already exists:
  - the symbol `includes-project'
  - the project the PATH contains
* If a project for the given name already exists:
  - the symbol `duplicate-name'
  - the project with the duplicate name
* If the given name is invalid:
  - the symbol `invalid-name'
  - the name
* If everything went well:
  - the symbol `success'
  - the created project

PATH: Filepath
NAME: String"
  (treemacs-block
   (treemacs-return-if (null path)
     `(invalid-path "Path is nil."))
   (let ((path-status (treemacs--get-path-status path))
         (added-in-workspace (treemacs-current-workspace)))
     (treemacs-return-if (not (file-readable-p path))
       `(invalid-path "Path is not readable does not exist."))
     (setq path (-> path (file-truename) (treemacs-canonical-path)))
     (-when-let (project (treemacs--find-project-for-path path))
       (treemacs-return `(duplicate-project ,project)))
     (treemacs-return-if (treemacs--is-name-invalid? name)
       `(invalid-name ,name))
     (-when-let (project (--first (treemacs-is-path (treemacs-project->path it) :in path)
                                  (treemacs-workspace->projects (treemacs-current-workspace))))
       (treemacs-return `(includes-project ,project)))
     (let ((project (treemacs-project->create! :name name :path path :path-status path-status)))
       (-when-let (double (--first (string= name (treemacs-project->name it))
                                   (treemacs-workspace->projects (treemacs-current-workspace))))
         (treemacs-return `(duplicate-name ,double)))
       (treemacs--add-project-to-current-workspace project)
       (treemacs--invalidate-buffer-project-cache)
       (treemacs-run-in-every-buffer
        (when (eq added-in-workspace workspace)
          (treemacs-with-writable-buffer
           (goto-char (treemacs--projects-end))
           (cond
            ;; Inserting the first and only button - no need to add spacing
            ((not (treemacs-current-button)))
            ;; Inserting before a button. This happens when only bottom extensions exist.
            ((bolp)
             (save-excursion (treemacs--insert-root-separator))
             ;; Unlock the marker - when the marker is at the beginning of the buffer,
             ;; expanding/collapsing extension nodes would move the marker and it was thus locked.
             (set-marker-insertion-type (treemacs--projects-end) t))
            ;; Inserting after a button (the standard case)
            ;; We should already be at EOL, but play it safe.
            (t
             (end-of-line)
             (treemacs--insert-root-separator)))
           (treemacs--add-root-element project)
           (treemacs-dom-node->insert-into-dom!
            (treemacs-dom-node->create! :key path :position (treemacs-project->position project)))
           (when treemacs-expand-added-projects
             (treemacs--expand-root-node (treemacs-project->position project))))))
       (treemacs--persist)
       (treemacs--invalidate-buffer-project-cache)
       (when (with-no-warnings treemacs-hide-gitignored-files-mode)
         (treemacs--prefetch-gitignore-cache path))
       (run-hook-with-args 'treemacs-create-project-functions project)
       `(success ,project)))))