-
Notifications
You must be signed in to change notification settings - Fork 4.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding window layout toggle (vertical <-> horizontal) #3460
Conversation
I love this :D |
Nice idea, but the current implementation doesn't save any window parameters or the window's dedication status. For example, if the non-selected window is dedicated to its buffer, after toggling the layout it becomes non-dedicated. Also, all window parameters that it had are lost. How about this implementation, which uses (defun spacemacs/window-layout-toggle ()
"Toggle between horizontal and vertical layout of two windows."
(interactive)
(when (= (count-windows) 2)
(let* ((window-tree (car (window-tree)))
(current-split-vertical-p (car window-tree))
(first-window (nth 2 window-tree))
(second-window (nth 3 window-tree))
(second-window-state (window-state-get second-window))
(splitter (if current-split-vertical-p
#'split-window-horizontally
#'split-window-vertically)))
(delete-other-windows first-window)
;; `window-state-put' also re-selects the window if needed, so we don't
;; need to call `select-window'
(window-state-put second-window-state (funcall splitter))))) |
7a44108
to
9b78009
Compare
@bmag Oh never thought about dedicated windows! That's one awesome feature. I'm pushing to this PR just add to avoid duplication (with all due credits to you! Thanks). |
@nixmaniack I'd like to (finally) merge this one in the next few days. Can you fix the conflicts please? |
All credits to @bmag for this function with window state preservation
9b78009
to
834c59f
Compare
@bmag Applied the patch on current develop. Should be good to go. |
Thank you 👍 Cherry-picked into develop, you can safely delete your branch. I added an error in case the number of windows isn't exactly 2 in 0d4a8a4 |
Generally I find toggling window layout when window I open unintentionally opens in other layout. This PR adds a toggle to easily switch between the layouts using
SPC w +
. Used+
as it's free binding and denotes both layouts in one symbol.