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 |
| ~[C-1..C-9, C-0]~ | switch to nth workspace and keep the transient state active |
| ~TAB~ | switch to last active workspace |
| ~c~ | close current workspace |
| ~d~ | close current workspace |
| ~n~ or ~l~ | switch to next 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 |

View file

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

View file

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