From 342df5a9e338f551a148a8b3519558bd13723e10 Mon Sep 17 00:00:00 2001 From: Emre Yolcu Date: Fri, 15 Aug 2025 20:53:13 -0400 Subject: [PATCH] Do not assume that the default margin widths are zero --- olivetti.el | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/olivetti.el b/olivetti.el index 6470ae7..ed5222a 100644 --- a/olivetti.el +++ b/olivetti.el @@ -265,9 +265,11 @@ if it is an integer, and otherwise return WIDTH." (defun olivetti-normalize-width (width window) "Parse WIDTH to a safe pixel value for `olivetti-body-width' for WINDOW." - (let ((char-width (frame-char-width (window-frame window))) - (window-width-pix (window-body-width window t)) - min-width-pix) + (let* ((char-width (frame-char-width (window-frame window))) + (window-width-pix (+ (window-body-width window t) + (* char-width + (+ left-margin-width right-margin-width)))) + min-width-pix) (setq min-width-pix (* char-width (+ olivetti-minimum-body-width (% olivetti-minimum-body-width 2)))) @@ -283,7 +285,7 @@ if it is an integer, and otherwise return WIDTH." (if (consp fringe-mode) (set-window-fringes window (car fringe-mode) (cdr fringe-mode)) (set-window-fringes window fringe-mode fringe-mode)) - (set-window-margins window nil)) + (set-window-margins window left-margin-width right-margin-width)) (defun olivetti-reset-all-windows () "Call `olivetti-reset-window' on all windows." @@ -324,10 +326,12 @@ window." ;; `fill-column' (when (null olivetti-body-width) (setq olivetti-body-width (+ fill-column 2))) - (let ((char-width-pix (frame-char-width (window-frame window-or-frame))) - (window-width-pix (window-body-width window-or-frame t)) - (safe-width-pix (olivetti-normalize-width - olivetti-body-width window-or-frame))) + (let* ((char-width-pix (frame-char-width (window-frame window-or-frame))) + (window-width-pix (+ (window-body-width window-or-frame t) + (* char-width-pix + (+ left-margin-width right-margin-width)))) + (safe-width-pix (olivetti-normalize-width + olivetti-body-width window-or-frame))) ;; Handle possible display of fringes (when (and window-system olivetti-style) (let ((fringe-total (- (window-pixel-width window-or-frame) @@ -350,11 +354,11 @@ window." (setq left-margin (max (round (/ (- margin-total-pix (car fringes)) char-width-pix)) - 0) + left-margin-width) right-margin (max (round (/ (- margin-total-pix (cadr fringes)) char-width-pix)) - 0)) + right-margin-width)) ;; Finally set the margins (set-window-margins window-or-frame left-margin right-margin))) ;; Set remaining window parameters