feature/workspaces: have switch-project recycle empty workspaces

If you're in an empty workspace, reuse it, rather than spawning a new
one. This lets you create a new workspace *then* switch project.
This commit is contained in:
Henrik Lissner 2018-02-06 17:49:51 -05:00
parent dce496e246
commit 68a4c85088
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395

View file

@ -490,28 +490,33 @@ created."
;;;###autoload ;;;###autoload
(defun +workspaces|switch-to-project (&optional inhibit-prompt) (defun +workspaces|switch-to-project (&optional inhibit-prompt)
"Creates a workspace dedicated to a new project. If one already exists, switch "Creates a workspace dedicated to a new project. If one already exists, switch
to it. Should be hooked to `projectile-after-switch-project-hook'." to it. If in the main workspace and it's empty, recycle that workspace, without
renaming it.
Should be hooked to `projectile-after-switch-project-hook'."
(when (and persp-mode +workspaces--project-dir) (when (and persp-mode +workspaces--project-dir)
(unwind-protect (unwind-protect
(let (persp-p) (if (+workspace-buffer-list)
(let* ((persp (let (persp-p)
(let* ((default-directory +workspaces--project-dir) (let* ((persp
projectile-project-name (let* ((default-directory +workspaces--project-dir)
projectile-require-project-root (project-name (doom-project-name 'nocache)))
projectile-cached-buffer-file-name (or (setq persp-p (+workspace-get project-name t))
projectile-cached-project-root (+workspace-new project-name))))
(project-name (projectile-project-name))) (new-name (persp-name persp)))
(or (setq persp-p (+workspace-get project-name t)) (+workspace-switch new-name)
(+workspace-new project-name)))) (unless persp-p
(new-name (persp-name persp))) (switch-to-buffer (doom-fallback-buffer)))
(+workspace-switch new-name) (unless inhibit-prompt
(unless persp-p (doom-project-find-file +workspaces--project-dir))
(switch-to-buffer (doom-fallback-buffer))) (+workspace-message
(unless inhibit-prompt (format "Switched to '%s' in new workspace" new-name)
(doom-project-find-file +workspaces--project-dir)) 'success)))
(+workspace-message (with-current-buffer (switch-to-buffer (doom-fallback-buffer))
(format "Switched to '%s' in new workspace" new-name) (setq default-directory +workspaces--project-dir)
'success))) (message "Switched to '%s'" (doom-project-name 'nocache)))
(unless inhibit-prompt
(doom-project-find-file +workspaces--project-dir)))
(setq +workspaces--project-dir nil)))) (setq +workspaces--project-dir nil))))