branch: elpa/visual-fill-column
commit 29d3084fa35dbc07b7adc87c570105b8d5842aaa
Author: TEC <[email protected]>
Commit: Joost Kremers <[email protected]>
Account for remapping in window width calculation
The window width calculation in
`visual-fill-column--window-max-text-width' uses `window-width' with the
active window as the sole argument. As of Emacs 29, this returns the
width of the window using the default face, even if the default face has
been remapped in the window: causing incorrect results when the window
is remapped.
Emacs 29 also introduces a special second argument value, `remap'
which (as we want) uses the remapped face, if applicable. This corrects
the width calculation. However, margin calculations are still done in
terms of the non-remapped default face, and so a conversion factor needs
to be applied when considering margins.
---
visual-fill-column.el | 18 +++++++++++++-----
1 file changed, 13 insertions(+), 5 deletions(-)
diff --git a/visual-fill-column.el b/visual-fill-column.el
index 36526fdada..4c1e32bff3 100644
--- a/visual-fill-column.el
+++ b/visual-fill-column.el
@@ -316,10 +316,14 @@ and `text-scale-mode-step'."
(with-current-buffer buffer
(expt text-scale-mode-step
text-scale-mode-amount))
- 1.0)))
- (truncate (/ (+ (window-width window)
- (or (car margins) 0)
- (or (cdr margins) 0))
+ 1.0))
+ (remap-scale
+ (if (>= emacs-major-version 29)
+ (/ (window-width window 'remap) (float (window-width window)))
+ 1.0)))
+ (truncate (/ (+ (window-width window (and (>= emacs-major-version 29)
'remap))
+ (* (or (car margins) 0) remap-scale)
+ (* (or (cdr margins) 0) remap-scale))
(float scale)))))
(defun visual-fill-column--add-extra-width (left right add-width)
@@ -334,11 +338,15 @@ cell of the new margins, which will never be less than
zero."
"Set window margins for WINDOW."
;; Calculate left & right margins.
(let* ((total-width (visual-fill-column--window-max-text-width window))
+ (remap-scale
+ (if (>= emacs-major-version 29)
+ (/ (window-width window 'remap) (float (window-width window)))
+ 1.0))
(width (or visual-fill-column-width
fill-column))
(margins (if (< (- total-width width) 0) ; margins must be >= 0
0
- (- total-width width)))
+ (round (/ (- total-width width) remap-scale))))
(left (if visual-fill-column-center-text
(/ margins 2)
0))