Skip to content

Commit

Permalink
Adding window layout toggle (vertical <-> horizontal)
Browse files Browse the repository at this point in the history
All credits to @bmag for this function with window state preservation
  • Loading branch information
nixmaniack authored and bmag committed Nov 15, 2016
1 parent d986068 commit 5c9615f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
18 changes: 18 additions & 0 deletions layers/+distributions/spacemacs-base/funcs.el
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,24 @@ windows."
(window-state-put state1 window2)
(window-state-put state2 window1)))

;; from @bmag
(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)))))

;; originally from magnars and modified by ffevotte for dedicated windows
;; support, it has quite diverged by now
(defun spacemacs/rotate-windows-forward (count)
Expand Down
1 change: 1 addition & 0 deletions layers/+distributions/spacemacs-base/keybindings.el
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,7 @@
"ww" 'other-window
"w/" 'split-window-right
"w=" 'balance-windows
"w+" 'spacemacs/window-layout-toggle
"w_" 'spacemacs/maximize-horizontally)
;; text -----------------------------------------------------------------------
(defalias 'count-region 'count-words-region)
Expand Down

0 comments on commit 5c9615f

Please sign in to comment.