dotfiles

🎜 Clone'em, tweak'em, stick'em in your $HOME 🎝
git clone https://git.kevinlegouguec.net/dotfiles
Log | Files | Refs | README

commit e2df3eb277bb0bb9acc0261bc7ad16c298740b53
parent 6891e979959f719675f612b607b780fdbe95c955
Author: KΓ©vin Le Gouguec <kevin.legouguec@gmail.com>
Date:   Sun,  6 Nov 2022 11:19:23 +0100

Undo margins when checking whether window is splittable

Diffstat:
M.emacs | 15+++++++++++++--
1 file changed, 13 insertions(+), 2 deletions(-)

diff --git 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."