feature/workspaces: refactor switch-project integration
This commit is contained in:
parent
7bfd0a3304
commit
e659ab0609
2 changed files with 27 additions and 28 deletions
|
@ -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."
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue