>From bc53825b31eb8130a43a79d2fd7643a187f5e04b Mon Sep 17 00:00:00 2001 From: Hugo Heagren Date: Tue, 26 Jul 2022 21:15:08 +0100 Subject: [PATCH 3/6] split-window-right: Add WINDOW-TO-SPLIT argument * lisp/window.el (split-window-right): 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-right'. --- doc/lispref/windows.texi | 9 +++++---- lisp/window.el | 21 ++++++++++----------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/doc/lispref/windows.texi b/doc/lispref/windows.texi index 51e54ebcd4..3b0c4e4197 100644 --- a/doc/lispref/windows.texi +++ b/doc/lispref/windows.texi @@ -1470,10 +1470,11 @@ Splitting Windows 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 diff --git a/lisp/window.el b/lisp/window.el index 556fcddf47..9acc393f30 100644 --- a/lisp/window.el +++ b/lisp/window.el @@ -5734,11 +5734,10 @@ split-root-window-below (interactive "P") (split-window-below size (frame-root-window))) -(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-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 @@ -5747,16 +5746,16 @@ split-window-right 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)) -- 2.20.1