diff --git a/core/core-projects.el b/core/core-projects.el index 2fce0b554..d4ba241a3 100644 --- a/core/core-projects.el +++ b/core/core-projects.el @@ -39,23 +39,6 @@ Emacs.") :config (projectile-mode +1) - ;; REVIEW Resolve the project root once, when the file/buffer is opened. This - ;; speeds up projectile's project root resolution by leaps, but does - ;; put you at risk of having a stale project root. - (setq-hook! '(change-major-mode-after-body-hook - ;; In case the user saves the file to a new location - after-save-hook - ;; ...or makes external changes then returns to Emacs - focus-in-hook - ;; ...or when we change the current project! - projectile-after-switch-project-hook) - projectile-project-root (if default-directory (doom-project-root))) - - ;; However, it may become a problem when switching projects, so remove the - ;; cached value when switching projects. - (setq-hook! 'projectile-before-switch-project-hook - projectile-project-root nil) - ;; Projectile runs four functions to determine the root (in this order): ;; ;; + `projectile-root-local' -> checks the `projectile-project-root' variable diff --git a/modules/ui/workspaces/autoload/workspaces.el b/modules/ui/workspaces/autoload/workspaces.el index de856b4bf..681bf43b5 100644 --- a/modules/ui/workspaces/autoload/workspaces.el +++ b/modules/ui/workspaces/autoload/workspaces.el @@ -525,42 +525,46 @@ the user to open a file in the new project. This be hooked to `projectile-after-switch-project-hook'." (when dir (setq +workspaces--project-dir dir)) - (when (and persp-mode +workspaces--project-dir) - (when projectile-before-switch-project-hook - (with-temp-buffer - ;; Load the project dir-local variables into the switch buffer, so the - ;; action can make use of them - (setq default-directory +workspaces--project-dir) - (hack-dir-local-variables-non-file-buffer) - (run-hooks 'projectile-before-switch-project-hook))) - (unwind-protect - (if (and (not (null +workspaces-on-switch-project-behavior)) - (or (eq +workspaces-on-switch-project-behavior t) - (equal (safe-persp-name (get-current-persp)) persp-nil-name) - (+workspace-buffer-list))) - (let* ((persp - (let ((project-name (doom-project-name +workspaces--project-dir))) - (or (+workspace-get project-name t) - (+workspace-new project-name)))) - (new-name (persp-name persp))) - (+workspace-switch new-name) - (with-current-buffer (doom-fallback-buffer) - (setq default-directory +workspaces--project-dir)) - (unless current-prefix-arg - (funcall +workspaces-switch-project-function +workspaces--project-dir)) - (+workspace-message - (format "Switched to '%s' in new workspace" new-name) - 'success)) - (with-current-buffer (doom-fallback-buffer) - (setq default-directory +workspaces--project-dir) - (hack-dir-local-variables-non-file-buffer) - (message "Switched to '%s'" (doom-project-name +workspaces--project-dir))) - (with-demoted-errors "Workspace error: %s" - (+workspace-rename (+workspace-current-name) (doom-project-name +workspaces--project-dir))) - (unless current-prefix-arg - (funcall +workspaces-switch-project-function +workspaces--project-dir))) - (run-hooks 'projectile-after-switch-project-hook) - (setq +workspaces--project-dir nil)))) + ;; HACK Clear projectile-project-root, otherwise cached roots may interfere + ;; with project switch (see #3166) + (let (projectile-project-root) + (when (and persp-mode +workspaces--project-dir) + (when projectile-before-switch-project-hook + (with-temp-buffer + ;; Load the project dir-local variables into the switch buffer, so the + ;; action can make use of them + (setq default-directory +workspaces--project-dir) + (hack-dir-local-variables-non-file-buffer) + (run-hooks 'projectile-before-switch-project-hook))) + (unwind-protect + (if (and (not (null +workspaces-on-switch-project-behavior)) + (or (eq +workspaces-on-switch-project-behavior t) + (equal (safe-persp-name (get-current-persp)) persp-nil-name) + (+workspace-buffer-list))) + (let* ((persp + (let ((project-name (doom-project-name +workspaces--project-dir))) + (or (+workspace-get project-name t) + (+workspace-new project-name)))) + (new-name (persp-name persp))) + (+workspace-switch new-name) + (with-current-buffer (doom-fallback-buffer) + (setq default-directory +workspaces--project-dir) + (hack-dir-local-variables-non-file-buffer)) + (unless current-prefix-arg + (funcall +workspaces-switch-project-function +workspaces--project-dir)) + (+workspace-message + (format "Switched to '%s' in new workspace" new-name) + 'success)) + (with-current-buffer (doom-fallback-buffer) + (setq default-directory +workspaces--project-dir) + (hack-dir-local-variables-non-file-buffer) + (message "Switched to '%s'" (doom-project-name +workspaces--project-dir))) + (with-demoted-errors "Workspace error: %s" + (+workspace-rename (+workspace-current-name) (doom-project-name +workspaces--project-dir))) + (unless current-prefix-arg + (funcall +workspaces-switch-project-function +workspaces--project-dir))) + (run-hooks 'projectile-after-switch-project-hook) + (setq +workspaces--project-dir nil))))) ;;