Skip to content
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

Closed

Conversation

nixmaniack
Copy link
Contributor

@nixmaniack nixmaniack commented Oct 19, 2015

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.

@robbyoconnor
Copy link
Contributor

I love this :D

@bmag
Copy link
Collaborator

bmag commented Oct 24, 2015

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 window-state-get and window-state-put? (I'm not sure how to make a PR for an existing PR, so posting it here)

(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)))))

@nixmaniack
Copy link
Contributor Author

@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).

@bmag
Copy link
Collaborator

bmag commented Nov 11, 2016

@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
@nixmaniack
Copy link
Contributor Author

@bmag Applied the patch on current develop. Should be good to go.

@bmag bmag self-assigned this Nov 15, 2016
@bmag
Copy link
Collaborator

bmag commented Nov 15, 2016

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

@bmag bmag closed this Nov 15, 2016
@bmag bmag removed the Merging... label Nov 15, 2016
@nixmaniack nixmaniack deleted the add_window_layout_toggle branch November 15, 2016 12:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants