-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Now that I understand better lazy loading and elisp I figured I'd give the perspectives layer another go. I try to replicate the microstate from Eyebrowse, but still working on the custom-perspectives.
- Loading branch information
Showing
3 changed files
with
171 additions
and
104 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,107 +1,163 @@ | ||
(setq perspectives-packages | ||
'( | ||
perspective | ||
persp-projectile | ||
)) | ||
'(perspective | ||
persp-projectile)) | ||
|
||
(defun perspectives/init-perspective () | ||
(use-package perspective | ||
:defer | ||
:commands (custom-persp | ||
persp-add-buffer | ||
persp-set-buffer | ||
persp-kill | ||
persp-remove-buffer | ||
persp-mode | ||
;; persp-cycle-next | ||
;; persp-cycle-prev | ||
persp-rename | ||
persp-switch | ||
projectile-persp-bridge | ||
) | ||
projectile-persp-bridge) | ||
:init | ||
(progn | ||
;; muh perspectives | ||
(defun custom-persp/emacs () | ||
(interactive) | ||
(custom-persp ".emacs.d" | ||
(find-file (locate-user-emacs-file "init.el")))) | ||
(persp-mode) | ||
|
||
(setq persp-show-modestring nil) | ||
(defun spacemacs/persp-change-to-number (number) | ||
(let* ((persps (persp-names)) | ||
(target-persp (nth number persps))) | ||
(persp-switch target-persp) | ||
(nth 1 (persp-names)))) | ||
|
||
(defun spacemacs/perspective-number () | ||
"Return the number of the current perspective." | ||
(let* ((num (eyebrowse--get 'current-slot)) | ||
(str (if num (int-to-string num)))) | ||
(cond | ||
((not (dotspacemacs|symbol-value | ||
dotspacemacs-mode-line-unicode-symbols)) str) | ||
((equal str "1") "➊") | ||
((equal str "2") "➋") | ||
((equal str "3") "➌") | ||
((equal str "4") "➍") | ||
((equal str "5") "➎") | ||
((equal str "6") "❻") | ||
((equal str "7") "➐") | ||
((equal str "8") "➑") | ||
((equal str "9") "➒") | ||
((equal str "0") "➓")))) | ||
|
||
(defun spacemacs/perspectives-ms-rename () | ||
"Rename a perspective and get back to micro-state." | ||
(interactive) | ||
(call-interactively #'persp-rename) | ||
(spacemacs/perspectives-micro-state)) | ||
|
||
(defun spacemacs//perspectives-ms-get-name-string (window-config) | ||
"Return the name for the given window-config" | ||
(let ((slot (car window-config)) | ||
(caption (eyebrowse-format-slot window-config))) | ||
(if (= slot current-slot) | ||
(format "[%s]" caption) | ||
caption))) | ||
|
||
(defun spacemacs//perspectives-ms-documentation () | ||
"Return the docstring for the perspectives micro-state." | ||
(let* ((current-persp (persp-name persp-curr)) | ||
(frame-perspectives (persp-names)) | ||
(all-perspectives (persp-all-names))) | ||
(concat | ||
"<" (when frame-perspectives | ||
(concat | ||
(mapconcat | ||
(lambda (persp) (persp-format-name persp)) | ||
frame-perspectives "> <") | ||
">" | ||
(when perspective-display-help | ||
(concat | ||
"\n[n] next, [p/N] previous, [TAB] back and forth, " | ||
"[c] close, [r] rename"))))))) | ||
|
||
(defun custom-persp/org () | ||
(interactive) | ||
(custom-persp "@org" | ||
(find-file (first org-agenda-files)))) | ||
(spacemacs|define-micro-state perspectives | ||
:doc (spacemacs//perspectives-ms-documentation) | ||
:use-minibuffer t | ||
:evil-leader "L" | ||
:bindings | ||
("<tab>" custom-persp-last) | ||
("c" persp-kill) | ||
("n" persp-next) | ||
("N" persp-prev) | ||
("p" persp-prev) | ||
("r" spacemacs/perspectives-ms-rename :exit t) | ||
("s" persp-switch :exit t)) | ||
|
||
(defun custom-persp/rcirc () | ||
(interactive) | ||
(custom-persp "@RCIRC" (spacemacs/rcirc nil))) | ||
;; Loading code for our custom perspectives | ||
;; Taken from Magnar Sveen | ||
(defmacro custom-persp (name &rest body) | ||
`(let ((initialize (not (gethash ,name perspectives-hash))) | ||
(current-perspective persp-curr)) | ||
(persp-switch ,name) | ||
(when initialize ,@body) | ||
(setq persp-last current-perspective))) | ||
|
||
(spacemacs/declare-prefix "L" "layouts") | ||
(spacemacs/declare-prefix "Lo" "custom-perspectives") | ||
(evil-leader/set-key | ||
"La" 'persp-add-buffer | ||
"LA" 'persp-set-buffer | ||
"Lc" 'persp-kill | ||
"Lk" 'persp-remove-buffer | ||
"Ln" 'persp-next | ||
"Loe" 'custom-persp/emacs | ||
"Loi" 'custom-persp/rcirc | ||
"Loo" 'custom-persp/org | ||
"Lp" 'persp-prev | ||
"Lr" 'persp-rename | ||
"Ls" 'persp-switch)) | ||
:config | ||
(progn | ||
(persp-mode t) | ||
;; loading code for our custom perspectives | ||
;; taken from Magnar Sveen | ||
(defmacro custom-persp (name &rest body) | ||
`(let ((initialize (not (gethash ,name perspectives-hash))) | ||
(current-perspective persp-curr)) | ||
(persp-switch ,name) | ||
(when initialize ,@body) | ||
(setq persp-last current-perspective))) | ||
(defun custom-persp/emacs () | ||
(interactive) | ||
(custom-persp ".emacs.d" | ||
(find-file (locate-user-emacs-file "init.el")))) | ||
|
||
(add-hook 'emacs-startup-hook '(lambda () | ||
(persp-rename "@spacemacs"))) | ||
;; Jump to last perspective | ||
;; taken from Magnar Sveen | ||
(defun custom-persp-last () | ||
(interactive) | ||
(persp-switch (persp-name persp-last))) | ||
(defun custom-persp/org () | ||
(interactive) | ||
(custom-persp "@org" | ||
(find-file (first org-agenda-files)))) | ||
|
||
;; (defun persp-cycle-next () | ||
;; "Cycle throught the available perspectives." | ||
;; (interactive) | ||
;; (let ((next-pos (1+ (persp-name persp-curr))) | ||
;; (list-size (length (persp-all-names)))) | ||
;; (cond ((eq 1 list-size) (persp-switch nil)) | ||
;; ((>= next-pos list-size) (persp-switch (nth 0 (persp-all-names)))) | ||
;; (t (persp-next))))) | ||
;; (defun persp-cycle-prev () | ||
;; "Cycle throught the available perspectives." | ||
;; (interactive) | ||
;; (let ((next-pos (- (persp-name persp-curr) 1)) | ||
;; (list-size (length (persp-all-names)))) | ||
;; (cond ((eq 1 list-size) (persp-switch nil)) | ||
;; ((< next-pos 0) (persp-switch (nth (- list-size 1) (persp-all-names)))) | ||
;; (t (persp-prev))))) | ||
) | ||
(defun custom-persp/rcirc () | ||
(interactive) | ||
(custom-persp "@RCIRC" (spacemacs/rcirc nil))) | ||
|
||
;; Jump to last perspective | ||
;; taken from Magnar Sveen | ||
(defun custom-persp-last () | ||
(interactive) | ||
(persp-switch (persp-name persp-last))) | ||
|
||
;; (defun persp-cycle-next () | ||
;; "Cycle throught the available perspectives." | ||
;; (interactive) | ||
;; (let ((next-pos (1+ (persp-name persp-curr))) | ||
;; (list-size (length (persp-all-names)))) | ||
;; (cond ((eq 1 list-size) (persp-switch nil)) | ||
;; ((>= next-pos list-size) (persp-switch (nth 0 (persp-all-names)))) | ||
;; (t (persp-next))))) | ||
;; (defun persp-cycle-prev () | ||
;; "Cycle throught the available perspectives." | ||
;; (interactive) | ||
;; (let ((next-pos (- (persp-name persp-curr) 1)) | ||
;; (list-size (length (persp-all-names)))) | ||
;; (cond ((eq 1 list-size) (persp-switch nil)) | ||
;; ((< next-pos 0) (persp-switch (nth (- list-size 1) (persp-all-names)))) | ||
;; (t (persp-prev))))) | ||
)) | ||
|
||
(defun perspectives/init-persp-projectile () | ||
(use-package persp-projectile | ||
:commands (projectile-persp-bridge) | ||
:if perspective-enable-persp-projectile | ||
:config | ||
(progn | ||
(projectile-persp-bridge helm-projectile-switch-project) | ||
|
||
(evil-leader/set-key | ||
"pp" 'spacemacs/persp-switch-project) | ||
|
||
(defun spacemacs/persp-switch-project () | ||
(interactive) | ||
(evil-leader/set-key | ||
"pp" 'helm-projectile-switch-project) | ||
(find-file "~/.spacemacs") | ||
(helm-projectile-switch-project) | ||
(persp-add-buffer "*spacemacs*") | ||
(persp-kill "@spacemacs"))))) | ||
:init | ||
(defvar persp-projectile-helm-source-projects | ||
(helm-build-in-buffer-source "Projectile projects" | ||
:data (lambda () | ||
(if (projectile-project-p) | ||
(cons (abbreviate-file-name (projectile-project-root)) | ||
(projectile-relevant-known-projects)) | ||
projectile-known-projects)) | ||
:fuzzy-match helm-projectile-fuzzy-match | ||
:mode-line helm-read-file-name-mode-line-string | ||
:action '(("Switch to project" . | ||
(lambda (project) | ||
(projectile-persp-switch-project project))))) | ||
"Helm source for known projectile projects.") | ||
(defun helm-projectile-persp-switch-project (arg) | ||
(interactive "P") | ||
(if arg | ||
(helm-projectile-switch-project) | ||
(helm :sources persp-projectile-helm-source-projects | ||
:buffer "*persp projectile helm*"))) | ||
(evil-leader/set-key | ||
"pp" 'helm-projectile-persp-switch-project))) |