Function: treemacs-create-workspace-from-project

treemacs-create-workspace-from-project is an interactive and byte-compiled function defined in treemacs-interface.el.

Signature

(treemacs-create-workspace-from-project &optional ARG)

Documentation

Create (and switch to) a workspace containing only the current project.

By default uses the project at point in the treemacs buffer. If there is no treemacs buffer, then the project of the current file is used instead. With a prefix ARG it is also possible to interactively select the project.

Key Bindings

Source Code

;; Defined in ~/.emacs.d/elpa/treemacs-20251226.1307/treemacs-interface.el
(defun treemacs-create-workspace-from-project (&optional arg)
  "Create (and switch to) a workspace containing only the current project.

By default uses the project at point in the treemacs buffer.  If there is no
treemacs buffer, then the project of the current file is used instead.  With a
prefix ARG it is also possible to interactively select the project."
  (interactive "P")
  (treemacs-block
    (-let [project nil]
      (if (eq t treemacs--in-this-buffer)
          (setf project (treemacs-project-of-node (treemacs-current-button)))
        (setf project (treemacs--find-project-for-buffer (buffer-file-name (current-buffer))))
        (treemacs-select-window))
      (when (or arg (null project))
        (setf project (treemacs--select-project-by-name))
        (treemacs-return-if (null project)))
      (let* ((ws-name (treemacs-project->name project))
             (new-ws (treemacs--find-workspace-by-name ws-name)))
        (if new-ws
            (setf (treemacs-workspace->projects new-ws) (list project))
          (-let [ws-create-result (treemacs-do-create-workspace ws-name)]
            (treemacs-error-return-if (not (equal 'success (car ws-create-result)))
              "Something went wrong when creating a new workspace: %s" ws-create-result)
            (setf new-ws (cdr ws-create-result))
            (setf (treemacs-workspace->projects new-ws) (list project))
            (treemacs--persist)))
        (treemacs-do-switch-workspace new-ws)
        (treemacs-pulse-on-success "Switched to project workspace '%s'"
          (propertize ws-name 'face 'font-lock-type-face))))))