From 6d44cec66619595412285dc89679c18f7ca4ad6b Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Sun, 6 Aug 2017 18:38:19 +0200 Subject: [PATCH] Fix new workspace & file prompt on project switch Properly initialize a new workspace, switch to the fallback buffer (scratch/dash), update its default-directory to the project root, and fuzzy-prompt for a file to open. --- .../feature/workspaces/autoload/workspaces.el | 18 ++++++++++++------ modules/feature/workspaces/config.el | 7 ++++--- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/modules/feature/workspaces/autoload/workspaces.el b/modules/feature/workspaces/autoload/workspaces.el index ce70c67f6..f87cd6d5a 100644 --- a/modules/feature/workspaces/autoload/workspaces.el +++ b/modules/feature/workspaces/autoload/workspaces.el @@ -459,12 +459,6 @@ the workspace and move to the next." (+workspace/new) (set-frame-parameter frame 'assoc-persp (+workspace-current-name))) -;;;###autoload -(defun +workspaces|create-project-workspace () - "Create a new workspace when switching project with `projectile'." - (when persp-mode - (+workspace-switch (projectile-project-name) t))) - ;;;###autoload (defun +workspaces|delete-associated-workspace-maybe (frame) "Delete workspace associated with current frame IF it has no real buffers." @@ -480,3 +474,15 @@ the workspace and move to the next." (when (doom-real-buffer-list) (apply orig-fn args)) t) + +;;;###autoload +(defun +workspaces*switch-project-by-name (orig-fn &rest args) + "Switch to a project and prompt for a file to open. + +Ensures the scratch (or dashboard) buffers are CDed into the project's root." + (when persp-mode + (+workspace-switch (car args) t) + (with-current-buffer (switch-to-buffer (doom-fallback-buffer)) + (setq default-directory (car args)))) + (apply orig-fn args)) + diff --git a/modules/feature/workspaces/config.el b/modules/feature/workspaces/config.el index 808e9ac95..bbf78bd3a 100644 --- a/modules/feature/workspaces/config.el +++ b/modules/feature/workspaces/config.el @@ -46,11 +46,12 @@ renamed.") (define-key persp-mode-map [remap delete-window] #'+workspace/close-window-or-workspace) - ;; per-frame workspaces + ;; per-frame and per-project workspaces (setq persp-init-new-frame-behaviour-override nil - persp-interactive-init-frame-behaviour-override #'+workspace-on-new-frame) - (add-hook 'projectile-before-switch-project-hook #'+workspaces|create-project-workspace) + persp-interactive-init-frame-behaviour-override #'+workspace-on-new-frame + projectile-switch-project-action #'projectile-find-file) (add-hook 'delete-frame-functions #'+workspaces|delete-associated-workspace-maybe) + (advice-add #'projectile-switch-project-by-name :around #'+workspaces*switch-project-by-name) ;; only auto-save when real buffers are present (advice-add #'persp-asave-on-exit :around #'+workspaces*autosave-real-buffers)