ThreeWindows

People used to work with one, two or four windows per frame. They are all good choices. Especially for four windows, it even looks funny. People donate their screen space to 4 tasks in parallel, any time when a task needs more space, just type C-x 1 to change to the full frame and then type C-<left> to come back(WinnerMode). Its a really funny way so that I had even made a function to split window in to 4 for me.

But quickly I noticed that I spent too many time in the endless C-x 1 and C-<left> cycles. So I start to work in 3 window mode – always keep a relatively bigger window so that I don’t need to change so frequently.

And since there are different size of windows, things must be able to be changed from each. So I made these functions to fulfill these requirements.

split-window-4

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;                                                 ;;
;;             window layout related               ;;
;;                                                 ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;  +-----------------------+----------------------+
;  |                       |                      |
;  |                       |                      |
;  |                       |                      |
;  +-----------------------+----------------------+
;  |                       |                      |
;  |                       |                      |
;  |                       |                      |
;  +-----------------------+----------------------+

(defun split-window-4()
 "Splite window into 4 sub-window"
 (interactive)
 (if (= 1 (length (window-list)))
     (progn (split-window-vertically)
	    (split-window-horizontally)
	    (other-window 2)
	    (split-window-horizontally)
	    )
   )
)

change-split-type

In case to handle 2 & 3 windows per frame, we need a helper function do to some work for us.

(defun change-split-type (split-fn &optional arg)
  "Change 3 window style from horizontal to vertical and vice-versa"
  (let ((bufList (mapcar 'window-buffer (window-list))))
    (select-window (get-largest-window))
    (funcall split-fn arg)
    (mapcar* 'set-window-buffer (window-list) bufList)))


change split type for 2 windows frame

Now things become very easy. You can now use this function to change from vertical split windows to horizontal split ones.


;  +----------------------+                +---------- +----------+
;  |                      |          \     |           |          |
;  |                      |  +-------+\    |           |          |
;  +----------------------+  +-------+/    |           |          |
;  |                      |          /     |           |          |
;  |                      |                |           |          |
;  +----------------------+                +---------- +----------+
;
;  +--------- +-----------+                +----------------------+
;  |          |           |          \     |                      |
;  |          |           |  +-------+\    |                      |
;  |          |           |  +-------+/    +----------------------+
;  |          |           |          /     |                      |
;  |          |           |                |                      |
;  +--------- +-----------+                +----------------------+



(defun change-split-type-2 (&optional arg)
  "Changes splitting from vertical to horizontal and vice-versa"
  (interactive "P")
  (let ((split-type (lambda (&optional arg)
                      (delete-other-windows-internal)
                      (if arg (split-window-vertically)
                        (split-window-horizontally)))))
    (change-split-type split-type arg)))


change split type for 3 windows frame

Both change-split-type-3-v & change-split-type-3-h accept prefix which could change split in another way. Just try them.

;  +-----------------------+                  +----------- +-----------+ 
;  |                       |    /       \     |            |           | 
;  |                       |   /+-------+\    |            |           | 
;  +-----------------------+   \+-------+/    |            |-----------|
;  |           |           |    \       /     |            |           | 
;  |           |           |                  |            |           | 
;  +-----------------------+                  +----------- +-----------+ 

;  +-----------------------+                  +----------- +-----------+ 
;  |                       |    /       \     |            |           | 
;  |                       |   /+-------+\    |            |           | 
;  +-----------------------+   \+-------+/    |------------|           |
;  |           |           |    \       /     |            |           | 
;  |           |           |                  |            |           | 
;  +-----------------------+                  +----------- +-----------+ 

;  +-----------------------+                  +----------- +-----------+ 
;  |           |           |    /       \     |            |           | 
;  |           |           |   /+-------+\    |            |           | 
;  +-----------------------+   \+-------+/    |------------|           |
;  |                       |    \       /     |            |           | 
;  |                       |                  |            |           | 
;  +-----------------------+                  +----------- +-----------+ 

;  +-----------------------+                  +----------- +-----------+ 
;  |           |           |    /       \     |            |           | 
;  |           |           |   /+-------+\    |            |           | 
;  +-----------------------+   \+-------+/    |            |-----------|
;  |                       |    \       /     |            |           | 
;  |                       |                  |            |           | 
;  +-----------------------+                  +----------- +-----------+ 



(defun change-split-type-3-v (&optional arg)
  "change 3 window style from horizon to vertical"
  (interactive "P")
  (change-split-type 'split-window-3-horizontally arg))

(defun change-split-type-3-h (&optional arg)
  "change 3 window style from vertical to horizon"
  (interactive "P")
  (change-split-type 'split-window-3-vertically arg))

(defun split-window-3-horizontally (&optional arg)
  "Split window into 3 while largest one is in horizon"
;  (interactive "P")
  (delete-other-windows)
  (split-window-horizontally)
  (if arg (other-window 1))
  (split-window-vertically))

(defun split-window-3-vertically (&optional arg)
  "Split window into 3 while largest one is in vertical"
;  (interactive "P")
  (delete-other-windows)
  (split-window-vertically)
  (if arg (other-window 1))
  (split-window-horizontally))



CategoryWindows