From e2df3eb277bb0bb9acc0261bc7ad16c298740b53 Mon Sep 17 00:00:00 2001 From: Kévin Le Gouguec Date: Sun, 6 Nov 2022 11:19:23 +0100 Subject: Undo margins when checking whether window is splittable --- .emacs | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to '.emacs') diff --git a/.emacs b/.emacs index c07980a..c6e5595 100644 --- a/.emacs +++ b/.emacs @@ -128,7 +128,7 @@ (defvar-local my/centered-width 'fill-column) (defvar-local my/centered-set-right-margin nil) -(defun my/centered--undo-margins (&optional _size window-to-split) +(defun my/centered--before-split (&optional _size window-to-split) (let ((windows (if (frame-root-window-p window-to-split) (window-list) (list window-to-split)))) @@ -136,7 +136,18 @@ (when (buffer-local-value 'my/centered-mode (window-buffer w)) (set-window-margins w nil nil))))) -(advice-add 'split-window-right :before 'my/centered--undo-margins) +(defun my/centered--around-splittable (splittable window &optional horizontal) + (if (and horizontal + (buffer-local-value 'my/centered-mode (window-buffer window))) + (let ((margins (window-margins window))) + (set-window-margins window nil nil) + (prog1 + (funcall splittable window horizontal) + (apply 'set-window-margins window margins))) + (funcall splittable window horizontal))) + +(advice-add 'split-window-right :before 'my/centered--before-split) +(advice-add 'window-splittable-p :around 'my/centered--around-splittable) (define-minor-mode my/centered-mode "Update margins to keep content centered." -- cgit v1.2.3