aboutsummaryrefslogtreecommitdiff
path: root/bard-elisp
diff options
context:
space:
mode:
authorDaniel <[email protected]>2025-01-26 16:00:21 -0500
committerDaniel <[email protected]>2025-01-26 16:00:21 -0500
commit0ad9e6b0b73b3b89d390b41f003473af685797f2 (patch)
tree5afc68ba8084df6e68acbde9ee4ba694f28a2eb2 /bard-elisp
parentd496bdac30aac5c16ce96a45a9ba210f062eb4e2 (diff)
save window state before toggling split
Diffstat (limited to 'bard-elisp')
-rw-r--r--bard-elisp/bard-window.el14
1 files changed, 11 insertions, 3 deletions
diff --git a/bard-elisp/bard-window.el b/bard-elisp/bard-window.el
index 274f583..8f7cbd5 100644
--- a/bard-elisp/bard-window.el
+++ b/bard-elisp/bard-window.el
@@ -145,14 +145,22 @@ This as the action function in a `display-buffer-alist' entry."
"" name)))
(defun bard/toggle-window-split ()
- "Toggle between horizontal and vertical window splits."
+ "Toggle between horizontal and vertical window splits, preserving buffer layout."
(interactive)
- (let ((split-direction (if (= (window-width) (frame-width))
+ (let ((current-buffers (mapcar #'window-buffer (window-list))) ; List of buffers in current windows
+ (split-direction (if (= (window-width) (frame-width))
'vertical
'horizontal)))
(delete-other-windows)
+ ;; Toggle the split direction
(if (eq split-direction 'horizontal)
(split-window-vertically)
- (split-window-horizontally))))
+ (split-window-horizontally))
+ ;; Restore buffers to the new windows
+ (let ((windows (window-list)))
+ (cl-loop for buffer in current-buffers
+ for window in windows
+ do (set-window-buffer window buffer)))))
+
(provide 'bard-window)