ivy: spacemacs layouts support

- port helm-perspectives
- port persp switch buffer
- port persp-close[kill]-other to use ivy
- layouts-ts: Make help more consistent
- layouts-ts: Reorganize docstring
Instead of one big list, try to organize into sections to make it easier
to find the right key
This commit is contained in:
justbur 2016-02-07 21:13:32 -05:00 committed by syl20bnr
parent 95a1583c73
commit d0cec17919
3 changed files with 98 additions and 43 deletions

View file

@ -412,7 +412,67 @@ Current Action: %s(ivy-action-name)
("t" (setq truncate-lines (not truncate-lines)))
("f" ivy-toggle-case-fold)
("o" ivy-occur :exit t))
(define-key ivy-minibuffer-map "\C-o" 'spacemacs/ivy-transient-state/body))))
(define-key ivy-minibuffer-map "\C-o" 'spacemacs/ivy-transient-state/body)
(defun spacemacs/ivy-perspectives ()
"Control Panel for perspectives. Has many actions.
If match is found
\(default) Select perspective
c: Close Perspective(s) <- mark with C-SPC to close more than one-window
k: Kill Perspective(s)
If match is not found
<enter> Creates perspective
Closing doesn't kill buffers inside the perspective while killing
perspectives does."
(interactive)
(ivy-read "Perspective: "
(persp-names)
:caller 'spacemacs/ivy-perspectives
:action (lambda (name)
(let ((persp-reset-windows-on-nil-window-conf t))
(persp-switch name)
(unless
(member name
(persp-names-current-frame-fast-ordered))
(spacemacs/home))))))
(ivy-set-actions
'spacemacs/ivy-perspectives
'(("c" persp-kill-without-buffers "Close perspective(s)")
("k" persp-kill "Kill perspective(s)")))
(defun spacemacs/ivy-persp-buffer ()
"Switch to perspective buffer using ivy."
(interactive)
(let (ivy-use-virtual-buffers)
(with-persp-buffer-list ()
(call-interactively 'ivy-switch-buffer))))
(defun spacemacs/ivy-persp-close-other ()
"Kills perspectives without killing the buffers"
(interactive)
(ivy-read (format "Close perspective [current %s]: "
(spacemacs//current-layout-name))
(persp-names)
:action 'persp-kill-without-buffers))
(defun spacemacs/ivy-persp-kill-other ()
"Kills perspectives with all their buffers"
(interactive)
(ivy-read (format "Kill perspective [current %s]: "
(spacemacs//current-layout-name))
(persp-names)
:action 'persp-kill))
(setq spacemacs-layouts-transient-state-remove-bindings
'("b" "l" "C" "X"))
(setq spacemacs-layouts-transient-state-add-bindings
'(("b" spacemacs/ivy-persp-buffer)
("l" spacemacs/ivy-perspectives)
("C" spacemacs/ivy-persp-close-other :exit t)
("X" spacemacs/ivy-persp-kill-other :exit t))))))
(defun spacemacs-ivy/init-smex ()
(use-package smex

View file

@ -117,22 +117,6 @@ perspectives does."
(projectile-switch-project-by-name project)))))))
:buffer "*Helm Projectile Layouts*"))
(defun spacemacs/ivy-persp-switch-project (arg)
(interactive "P")
(ivy-read "Switch to Project Perspective:"
(if (projectile-project-p)
(cons (abbreviate-file-name (projectile-project-root))
(projectile-relevant-known-projects))
projectile-known-projects)
:action (lambda (project)
(let ((persp-reset-windows-on-nil-window-conf t))
(persp-switch project)
(let ((projectile-completion-system 'ivy))
(projectile-switch-project-by-name project))))
)
)
;; Autosave ----------------------------------------------------------------
(defun spacemacs//layout-autosave ()

View file

@ -88,37 +88,35 @@
(spacemacs//layout-format-name
persp (position persp persp-list))) persp-list " | "))))
(concat formatted-persp-list
(when (equal 1 spacemacs--layouts-ms-doc-toggle)
spacemacs--layouts-ms-documentation))))
(if (equal 1 spacemacs--layouts-ms-doc-toggle)
spacemacs--layouts-ms-documentation
(concat
"\n ["
(propertize "?" 'face 'hydra-face-red)
"] toggle help")))))
(spacemacs|define-transient-state layouts
:title "Layouts Transient State"
:additional-docs
(spacemacs--layouts-ms-documentation .
"
[_?_]^^^^ toggle this help
[_0_,_9_]^^ switch to nth layout
[_<tab>_]^^^^ switch to the last
[_A_]^^^^ add all buffers from another layout
[_a_]^^^^ add all the buffers from another layout in the current one
[_b_]^^^^ select a buffer in the current layout
[_d_]^^^^ close the current layout and keep its buffers
[_D_]^^^^ close the other layouts and keep their buffers
[_h_]^^^^ go to default layout
[_l_]^^^^ select/create a layout with helm
[_L_]^^^^ load layouts from file
[_n_/_C-l_]^^ next layout in list
[_N_/_p_/_C-h_] previous layout in list
[_o_]^^^^ open a custom layout
[_r_]^^^^ remove current buffer from layout
[_R_]^^^^ rename current layout
[_s_]^^^^ save all layouts
[_S_]^^^^ save layouts by names
[_t_]^^^^ show a buffer without adding it to current layout
[_w_]^^^^ workspaces micro-state (needs eyebrowse layer enabled)
[_x_]^^^^ kill current layout with its buffers
[_X_]^^^^ kill other layouts with their buffers")
"\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
[_<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
")
:bindings
;; need to exit in case number doesn't exist
("?" spacemacs//layouts-ms-toggle-doc)
@ -356,5 +354,18 @@ current perspective."
"pl" 'spacemacs/helm-persp-switch-project))
(defun spacemacs-layouts/post-init-swiper ()
(defun spacemacs/ivy-persp-switch-project (arg)
(interactive "P")
(ivy-read "Switch to Project Perspective: "
(if (projectile-project-p)
(cons (abbreviate-file-name (projectile-project-root))
(projectile-relevant-known-projects))
projectile-known-projects)
:action (lambda (project)
(let ((persp-reset-windows-on-nil-window-conf t))
(persp-switch project)
(let ((projectile-completion-system 'ivy))
(projectile-switch-project-by-name project))))))
(spacemacs/set-leader-keys
"pl" 'spacemacs/ivy-persp-switch-project))