feature/workspaces: refactor persp-mode init

This commit is contained in:
Henrik Lissner 2018-01-03 13:24:11 -05:00
parent 73fa9ceab3
commit f3562eb038
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395
3 changed files with 118 additions and 66 deletions

View file

@ -187,6 +187,13 @@ buffers."
+workspaces-main)))
(persp-frame-switch name))
;;;###autoload
(defun +workspace-on-new-frame (frame &optional _new-frame-p)
"Spawn a perspective for each new frame."
(select-frame frame)
(+workspace/new)
(set-frame-parameter frame 'assoc-persp (+workspace-current-name)))
;;
;; Interactive commands
@ -473,12 +480,10 @@ the workspace and move to the next."
(interactive)
(message "%s" (+workspace--tabline)))
;;;###autoload
(defun +workspace-on-new-frame (frame &optional _new-frame-p)
"Spawn a perspective for each new frame."
(select-frame frame)
(+workspace/new)
(set-frame-parameter frame 'assoc-persp (+workspace-current-name)))
;;
;; Hooks
;;
;;;###autoload
(defun +workspaces|delete-associated-workspace-maybe (frame)
@ -489,6 +494,32 @@ the workspace and move to the next."
(not (equal frame-persp +workspaces-main)))
(+workspace/delete frame-persp)))))
;;;###autoload
(defun +workspaces|per-project (&optional root)
"Open a new workspace when switching to another project.
Ensures the scratch (or dashboard) buffers are CDed into the project's root."
(when persp-mode
(let ((cwd default-directory))
(+workspace-switch (projectile-project-name) t)
(switch-to-buffer (doom-fallback-buffer))
(setq default-directory cwd)
(+workspace-message
(format "Switched to '%s' in new workspace" (+workspace-current-name))
'success))))
;;;###autoload
(defun +workspaces|cleanup-unassociated-buffers ()
(cl-loop for buf in (buffer-list)
unless (persp--buffer-in-persps buf)
if (kill-buffer buf)
do (cl-incf n)))
;;
;; Advice
;;
;;;###autoload
(defun +workspaces*autosave-real-buffers (orig-fn &rest args)
"Don't autosave if no real buffers are open."