aboutsummaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
authorCraig Jennings <c@cjennings.net>2026-06-20 10:34:45 -0400
committerCraig Jennings <c@cjennings.net>2026-06-20 10:34:45 -0400
commitc152aa1fe95845bb2fe8dc59098e1925c30eb6e5 (patch)
tree74413fbcc59ea23afdb973a9195c40815aeda81f /modules
parent5fd29d8dc004dcbd0942e1ac990ddc9ce67d8ea7 (diff)
downloaddotemacs-c152aa1fe95845bb2fe8dc59098e1925c30eb6e5.tar.gz
dotemacs-c152aa1fe95845bb2fe8dc59098e1925c30eb6e5.zip
feat(windows): pull a window away from a sole window with C-; b + arrow
When the selected window fills the frame there is no divider to resize, so the arrow now splits toward its direction with the previous buffer and the original window shrinks from that edge. Multi-window resize is unchanged.
Diffstat (limited to 'modules')
-rw-r--r--modules/ui-navigation.el38
1 files changed, 33 insertions, 5 deletions
diff --git a/modules/ui-navigation.el b/modules/ui-navigation.el
index d8d7162e..00fa841e 100644
--- a/modules/ui-navigation.el
+++ b/modules/ui-navigation.el
@@ -75,14 +75,42 @@ resize -- each moves the active window's divider in the arrow's direction
"<up>" #'windsize-up
"<down>" #'windsize-down)
+(defun cj/window-arrow-direction (key)
+ "Map a windsize arrow KEY description to a split direction.
+KEY is one of \"<left>\" \"<right>\" \"<up>\" \"<down>\"; returns
+left/right/above/below respectively, or nil for anything else."
+ (pcase key
+ ("<left>" 'left)
+ ("<right>" 'right)
+ ("<up>" 'above)
+ ("<down>" 'below)
+ (_ nil)))
+
+(defun cj/window--pull-away (direction)
+ "Split the sole window toward DIRECTION and reveal the previous buffer.
+DIRECTION is one of left/right/above/below. A new window opens on that
+side showing `other-buffer'; focus stays on the original window so it
+shrinks from that edge, letting a fullscreen window (e.g. a terminal)
+share the frame. No-op when DIRECTION is nil."
+ (when direction
+ (let ((new (split-window (selected-window) nil direction)))
+ (set-window-buffer new (other-buffer (current-buffer) t))
+ new)))
+
(defun cj/window-resize-sticky ()
"Resize the active window's divider in the just-pressed arrow's direction
-(via `windsize'), then keep `cj/window-resize-map' active so bare arrows keep
-nudging until any other key. Bound to `C-; b <left>/<right>/<up>/<down>'."
+\(via `windsize'), then keep `cj/window-resize-map' active so bare arrows keep
+nudging until any other key. Bound to `C-; b <left>/<right>/<up>/<down>'.
+
+When the selected window is the sole window in the frame there is no
+divider to move, so the arrow instead pulls a new window away toward that
+edge (`cj/window--pull-away'), revealing the previous buffer."
(interactive)
- (let ((cmd (keymap-lookup cj/window-resize-map
- (key-description (vector last-command-event)))))
- (when cmd (call-interactively cmd)))
+ (let ((key (key-description (vector last-command-event))))
+ (if (one-window-p)
+ (cj/window--pull-away (cj/window-arrow-direction key))
+ (let ((cmd (keymap-lookup cj/window-resize-map key)))
+ (when cmd (call-interactively cmd)))))
(set-transient-map cj/window-resize-map t))
;; ------------------------------ Window Splitting -----------------------------