Making Emacs Dashboard Show Treemacs Workspaces

I don't use projectile, or project.el, or any other project management system in Emacs. Maybe I should, but I "grew up" without having these systems and in my opinion they add complexity onto something that your filesystem (and git) already does fine on its own. So, to that end, I use Treemacs extensively for project management.

I generally follow a Workspace -> Project hierarchy. For example, here's a small snippet of my Treemacs persist file, with two workspaces and some varying projects underneath them.

* Website
** cyan.sh
 - path :: ~/.../cyan.sh
* Extending Emacs
** dotfiles
- path :: ~/.emacs.d
** ouroboros themes
- path :: ~/..../ouroboros-emacs-themes

One thing that I wanted for a while was the ability to show workspaces in Dashboard, because I usually want to go back to my most recent workspace when launching a new client instance. Same reason that people want thier projectile projects to show up. Unfortunately, Dashboard doesn't have any such integration already, so I had to hack some together. If I was smarter, I would do this in a way that's more portable. Currently it requires both Dashboard and Treemacs to be installed via Straight, as per the first two lines.

(load-file (concat user-emacs-directory "straight/build/dashboard/dashboard-widgets.el"))
(load-file (concat user-emacs-directory "straight/build/treemacs/treemacs-workspaces.el"))


(add-to-list 'dashboard-item-generators
           '(workspaces . dashboard-insert-workspaces)
           t)

(add-to-list 'dashboard-item-shortcuts
           '(workspaces . "w")
           t)

(defun dashboard-insert-workspaces (list-size)
  "Add the list of LIST-SIZE items of treemacs workspaces."
  (dashboard-insert-section
   "Workspaces:"
   (dashboard-subseq (mapcar (lambda (x) (cl-struct-slot-value 'treemacs-workspace 'name x)) treemacs--workspaces) list-size)
   list-size
   'workspaces
   (dashboard-get-shortcut 'workspaces)
   `(lambda (&rest _) (treemacs-do-switch-workspace ,el))
   (let* ((workspace-name el))
     workspace-name)))