For interactive use, Emacs provides two commands which always split
the selected window. These call @code{split-window} internally.
-@deffn Command split-window-right &optional size
-This function splits the selected window into two side-by-side
-windows, putting the selected window on the left. If @var{size} is
-positive, the left window gets @var{size} columns; if @var{size} is
+@deffn Command split-window-right &optional size window-to-split
+This function splits the window @var{window-to-split} into two
+side-by-side windows, putting @var{window-to-split} on the left.
+@var{window-to-split} defaults to the selected window. If @var{size}
+is positive, the left window gets @var{size} columns; if @var{size} is
negative, the right window gets @minus{}@var{size} columns.
@end deffn
-@deffn Command split-window-below &optional size
-This function splits the selected window into two windows, one above
-the other, leaving the upper window selected. If @var{size} is
-positive, the upper window gets @var{size} lines; if @var{size} is
+@deffn Command split-window-below &optional size window-to-split
+This function splits the window @var{window-to-split} into two
+windows, one above the other, leaving the upper window selected.
+@var{window-to-split} defaults to the selected window. If @var{size}
+is positive, the upper window gets @var{size} lines; if @var{size} is
negative, the lower window gets @minus{}@var{size} lines.
@end deffn
+@deffn Command split-root-window-below &optional size
+This function splits the whole frame in two. The current window
+configuration is retained on the top, and a new window is created
+below, taking up the whole width of the frame. @var{size} is treated
+as by @code{split-window-below}.
+@end deffn
+
+@deffn Command split-root-window-right &optional size
+This function splits the whole frame in two. The current window
+configuration is retained on the left, and a new window is created on
+the right, taking up the whole height of the frame. @var{size} is treated
+as by @code{split-window-right}.
+@end deffn
+
@defopt split-window-keep-point
If the value of this variable is non-@code{nil} (the default),
@code{split-window-below} behaves as described above.
:type 'boolean
:group 'windows)
-(defun split-window-below (&optional size)
- "Split the selected window into two windows, one above the other.
-The selected window is above. The newly split-off window is
+(defun split-window-below (&optional size window-to-split)
+ "Split WINDOW-TO-SPLIT into two windows, one above the other.
+WINDOW-TO-SPLIT is above. The newly split-off window is
below and displays the same buffer. Return the new window.
If optional argument SIZE is omitted or nil, both windows get the
lower (new) window gets -SIZE lines.
If the variable `split-window-keep-point' is non-nil, both
-windows get the same value of point as the selected window.
+windows get the same value of point as the WINDOW-TO-SPLIT.
Otherwise, the window starts are chosen so as to minimize the
amount of redisplay; this is convenient on slow terminals."
- (interactive "P")
- (let ((old-window (selected-window))
- (old-point (window-point))
- (size (and size (prefix-numeric-value size)))
+ (interactive `(,(when current-prefix-arg
+ (prefix-numeric-value current-prefix-arg))
+ ,(selected-window)))
+ (let ((old-point (window-point))
moved-by-window-height moved new-window bottom)
(when (and size (< size 0) (< (- size) window-min-height))
;; `split-window' would not signal an error here.
(error "Size of new window too small"))
- (setq new-window (split-window nil size))
+ (setq new-window (split-window window-to-split size))
(unless split-window-keep-point
- (with-current-buffer (window-buffer)
+ (with-current-buffer (window-buffer window-to-split)
;; Use `save-excursion' around vertical movements below
- ;; (Bug#10971). Note: When the selected window's buffer has a
+ ;; (Bug#10971). Note: When WINDOW-TO-SPLIT's buffer has a
;; header line, up to two lines of the buffer may not show up
;; in the resulting configuration.
(save-excursion
(setq bottom (point)))
(and moved-by-window-height
(<= bottom (point))
- (set-window-point old-window (1- bottom)))
+ (set-window-point window-to-split (1- bottom)))
(and moved-by-window-height
(<= (window-start new-window) old-point)
(set-window-point new-window old-point)
(select-window new-window))))
;; Always copy quit-restore parameter in interactive use.
- (let ((quit-restore (window-parameter old-window 'quit-restore)))
+ (let ((quit-restore (window-parameter window-to-split 'quit-restore)))
(when quit-restore
(set-window-parameter new-window 'quit-restore quit-restore)))
new-window))
(defalias 'split-window-vertically 'split-window-below)
-(defun split-window-right (&optional size)
- "Split the selected window into two side-by-side windows.
-The selected window is on the left. The newly split-off window
-is on the right and displays the same buffer. Return the new
-window.
+(defun split-root-window-below (&optional size)
+ "Split root window of current frame in two.
+The current window configuration is retained in the top window,
+the lower window takes up the whole width of the frame. SIZE is
+handled as in `split-window-below'."
+ (interactive "P")
+ (split-window-below size (frame-root-window)))
+
+(defun split-window-right (&optional size window-to-split)
+ "Split WINDOW-TO-SPLIT into two side-by-side windows.
+WINDOW-TO-SPLIT is on the left. The newly split-off window is on
+the right and displays the same buffer. Return the new window.
If optional argument SIZE is omitted or nil, both windows get the
same width, or close to it. If SIZE is positive, the left-hand
the width of the window's scroll bar; if there are no scroll
bars, it includes the width of the divider column to the window's
right, if any."
- (interactive "P")
- (let ((old-window (selected-window))
- (size (and size (prefix-numeric-value size)))
- new-window)
+ (interactive `(,(when current-prefix-arg
+ (prefix-numeric-value current-prefix-arg))
+ ,(selected-window)))
+ (let (new-window)
(when (and size (< size 0) (< (- size) window-min-width))
;; `split-window' would not signal an error here.
(error "Size of new window too small"))
- (setq new-window (split-window nil size t))
+ (setq new-window (split-window window-to-split size t))
;; Always copy quit-restore parameter in interactive use.
- (let ((quit-restore (window-parameter old-window 'quit-restore)))
+ (let ((quit-restore (window-parameter window-to-split 'quit-restore)))
(when quit-restore
(set-window-parameter new-window 'quit-restore quit-restore)))
new-window))
(defalias 'split-window-horizontally 'split-window-right)
+
+(defun split-root-window-right (&optional size)
+ "Split root window of current frame into two side-by-side windows.
+The current window configuration is retained within the left
+window, and a new window is created on the right, taking up the
+whole height of the frame. SIZE is treated as by
+`split-window-right'."
+ (interactive "P")
+ (split-window-right size (frame-root-window)))
\f
;;; Balancing windows.
(define-key ctl-x-map "{" 'shrink-window-horizontally)
(define-key ctl-x-map "-" 'shrink-window-if-larger-than-buffer)
(define-key ctl-x-map "+" 'balance-windows)
+(define-key ctl-x-map "7" 'split-root-window-below)
+(define-key ctl-x-map "9" 'split-root-window-right)
(define-key ctl-x-4-map "0" 'kill-buffer-and-window)
(define-key ctl-x-4-map "1" 'same-window-prefix)
(define-key ctl-x-4-map "4" 'other-window-prefix)