Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make eyebrowse workspaces local to perspective #4068

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions layers/+window-management/spacemacs-layouts/funcs.el
Original file line number Diff line number Diff line change
Expand Up @@ -133,3 +133,44 @@ Cancels autosave on exiting perspectives mode."
(when spacemacs--layouts-autosave-timer
(cancel-timer spacemacs--layouts-autosave-timer)
(setq spacemacs--layouts-autosave-timer nil))))

;; Eyebrowse - allow perspective-local workspaces --------------------------

(defun spacemacs/load-eyebrowse-for-perspective (&optional frame)
"Load an eyebrowse workspace according to a perspective's parameters.
FRAME's perspective is the perspective that is considered, defaulting to
the current frame's perspective.
If the perspective doesn't have a workspace, create one."
(let* ((persp (get-frame-persp frame))
(window-configs (persp-parameter 'eyebrowse-window-configs persp))
(current-slot (persp-parameter 'eyebrowse-current-slot persp))
(last-slot (persp-parameter 'eyebrowse-last-slot persp)))
(if window-configs
(progn
(eyebrowse--set 'window-configs window-configs frame)
(eyebrowse--set 'current-slot current-slot frame)
(eyebrowse--set 'last-slot last-slot frame)
(eyebrowse--load-window-config current-slot))
(eyebrowse--set 'window-configs nil frame)
(eyebrowse-init frame)
(spacemacs/save-eyebrowse-for-perspective frame))))

(defun spacemacs/update-eyebrowse-for-perspective (_new-persp-name)
"Update and save current frame's eyebrowse workspace to its perspective.
Parameter _NEW-PERSP-NAME is ignored, and exists only for compatibility with
`persp-before-switch-functions'."
(eyebrowse--update-window-config-element
(eyebrowse--current-window-config (eyebrowse--get 'current-slot)
(eyebrowse--get 'current-tag)))
(spacemacs/save-eyebrowse-for-perspective))

(defun spacemacs/save-eyebrowse-for-perspective (&optional frame)
"Save FRAME's eyebrowse workspace to FRAME's perspective.
FRAME defaults to the current frame."
(let ((persp (get-frame-persp frame)))
(set-persp-parameter
'eyebrowse-window-configs (eyebrowse--get 'window-configs frame) persp)
(set-persp-parameter
'eyebrowse-current-slot (eyebrowse--get 'current-slot frame) persp)
(set-persp-parameter
'eyebrowse-last-slot (eyebrowse--get 'last-slot frame) persp)))
7 changes: 6 additions & 1 deletion layers/+window-management/spacemacs-layouts/packages.el
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
;; This file is not part of GNU Emacs.
;;
;;; License: GPLv3
(setq spacemacs-layouts-packages '(persp-mode spaceline))
(setq spacemacs-layouts-packages '(persp-mode spaceline eyebrowse))

(defun spacemacs-layouts/init-persp-mode ()
(use-package persp-mode
Expand Down Expand Up @@ -298,3 +298,8 @@ format so they are supported by the
(or (not (equal persp-nil-name
(safe-persp-name (get-frame-persp))))
dotspacemacs-display-default-layout))))

(defun spacemacs-layouts/post-init-eyebrowse ()
(add-hook 'persp-before-switch-functions #'spacemacs/update-eyebrowse-for-perspective)
(add-hook 'eyebrowse-post-window-switch-hook #'spacemacs/save-eyebrowse-for-perspective)
(add-hook 'persp-activated-hook #'spacemacs/load-eyebrowse-for-perspective))