layouts and workspace: use new transient state keywords

Also cleanup the code and unify key bindings to make them consistent
between the two transient states.
This commit is contained in:
syl20bnr 2016-03-04 19:05:28 -05:00
parent bfec254221
commit e2dbe1938c
3 changed files with 70 additions and 100 deletions

View file

@ -63,8 +63,8 @@ Set the variable =eyebrowse-display-help= to =nil=
| ~[1..9, 0]~ | switch to nth workspace | | ~[1..9, 0]~ | switch to nth workspace |
| ~[C-1..C-9, C-0]~ | switch to nth workspace and keep the transient state active | | ~[C-1..C-9, C-0]~ | switch to nth workspace and keep the transient state active |
| ~TAB~ | switch to last active workspace | | ~TAB~ | switch to last active workspace |
| ~c~ | close current workspace | | ~d~ | close current workspace |
| ~n~ or ~l~ | switch to next workspace | | ~n~ or ~l~ | switch to next workspace |
| ~N~ or ~p~ or ~h~ | switch to previous workspace | | ~N~ or ~p~ or ~h~ | switch to previous workspace |
| ~r~ | set a tag to the current workspace | | ~R~ | set a tag to the current workspace |
| ~w~ | switched to tagged workspace | | ~w~ | switched to tagged workspace |

View file

