Skip to content

Switch to last active perspective on layout autoresume#141

Open
GreenRecycleBin wants to merge 2 commits intoBad-ptr:masterfrom
GreenRecycleBin:switch-to-last-active-perspective-on-layout-autoresume
Open

Switch to last active perspective on layout autoresume#141
GreenRecycleBin wants to merge 2 commits intoBad-ptr:masterfrom
GreenRecycleBin:switch-to-last-active-perspective-on-layout-autoresume

Conversation

@GreenRecycleBin
Copy link

Spacemacs supports autoresuming layouts on startup by setting dotspacemacs-auto-resume-layouts to t. However, the last active perspective is not switched to automatically. Instead, the default, i.e., nil perspective is.

This PR:

  • Adds an active field to the perspective struct
  • Adds bookkeeping for the new field when (de)activating perspectives
  • Saves/loads the field
  • Switches to the last active perspective after load

I tested it manually and it worked. On startup, Spacemacs autoresumes the layouts, and additionally switched to the last active perspective. The only extra step, specific to Spacemacs, is to close the Spacemacs buffer because there's no option to disable it on startup except for changing the code.

(I also tried reusing persp-special-last-buffer here, but that didn't work because it's cleared and only set on mode activation.)

@GreenRecycleBin GreenRecycleBin force-pushed the switch-to-last-active-perspective-on-layout-autoresume branch from 525df32 to f01a5f6 Compare May 22, 2023 10:27
@GreenRecycleBin
Copy link
Author

@Bad-ptr Would you be able to review this? 👋

@GreenRecycleBin GreenRecycleBin force-pushed the switch-to-last-active-perspective-on-layout-autoresume branch from f01a5f6 to 43afefd Compare May 27, 2023 11:36
@Bad-ptr
Copy link
Owner

Bad-ptr commented Sep 26, 2023

Adds an active field to the perspective struct

I think that you can utilize the "perspective parameters" feature. By using persp-parameter, set-persp-parameter, delete-persp-parameter functions. So that when you switch perspectives the last-active parameter will be deleted for a currently active perspective and set to t for a perspective you are switching to. Then it will be save/loaded for free.

Add to the persp-after-load-state-functions a function like

(defun persp-switch-to-last-active-after-load (file phash persp-names)
  (when (eq phash *persp-hash*) ;; this 'when' is important
    (when-let ((la-persp (find-if (apply-partially #'persp-parameter 'last-active)
                                  (persp-persps))))
      (persp-switch (safe-persp-name la-persp)))))

And to the persp-before-switch-functions:

(defun persp-before-switch-track-last-active (name f-or-w)
  (delete-persp-parameter 'last-active (current-persp))
  (when-let ((new-a-p (persp-add-new name)))
    (set-persp-parameter 'last-active t new-a-p)))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants