diff --git a/modules/feature/workspaces/autoload/workspaces.el b/modules/feature/workspaces/autoload/workspaces.el index fda46bd91..af7b990ed 100644 --- a/modules/feature/workspaces/autoload/workspaces.el +++ b/modules/feature/workspaces/autoload/workspaces.el @@ -497,35 +497,37 @@ created." (setq +workspaces--project-dir default-directory)) ;;;###autoload -(defun +workspaces|switch-to-project (&optional inhibit-prompt) +(defun +workspaces|switch-to-project (&optional dir) "Creates a workspace dedicated to a new project. If one already exists, switch 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 dir + (setq +workspaces--project-dir dir)) (when (and persp-mode +workspaces--project-dir) (unwind-protect (if (+workspace-buffer-list) - (let (persp-p) - (let* ((persp - (let* ((default-directory +workspaces--project-dir) - (project-name (doom-project-name 'nocache))) - (or (setq persp-p (+workspace-get project-name t)) - (+workspace-new project-name)))) - (new-name (persp-name persp))) - (+workspace-switch new-name) - (unless persp-p - (switch-to-buffer (doom-fallback-buffer))) - (unless inhibit-prompt - (doom-project-find-file +workspaces--project-dir)) - (+workspace-message - (format "Switched to '%s' in new workspace" new-name) - 'success))) + (let* (persp-p + (persp + (let* ((default-directory +workspaces--project-dir) + (project-name (doom-project-name 'nocache))) + (or (setq persp-p (+workspace-get project-name t)) + (+workspace-new project-name)))) + (new-name (persp-name persp))) + (+workspace-switch new-name) + (unless persp-p + (switch-to-buffer (doom-fallback-buffer))) + (with-current-buffer (doom-fallback-buffer) + (setq default-directory +workspaces--project-dir)) + (funcall +workspaces-switch-project-function +workspaces--project-dir) + (+workspace-message + (format "Switched to '%s' in new workspace" new-name) + 'success)) (with-current-buffer (switch-to-buffer (doom-fallback-buffer)) (setq default-directory +workspaces--project-dir) (message "Switched to '%s'" (doom-project-name 'nocache))) - (unless inhibit-prompt - (doom-project-find-file +workspaces--project-dir))) + (funcall +workspaces-switch-project-function +workspaces--project-dir)) (setq +workspaces--project-dir nil)))) @@ -533,14 +535,6 @@ Should be hooked to `projectile-after-switch-project-hook'." ;; Advice ;; -;;;###autoload -(defun +workspaces*switch-counsel-project-action (project) - "A `counsel-projectile-switch-project-action' that creates a dedicated -workspace for a new project, before prompting to open a file." - (let ((+workspaces--project-dir project) - (inhibit-message t)) - (+workspaces|switch-to-project 'inhibit-prompt))) - ;;;###autoload (defun +workspaces*autosave-real-buffers (orig-fn &rest args) "Don't autosave if no real buffers are open." diff --git a/modules/feature/workspaces/config.el b/modules/feature/workspaces/config.el index 330b9b2d6..947de9ed0 100644 --- a/modules/feature/workspaces/config.el +++ b/modules/feature/workspaces/config.el @@ -16,6 +16,11 @@ "The name of the primary and initial workspace, which cannot be deleted or renamed.") +(defvar +workspaces-switch-project-function #'doom-project-find-file + "The function to run after `projectile-switch-project' or +`counsel-projectile-switch-project'. This function must take one argument: the +new project directory.") + ;; FIXME actually use this for wconf bookmark system (defvar +workspaces-data-file "_workspaces" "The basename of the file to store single workspace perspectives. Will be @@ -98,8 +103,8 @@ Uses `+workspaces-main' to determine the name of the main workspace." (add-hook 'delete-frame-functions #'+workspaces|delete-associated-workspace) ;; per-project workspaces - (setq projectile-switch-project-action #'+workspaces|set-project-action) - (advice-add #'counsel-projectile-switch-project-by-name :before #'+workspaces*switch-counsel-project-action) + (setq projectile-switch-project-action #'+workspaces|set-project-action + counsel-projectile-switch-project-action #'+workspaces|switch-to-project) (add-hook 'projectile-after-switch-project-hook #'+workspaces|switch-to-project) ;;