Skip to content

Commit

Permalink
spacemacs-layouts: Add project buffers to new persp
Browse files Browse the repository at this point in the history
Fix issue #11282.

When a new perspective (layout) is created and we are in a Projectile
project, add all buffers belonging to that project to the perspective.

* layers/+spacemacs/spacemacs-layouts/funcs.el
(spacemacs//add-project-buffers-to-persp): Add new function.
* layers/+spacemacs/spacemacs-layouts/packages.el
(spacemacs-layouts/init-persp-mode): Add
spacemacs//add-project-buffers-to-persp to persp-created-functions.
  • Loading branch information
Miciah authored and duianto committed Apr 24, 2019
1 parent 31bff63 commit 9fcf8c8
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.develop
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,7 @@ Other:
- Fixed bug that could overwrites customize variables (thanks to bmag)
- Don't suggest ~SPC q r~ if =restart-emacs= package is missing after an
update (thanks to Keshav Kini)
- spacemacs-layouts: Add Projectile project buffers to new perspectives.
- Resolve symlinks in warning message about duplicate layers
(thanks to Ben Gamari)
- Check toggle condition in status function (thanks to Eivind Fonn)
Expand Down
8 changes: 8 additions & 0 deletions layers/+spacemacs/spacemacs-layouts/funcs.el
Original file line number Diff line number Diff line change
Expand Up @@ -689,3 +689,11 @@ containing the buffer."
(append (persp-parameter 'gui-eyebrowse-window-configs persp)
(persp-parameter 'term-eyebrowse-window-configs persp)))
(eyebrowse--rename-window-config-buffers window-config old new)))))


;; Persp and Projectile integration

(defun spacemacs//add-project-buffers-to-persp (persp _persp-hash)
(if-let ((buffers (and (projectile-project-p)
(projectile-project-buffers))))
(persp-add-buffer buffers persp nil nil)))
2 changes: 2 additions & 0 deletions layers/+spacemacs/spacemacs-layouts/packages.el
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,8 @@
(defadvice persp-activate (before spacemacs//save-toggle-layout activate)
(setq spacemacs--last-selected-layout persp-last-persp-name))
(add-hook 'persp-mode-hook 'spacemacs//layout-autosave)
(add-hook 'persp-created-functions
#'spacemacs//add-project-buffers-to-persp)
(advice-add 'persp-load-state-from-file :before 'spacemacs//layout-wait-for-modeline)
;; Override SPC TAB to only change buffers in perspective
(spacemacs/set-leader-keys
Expand Down

4 comments on commit 9fcf8c8

@ynilu
Copy link
Contributor

@ynilu ynilu commented on 9fcf8c8 Apr 29, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change make no sense to SPC p l users. Every time I want to open a project in new perspective, the buffers of the previous project are all added to the new perspective which is for another project.

@duianto
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Miciah Do you know how ynilu's issue could be solved?

@Miciah
Copy link
Contributor Author

@Miciah Miciah commented on 9fcf8c8 May 11, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for letting me know about the problem! Please see #12287 for a proposed solution.

@duianto
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ynilu The following PR is now on the develop branch:
spacemacs-layouts: Fix adding buffers to new persp #12287

Please sign in to comment.