>From b211505e9ddc4a2685f55f2afb43bcf5c4a7b860 Mon Sep 17 00:00:00 2001 From: Hugo Heagren Date: Tue, 26 Jul 2022 21:12:03 +0100 Subject: [PATCH 1/6] split-window-below: Add WINDOW-TO-SPLIT argument * lisp/window.el (split-window-below): Add optional argument to control which window is split (previously, would only split selected window). Update docstring. * doc/lispref/windows.texi (Splitting Windows): Update docs for `split-window-below'. --- doc/lispref/windows.texi | 9 +++++---- lisp/window.el | 26 +++++++++++++------------- 2 files changed, 18 insertions(+), 17 deletions(-) diff --git a/doc/lispref/windows.texi b/doc/lispref/windows.texi index 704ed30366..255e33ad0d 100644 --- a/doc/lispref/windows.texi +++ b/doc/lispref/windows.texi @@ -1477,10 +1477,11 @@ Splitting Windows 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 diff --git a/lisp/window.el b/lisp/window.el index eba888a89d..69089e63f5 100644 --- a/lisp/window.el +++ b/lisp/window.el @@ -5672,9 +5672,9 @@ split-window-keep-point :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 @@ -5683,22 +5683,22 @@ split-window-below 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 @@ -5713,13 +5713,13 @@ split-window-below (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)) -- 2.20.1