Last active
October 30, 2016 02:52
-
-
Save rakanalh/00d4e208c61c49e08a713290ed4c9a28 to your computer and use it in GitHub Desktop.
Emacs - Git branch based perspectives
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defun close-all-buffers () | |
(interactive) | |
(mapc 'kill-buffer (buffer-list))) | |
(defun persp/get-root (branch-name) | |
(let ((current-project (projectile-project-name))) | |
(message current-project) | |
(message branch-name) | |
(if (and (not current-project) (not branch-name)) | |
(error "Could not find persp root")) | |
(if (and current-project branch-name) | |
(concat current-project "-" branch-name) | |
(if current-project | |
current-project | |
branch-name)))) | |
(defun persp/close-perspective (&optional closed-branch) | |
(interactive) | |
(let* ((current-branch (if closed-branch | |
closed-branch | |
(magit-get-current-branch))) | |
(persp-project-root (persp/get-root current-branch))) | |
(if persp-project-root | |
(progn | |
(message (concat "Saving " persp-project-root ".persp")) | |
(persp-save-state-to-file (concat persp-project-root ".persp")) | |
(close-all-buffers))))) | |
(defun persp/switch-to-current-branch-persp () | |
(interactive) | |
(let ((closed-branch (magit-get-previous-branch))) | |
(persp/close-perspective closed-branch)) | |
(message "Closed perspective") | |
(let ((persp-project-root (persp/get-root (magit-get-current-branch)))) | |
(message (concat "Loading " persp-project-root ".persp")) | |
(persp-load-state-from-file (concat persp-project-root ".persp")))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(use-package persp-mode | |
:init | |
(persp-mode) | |
(setq persp-save-dir (concat private-dir "/persp-confs/") | |
persp-auto-save-opt 0) | |
:config | |
(add-hook 'kill-emacs-hook 'persp/close-perspective) | |
:bind | |
("C-x p p" . persp/switch-to-current-branch-persp)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment