Include Clojure *cider-repl* and *test-report* to the active workspace

I usually have several workspaces with different Clojure projects opened. (in fact, with different worktrees) I want each workspace to have its own *test-report* and *cider-repl* when these buffers were opened. I’ve been doing this for a couple of days and it’s working for me:

  ;; include cider buffer into current workspace
  (add-hook 'cider-repl-mode-hook
            (lambda ()
              (persp-add-buffer (current-buffer))))

  ;; include test-report buffer into current workspace
  (add-hook 'cider-test-report-mode-hook
            (lambda ()
              (persp-add-buffer (current-buffer))))

  ;; include temp buffers created by cider into current workspace
  (add-hook 'cider-popup-buffer-mode-hook
            (lambda ()
              (persp-add-buffer (current-buffer))))

Is there a better way to make this work?

2 Likes

To generalize somewhat, I’m also curious about handling these special buffers. I’d prefer if many of them were associated with workspaces, such as those created with evil-buffer-new. Right now most of them end up in the worskpaceless void, and I have to dig for them with consult-buffer rather than +vertico/switch-workspace-buffer.

I’m guessing there’s multiple approaches, including hooking or advising the functions that generate them, setting up a regexp that forces matching buffer names workspace-local, or hooking into special modes when available, as done here. This could be a good configuration tutorial, if anyone is familiar.