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 committed Oct 25, 2015
1 parent 405dc66 commit 9b78009
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
18 changes: 18 additions & 0 deletions layers/+distribution/spacemacs-base/funcs.el
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,24 @@ the current state and point position."
(when (string-match regexp buf-name)
(return t))))))

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

;; from magnars modified by ffevotte for dedicated windows support
(defun spacemacs/rotate-windows (count)
"Rotate your windows.
Expand Down
3 changes: 2 additions & 1 deletion layers/+distribution/spacemacs-base/keybindings.el
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,8 @@ Ensure that helm is required before calling FUNC."
"wV" 'split-window-right-and-focus
"ww" 'other-window
"w/" 'split-window-right
"w=" 'balance-windows)
"w=" 'balance-windows
"w+" 'spacemacs/window-layout-toggle)
;; text -----------------------------------------------------------------------
(defalias 'count-region 'count-words-region)

Expand Down

0 comments on commit 9b78009

Please sign in to comment.