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))
|
(setq +workspaces--project-dir default-directory))
|
||||||
|
|
||||||
;;;###autoload
|
;;;###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
|
"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
|
to it. If in the main workspace and it's empty, recycle that workspace, without
|
||||||
renaming it.
|
renaming it.
|
||||||
|
|
||||||
Should be hooked to `projectile-after-switch-project-hook'."
|
Should be hooked to `projectile-after-switch-project-hook'."
|
||||||
|
(when dir
|
||||||
|
(setq +workspaces--project-dir dir))
|
||||||
(when (and persp-mode +workspaces--project-dir)
|
(when (and persp-mode +workspaces--project-dir)
|
||||||
(unwind-protect
|
(unwind-protect
|
||||||
(if (+workspace-buffer-list)
|
(if (+workspace-buffer-list)
|
||||||
(let (persp-p)
|
(let* (persp-p
|
||||||
(let* ((persp
|
(persp
|
||||||
(let* ((default-directory +workspaces--project-dir)
|
(let* ((default-directory +workspaces--project-dir)
|
||||||
(project-name (doom-project-name 'nocache)))
|
(project-name (doom-project-name 'nocache)))
|
||||||
(or (setq persp-p (+workspace-get project-name t))
|
(or (setq persp-p (+workspace-get project-name t))
|
||||||
(+workspace-new project-name))))
|
(+workspace-new project-name))))
|
||||||
(new-name (persp-name persp)))
|
(new-name (persp-name persp)))
|
||||||
(+workspace-switch new-name)
|
(+workspace-switch new-name)
|
||||||
(unless persp-p
|
(unless persp-p
|
||||||
(switch-to-buffer (doom-fallback-buffer)))
|
(switch-to-buffer (doom-fallback-buffer)))
|
||||||
(unless inhibit-prompt
|
(with-current-buffer (doom-fallback-buffer)
|
||||||
(doom-project-find-file +workspaces--project-dir))
|
(setq default-directory +workspaces--project-dir))
|
||||||
(+workspace-message
|
(funcall +workspaces-switch-project-function +workspaces--project-dir)
|
||||||
(format "Switched to '%s' in new workspace" new-name)
|
(+workspace-message
|
||||||
'success)))
|
(format "Switched to '%s' in new workspace" new-name)
|
||||||
|
'success))
|
||||||
(with-current-buffer (switch-to-buffer (doom-fallback-buffer))
|
(with-current-buffer (switch-to-buffer (doom-fallback-buffer))
|
||||||
(setq default-directory +workspaces--project-dir)
|
(setq default-directory +workspaces--project-dir)
|
||||||
(message "Switched to '%s'" (doom-project-name 'nocache)))
|
(message "Switched to '%s'" (doom-project-name 'nocache)))
|
||||||
(unless inhibit-prompt
|
(funcall +workspaces-switch-project-function +workspaces--project-dir))
|
||||||
(doom-project-find-file +workspaces--project-dir)))
|
|
||||||
(setq +workspaces--project-dir nil))))
|
(setq +workspaces--project-dir nil))))
|
||||||
|
|
||||||
|
|
||||||
|
@ -533,14 +535,6 @@ Should be hooked to `projectile-after-switch-project-hook'."
|
||||||
;; Advice
|
;; 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
|
;;;###autoload
|
||||||
(defun +workspaces*autosave-real-buffers (orig-fn &rest args)
|
(defun +workspaces*autosave-real-buffers (orig-fn &rest args)
|
||||||
"Don't autosave if no real buffers are open."
|
"Don't autosave if no real buffers are open."
|
||||||
|
|
|
@ -16,6 +16,11 @@
|
||||||
"The name of the primary and initial workspace, which cannot be deleted or
|
"The name of the primary and initial workspace, which cannot be deleted or
|
||||||
renamed.")
|
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
|
;; FIXME actually use this for wconf bookmark system
|
||||||
(defvar +workspaces-data-file "_workspaces"
|
(defvar +workspaces-data-file "_workspaces"
|
||||||
"The basename of the file to store single workspace perspectives. Will be
|
"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)
|
(add-hook 'delete-frame-functions #'+workspaces|delete-associated-workspace)
|
||||||
|
|
||||||
;; per-project workspaces
|
;; per-project workspaces
|
||||||
(setq projectile-switch-project-action #'+workspaces|set-project-action)
|
(setq projectile-switch-project-action #'+workspaces|set-project-action
|
||||||
(advice-add #'counsel-projectile-switch-project-by-name :before #'+workspaces*switch-counsel-project-action)
|
counsel-projectile-switch-project-action #'+workspaces|switch-to-project)
|
||||||
(add-hook 'projectile-after-switch-project-hook #'+workspaces|switch-to-project)
|
(add-hook 'projectile-after-switch-project-hook #'+workspaces|switch-to-project)
|
||||||
|
|
||||||
;;
|
;;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue