From 0ad9e6b0b73b3b89d390b41f003473af685797f2 Mon Sep 17 00:00:00 2001 From: Daniel <89086143+BardofSprites@users.noreply.github.com> Date: Sun, 26 Jan 2025 16:00:21 -0500 Subject: save window state before toggling split --- bard-elisp/bard-window.el | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'bard-elisp/bard-window.el') 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) -- cgit v1.2.3