@ -56,32 +56,27 @@ workspace, preferably in the current window."
display-buffer-same-window) display-buffer-same-window)
(inhibit-same-window . nil)))) (inhibit-same-window . nil))))
(defun spacemacs/workspaces-ms-rename () (defun spacemacs/workspaces-ts-rename ()
"Rename a workspace and get back to transient-state." "Rename a workspace and get back to transient-state."
(interactive) (interactive)
(eyebrowse-rename-window-config (eyebrowse--get 'current-slot) nil) (eyebrowse-rename-window-config (eyebrowse--get 'current-slot) nil)
(spacemacs/workspaces-transient-state/body)) (spacemacs/workspaces-transient-state/body))
(defun spacemacs//workspaces-ms-get-slot-name (window-config) (spacemacs|transient-state-format-hint workspaces
"Return the name for the given window-config" spacemacs--workspaces-ts-full-hint
(let ((slot (car window-config)) "\n\n
(caption (eyebrowse-format-slot window-config))) Go to^^^^^^ Remove/Rename...^^
(if (= slot current-slot) --^-^--^^^^----------------------- --^-^---------------------------
(format "[%s]" caption) [_0_,_9_]^^ nth/new workspace [_d_] close current workspace
caption))) [_C-0_,_C-9_]^^ nth/new workspace [_R_] rename current workspace
[_n_/_C-l_]^^ next workspace
(defun spacemacs//workspaces-ms-get-window-configs () [_N_/_p_/_C-h_] prev workspace
"Return the list of window configs." [_<tab>_]^^^^ last workspace\n")
(--sort (if (eq (car other) 0)
t
(< (car it) (car other)))
(eyebrowse--get 'window-configs)))
(spacemacs|define-transient-state workspaces (spacemacs|define-transient-state workspaces
:title "Workspaces Transient State" :title "Workspaces Transient State"
:additional-docs :hint-is-doc t
(spacemacs--workspaces-ms-documentation . :dynamic-hint (spacemacs//workspaces-ts-hint)
"\n\n[_0_.._9_] switch to workspace [_n_/_p_] next/prev [_<tab>_] last [_c_] close [_r_] rename")
:bindings :bindings
("0" eyebrowse-switch-to-window-config-0 :exit t) ("0" eyebrowse-switch-to-window-config-0 :exit t)
("1" eyebrowse-switch-to-window-config-1 :exit t) ("1" eyebrowse-switch-to-window-config-1 :exit t)
@ -104,18 +99,20 @@ workspace, preferably in the current window."
("C-8" eyebrowse-switch-to-window-config-8) ("C-8" eyebrowse-switch-to-window-config-8)
("C-9" eyebrowse-switch-to-window-config-9) ("C-9" eyebrowse-switch-to-window-config-9)
("<tab>" eyebrowse-last-window-config) ("<tab>" eyebrowse-last-window-config)
("C-h" eyebrowse-prev-window-config)
("C-i" eyebrowse-last-window-config) ("C-i" eyebrowse-last-window-config)
("c" eyebrowse-close-window-config) ("C-l" eyebrowse-next-window-config)
("d" eyebrowse-close-window-config)
("h" eyebrowse-prev-window-config) ("h" eyebrowse-prev-window-config)
("l" eyebrowse-next-window-config) ("l" eyebrowse-next-window-config)
("n" eyebrowse-next-window-config) ("n" eyebrowse-next-window-config)
("N" eyebrowse-prev-window-config) ("N" eyebrowse-prev-window-config)
("p" eyebrowse-prev-window-config) ("p" eyebrowse-prev-window-config)
("r" spacemacs/workspaces-ms-rename :exit t) ("R" spacemacs/workspaces-ts-rename :exit t)
("w" eyebrowse-switch-to-window-config :exit t)) ("w" eyebrowse-switch-to-window-config :exit t))
(defun spacemacs//workspace-format-name (workspace) (defun spacemacs//workspace-format-name (workspace)
"Return a porpertized string given a WORKSPACE name."
(let* ((current (eq (eyebrowse--get 'current-slot) (car workspace))) (let* ((current (eq (eyebrowse--get 'current-slot) (car workspace)))
(name (nth 2 workspace)) (name (nth 2 workspace))
(number (car workspace)) (number (car workspace))
@ -126,25 +123,13 @@ workspace, preferably in the current window."
(propertize (concat "[" caption "]") 'face 'warning) (propertize (concat "[" caption "]") 'face 'warning)
caption))) caption)))
(defun spacemacs//workspaces-ms-list () (defun spacemacs//workspaces-ts-hint ()
"Return the list of workspaces for the workspacae "Return a one liner string containing all the workspace names."
transient state."
(mapconcat 'spacemacs//workspace-format-name
(eyebrowse--get 'window-configs)
" | "))
(add-hook
'spacemacs-post-user-config-hook
(lambda ()
(setq spacemacs/workspaces-transient-state/hint
`(concat
,(when dotspacemacs-show-transient-state-title
(concat (concat
(propertize "Workspaces Transient State" " "
'face 'spacemacs-transient-state-title-face) (mapconcat 'spacemacs//workspace-format-name
"\n")) (eyebrowse--get 'window-configs) " | ")
(spacemacs//workspaces-ms-list) (when eyebrowse-display-help spacemacs--workspaces-ts-full-hint)))
spacemacs--workspaces-ms-documentation))) 'append)
;; The layouts layer defines this keybinding inside a transient-state ;; The layouts layer defines this keybinding inside a transient-state
;; thus this is only needed if that layer is not used ;; thus this is only needed if that layer is not used

View file

@ -35,7 +35,7 @@
;; always activate persp-mode ;; always activate persp-mode
(persp-mode) (persp-mode)
(defvar spacemacs--layouts-ms-doc-toggle 0 (defvar spacemacs--layouts-ts-full-hint-toggle 0
"Display a short doc when nil, full doc otherwise.") "Display a short doc when nil, full doc otherwise.")
(defvar spacemacs--last-selected-layout persp-nil-name (defvar spacemacs--last-selected-layout persp-nil-name
@ -58,11 +58,11 @@
;; Perspectives transient-state ------------------------------------------- ;; Perspectives transient-state -------------------------------------------
(defun spacemacs//layouts-ms-toggle-doc () (defun spacemacs//layouts-ts-toggle-hint ()
"Toggle the full documenation for the layouts transient-state." "Toggle the full hint docstring for the layouts transient-state."
(interactive) (interactive)
(setq spacemacs--layouts-ms-doc-toggle (setq spacemacs--layouts-ts-full-hint-toggle
(logxor spacemacs--layouts-ms-doc-toggle 1))) (logxor spacemacs--layouts-ts-full-hint-toggle 1)))
(defun spacemacs//layout-format-name (name pos) (defun spacemacs//layout-format-name (name pos)
"Format the layout name given by NAME for display in mode-line." "Format the layout name given by NAME for display in mode-line."
@ -77,49 +77,52 @@
(propertize (concat "[" caption "]") 'face 'warning) (propertize (concat "[" caption "]") 'face 'warning)
caption))) caption)))
(defun spacemacs//layouts-ms-doc () (defun spacemacs//layouts-ts-hint ()
"Return the docstring for the layouts transient-state." "Return a one liner string containing all the layout names."
(let* ((persp-list (or (persp-names-current-frame-fast-ordered) (let* ((persp-list (or (persp-names-current-frame-fast-ordered)
(list persp-nil-name))) (list persp-nil-name)))
(formatted-persp-list (formatted-persp-list
(concat (concat " "
(mapconcat (mapconcat (lambda (persp)
(lambda (persp)
(spacemacs//layout-format-name (spacemacs//layout-format-name
persp (position persp persp-list))) persp-list " | ")))) persp (position persp persp-list)))
(concat formatted-persp-list persp-list " | "))))
(if (equal 1 spacemacs--layouts-ms-doc-toggle)
spacemacs--layouts-ms-documentation
(concat (concat
"\n [" formatted-persp-list
(if (equal 1 spacemacs--layouts-ts-full-hint-toggle)
spacemacs--layouts-ts-full-hint
(concat " (["
(propertize "?" 'face 'hydra-face-red) (propertize "?" 'face 'hydra-face-red)
"] toggle help"))))) "] help)")))))
(spacemacs|define-transient-state layouts (spacemacs|transient-state-format-hint layouts
:title "Layouts Transient State" spacemacs--layouts-ts-full-hint
:additional-docs "\n\n
(spacemacs--layouts-ms-documentation . Go to^^^^^^ Add/Remove/Rename...^^
"\n
Go to^^^^^^ Add/Remove/Rename^^
--^-^--^^^^----------------------- --^-^--------------------------- --^-^--^^^^----------------------- --^-^---------------------------
[_b_]^^^^ buffer in layout [_a_] add buffer [_b_]^^^^ buffer in layout [_a_] add buffer
[_h_]^^^^ default layout [_A_] add all from layout [_h_]^^^^ default layout [_A_] add all from layout
[_o_]^^^^ custom layout [_r_] remove current buffer [_o_]^^^^ custom layout [_r_] remove current buffer
[_l_]^^^^ layout w/helm/ivy [_d_] close current layout [_l_]^^^^ layout w/helm/ivy [_d_] close current layout
[_L_]^^^^ layouts in file [_D_] close other layout [_L_]^^^^ layouts in file [_D_] close other layout
[_0_,_9_]^^ nth layout [_x_] kill current w/buffers [_0_,_9_]^^ nth/new layout [_x_] kill current w/buffers
[_n_/_C-l_]^^ next layout [_X_] kill other w/buffers [_C-0_,_C-9_]^^ nth/new layout [_X_] kill other w/buffers
[_N_/_p_/_C-h_] prev layout [_R_] rename current layout [_n_/_C-l_]^^ next layout [_R_] rename current layout
[_N_/_p_/_C-h_] prev layout
[_<tab>_]^^^^ last layout [_<tab>_]^^^^ last layout
--^^^^^^^^---------------------------------------------------------- --^^^^^^^^----------------------------------------------------------
[_s_/_S_] save all layouts/save by names [_s_/_S_] save all layouts/save by names
[_t_]^^ show a buffer without adding it to current layout [_t_]^^ show a buffer without adding it to current layout
[_w_]^^ workspaces micro-state (requires eyebrowse layer) [_w_]^^ workspaces micro-state (requires eyebrowse layer)
[_?_]^^ toggle help [_?_]^^ toggle help\n")
")
(spacemacs|define-transient-state layouts
:title "Layouts Transient State"
:hint-is-doc t
:dynamic-hint (spacemacs//layouts-ts-hint)
:bindings :bindings
;; need to exit in case number doesn't exist ;; need to exit in case number doesn't exist
("?" spacemacs//layouts-ms-toggle-doc) ("?" spacemacs//layouts-ts-toggle-hint)
("1" spacemacs/persp-switch-to-1 :exit t) ("1" spacemacs/persp-switch-to-1 :exit t)
("2" spacemacs/persp-switch-to-2 :exit t) ("2" spacemacs/persp-switch-to-2 :exit t)
("3" spacemacs/persp-switch-to-3 :exit t) ("3" spacemacs/persp-switch-to-3 :exit t)
@ -147,8 +150,8 @@
("a" persp-add-buffer :exit t) ("a" persp-add-buffer :exit t)
("A" persp-import-buffers :exit t) ("A" persp-import-buffers :exit t)
("b" spacemacs/persp-helm-mini :exit t) ("b" spacemacs/persp-helm-mini :exit t)
("d" spacemacs/layouts-ms-close) ("d" spacemacs/layouts-ts-close)
("D" spacemacs/layouts-ms-close-other :exit t) ("D" spacemacs/layouts-ts-close-other :exit t)
("h" spacemacs/layout-goto-default :exit t) ("h" spacemacs/layout-goto-default :exit t)
("l" spacemacs/helm-perspectives :exit t) ("l" spacemacs/helm-perspectives :exit t)
("L" persp-load-state-from-file :exit t) ("L" persp-load-state-from-file :exit t)
@ -157,28 +160,15 @@
("o" spacemacs/select-custom-layout :exit t) ("o" spacemacs/select-custom-layout :exit t)
("p" persp-prev) ("p" persp-prev)
("r" persp-remove-buffer :exit t) ("r" persp-remove-buffer :exit t)
("R" spacemacs/layouts-ms-rename :exit t) ("R" spacemacs/layouts-ts-rename :exit t)
("s" persp-save-state-to-file :exit t) ("s" persp-save-state-to-file :exit t)
("S" persp-save-to-file-by-names :exit t) ("S" persp-save-to-file-by-names :exit t)
("t" persp-temporarily-display-buffer :exit t) ("t" persp-temporarily-display-buffer :exit t)
("w" spacemacs/layout-workspaces-transient-state :exit t) ("w" spacemacs/layout-workspaces-transient-state :exit t)
("x" spacemacs/layouts-ms-kill) ("x" spacemacs/layouts-ts-kill)
("X" spacemacs/layouts-ms-kill-other :exit t)) ("X" spacemacs/layouts-ts-kill-other :exit t))
(spacemacs/set-leader-keys "l" 'spacemacs/layouts-transient-state/body) (spacemacs/set-leader-keys "l" 'spacemacs/layouts-transient-state/body)
;; This enables the dynamic behavior from micro-states using ?
(add-hook 'spacemacs-post-user-config-hook
(lambda ()
(setq spacemacs/layouts-transient-state/hint
`(concat
,(when dotspacemacs-show-transient-state-title
(concat
(propertize "Layouts Transient State"
'face 'spacemacs-transient-state-title-face)
"\n"))
(spacemacs//layouts-ms-doc))))
t)
(defun spacemacs/layout-switch-by-pos (pos) (defun spacemacs/layout-switch-by-pos (pos)
"Switch to perspective of position POS." "Switch to perspective of position POS."
(let ((persp-to-switch (let ((persp-to-switch
@ -205,37 +195,32 @@
(when dotspacemacs-default-layout-name (when dotspacemacs-default-layout-name
(persp-switch dotspacemacs-default-layout-name))) (persp-switch dotspacemacs-default-layout-name)))
(defun spacemacs/layouts-ms-rename () (defun spacemacs/layouts-ts-rename ()
"Rename a layout and get back to the perspectives transient-state." "Rename a layout and get back to the perspectives transient-state."
(interactive) (interactive)
(call-interactively 'persp-rename) (call-interactively 'persp-rename)
(spacemacs/layouts-transient-state/body)) (spacemacs/layouts-transient-state/body))
(defun spacemacs/layouts-ms-close () (defun spacemacs/layouts-ts-close ()
"Kill current perspective" "Kill current perspective"
(interactive) (interactive)
(persp-kill-without-buffers (spacemacs//current-layout-name))) (persp-kill-without-buffers (spacemacs//current-layout-name)))
(defun spacemacs/layouts-ms-close-other () (defun spacemacs/layouts-ts-close-other ()
(interactive) (interactive)
(call-interactively 'spacemacs/helm-persp-close) (call-interactively 'spacemacs/helm-persp-close)
(spacemacs/layouts-transient-state/body)) (spacemacs/layouts-transient-state/body))
(defun spacemacs/layouts-ms-kill () (defun spacemacs/layouts-ts-kill ()
"Kill current perspective" "Kill current perspective"
(interactive) (interactive)
(persp-kill (spacemacs//current-layout-name))) (persp-kill (spacemacs//current-layout-name)))
(defun spacemacs/layouts-ms-kill-other () (defun spacemacs/layouts-ts-kill-other ()
(interactive) (interactive)
(call-interactively 'spacemacs/helm-persp-kill) (call-interactively 'spacemacs/helm-persp-kill)
(spacemacs/layouts-transient-state/body)) (spacemacs/layouts-transient-state/body))
(defun spacemacs/layouts-ms-last ()
"Switch to the last active perspective"
(interactive)
(persp-switch persp-last-persp-name))
;; Custom perspectives transient-state ------------------------------------- ;; Custom perspectives transient-state -------------------------------------
(defun spacemacs//custom-layout-func-name (name) (defun spacemacs//custom-layout-func-name (name)