And prevent explicit projectile-project-root interfering with project switching.
This commit is contained in:
parent
db25224e18
commit
60ca118eb2
2 changed files with 40 additions and 53 deletions
|
@ -39,23 +39,6 @@ Emacs.")
|
||||||
:config
|
:config
|
||||||
(projectile-mode +1)
|
(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 runs four functions to determine the root (in this order):
|
||||||
;;
|
;;
|
||||||
;; + `projectile-root-local' -> checks the `projectile-project-root' variable
|
;; + `projectile-root-local' -> checks the `projectile-project-root' variable
|
||||||
|
|
|
@ -525,42 +525,46 @@ the user to open a file in the new project.
|
||||||
This be hooked to `projectile-after-switch-project-hook'."
|
This be hooked to `projectile-after-switch-project-hook'."
|
||||||
(when dir
|
(when dir
|
||||||
(setq +workspaces--project-dir dir))
|
(setq +workspaces--project-dir dir))
|
||||||
(when (and persp-mode +workspaces--project-dir)
|
;; HACK Clear projectile-project-root, otherwise cached roots may interfere
|
||||||
(when projectile-before-switch-project-hook
|
;; with project switch (see #3166)
|
||||||
(with-temp-buffer
|
(let (projectile-project-root)
|
||||||
;; Load the project dir-local variables into the switch buffer, so the
|
(when (and persp-mode +workspaces--project-dir)
|
||||||
;; action can make use of them
|
(when projectile-before-switch-project-hook
|
||||||
(setq default-directory +workspaces--project-dir)
|
(with-temp-buffer
|
||||||
(hack-dir-local-variables-non-file-buffer)
|
;; Load the project dir-local variables into the switch buffer, so the
|
||||||
(run-hooks 'projectile-before-switch-project-hook)))
|
;; action can make use of them
|
||||||
(unwind-protect
|
(setq default-directory +workspaces--project-dir)
|
||||||
(if (and (not (null +workspaces-on-switch-project-behavior))
|
(hack-dir-local-variables-non-file-buffer)
|
||||||
(or (eq +workspaces-on-switch-project-behavior t)
|
(run-hooks 'projectile-before-switch-project-hook)))
|
||||||
(equal (safe-persp-name (get-current-persp)) persp-nil-name)
|
(unwind-protect
|
||||||
(+workspace-buffer-list)))
|
(if (and (not (null +workspaces-on-switch-project-behavior))
|
||||||
(let* ((persp
|
(or (eq +workspaces-on-switch-project-behavior t)
|
||||||
(let ((project-name (doom-project-name +workspaces--project-dir)))
|
(equal (safe-persp-name (get-current-persp)) persp-nil-name)
|
||||||
(or (+workspace-get project-name t)
|
(+workspace-buffer-list)))
|
||||||
(+workspace-new project-name))))
|
(let* ((persp
|
||||||
(new-name (persp-name persp)))
|
(let ((project-name (doom-project-name +workspaces--project-dir)))
|
||||||
(+workspace-switch new-name)
|
(or (+workspace-get project-name t)
|
||||||
(with-current-buffer (doom-fallback-buffer)
|
(+workspace-new project-name))))
|
||||||
(setq default-directory +workspaces--project-dir))
|
(new-name (persp-name persp)))
|
||||||
(unless current-prefix-arg
|
(+workspace-switch new-name)
|
||||||
(funcall +workspaces-switch-project-function +workspaces--project-dir))
|
(with-current-buffer (doom-fallback-buffer)
|
||||||
(+workspace-message
|
(setq default-directory +workspaces--project-dir)
|
||||||
(format "Switched to '%s' in new workspace" new-name)
|
(hack-dir-local-variables-non-file-buffer))
|
||||||
'success))
|
(unless current-prefix-arg
|
||||||
(with-current-buffer (doom-fallback-buffer)
|
(funcall +workspaces-switch-project-function +workspaces--project-dir))
|
||||||
(setq default-directory +workspaces--project-dir)
|
(+workspace-message
|
||||||
(hack-dir-local-variables-non-file-buffer)
|
(format "Switched to '%s' in new workspace" new-name)
|
||||||
(message "Switched to '%s'" (doom-project-name +workspaces--project-dir)))
|
'success))
|
||||||
(with-demoted-errors "Workspace error: %s"
|
(with-current-buffer (doom-fallback-buffer)
|
||||||
(+workspace-rename (+workspace-current-name) (doom-project-name +workspaces--project-dir)))
|
(setq default-directory +workspaces--project-dir)
|
||||||
(unless current-prefix-arg
|
(hack-dir-local-variables-non-file-buffer)
|
||||||
(funcall +workspaces-switch-project-function +workspaces--project-dir)))
|
(message "Switched to '%s'" (doom-project-name +workspaces--project-dir)))
|
||||||
(run-hooks 'projectile-after-switch-project-hook)
|
(with-demoted-errors "Workspace error: %s"
|
||||||
(setq +workspaces--project-dir nil))))
|
(+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)))))
|
||||||
|
|
||||||
|
|
||||||
;;
|
;;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue