Function: treemacs-do-switch-workspace

treemacs-do-switch-workspace is a byte-compiled function defined in treemacs-workspaces.el.

Signature

(treemacs-do-switch-workspace &optional WORKSPACE)

Documentation

Switch to a new WORKSPACE.

Workspace may either be a workspace name, a workspace object, or be left out. In the latter case the workspace to switch to will be selected interactively. Return values may be as follows:

* If there are no workspaces to switch to:
  - the symbol only-one-workspace
* If the given workspace could not be found (if WORKSPACE was a name string)
  - the symbol workspace-not-found
  - the given workspace name
* If everything went well:
  - the symbol success
  - the selected workspace

Source Code

;; Defined in ~/.emacs.d/elpa/treemacs-20251226.1307/treemacs-workspaces.el
(defun treemacs-do-switch-workspace (&optional workspace)
  "Switch to a new WORKSPACE.
Workspace may either be a workspace name, a workspace object, or be left out.
In the latter case the workspace to switch to will be selected interactively.
Return values may be as follows:

* If there are no workspaces to switch to:
  - the symbol `only-one-workspace'
* If the given workspace could not be found (if WORKSPACE was a name string)
  - the symbol `workspace-not-found'
  - the given workspace name
* If everything went well:
  - the symbol `success'
  - the selected workspace"
  (treemacs--maybe-load-workspaces)
  (treemacs-block
   (treemacs-return-if (= 1 (length treemacs--workspaces))
     'only-one-workspace)
   (let (new-workspace)
     (cond
      ((treemacs-workspace-p workspace)
       (setf new-workspace workspace))
      ((stringp workspace)
       (setf new-workspace (treemacs-find-workspace-by-name workspace))
       (treemacs-return-if (null new-workspace)
         `(workspace-not-found ,workspace)))
      ((null workspace)
       (let* ((workspaces (->> treemacs--workspaces
                               (--reject (eq it (treemacs-current-workspace)))
                               (--map (cons (treemacs-workspace->name it) it))))
              (name (completing-read
                     "Switch to: "
                     (treemacs--pre-sorted-list workspaces)
                     nil :require-match)))
         (setf new-workspace (cdr (--first (string= (car it) name) workspaces))))))
     (setf (treemacs-current-workspace) new-workspace)
     (treemacs--invalidate-buffer-project-cache)
     (treemacs--rerender-after-workspace-change)
     (when (with-no-warnings treemacs-hide-gitignored-files-mode)
       (treemacs--prefetch-gitignore-cache 'all))
     (run-hooks 'treemacs-switch-workspace-hook)
     (treemacs-return
      `(success ,new-workspace)))))