summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKévin Le Gouguec <kevin.legouguec@gmail.com>2022-11-06 11:19:23 +0100
committerKévin Le Gouguec <kevin.legouguec@gmail.com>2022-11-06 11:20:48 +0100
commite2df3eb277bb0bb9acc0261bc7ad16c298740b53 (patch)
tree40f2665ea1862af1b0b906924237f3c0157224e1
parent6891e979959f719675f612b607b780fdbe95c955 (diff)
downloaddotfiles-e2df3eb277bb0bb9acc0261bc7ad16c298740b53.tar.xz
Undo margins when checking whether window is splittable
-rw-r--r--.emacs15
1 files changed, 13 insertions, 2 deletions
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."